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
=== modified file 'qt/core/browser/oxide_qt_browser_platform_integration.cc'
--- qt/core/browser/oxide_qt_browser_platform_integration.cc 2014-11-13 08:41:43 +0000
+++ qt/core/browser/oxide_qt_browser_platform_integration.cc 2014-11-14 14:36:23 +0000
@@ -47,10 +47,17 @@
4747
48BrowserPlatformIntegration::BrowserPlatformIntegration(48BrowserPlatformIntegration::BrowserPlatformIntegration(
49 GLContextAdopted* gl_share_context)49 GLContextAdopted* gl_share_context)
50 : gl_share_context_(gl_share_context) {}50 : gl_share_context_(gl_share_context) {
51 QObject::connect(qApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)),
52 this, SLOT(onApplicationStateChanged()));
53}
5154
52BrowserPlatformIntegration::~BrowserPlatformIntegration() {}55BrowserPlatformIntegration::~BrowserPlatformIntegration() {}
5356
57void BrowserPlatformIntegration::onApplicationStateChanged() {
58 NotifyApplicationStateChanged();
59}
60
54bool BrowserPlatformIntegration::LaunchURLExternally(const GURL& url) {61bool BrowserPlatformIntegration::LaunchURLExternally(const GURL& url) {
55 return QDesktopServices::openUrl(QUrl(QString::fromStdString(url.spec())));62 return QDesktopServices::openUrl(QUrl(QString::fromStdString(url.spec())));
56}63}
@@ -109,6 +116,15 @@
109 return new LocationProvider();116 return new LocationProvider();
110}117}
111118
119oxide::BrowserPlatformIntegration::ApplicationState
120BrowserPlatformIntegration::GetApplicationState() {
121 if (qApp->applicationState() == Qt::ApplicationActive) {
122 return APPLICATION_STATE_ACTIVE;
123 } else {
124 return APPLICATION_STATE_INACTIVE;
125 }
126}
127
112QThread* GetIOQThread() {128QThread* GetIOQThread() {
113 return g_io_thread.Get();129 return g_io_thread.Get();
114}130}
115131
=== modified file 'qt/core/browser/oxide_qt_browser_platform_integration.h'
--- qt/core/browser/oxide_qt_browser_platform_integration.h 2014-11-12 14:50:11 +0000
+++ qt/core/browser/oxide_qt_browser_platform_integration.h 2014-11-14 14:36:23 +0000
@@ -18,6 +18,7 @@
18#ifndef _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_18#ifndef _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_
19#define _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_19#define _OXIDE_QT_CORE_BROWSER_PLATFORM_INTEGRATION_H_
2020
21#include <QObject>
21#include <QtGlobal>22#include <QtGlobal>
2223
23#include "base/macros.h"24#include "base/macros.h"
@@ -35,11 +36,16 @@
35class GLContextAdopted;36class GLContextAdopted;
3637
37class BrowserPlatformIntegration final38class BrowserPlatformIntegration final
38 : public oxide::BrowserPlatformIntegration {39 : public QObject, public oxide::BrowserPlatformIntegration {
40 Q_OBJECT
41
39 public:42 public:
40 BrowserPlatformIntegration(GLContextAdopted* gl_share_context);43 BrowserPlatformIntegration(GLContextAdopted* gl_share_context);
41 ~BrowserPlatformIntegration();44 ~BrowserPlatformIntegration();
4245
46 private Q_SLOTS:
47 void onApplicationStateChanged();
48
43 private:49 private:
44 bool LaunchURLExternally(const GURL& url) final;50 bool LaunchURLExternally(const GURL& url) final;
45 bool IsTouchSupported() final;51 bool IsTouchSupported() final;
@@ -49,6 +55,7 @@
49 scoped_ptr<oxide::MessagePump> CreateUIMessagePump() final;55 scoped_ptr<oxide::MessagePump> CreateUIMessagePump() final;
50 void BrowserThreadInit(content::BrowserThread::ID id) final;56 void BrowserThreadInit(content::BrowserThread::ID id) final;
51 content::LocationProvider* CreateLocationProvider() final;57 content::LocationProvider* CreateLocationProvider() final;
58 ApplicationState GetApplicationState() final;
5259
53 scoped_refptr<GLContextAdopted> gl_share_context_;60 scoped_refptr<GLContextAdopted> gl_share_context_;
5461
5562
=== modified file 'qt/core/core.gyp'
--- qt/core/core.gyp 2014-11-12 14:50:11 +0000
+++ qt/core/core.gyp 2014-11-14 14:36:23 +0000
@@ -67,6 +67,7 @@
67 '<(DEPTH)'67 '<(DEPTH)'
68 ],68 ],
69 'sources': [69 'sources': [
70 '<(INTERMEDIATE_DIR)/moc_oxide_qt_browser_platform_integration.cc',
70 '<(INTERMEDIATE_DIR)/moc_oxide_qt_web_view.cc',71 '<(INTERMEDIATE_DIR)/moc_oxide_qt_web_view.cc',
71 'api/internal/oxideqwebpreferences_p.cc',72 'api/internal/oxideqwebpreferences_p.cc',
72 'app/oxide_qt_main.cc',73 'app/oxide_qt_main.cc',
@@ -128,6 +129,11 @@
128 'includes': [ 'moc.gypi' ]129 'includes': [ 'moc.gypi' ]
129 },130 },
130 {131 {
132 'action_name': 'moc_oxide_qt_browser_platform_integration.cc',
133 'moc_input': 'browser/oxide_qt_browser_platform_integration.h',
134 'includes': [ 'moc.gypi' ]
135 },
136 {
131 'action_name': 'moc_oxide_qt_web_view.cc',137 'action_name': 'moc_oxide_qt_web_view.cc',
132 'moc_input': 'browser/oxide_qt_web_view.h',138 'moc_input': 'browser/oxide_qt_web_view.h',
133 'includes': [ 'moc.gypi' ]139 'includes': [ 'moc.gypi' ]
134140
=== modified file 'shared/browser/oxide_browser_platform_integration.cc'
--- shared/browser/oxide_browser_platform_integration.cc 2014-11-08 00:28:36 +0000
+++ shared/browser/oxide_browser_platform_integration.cc 2014-11-14 14:36:23 +0000
@@ -19,6 +19,8 @@
1919
20#include "base/logging.h"20#include "base/logging.h"
2121
22#include "oxide_browser_platform_integration_observer.h"
23
22namespace oxide {24namespace oxide {
2325
24namespace {26namespace {
@@ -67,4 +69,25 @@
67 return NULL;69 return NULL;
68}70}
6971
72BrowserPlatformIntegration::ApplicationState
73BrowserPlatformIntegration::GetApplicationState() {
74 return APPLICATION_STATE_ACTIVE;
75}
76
77void BrowserPlatformIntegration::AddObserver(
78 BrowserPlatformIntegrationObserver* observer) {
79 observers_.AddObserver(observer);
80}
81
82void BrowserPlatformIntegration::RemoveObserver(
83 BrowserPlatformIntegrationObserver* observer) {
84 observers_.RemoveObserver(observer);
85}
86
87void BrowserPlatformIntegration::NotifyApplicationStateChanged() {
88 FOR_EACH_OBSERVER(BrowserPlatformIntegrationObserver,
89 observers_,
90 ApplicationStateChanged());
91}
92
70} // namespace oxide93} // namespace oxide
7194
=== modified file 'shared/browser/oxide_browser_platform_integration.h'
--- shared/browser/oxide_browser_platform_integration.h 2014-11-08 00:28:36 +0000
+++ shared/browser/oxide_browser_platform_integration.h 2014-11-14 14:36:23 +0000
@@ -20,6 +20,7 @@
2020
21#include "base/macros.h"21#include "base/macros.h"
22#include "base/memory/scoped_ptr.h"22#include "base/memory/scoped_ptr.h"
23#include "base/observer_list.h"
23#include "content/public/browser/browser_thread.h"24#include "content/public/browser/browser_thread.h"
24#include "third_party/WebKit/public/platform/WebScreenInfo.h"25#include "third_party/WebKit/public/platform/WebScreenInfo.h"
2526
@@ -31,6 +32,7 @@
3132
32namespace oxide {33namespace oxide {
3334
35class BrowserPlatformIntegrationObserver;
34class GLContextAdopted;36class GLContextAdopted;
35class MessagePump;37class MessagePump;
3638
@@ -38,6 +40,11 @@
38 public:40 public:
39 virtual ~BrowserPlatformIntegration();41 virtual ~BrowserPlatformIntegration();
4042
43 enum ApplicationState {
44 APPLICATION_STATE_INACTIVE,
45 APPLICATION_STATE_ACTIVE
46 };
47
41 // Can be called on any thread. Destruction of this class48 // Can be called on any thread. Destruction of this class
42 // must only happen once all Chromium threads have been shut down49 // must only happen once all Chromium threads have been shut down
43 static BrowserPlatformIntegration* GetInstance();50 static BrowserPlatformIntegration* GetInstance();
@@ -62,10 +69,21 @@
62 // Called on the geolocation thread69 // Called on the geolocation thread
63 virtual content::LocationProvider* CreateLocationProvider();70 virtual content::LocationProvider* CreateLocationProvider();
6471
72 virtual ApplicationState GetApplicationState();
73
65 protected:74 protected:
66 BrowserPlatformIntegration();75 BrowserPlatformIntegration();
6776
77 void NotifyApplicationStateChanged();
78
68 private:79 private:
80 friend class BrowserPlatformIntegrationObserver;
81
82 void AddObserver(BrowserPlatformIntegrationObserver* observer);
83 void RemoveObserver(BrowserPlatformIntegrationObserver* observer);
84
85 ObserverList<BrowserPlatformIntegrationObserver> observers_;
86
69 DISALLOW_COPY_AND_ASSIGN(BrowserPlatformIntegration);87 DISALLOW_COPY_AND_ASSIGN(BrowserPlatformIntegration);
70};88};
7189
7290
=== added file 'shared/browser/oxide_browser_platform_integration_observer.cc'
--- shared/browser/oxide_browser_platform_integration_observer.cc 1970-01-01 00:00:00 +0000
+++ shared/browser/oxide_browser_platform_integration_observer.cc 2014-11-14 14:36:23 +0000
@@ -0,0 +1,30 @@
1// vim:expandtab:shiftwidth=2:tabstop=2:
2// Copyright (C) 2014 Canonical Ltd.
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18#include "oxide_browser_platform_integration_observer.h"
19
20namespace oxide {
21
22BrowserPlatformIntegrationObserver::BrowserPlatformIntegrationObserver() {
23 BrowserPlatformIntegration::GetInstance()->AddObserver(this);
24}
25
26BrowserPlatformIntegrationObserver::~BrowserPlatformIntegrationObserver() {
27 BrowserPlatformIntegration::GetInstance()->RemoveObserver(this);
28}
29
30} // namespace oxide
031
=== added file 'shared/browser/oxide_browser_platform_integration_observer.h'
--- shared/browser/oxide_browser_platform_integration_observer.h 1970-01-01 00:00:00 +0000
+++ shared/browser/oxide_browser_platform_integration_observer.h 2014-11-14 14:36:23 +0000
@@ -0,0 +1,37 @@
1// vim:expandtab:shiftwidth=2:tabstop=2:
2// Copyright (C) 2014 Canonical Ltd.
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
18#ifndef _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_OBSERVER_H_
19#define _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_OBSERVER_H_
20
21#include "oxide_browser_platform_integration.h"
22
23namespace oxide {
24
25class BrowserPlatformIntegrationObserver {
26 public:
27 virtual ~BrowserPlatformIntegrationObserver();
28
29 virtual void ApplicationStateChanged() {}
30
31 protected:
32 BrowserPlatformIntegrationObserver();
33};
34
35} // namespace oxide
36
37#endif // _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_OBSERVER_H_
038
=== modified file 'shared/browser/oxide_power_save_blocker.cc'
--- shared/browser/oxide_power_save_blocker.cc 2014-10-27 16:32:42 +0000
+++ shared/browser/oxide_power_save_blocker.cc 2014-11-14 14:36:23 +0000
@@ -31,6 +31,7 @@
3131
32#include "shared/port/content/browser/power_save_blocker_oxide.h"32#include "shared/port/content/browser/power_save_blocker_oxide.h"
3333
34#include "oxide_browser_platform_integration_observer.h"
34#include "oxide_form_factor.h"35#include "oxide_form_factor.h"
3536
36namespace oxide {37namespace oxide {
@@ -43,7 +44,8 @@
4344
44}45}
4546
46class PowerSaveBlocker : public content::PowerSaveBlockerOxideDelegate {47class PowerSaveBlocker : public content::PowerSaveBlockerOxideDelegate,
48 public BrowserPlatformIntegrationObserver {
47 public:49 public:
48 PowerSaveBlocker();50 PowerSaveBlocker();
4951
@@ -56,16 +58,22 @@
56 void ApplyBlock();58 void ApplyBlock();
57 void RemoveBlock();59 void RemoveBlock();
5860
61 // BrowserPlatformIntegrationObserver implementation
62 void ApplicationStateChanged() final;
63
59 oxide::FormFactor form_factor_;64 oxide::FormFactor form_factor_;
60 scoped_refptr<dbus::Bus> bus_;65 scoped_refptr<dbus::Bus> bus_;
61 int cookie_;66 int cookie_;
62};67};
6368
64void PowerSaveBlocker::Init() {69void PowerSaveBlocker::Init() {
65 content::BrowserThread::PostTask(70 if (BrowserPlatformIntegration::GetInstance()->GetApplicationState() ==
66 content::BrowserThread::FILE,71 BrowserPlatformIntegration::APPLICATION_STATE_ACTIVE) {
67 FROM_HERE,72 content::BrowserThread::PostTask(
68 base::Bind(&PowerSaveBlocker::ApplyBlock, this));73 content::BrowserThread::FILE,
74 FROM_HERE,
75 base::Bind(&PowerSaveBlocker::ApplyBlock, this));
76 }
69}77}
7078
71void PowerSaveBlocker::CleanUp() {79void PowerSaveBlocker::CleanUp() {
@@ -116,9 +124,8 @@
116124
117 if (form_factor_ == oxide::FORM_FACTOR_PHONE ||125 if (form_factor_ == oxide::FORM_FACTOR_PHONE ||
118 form_factor_ == oxide::FORM_FACTOR_TABLET) {126 form_factor_ == oxide::FORM_FACTOR_TABLET) {
119 DCHECK(bus_.get());
120
121 if (cookie_ != 0) {127 if (cookie_ != 0) {
128 DCHECK(bus_.get());
122 scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(129 scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
123 kUnityScreenServiceName,130 kUnityScreenServiceName,
124 dbus::ObjectPath(kUnityScreenPath));131 dbus::ObjectPath(kUnityScreenPath));
@@ -132,16 +139,30 @@
132 cookie_ = 0;139 cookie_ = 0;
133 }140 }
134141
135 bus_->ShutdownAndBlock();142 if (bus_.get()) {
136 bus_ = NULL;143 bus_->ShutdownAndBlock();
144 bus_ = NULL;
145 }
137 } else {146 } else {
138 NOTIMPLEMENTED();147 NOTIMPLEMENTED();
139 }148 }
140}149}
141150
151void PowerSaveBlocker::ApplicationStateChanged() {
152 BrowserPlatformIntegration::ApplicationState state =
153 BrowserPlatformIntegration::GetInstance()->GetApplicationState();
154 if ((state == BrowserPlatformIntegration::APPLICATION_STATE_INACTIVE) &&
155 (cookie_ != 0)) {
156 CleanUp();
157 } else if ((state == BrowserPlatformIntegration::APPLICATION_STATE_ACTIVE) &&
158 (cookie_ == 0)) {
159 Init();
160 }
161}
162
142PowerSaveBlocker::PowerSaveBlocker()163PowerSaveBlocker::PowerSaveBlocker()
143 : form_factor_(oxide::GetFormFactorHint()),164 : form_factor_(oxide::GetFormFactorHint())
144 cookie_(0) {}165 , cookie_(0) {}
145166
146content::PowerSaveBlockerOxideDelegate* CreatePowerSaveBlocker(167content::PowerSaveBlockerOxideDelegate* CreatePowerSaveBlocker(
147 content::PowerSaveBlocker::PowerSaveBlockerType type,168 content::PowerSaveBlocker::PowerSaveBlockerType type,
148169
=== modified file 'shared/shared.gyp'
--- shared/shared.gyp 2014-11-08 01:06:30 +0000
+++ shared/shared.gyp 2014-11-14 14:36:23 +0000
@@ -253,6 +253,8 @@
253 'browser/oxide_browser_main_parts.h',253 'browser/oxide_browser_main_parts.h',
254 'browser/oxide_browser_platform_integration.cc',254 'browser/oxide_browser_platform_integration.cc',
255 'browser/oxide_browser_platform_integration.h',255 'browser/oxide_browser_platform_integration.h',
256 'browser/oxide_browser_platform_integration_observer.cc',
257 'browser/oxide_browser_platform_integration_observer.h',
256 'browser/oxide_browser_process_main.cc',258 'browser/oxide_browser_process_main.cc',
257 'browser/oxide_browser_process_main.h',259 'browser/oxide_browser_process_main.h',
258 'browser/oxide_content_browser_client.cc',260 'browser/oxide_content_browser_client.cc',

Subscribers

People subscribed via source and target branches