Merge lp:~osomon/oxide/applicationstatechanged into lp:~oxide-developers/oxide/oxide.trunk
- applicationstatechanged
- Merge into oxide.trunk
Proposed by
Olivier Tilloy
Status: | Merged | ||||
---|---|---|---|---|---|
Merged at revision: | 863 | ||||
Proposed branch: | lp:~osomon/oxide/applicationstatechanged | ||||
Merge into: | lp:~oxide-developers/oxide/oxide.trunk | ||||
Diff against target: |
378 lines (+173/-13) 9 files modified
qt/core/browser/oxide_qt_browser_platform_integration.cc (+17/-1) qt/core/browser/oxide_qt_browser_platform_integration.h (+8/-1) qt/core/core.gyp (+6/-0) shared/browser/oxide_browser_platform_integration.cc (+23/-0) shared/browser/oxide_browser_platform_integration.h (+18/-0) shared/browser/oxide_browser_platform_integration_observer.cc (+30/-0) shared/browser/oxide_browser_platform_integration_observer.h (+37/-0) shared/browser/oxide_power_save_blocker.cc (+32/-11) shared/shared.gyp (+2/-0) |
||||
To merge this branch: | bzr merge lp:~osomon/oxide/applicationstatechanged | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Coulson | Approve | ||
Review via email: mp+241789@code.launchpad.net |
Commit message
Monitor application state changes, and update PowerSaveBlocker state accordingly
(remove the screen dim lock when the app goes into the background, and restore it when it comes to the foreground).
Description of the change
To post a comment you must log in.
- 863. By Olivier Tilloy
-
Remove useless explicit call to QObject constructor.
- 864. By Olivier Tilloy
-
Get rid of the Observe method and the non-default constructor,
and make the default constructor add itself to the BrowserPlatformIntegration singleton. - 865. By Olivier Tilloy
-
Drop the state argument from the notification,
and add a BrowserPlatformIntegration: :GetApplication State() instead. - 866. By Olivier Tilloy
-
Removed an unneeded slot parameter.
Revision history for this message
Chris Coulson (chrisccoulson) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'qt/core/browser/oxide_qt_browser_platform_integration.cc' | |||
2 | --- qt/core/browser/oxide_qt_browser_platform_integration.cc 2014-11-13 08:41:43 +0000 | |||
3 | +++ qt/core/browser/oxide_qt_browser_platform_integration.cc 2014-11-14 14:36:23 +0000 | |||
4 | @@ -47,10 +47,17 @@ | |||
5 | 47 | 47 | ||
6 | 48 | BrowserPlatformIntegration::BrowserPlatformIntegration( | 48 | BrowserPlatformIntegration::BrowserPlatformIntegration( |
7 | 49 | GLContextAdopted* gl_share_context) | 49 | GLContextAdopted* gl_share_context) |
9 | 50 | : gl_share_context_(gl_share_context) {} | 50 | : gl_share_context_(gl_share_context) { |
10 | 51 | QObject::connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), | ||
11 | 52 | this, SLOT(onApplicationStateChanged())); | ||
12 | 53 | } | ||
13 | 51 | 54 | ||
14 | 52 | BrowserPlatformIntegration::~BrowserPlatformIntegration() {} | 55 | BrowserPlatformIntegration::~BrowserPlatformIntegration() {} |
15 | 53 | 56 | ||
16 | 57 | void BrowserPlatformIntegration::onApplicationStateChanged() { | ||
17 | 58 | NotifyApplicationStateChanged(); | ||
18 | 59 | } | ||
19 | 60 | |||
20 | 54 | bool BrowserPlatformIntegration::LaunchURLExternally(const GURL& url) { | 61 | bool BrowserPlatformIntegration::LaunchURLExternally(const GURL& url) { |
21 | 55 | return QDesktopServices::openUrl(QUrl(QString::fromStdString(url.spec()))); | 62 | return QDesktopServices::openUrl(QUrl(QString::fromStdString(url.spec()))); |
22 | 56 | } | 63 | } |
23 | @@ -109,6 +116,15 @@ | |||
24 | 109 | return new LocationProvider(); | 116 | return new LocationProvider(); |
25 | 110 | } | 117 | } |
26 | 111 | 118 | ||
27 | 119 | oxide::BrowserPlatformIntegration::ApplicationState | ||
28 | 120 | BrowserPlatformIntegration::GetApplicationState() { | ||
29 | 121 | if (qApp->applicationState() == Qt::ApplicationActive) { | ||
30 | 122 | return APPLICATION_STATE_ACTIVE; | ||
31 | 123 | } else { | ||
32 | 124 | return APPLICATION_STATE_INACTIVE; | ||
33 | 125 | } | ||
34 | 126 | } | ||
35 | 127 | |||
36 | 112 | QThread* GetIOQThread() { | 128 | QThread* GetIOQThread() { |
37 | 113 | return g_io_thread.Get(); | 129 | return g_io_thread.Get(); |
38 | 114 | } | 130 | } |
39 | 115 | 131 | ||
40 | === modified file 'qt/core/browser/oxide_qt_browser_platform_integration.h' | |||
41 | --- qt/core/browser/oxide_qt_browser_platform_integration.h 2014-11-12 14:50:11 +0000 | |||
42 | +++ qt/core/browser/oxide_qt_browser_platform_integration.h 2014-11-14 14:36:23 +0000 | |||
43 | @@ -18,6 +18,7 @@ | |||
44 | 18 | #ifndef _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_ | 18 | #ifndef _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_ |
45 | 19 | #define _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_ | 19 | #define _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_ |
46 | 20 | 20 | ||
47 | 21 | #include <QObject> | ||
48 | 21 | #include <QtGlobal> | 22 | #include <QtGlobal> |
49 | 22 | 23 | ||
50 | 23 | #include "base/macros.h" | 24 | #include "base/macros.h" |
51 | @@ -35,11 +36,16 @@ | |||
52 | 35 | class GLContextAdopted; | 36 | class GLContextAdopted; |
53 | 36 | 37 | ||
54 | 37 | class BrowserPlatformIntegration final | 38 | class BrowserPlatformIntegration final |
56 | 38 | : public oxide::BrowserPlatformIntegration { | 39 | : public QObject, public oxide::BrowserPlatformIntegration { |
57 | 40 | Q_OBJECT | ||
58 | 41 | |||
59 | 39 | public: | 42 | public: |
60 | 40 | BrowserPlatformIntegration(GLContextAdopted* gl_share_context); | 43 | BrowserPlatformIntegration(GLContextAdopted* gl_share_context); |
61 | 41 | ~BrowserPlatformIntegration(); | 44 | ~BrowserPlatformIntegration(); |
62 | 42 | 45 | ||
63 | 46 | private Q_SLOTS: | ||
64 | 47 | void onApplicationStateChanged(); | ||
65 | 48 | |||
66 | 43 | private: | 49 | private: |
67 | 44 | bool LaunchURLExternally(const GURL& url) final; | 50 | bool LaunchURLExternally(const GURL& url) final; |
68 | 45 | bool IsTouchSupported() final; | 51 | bool IsTouchSupported() final; |
69 | @@ -49,6 +55,7 @@ | |||
70 | 49 | scoped_ptr<oxide::MessagePump> CreateUIMessagePump() final; | 55 | scoped_ptr<oxide::MessagePump> CreateUIMessagePump() final; |
71 | 50 | void BrowserThreadInit(content::BrowserThread::ID id) final; | 56 | void BrowserThreadInit(content::BrowserThread::ID id) final; |
72 | 51 | content::LocationProvider* CreateLocationProvider() final; | 57 | content::LocationProvider* CreateLocationProvider() final; |
73 | 58 | ApplicationState GetApplicationState() final; | ||
74 | 52 | 59 | ||
75 | 53 | scoped_refptr<GLContextAdopted> gl_share_context_; | 60 | scoped_refptr<GLContextAdopted> gl_share_context_; |
76 | 54 | 61 | ||
77 | 55 | 62 | ||
78 | === modified file 'qt/core/core.gyp' | |||
79 | --- qt/core/core.gyp 2014-11-12 14:50:11 +0000 | |||
80 | +++ qt/core/core.gyp 2014-11-14 14:36:23 +0000 | |||
81 | @@ -67,6 +67,7 @@ | |||
82 | 67 | '<(DEPTH)' | 67 | '<(DEPTH)' |
83 | 68 | ], | 68 | ], |
84 | 69 | 'sources': [ | 69 | 'sources': [ |
85 | 70 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_browser_platform_integration.cc', | ||
86 | 70 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_web_view.cc', | 71 | '<(INTERMEDIATE_DIR)/moc_oxide_qt_web_view.cc', |
87 | 71 | 'api/internal/oxideqwebpreferences_p.cc', | 72 | 'api/internal/oxideqwebpreferences_p.cc', |
88 | 72 | 'app/oxide_qt_main.cc', | 73 | 'app/oxide_qt_main.cc', |
89 | @@ -128,6 +129,11 @@ | |||
90 | 128 | 'includes': [ 'moc.gypi' ] | 129 | 'includes': [ 'moc.gypi' ] |
91 | 129 | }, | 130 | }, |
92 | 130 | { | 131 | { |
93 | 132 | 'action_name': 'moc_oxide_qt_browser_platform_integration.cc', | ||
94 | 133 | 'moc_input': 'browser/oxide_qt_browser_platform_integration.h', | ||
95 | 134 | 'includes': [ 'moc.gypi' ] | ||
96 | 135 | }, | ||
97 | 136 | { | ||
98 | 131 | 'action_name': 'moc_oxide_qt_web_view.cc', | 137 | 'action_name': 'moc_oxide_qt_web_view.cc', |
99 | 132 | 'moc_input': 'browser/oxide_qt_web_view.h', | 138 | 'moc_input': 'browser/oxide_qt_web_view.h', |
100 | 133 | 'includes': [ 'moc.gypi' ] | 139 | 'includes': [ 'moc.gypi' ] |
101 | 134 | 140 | ||
102 | === modified file 'shared/browser/oxide_browser_platform_integration.cc' | |||
103 | --- shared/browser/oxide_browser_platform_integration.cc 2014-11-08 00:28:36 +0000 | |||
104 | +++ shared/browser/oxide_browser_platform_integration.cc 2014-11-14 14:36:23 +0000 | |||
105 | @@ -19,6 +19,8 @@ | |||
106 | 19 | 19 | ||
107 | 20 | #include "base/logging.h" | 20 | #include "base/logging.h" |
108 | 21 | 21 | ||
109 | 22 | #include "oxide_browser_platform_integration_observer.h" | ||
110 | 23 | |||
111 | 22 | namespace oxide { | 24 | namespace oxide { |
112 | 23 | 25 | ||
113 | 24 | namespace { | 26 | namespace { |
114 | @@ -67,4 +69,25 @@ | |||
115 | 67 | return NULL; | 69 | return NULL; |
116 | 68 | } | 70 | } |
117 | 69 | 71 | ||
118 | 72 | BrowserPlatformIntegration::ApplicationState | ||
119 | 73 | BrowserPlatformIntegration::GetApplicationState() { | ||
120 | 74 | return APPLICATION_STATE_ACTIVE; | ||
121 | 75 | } | ||
122 | 76 | |||
123 | 77 | void BrowserPlatformIntegration::AddObserver( | ||
124 | 78 | BrowserPlatformIntegrationObserver* observer) { | ||
125 | 79 | observers_.AddObserver(observer); | ||
126 | 80 | } | ||
127 | 81 | |||
128 | 82 | void BrowserPlatformIntegration::RemoveObserver( | ||
129 | 83 | BrowserPlatformIntegrationObserver* observer) { | ||
130 | 84 | observers_.RemoveObserver(observer); | ||
131 | 85 | } | ||
132 | 86 | |||
133 | 87 | void BrowserPlatformIntegration::NotifyApplicationStateChanged() { | ||
134 | 88 | FOR_EACH_OBSERVER(BrowserPlatformIntegrationObserver, | ||
135 | 89 | observers_, | ||
136 | 90 | ApplicationStateChanged()); | ||
137 | 91 | } | ||
138 | 92 | |||
139 | 70 | } // namespace oxide | 93 | } // namespace oxide |
140 | 71 | 94 | ||
141 | === modified file 'shared/browser/oxide_browser_platform_integration.h' | |||
142 | --- shared/browser/oxide_browser_platform_integration.h 2014-11-08 00:28:36 +0000 | |||
143 | +++ shared/browser/oxide_browser_platform_integration.h 2014-11-14 14:36:23 +0000 | |||
144 | @@ -20,6 +20,7 @@ | |||
145 | 20 | 20 | ||
146 | 21 | #include "base/macros.h" | 21 | #include "base/macros.h" |
147 | 22 | #include "base/memory/scoped_ptr.h" | 22 | #include "base/memory/scoped_ptr.h" |
148 | 23 | #include "base/observer_list.h" | ||
149 | 23 | #include "content/public/browser/browser_thread.h" | 24 | #include "content/public/browser/browser_thread.h" |
150 | 24 | #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 25 | #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
151 | 25 | 26 | ||
152 | @@ -31,6 +32,7 @@ | |||
153 | 31 | 32 | ||
154 | 32 | namespace oxide { | 33 | namespace oxide { |
155 | 33 | 34 | ||
156 | 35 | class BrowserPlatformIntegrationObserver; | ||
157 | 34 | class GLContextAdopted; | 36 | class GLContextAdopted; |
158 | 35 | class MessagePump; | 37 | class MessagePump; |
159 | 36 | 38 | ||
160 | @@ -38,6 +40,11 @@ | |||
161 | 38 | public: | 40 | public: |
162 | 39 | virtual ~BrowserPlatformIntegration(); | 41 | virtual ~BrowserPlatformIntegration(); |
163 | 40 | 42 | ||
164 | 43 | enum ApplicationState { | ||
165 | 44 | APPLICATION_STATE_INACTIVE, | ||
166 | 45 | APPLICATION_STATE_ACTIVE | ||
167 | 46 | }; | ||
168 | 47 | |||
169 | 41 | // Can be called on any thread. Destruction of this class | 48 | // Can be called on any thread. Destruction of this class |
170 | 42 | // must only happen once all Chromium threads have been shut down | 49 | // must only happen once all Chromium threads have been shut down |
171 | 43 | static BrowserPlatformIntegration* GetInstance(); | 50 | static BrowserPlatformIntegration* GetInstance(); |
172 | @@ -62,10 +69,21 @@ | |||
173 | 62 | // Called on the geolocation thread | 69 | // Called on the geolocation thread |
174 | 63 | virtual content::LocationProvider* CreateLocationProvider(); | 70 | virtual content::LocationProvider* CreateLocationProvider(); |
175 | 64 | 71 | ||
176 | 72 | virtual ApplicationState GetApplicationState(); | ||
177 | 73 | |||
178 | 65 | protected: | 74 | protected: |
179 | 66 | BrowserPlatformIntegration(); | 75 | BrowserPlatformIntegration(); |
180 | 67 | 76 | ||
181 | 77 | void NotifyApplicationStateChanged(); | ||
182 | 78 | |||
183 | 68 | private: | 79 | private: |
184 | 80 | friend class BrowserPlatformIntegrationObserver; | ||
185 | 81 | |||
186 | 82 | void AddObserver(BrowserPlatformIntegrationObserver* observer); | ||
187 | 83 | void RemoveObserver(BrowserPlatformIntegrationObserver* observer); | ||
188 | 84 | |||
189 | 85 | ObserverList<BrowserPlatformIntegrationObserver> observers_; | ||
190 | 86 | |||
191 | 69 | DISALLOW_COPY_AND_ASSIGN(BrowserPlatformIntegration); | 87 | DISALLOW_COPY_AND_ASSIGN(BrowserPlatformIntegration); |
192 | 70 | }; | 88 | }; |
193 | 71 | 89 | ||
194 | 72 | 90 | ||
195 | === added file 'shared/browser/oxide_browser_platform_integration_observer.cc' | |||
196 | --- shared/browser/oxide_browser_platform_integration_observer.cc 1970-01-01 00:00:00 +0000 | |||
197 | +++ shared/browser/oxide_browser_platform_integration_observer.cc 2014-11-14 14:36:23 +0000 | |||
198 | @@ -0,0 +1,30 @@ | |||
199 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
200 | 2 | // Copyright (C) 2014 Canonical Ltd. | ||
201 | 3 | |||
202 | 4 | // This library is free software; you can redistribute it and/or | ||
203 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
204 | 6 | // License as published by the Free Software Foundation; either | ||
205 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
206 | 8 | |||
207 | 9 | // This library is distributed in the hope that it will be useful, | ||
208 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
209 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
210 | 12 | // Lesser General Public License for more details. | ||
211 | 13 | |||
212 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
213 | 15 | // License along with this library; if not, write to the Free Software | ||
214 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
215 | 17 | |||
216 | 18 | #include "oxide_browser_platform_integration_observer.h" | ||
217 | 19 | |||
218 | 20 | namespace oxide { | ||
219 | 21 | |||
220 | 22 | BrowserPlatformIntegrationObserver::BrowserPlatformIntegrationObserver() { | ||
221 | 23 | BrowserPlatformIntegration::GetInstance()->AddObserver(this); | ||
222 | 24 | } | ||
223 | 25 | |||
224 | 26 | BrowserPlatformIntegrationObserver::~BrowserPlatformIntegrationObserver() { | ||
225 | 27 | BrowserPlatformIntegration::GetInstance()->RemoveObserver(this); | ||
226 | 28 | } | ||
227 | 29 | |||
228 | 30 | } // namespace oxide | ||
229 | 0 | 31 | ||
230 | === added file 'shared/browser/oxide_browser_platform_integration_observer.h' | |||
231 | --- shared/browser/oxide_browser_platform_integration_observer.h 1970-01-01 00:00:00 +0000 | |||
232 | +++ shared/browser/oxide_browser_platform_integration_observer.h 2014-11-14 14:36:23 +0000 | |||
233 | @@ -0,0 +1,37 @@ | |||
234 | 1 | // vim:expandtab:shiftwidth=2:tabstop=2: | ||
235 | 2 | // Copyright (C) 2014 Canonical Ltd. | ||
236 | 3 | |||
237 | 4 | // This library is free software; you can redistribute it and/or | ||
238 | 5 | // modify it under the terms of the GNU Lesser General Public | ||
239 | 6 | // License as published by the Free Software Foundation; either | ||
240 | 7 | // version 2.1 of the License, or (at your option) any later version. | ||
241 | 8 | |||
242 | 9 | // This library is distributed in the hope that it will be useful, | ||
243 | 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
244 | 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
245 | 12 | // Lesser General Public License for more details. | ||
246 | 13 | |||
247 | 14 | // You should have received a copy of the GNU Lesser General Public | ||
248 | 15 | // License along with this library; if not, write to the Free Software | ||
249 | 16 | // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
250 | 17 | |||
251 | 18 | #ifndef _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_OBSERVER_H_ | ||
252 | 19 | #define _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_OBSERVER_H_ | ||
253 | 20 | |||
254 | 21 | #include "oxide_browser_platform_integration.h" | ||
255 | 22 | |||
256 | 23 | namespace oxide { | ||
257 | 24 | |||
258 | 25 | class BrowserPlatformIntegrationObserver { | ||
259 | 26 | public: | ||
260 | 27 | virtual ~BrowserPlatformIntegrationObserver(); | ||
261 | 28 | |||
262 | 29 | virtual void ApplicationStateChanged() {} | ||
263 | 30 | |||
264 | 31 | protected: | ||
265 | 32 | BrowserPlatformIntegrationObserver(); | ||
266 | 33 | }; | ||
267 | 34 | |||
268 | 35 | } // namespace oxide | ||
269 | 36 | |||
270 | 37 | #endif // _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_OBSERVER_H_ | ||
271 | 0 | 38 | ||
272 | === modified file 'shared/browser/oxide_power_save_blocker.cc' | |||
273 | --- shared/browser/oxide_power_save_blocker.cc 2014-10-27 16:32:42 +0000 | |||
274 | +++ shared/browser/oxide_power_save_blocker.cc 2014-11-14 14:36:23 +0000 | |||
275 | @@ -31,6 +31,7 @@ | |||
276 | 31 | 31 | ||
277 | 32 | #include "shared/port/content/browser/power_save_blocker_oxide.h" | 32 | #include "shared/port/content/browser/power_save_blocker_oxide.h" |
278 | 33 | 33 | ||
279 | 34 | #include "oxide_browser_platform_integration_observer.h" | ||
280 | 34 | #include "oxide_form_factor.h" | 35 | #include "oxide_form_factor.h" |
281 | 35 | 36 | ||
282 | 36 | namespace oxide { | 37 | namespace oxide { |
283 | @@ -43,7 +44,8 @@ | |||
284 | 43 | 44 | ||
285 | 44 | } | 45 | } |
286 | 45 | 46 | ||
288 | 46 | class PowerSaveBlocker : public content::PowerSaveBlockerOxideDelegate { | 47 | class PowerSaveBlocker : public content::PowerSaveBlockerOxideDelegate, |
289 | 48 | public BrowserPlatformIntegrationObserver { | ||
290 | 47 | public: | 49 | public: |
291 | 48 | PowerSaveBlocker(); | 50 | PowerSaveBlocker(); |
292 | 49 | 51 | ||
293 | @@ -56,16 +58,22 @@ | |||
294 | 56 | void ApplyBlock(); | 58 | void ApplyBlock(); |
295 | 57 | void RemoveBlock(); | 59 | void RemoveBlock(); |
296 | 58 | 60 | ||
297 | 61 | // BrowserPlatformIntegrationObserver implementation | ||
298 | 62 | void ApplicationStateChanged() final; | ||
299 | 63 | |||
300 | 59 | oxide::FormFactor form_factor_; | 64 | oxide::FormFactor form_factor_; |
301 | 60 | scoped_refptr<dbus::Bus> bus_; | 65 | scoped_refptr<dbus::Bus> bus_; |
302 | 61 | int cookie_; | 66 | int cookie_; |
303 | 62 | }; | 67 | }; |
304 | 63 | 68 | ||
305 | 64 | void PowerSaveBlocker::Init() { | 69 | void PowerSaveBlocker::Init() { |
310 | 65 | content::BrowserThread::PostTask( | 70 | if (BrowserPlatformIntegration::GetInstance()->GetApplicationState() == |
311 | 66 | content::BrowserThread::FILE, | 71 | BrowserPlatformIntegration::APPLICATION_STATE_ACTIVE) { |
312 | 67 | FROM_HERE, | 72 | content::BrowserThread::PostTask( |
313 | 68 | base::Bind(&PowerSaveBlocker::ApplyBlock, this)); | 73 | content::BrowserThread::FILE, |
314 | 74 | FROM_HERE, | ||
315 | 75 | base::Bind(&PowerSaveBlocker::ApplyBlock, this)); | ||
316 | 76 | } | ||
317 | 69 | } | 77 | } |
318 | 70 | 78 | ||
319 | 71 | void PowerSaveBlocker::CleanUp() { | 79 | void PowerSaveBlocker::CleanUp() { |
320 | @@ -116,9 +124,8 @@ | |||
321 | 116 | 124 | ||
322 | 117 | if (form_factor_ == oxide::FORM_FACTOR_PHONE || | 125 | if (form_factor_ == oxide::FORM_FACTOR_PHONE || |
323 | 118 | form_factor_ == oxide::FORM_FACTOR_TABLET) { | 126 | form_factor_ == oxide::FORM_FACTOR_TABLET) { |
324 | 119 | DCHECK(bus_.get()); | ||
325 | 120 | |||
326 | 121 | if (cookie_ != 0) { | 127 | if (cookie_ != 0) { |
327 | 128 | DCHECK(bus_.get()); | ||
328 | 122 | scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy( | 129 | scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy( |
329 | 123 | kUnityScreenServiceName, | 130 | kUnityScreenServiceName, |
330 | 124 | dbus::ObjectPath(kUnityScreenPath)); | 131 | dbus::ObjectPath(kUnityScreenPath)); |
331 | @@ -132,16 +139,30 @@ | |||
332 | 132 | cookie_ = 0; | 139 | cookie_ = 0; |
333 | 133 | } | 140 | } |
334 | 134 | 141 | ||
337 | 135 | bus_->ShutdownAndBlock(); | 142 | if (bus_.get()) { |
338 | 136 | bus_ = NULL; | 143 | bus_->ShutdownAndBlock(); |
339 | 144 | bus_ = NULL; | ||
340 | 145 | } | ||
341 | 137 | } else { | 146 | } else { |
342 | 138 | NOTIMPLEMENTED(); | 147 | NOTIMPLEMENTED(); |
343 | 139 | } | 148 | } |
344 | 140 | } | 149 | } |
345 | 141 | 150 | ||
346 | 151 | void PowerSaveBlocker::ApplicationStateChanged() { | ||
347 | 152 | BrowserPlatformIntegration::ApplicationState state = | ||
348 | 153 | BrowserPlatformIntegration::GetInstance()->GetApplicationState(); | ||
349 | 154 | if ((state == BrowserPlatformIntegration::APPLICATION_STATE_INACTIVE) && | ||
350 | 155 | (cookie_ != 0)) { | ||
351 | 156 | CleanUp(); | ||
352 | 157 | } else if ((state == BrowserPlatformIntegration::APPLICATION_STATE_ACTIVE) && | ||
353 | 158 | (cookie_ == 0)) { | ||
354 | 159 | Init(); | ||
355 | 160 | } | ||
356 | 161 | } | ||
357 | 162 | |||
358 | 142 | PowerSaveBlocker::PowerSaveBlocker() | 163 | PowerSaveBlocker::PowerSaveBlocker() |
361 | 143 | : form_factor_(oxide::GetFormFactorHint()), | 164 | : form_factor_(oxide::GetFormFactorHint()) |
362 | 144 | cookie_(0) {} | 165 | , cookie_(0) {} |
363 | 145 | 166 | ||
364 | 146 | content::PowerSaveBlockerOxideDelegate* CreatePowerSaveBlocker( | 167 | content::PowerSaveBlockerOxideDelegate* CreatePowerSaveBlocker( |
365 | 147 | content::PowerSaveBlocker::PowerSaveBlockerType type, | 168 | content::PowerSaveBlocker::PowerSaveBlockerType type, |
366 | 148 | 169 | ||
367 | === modified file 'shared/shared.gyp' | |||
368 | --- shared/shared.gyp 2014-11-08 01:06:30 +0000 | |||
369 | +++ shared/shared.gyp 2014-11-14 14:36:23 +0000 | |||
370 | @@ -253,6 +253,8 @@ | |||
371 | 253 | 'browser/oxide_browser_main_parts.h', | 253 | 'browser/oxide_browser_main_parts.h', |
372 | 254 | 'browser/oxide_browser_platform_integration.cc', | 254 | 'browser/oxide_browser_platform_integration.cc', |
373 | 255 | 'browser/oxide_browser_platform_integration.h', | 255 | 'browser/oxide_browser_platform_integration.h', |
374 | 256 | 'browser/oxide_browser_platform_integration_observer.cc', | ||
375 | 257 | 'browser/oxide_browser_platform_integration_observer.h', | ||
376 | 256 | 'browser/oxide_browser_process_main.cc', | 258 | 'browser/oxide_browser_process_main.cc', |
377 | 257 | 'browser/oxide_browser_process_main.h', | 259 | 'browser/oxide_browser_process_main.h', |
378 | 258 | 'browser/oxide_content_browser_client.cc', | 260 | 'browser/oxide_content_browser_client.cc', |
Thanks for this. I've added a couple of comments inline.
Also, I wonder whether it would be better to drop the state argument from the notification and add a BrowserPlatform Integration: :GetApplication State() instead. There's always the possibility of a PowerSaveBlocker being created inbetween the notification firing and the application being stopped.