Merge lp:~osomon/oxide/applicationstatechanged into lp:~oxide-developers/oxide/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
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).

To post a comment you must log in.
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

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 BrowserPlatformIntegration::GetApplicationState() instead. There's always the possibility of a PowerSaveBlocker being created inbetween the notification firing and the application being stopped.

review: Needs Fixing
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::GetApplicationState() 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
6 BrowserPlatformIntegration::BrowserPlatformIntegration(
7 GLContextAdopted* gl_share_context)
8- : gl_share_context_(gl_share_context) {}
9+ : gl_share_context_(gl_share_context) {
10+ QObject::connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
11+ this, SLOT(onApplicationStateChanged()));
12+}
13
14 BrowserPlatformIntegration::~BrowserPlatformIntegration() {}
15
16+void BrowserPlatformIntegration::onApplicationStateChanged() {
17+ NotifyApplicationStateChanged();
18+}
19+
20 bool BrowserPlatformIntegration::LaunchURLExternally(const GURL& url) {
21 return QDesktopServices::openUrl(QUrl(QString::fromStdString(url.spec())));
22 }
23@@ -109,6 +116,15 @@
24 return new LocationProvider();
25 }
26
27+oxide::BrowserPlatformIntegration::ApplicationState
28+BrowserPlatformIntegration::GetApplicationState() {
29+ if (qApp->applicationState() == Qt::ApplicationActive) {
30+ return APPLICATION_STATE_ACTIVE;
31+ } else {
32+ return APPLICATION_STATE_INACTIVE;
33+ }
34+}
35+
36 QThread* GetIOQThread() {
37 return g_io_thread.Get();
38 }
39
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 #ifndef _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_
45 #define _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_
46
47+#include <QObject>
48 #include <QtGlobal>
49
50 #include "base/macros.h"
51@@ -35,11 +36,16 @@
52 class GLContextAdopted;
53
54 class BrowserPlatformIntegration final
55- : public oxide::BrowserPlatformIntegration {
56+ : public QObject, public oxide::BrowserPlatformIntegration {
57+ Q_OBJECT
58+
59 public:
60 BrowserPlatformIntegration(GLContextAdopted* gl_share_context);
61 ~BrowserPlatformIntegration();
62
63+ private Q_SLOTS:
64+ void onApplicationStateChanged();
65+
66 private:
67 bool LaunchURLExternally(const GURL& url) final;
68 bool IsTouchSupported() final;
69@@ -49,6 +55,7 @@
70 scoped_ptr<oxide::MessagePump> CreateUIMessagePump() final;
71 void BrowserThreadInit(content::BrowserThread::ID id) final;
72 content::LocationProvider* CreateLocationProvider() final;
73+ ApplicationState GetApplicationState() final;
74
75 scoped_refptr<GLContextAdopted> gl_share_context_;
76
77
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 '<(DEPTH)'
83 ],
84 'sources': [
85+ '<(INTERMEDIATE_DIR)/moc_oxide_qt_browser_platform_integration.cc',
86 '<(INTERMEDIATE_DIR)/moc_oxide_qt_web_view.cc',
87 'api/internal/oxideqwebpreferences_p.cc',
88 'app/oxide_qt_main.cc',
89@@ -128,6 +129,11 @@
90 'includes': [ 'moc.gypi' ]
91 },
92 {
93+ 'action_name': 'moc_oxide_qt_browser_platform_integration.cc',
94+ 'moc_input': 'browser/oxide_qt_browser_platform_integration.h',
95+ 'includes': [ 'moc.gypi' ]
96+ },
97+ {
98 'action_name': 'moc_oxide_qt_web_view.cc',
99 'moc_input': 'browser/oxide_qt_web_view.h',
100 'includes': [ 'moc.gypi' ]
101
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
107 #include "base/logging.h"
108
109+#include "oxide_browser_platform_integration_observer.h"
110+
111 namespace oxide {
112
113 namespace {
114@@ -67,4 +69,25 @@
115 return NULL;
116 }
117
118+BrowserPlatformIntegration::ApplicationState
119+BrowserPlatformIntegration::GetApplicationState() {
120+ return APPLICATION_STATE_ACTIVE;
121+}
122+
123+void BrowserPlatformIntegration::AddObserver(
124+ BrowserPlatformIntegrationObserver* observer) {
125+ observers_.AddObserver(observer);
126+}
127+
128+void BrowserPlatformIntegration::RemoveObserver(
129+ BrowserPlatformIntegrationObserver* observer) {
130+ observers_.RemoveObserver(observer);
131+}
132+
133+void BrowserPlatformIntegration::NotifyApplicationStateChanged() {
134+ FOR_EACH_OBSERVER(BrowserPlatformIntegrationObserver,
135+ observers_,
136+ ApplicationStateChanged());
137+}
138+
139 } // namespace oxide
140
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
146 #include "base/macros.h"
147 #include "base/memory/scoped_ptr.h"
148+#include "base/observer_list.h"
149 #include "content/public/browser/browser_thread.h"
150 #include "third_party/WebKit/public/platform/WebScreenInfo.h"
151
152@@ -31,6 +32,7 @@
153
154 namespace oxide {
155
156+class BrowserPlatformIntegrationObserver;
157 class GLContextAdopted;
158 class MessagePump;
159
160@@ -38,6 +40,11 @@
161 public:
162 virtual ~BrowserPlatformIntegration();
163
164+ enum ApplicationState {
165+ APPLICATION_STATE_INACTIVE,
166+ APPLICATION_STATE_ACTIVE
167+ };
168+
169 // Can be called on any thread. Destruction of this class
170 // must only happen once all Chromium threads have been shut down
171 static BrowserPlatformIntegration* GetInstance();
172@@ -62,10 +69,21 @@
173 // Called on the geolocation thread
174 virtual content::LocationProvider* CreateLocationProvider();
175
176+ virtual ApplicationState GetApplicationState();
177+
178 protected:
179 BrowserPlatformIntegration();
180
181+ void NotifyApplicationStateChanged();
182+
183 private:
184+ friend class BrowserPlatformIntegrationObserver;
185+
186+ void AddObserver(BrowserPlatformIntegrationObserver* observer);
187+ void RemoveObserver(BrowserPlatformIntegrationObserver* observer);
188+
189+ ObserverList<BrowserPlatformIntegrationObserver> observers_;
190+
191 DISALLOW_COPY_AND_ASSIGN(BrowserPlatformIntegration);
192 };
193
194
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+// vim:expandtab:shiftwidth=2:tabstop=2:
200+// Copyright (C) 2014 Canonical Ltd.
201+
202+// This library is free software; you can redistribute it and/or
203+// modify it under the terms of the GNU Lesser General Public
204+// License as published by the Free Software Foundation; either
205+// version 2.1 of the License, or (at your option) any later version.
206+
207+// This library is distributed in the hope that it will be useful,
208+// but WITHOUT ANY WARRANTY; without even the implied warranty of
209+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
210+// Lesser General Public License for more details.
211+
212+// You should have received a copy of the GNU Lesser General Public
213+// License along with this library; if not, write to the Free Software
214+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
215+
216+#include "oxide_browser_platform_integration_observer.h"
217+
218+namespace oxide {
219+
220+BrowserPlatformIntegrationObserver::BrowserPlatformIntegrationObserver() {
221+ BrowserPlatformIntegration::GetInstance()->AddObserver(this);
222+}
223+
224+BrowserPlatformIntegrationObserver::~BrowserPlatformIntegrationObserver() {
225+ BrowserPlatformIntegration::GetInstance()->RemoveObserver(this);
226+}
227+
228+} // namespace oxide
229
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+// vim:expandtab:shiftwidth=2:tabstop=2:
235+// Copyright (C) 2014 Canonical Ltd.
236+
237+// This library is free software; you can redistribute it and/or
238+// modify it under the terms of the GNU Lesser General Public
239+// License as published by the Free Software Foundation; either
240+// version 2.1 of the License, or (at your option) any later version.
241+
242+// This library is distributed in the hope that it will be useful,
243+// but WITHOUT ANY WARRANTY; without even the implied warranty of
244+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
245+// Lesser General Public License for more details.
246+
247+// You should have received a copy of the GNU Lesser General Public
248+// License along with this library; if not, write to the Free Software
249+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
250+
251+#ifndef _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_OBSERVER_H_
252+#define _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_OBSERVER_H_
253+
254+#include "oxide_browser_platform_integration.h"
255+
256+namespace oxide {
257+
258+class BrowserPlatformIntegrationObserver {
259+ public:
260+ virtual ~BrowserPlatformIntegrationObserver();
261+
262+ virtual void ApplicationStateChanged() {}
263+
264+ protected:
265+ BrowserPlatformIntegrationObserver();
266+};
267+
268+} // namespace oxide
269+
270+#endif // _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_OBSERVER_H_
271
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
277 #include "shared/port/content/browser/power_save_blocker_oxide.h"
278
279+#include "oxide_browser_platform_integration_observer.h"
280 #include "oxide_form_factor.h"
281
282 namespace oxide {
283@@ -43,7 +44,8 @@
284
285 }
286
287-class PowerSaveBlocker : public content::PowerSaveBlockerOxideDelegate {
288+class PowerSaveBlocker : public content::PowerSaveBlockerOxideDelegate,
289+ public BrowserPlatformIntegrationObserver {
290 public:
291 PowerSaveBlocker();
292
293@@ -56,16 +58,22 @@
294 void ApplyBlock();
295 void RemoveBlock();
296
297+ // BrowserPlatformIntegrationObserver implementation
298+ void ApplicationStateChanged() final;
299+
300 oxide::FormFactor form_factor_;
301 scoped_refptr<dbus::Bus> bus_;
302 int cookie_;
303 };
304
305 void PowerSaveBlocker::Init() {
306- content::BrowserThread::PostTask(
307- content::BrowserThread::FILE,
308- FROM_HERE,
309- base::Bind(&PowerSaveBlocker::ApplyBlock, this));
310+ if (BrowserPlatformIntegration::GetInstance()->GetApplicationState() ==
311+ BrowserPlatformIntegration::APPLICATION_STATE_ACTIVE) {
312+ content::BrowserThread::PostTask(
313+ content::BrowserThread::FILE,
314+ FROM_HERE,
315+ base::Bind(&PowerSaveBlocker::ApplyBlock, this));
316+ }
317 }
318
319 void PowerSaveBlocker::CleanUp() {
320@@ -116,9 +124,8 @@
321
322 if (form_factor_ == oxide::FORM_FACTOR_PHONE ||
323 form_factor_ == oxide::FORM_FACTOR_TABLET) {
324- DCHECK(bus_.get());
325-
326 if (cookie_ != 0) {
327+ DCHECK(bus_.get());
328 scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
329 kUnityScreenServiceName,
330 dbus::ObjectPath(kUnityScreenPath));
331@@ -132,16 +139,30 @@
332 cookie_ = 0;
333 }
334
335- bus_->ShutdownAndBlock();
336- bus_ = NULL;
337+ if (bus_.get()) {
338+ bus_->ShutdownAndBlock();
339+ bus_ = NULL;
340+ }
341 } else {
342 NOTIMPLEMENTED();
343 }
344 }
345
346+void PowerSaveBlocker::ApplicationStateChanged() {
347+ BrowserPlatformIntegration::ApplicationState state =
348+ BrowserPlatformIntegration::GetInstance()->GetApplicationState();
349+ if ((state == BrowserPlatformIntegration::APPLICATION_STATE_INACTIVE) &&
350+ (cookie_ != 0)) {
351+ CleanUp();
352+ } else if ((state == BrowserPlatformIntegration::APPLICATION_STATE_ACTIVE) &&
353+ (cookie_ == 0)) {
354+ Init();
355+ }
356+}
357+
358 PowerSaveBlocker::PowerSaveBlocker()
359- : form_factor_(oxide::GetFormFactorHint()),
360- cookie_(0) {}
361+ : form_factor_(oxide::GetFormFactorHint())
362+ , cookie_(0) {}
363
364 content::PowerSaveBlockerOxideDelegate* CreatePowerSaveBlocker(
365 content::PowerSaveBlocker::PowerSaveBlockerType type,
366
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 'browser/oxide_browser_main_parts.h',
372 'browser/oxide_browser_platform_integration.cc',
373 'browser/oxide_browser_platform_integration.h',
374+ 'browser/oxide_browser_platform_integration_observer.cc',
375+ 'browser/oxide_browser_platform_integration_observer.h',
376 'browser/oxide_browser_process_main.cc',
377 'browser/oxide_browser_process_main.h',
378 'browser/oxide_content_browser_client.cc',

Subscribers

People subscribed via source and target branches