Merge lp:~justinmcp/oxide/1328494 into lp:~oxide-developers/oxide/oxide.trunk

Proposed by Justin McPherson
Status: Merged
Merged at revision: 1166
Proposed branch: lp:~justinmcp/oxide/1328494
Merge into: lp:~oxide-developers/oxide/oxide.trunk
Diff against target: 340 lines (+159/-55)
5 files modified
qt/core/browser/oxide_qt_browser_platform_integration.cc (+4/-0)
qt/core/browser/oxide_qt_browser_platform_integration.h (+1/-0)
shared/browser/oxide_browser_platform_integration.cc (+6/-0)
shared/browser/oxide_browser_platform_integration.h (+5/-0)
shared/browser/oxide_power_save_blocker.cc (+143/-55)
To merge this branch: bzr merge lp:~justinmcp/oxide/1328494
Reviewer Review Type Date Requested Status
Chris Coulson Approve
Review via email: mp+263998@code.launchpad.net

Commit message

Request that the screensaver be inhibited (desktop)

This adds to the already existing code to do this by activating the desktop path.

To post a comment you must log in.
lp:~justinmcp/oxide/1328494 updated
1162. By Justin McPherson

Be more specific about type

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Thanks. This looks mostly ok - I've just left a few minor comments

review: Needs Fixing
lp:~justinmcp/oxide/1328494 updated
1163. By Justin McPherson

Merge from trunk.

1164. By Justin McPherson

Results of review.

1165. By Justin McPherson

Remove unnecessary header include.

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 2015-06-22 23:56:59 +0000
+++ qt/core/browser/oxide_qt_browser_platform_integration.cc 2015-07-22 04:34:45 +0000
@@ -162,6 +162,10 @@
162 return state_;162 return state_;
163}163}
164164
165std::string BrowserPlatformIntegration::GetApplicationName() {
166 return qApp->applicationName().toStdString();
167}
168
165bool BrowserPlatformIntegration::eventFilter(QObject* watched, QEvent* event) {169bool BrowserPlatformIntegration::eventFilter(QObject* watched, QEvent* event) {
166 if (event->type() == QEvent::ApplicationActivate ||170 if (event->type() == QEvent::ApplicationActivate ||
167 event->type() == QEvent::ApplicationDeactivate) {171 event->type() == QEvent::ApplicationDeactivate) {
168172
=== modified file 'qt/core/browser/oxide_qt_browser_platform_integration.h'
--- qt/core/browser/oxide_qt_browser_platform_integration.h 2015-06-12 07:39:38 +0000
+++ qt/core/browser/oxide_qt_browser_platform_integration.h 2015-07-22 04:34:45 +0000
@@ -57,6 +57,7 @@
57 void BrowserThreadInit(content::BrowserThread::ID id) override;57 void BrowserThreadInit(content::BrowserThread::ID id) override;
58 content::LocationProvider* CreateLocationProvider() override;58 content::LocationProvider* CreateLocationProvider() override;
59 ApplicationState GetApplicationState() override;59 ApplicationState GetApplicationState() override;
60 std::string GetApplicationName() override;
60 ui::ClipboardOxideFactory GetClipboardOxideFactory() override;61 ui::ClipboardOxideFactory GetClipboardOxideFactory() override;
6162
62 // QObject implementation63 // QObject implementation
6364
=== modified file 'shared/browser/oxide_browser_platform_integration.cc'
--- shared/browser/oxide_browser_platform_integration.cc 2015-05-27 20:56:59 +0000
+++ shared/browser/oxide_browser_platform_integration.cc 2015-07-22 04:34:45 +0000
@@ -25,6 +25,8 @@
2525
26namespace {26namespace {
2727
28const char kDefaultApplicationName[] = "Oxide";
29
28BrowserPlatformIntegration* g_instance;30BrowserPlatformIntegration* g_instance;
2931
30}32}
@@ -74,6 +76,10 @@
74 return APPLICATION_STATE_ACTIVE;76 return APPLICATION_STATE_ACTIVE;
75}77}
7678
79std::string BrowserPlatformIntegration::GetApplicationName() {
80 return kDefaultApplicationName;
81}
82
77void BrowserPlatformIntegration::AddObserver(83void BrowserPlatformIntegration::AddObserver(
78 BrowserPlatformIntegrationObserver* observer) {84 BrowserPlatformIntegrationObserver* observer) {
79 observers_.AddObserver(observer);85 observers_.AddObserver(observer);
8086
=== modified file 'shared/browser/oxide_browser_platform_integration.h'
--- shared/browser/oxide_browser_platform_integration.h 2015-06-12 07:39:38 +0000
+++ shared/browser/oxide_browser_platform_integration.h 2015-07-22 04:34:45 +0000
@@ -18,6 +18,8 @@
18#ifndef _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_H_18#ifndef _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_H_
19#define _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_H_19#define _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_H_
2020
21#include <string>
22
21#include "base/macros.h"23#include "base/macros.h"
22#include "base/memory/scoped_ptr.h"24#include "base/memory/scoped_ptr.h"
23#include "base/observer_list.h"25#include "base/observer_list.h"
@@ -96,6 +98,9 @@
96 // Get the current application state98 // Get the current application state
97 virtual ApplicationState GetApplicationState();99 virtual ApplicationState GetApplicationState();
98100
101 // Get the application name
102 virtual std::string GetApplicationName();
103
99 protected:104 protected:
100 BrowserPlatformIntegration();105 BrowserPlatformIntegration();
101106
102107
=== modified file 'shared/browser/oxide_power_save_blocker.cc'
--- shared/browser/oxide_power_save_blocker.cc 2015-05-27 20:56:59 +0000
+++ shared/browser/oxide_power_save_blocker.cc 2015-07-22 04:34:45 +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.h"
34#include "oxide_browser_platform_integration_observer.h"35#include "oxide_browser_platform_integration_observer.h"
35#include "oxide_form_factor.h"36#include "oxide_form_factor.h"
3637
@@ -43,12 +44,18 @@
43const char kUnityScreenInterface[] = "com.canonical.Unity.Screen";44const char kUnityScreenInterface[] = "com.canonical.Unity.Screen";
44const int kInvalidCookie = -1;45const int kInvalidCookie = -1;
4546
47const char kFreeDesktopScreenSaverName[] = "org.freedesktop.ScreenSaver";
48const char kFreeDesktopScreenSaverPath[] = "/org/freedesktop/ScreenSaver";
49const char kFreeDestopScreenSaverInterface[] = "org.freedesktop.ScreenSaver";
50
51const char kDefaultInhibitReason[] = "Active Application";
52
46}53}
4754
48class PowerSaveBlocker : public content::PowerSaveBlockerOxideDelegate,55class PowerSaveBlocker : public content::PowerSaveBlockerOxideDelegate,
49 public BrowserPlatformIntegrationObserver {56 public BrowserPlatformIntegrationObserver {
50 public:57 public:
51 PowerSaveBlocker();58 PowerSaveBlocker(const std::string& description);
5259
53 private:60 private:
54 virtual ~PowerSaveBlocker() {}61 virtual ~PowerSaveBlocker() {}
@@ -59,12 +66,22 @@
59 void ApplyBlock();66 void ApplyBlock();
60 void RemoveBlock();67 void RemoveBlock();
6168
69 void ApplyBlockUnityScreenService();
70 void RemoveBlockUnityScreenService();
71
72 void ApplyBlockFreedesktop();
73 void RemoveBlockFreedesktop();
74
62 // BrowserPlatformIntegrationObserver implementation75 // BrowserPlatformIntegrationObserver implementation
63 void ApplicationStateChanged() final;76 void ApplicationStateChanged() final;
6477
65 oxide::FormFactor form_factor_;78 oxide::FormFactor form_factor_;
66 scoped_refptr<dbus::Bus> bus_;79 scoped_refptr<dbus::Bus> bus_;
67 int cookie_;80 union {
81 int32_t unity_cookie_;
82 uint32_t freedesktop_cookie_;
83 };
84 std::string description_;
68};85};
6986
70void PowerSaveBlocker::Init() {87void PowerSaveBlocker::Init() {
@@ -89,34 +106,9 @@
89106
90 if (form_factor_ == oxide::FORM_FACTOR_PHONE ||107 if (form_factor_ == oxide::FORM_FACTOR_PHONE ||
91 form_factor_ == oxide::FORM_FACTOR_TABLET) {108 form_factor_ == oxide::FORM_FACTOR_TABLET) {
92 DCHECK(!bus_.get());109 ApplyBlockUnityScreenService();
93 dbus::Bus::Options options;
94 options.bus_type = dbus::Bus::SYSTEM;
95 options.connection_type = dbus::Bus::PRIVATE;
96 bus_ = new dbus::Bus(options);
97
98 scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
99 kUnityScreenServiceName,
100 dbus::ObjectPath(kUnityScreenPath));
101 scoped_ptr<dbus::MethodCall> method_call;
102 method_call.reset(
103 new dbus::MethodCall(kUnityScreenInterface, "keepDisplayOn"));
104 scoped_ptr<dbus::MessageWriter> message_writer;
105 message_writer.reset(new dbus::MessageWriter(method_call.get()));
106
107 scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
108 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
109 if (response) {
110 dbus::MessageReader message_reader(response.get());
111 if (!message_reader.PopInt32(&cookie_)) {
112 LOG(ERROR) << "Invalid response for screen blanking inhibition request: "
113 << response->ToString();
114 }
115 } else {
116 LOG(ERROR) << "Failed to inhibit screen blanking";
117 }
118 } else {110 } else {
119 NOTIMPLEMENTED();111 ApplyBlockFreedesktop();
120 }112 }
121}113}
122114
@@ -125,27 +117,121 @@
125117
126 if (form_factor_ == oxide::FORM_FACTOR_PHONE ||118 if (form_factor_ == oxide::FORM_FACTOR_PHONE ||
127 form_factor_ == oxide::FORM_FACTOR_TABLET) {119 form_factor_ == oxide::FORM_FACTOR_TABLET) {
128 if (cookie_ != kInvalidCookie) {120 RemoveBlockUnityScreenService();
129 DCHECK(bus_.get());121 } else {
130 scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(122 RemoveBlockFreedesktop();
131 kUnityScreenServiceName,123 }
132 dbus::ObjectPath(kUnityScreenPath));124}
133 scoped_ptr<dbus::MethodCall> method_call;125
134 method_call.reset(126void PowerSaveBlocker::ApplyBlockUnityScreenService() {
135 new dbus::MethodCall(kUnityScreenInterface, "removeDisplayOnRequest"));127 DCHECK(!bus_.get());
136 dbus::MessageWriter message_writer(method_call.get());128 dbus::Bus::Options options;
137 message_writer.AppendInt32(cookie_);129 options.bus_type = dbus::Bus::SYSTEM;
138 object_proxy->CallMethodAndBlock(130 options.connection_type = dbus::Bus::PRIVATE;
139 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);131 bus_ = new dbus::Bus(options);
140 cookie_ = kInvalidCookie;132
141 }133 scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
142134 kUnityScreenServiceName,
143 if (bus_.get()) {135 dbus::ObjectPath(kUnityScreenPath));
144 bus_->ShutdownAndBlock();136 scoped_ptr<dbus::MethodCall> method_call;
145 bus_ = nullptr;137 method_call.reset(
146 }138 new dbus::MethodCall(kUnityScreenInterface, "keepDisplayOn"));
147 } else {139 scoped_ptr<dbus::MessageWriter> message_writer;
148 NOTIMPLEMENTED();140 message_writer.reset(new dbus::MessageWriter(method_call.get()));
141
142 scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
143 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
144 if (response) {
145 dbus::MessageReader message_reader(response.get());
146 if (!message_reader.PopInt32(&unity_cookie_)) {
147 LOG(ERROR) << "Invalid response for screen blanking inhibition request: "
148 << response->ToString();
149 }
150 } else {
151 LOG(ERROR) << "Failed to inhibit screen blanking";
152 }
153}
154
155void PowerSaveBlocker::RemoveBlockUnityScreenService() {
156 if (unity_cookie_ != kInvalidCookie) {
157 DCHECK(bus_.get());
158 scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
159 kUnityScreenServiceName,
160 dbus::ObjectPath(kUnityScreenPath));
161 scoped_ptr<dbus::MethodCall> method_call;
162 method_call.reset(
163 new dbus::MethodCall(kUnityScreenInterface, "removeDisplayOnRequest"));
164 dbus::MessageWriter message_writer(method_call.get());
165 message_writer.AppendInt32(unity_cookie_);
166 object_proxy->CallMethodAndBlock(
167 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
168 unity_cookie_ = kInvalidCookie;
169 }
170
171 if (bus_.get()) {
172 bus_->ShutdownAndBlock();
173 bus_ = nullptr;
174 }
175}
176
177void PowerSaveBlocker::ApplyBlockFreedesktop() {
178 std::string application_name =
179 BrowserPlatformIntegration::GetInstance()->GetApplicationName();
180 std::string description{kDefaultInhibitReason};
181
182 if (!description_.empty()) {
183 description = description_;
184 }
185
186 DCHECK(!bus_.get());
187 dbus::Bus::Options options;
188 options.bus_type = dbus::Bus::SESSION;
189 options.connection_type = dbus::Bus::PRIVATE;
190 bus_ = new dbus::Bus(options);
191
192 scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
193 kFreeDesktopScreenSaverName,
194 dbus::ObjectPath(kFreeDesktopScreenSaverPath));
195 scoped_ptr<dbus::MethodCall> method_call;
196 method_call.reset(
197 new dbus::MethodCall(kFreeDestopScreenSaverInterface, "Inhibit"));
198 scoped_ptr<dbus::MessageWriter> message_writer;
199 message_writer.reset(new dbus::MessageWriter(method_call.get()));
200 message_writer->AppendString(application_name);
201 message_writer->AppendString(description);
202
203 scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
204 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
205 if (response) {
206 dbus::MessageReader message_reader(response.get());
207 if (!message_reader.PopUint32(&freedesktop_cookie_)) {
208 LOG(ERROR) << "Invalid response for screen blanking inhibition request: "
209 << response->ToString();
210 }
211 } else {
212 LOG(ERROR) << "Failed to inhibit screen blanking";
213 }
214}
215
216void PowerSaveBlocker::RemoveBlockFreedesktop() {
217 if (freedesktop_cookie_ != uint32_t(kInvalidCookie)) {
218 DCHECK(bus_.get());
219 scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
220 kFreeDesktopScreenSaverName,
221 dbus::ObjectPath(kFreeDesktopScreenSaverPath));
222 scoped_ptr<dbus::MethodCall> method_call;
223 method_call.reset(
224 new dbus::MethodCall(kFreeDestopScreenSaverInterface, "UnInhibit"));
225 dbus::MessageWriter message_writer(method_call.get());
226 message_writer.AppendUint32(freedesktop_cookie_);
227 object_proxy->CallMethodAndBlock(
228 method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
229 freedesktop_cookie_ = kInvalidCookie;
230 }
231
232 if (bus_.get()) {
233 bus_->ShutdownAndBlock();
234 bus_ = nullptr;
149 }235 }
150}236}
151237
@@ -153,23 +239,25 @@
153 BrowserPlatformIntegration::ApplicationState state =239 BrowserPlatformIntegration::ApplicationState state =
154 BrowserPlatformIntegration::GetInstance()->GetApplicationState();240 BrowserPlatformIntegration::GetInstance()->GetApplicationState();
155 if (state != BrowserPlatformIntegration::APPLICATION_STATE_SUSPENDED &&241 if (state != BrowserPlatformIntegration::APPLICATION_STATE_SUSPENDED &&
156 cookie_ == kInvalidCookie) {242 unity_cookie_ == kInvalidCookie) {
157 Init();243 Init();
158 } else if (state == BrowserPlatformIntegration::APPLICATION_STATE_SUSPENDED &&244 } else if (state == BrowserPlatformIntegration::APPLICATION_STATE_SUSPENDED &&
159 cookie_ != kInvalidCookie) {245 unity_cookie_ != kInvalidCookie) {
160 CleanUp();246 CleanUp();
161 }247 }
162}248}
163249
164PowerSaveBlocker::PowerSaveBlocker()250PowerSaveBlocker::PowerSaveBlocker(const std::string& description)
165 : form_factor_(oxide::GetFormFactorHint())251 : form_factor_(oxide::GetFormFactorHint())
166 , cookie_(kInvalidCookie) {}252 , unity_cookie_(kInvalidCookie)
253 , description_(description)
254{}
167255
168content::PowerSaveBlockerOxideDelegate* CreatePowerSaveBlocker(256content::PowerSaveBlockerOxideDelegate* CreatePowerSaveBlocker(
169 content::PowerSaveBlocker::PowerSaveBlockerType type,257 content::PowerSaveBlocker::PowerSaveBlockerType type,
170 content::PowerSaveBlocker::Reason reason,258 content::PowerSaveBlocker::Reason reason,
171 const std::string& description) {259 const std::string& description) {
172 return new PowerSaveBlocker();260 return new PowerSaveBlocker(description);
173}261}
174262
175} // namespace oxide263} // namespace oxide

Subscribers

People subscribed via source and target branches