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

Proposed by Justin McPherson on 2015-07-07
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 2015-07-07 Approve on 2015-07-27
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 on 2015-07-09
1162. By Justin McPherson on 2015-07-09

Be more specific about type

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 on 2015-07-22
1163. By Justin McPherson on 2015-07-22

Merge from trunk.

1164. By Justin McPherson on 2015-07-22

Results of review.

1165. By Justin McPherson on 2015-07-22

Remove unnecessary header include.

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 2015-06-22 23:56:59 +0000
3+++ qt/core/browser/oxide_qt_browser_platform_integration.cc 2015-07-22 04:34:45 +0000
4@@ -162,6 +162,10 @@
5 return state_;
6 }
7
8+std::string BrowserPlatformIntegration::GetApplicationName() {
9+ return qApp->applicationName().toStdString();
10+}
11+
12 bool BrowserPlatformIntegration::eventFilter(QObject* watched, QEvent* event) {
13 if (event->type() == QEvent::ApplicationActivate ||
14 event->type() == QEvent::ApplicationDeactivate) {
15
16=== modified file 'qt/core/browser/oxide_qt_browser_platform_integration.h'
17--- qt/core/browser/oxide_qt_browser_platform_integration.h 2015-06-12 07:39:38 +0000
18+++ qt/core/browser/oxide_qt_browser_platform_integration.h 2015-07-22 04:34:45 +0000
19@@ -57,6 +57,7 @@
20 void BrowserThreadInit(content::BrowserThread::ID id) override;
21 content::LocationProvider* CreateLocationProvider() override;
22 ApplicationState GetApplicationState() override;
23+ std::string GetApplicationName() override;
24 ui::ClipboardOxideFactory GetClipboardOxideFactory() override;
25
26 // QObject implementation
27
28=== modified file 'shared/browser/oxide_browser_platform_integration.cc'
29--- shared/browser/oxide_browser_platform_integration.cc 2015-05-27 20:56:59 +0000
30+++ shared/browser/oxide_browser_platform_integration.cc 2015-07-22 04:34:45 +0000
31@@ -25,6 +25,8 @@
32
33 namespace {
34
35+const char kDefaultApplicationName[] = "Oxide";
36+
37 BrowserPlatformIntegration* g_instance;
38
39 }
40@@ -74,6 +76,10 @@
41 return APPLICATION_STATE_ACTIVE;
42 }
43
44+std::string BrowserPlatformIntegration::GetApplicationName() {
45+ return kDefaultApplicationName;
46+}
47+
48 void BrowserPlatformIntegration::AddObserver(
49 BrowserPlatformIntegrationObserver* observer) {
50 observers_.AddObserver(observer);
51
52=== modified file 'shared/browser/oxide_browser_platform_integration.h'
53--- shared/browser/oxide_browser_platform_integration.h 2015-06-12 07:39:38 +0000
54+++ shared/browser/oxide_browser_platform_integration.h 2015-07-22 04:34:45 +0000
55@@ -18,6 +18,8 @@
56 #ifndef _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_H_
57 #define _OXIDE_SHARED_BROWSER_PLATFORM_INTEGRATION_H_
58
59+#include <string>
60+
61 #include "base/macros.h"
62 #include "base/memory/scoped_ptr.h"
63 #include "base/observer_list.h"
64@@ -96,6 +98,9 @@
65 // Get the current application state
66 virtual ApplicationState GetApplicationState();
67
68+ // Get the application name
69+ virtual std::string GetApplicationName();
70+
71 protected:
72 BrowserPlatformIntegration();
73
74
75=== modified file 'shared/browser/oxide_power_save_blocker.cc'
76--- shared/browser/oxide_power_save_blocker.cc 2015-05-27 20:56:59 +0000
77+++ shared/browser/oxide_power_save_blocker.cc 2015-07-22 04:34:45 +0000
78@@ -31,6 +31,7 @@
79
80 #include "shared/port/content/browser/power_save_blocker_oxide.h"
81
82+#include "oxide_browser_platform_integration.h"
83 #include "oxide_browser_platform_integration_observer.h"
84 #include "oxide_form_factor.h"
85
86@@ -43,12 +44,18 @@
87 const char kUnityScreenInterface[] = "com.canonical.Unity.Screen";
88 const int kInvalidCookie = -1;
89
90+const char kFreeDesktopScreenSaverName[] = "org.freedesktop.ScreenSaver";
91+const char kFreeDesktopScreenSaverPath[] = "/org/freedesktop/ScreenSaver";
92+const char kFreeDestopScreenSaverInterface[] = "org.freedesktop.ScreenSaver";
93+
94+const char kDefaultInhibitReason[] = "Active Application";
95+
96 }
97
98 class PowerSaveBlocker : public content::PowerSaveBlockerOxideDelegate,
99 public BrowserPlatformIntegrationObserver {
100 public:
101- PowerSaveBlocker();
102+ PowerSaveBlocker(const std::string& description);
103
104 private:
105 virtual ~PowerSaveBlocker() {}
106@@ -59,12 +66,22 @@
107 void ApplyBlock();
108 void RemoveBlock();
109
110+ void ApplyBlockUnityScreenService();
111+ void RemoveBlockUnityScreenService();
112+
113+ void ApplyBlockFreedesktop();
114+ void RemoveBlockFreedesktop();
115+
116 // BrowserPlatformIntegrationObserver implementation
117 void ApplicationStateChanged() final;
118
119 oxide::FormFactor form_factor_;
120 scoped_refptr<dbus::Bus> bus_;
121- int cookie_;
122+ union {
123+ int32_t unity_cookie_;
124+ uint32_t freedesktop_cookie_;
125+ };
126+ std::string description_;
127 };
128
129 void PowerSaveBlocker::Init() {
130@@ -89,34 +106,9 @@
131
132 if (form_factor_ == oxide::FORM_FACTOR_PHONE ||
133 form_factor_ == oxide::FORM_FACTOR_TABLET) {
134- DCHECK(!bus_.get());
135- dbus::Bus::Options options;
136- options.bus_type = dbus::Bus::SYSTEM;
137- options.connection_type = dbus::Bus::PRIVATE;
138- bus_ = new dbus::Bus(options);
139-
140- scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
141- kUnityScreenServiceName,
142- dbus::ObjectPath(kUnityScreenPath));
143- scoped_ptr<dbus::MethodCall> method_call;
144- method_call.reset(
145- new dbus::MethodCall(kUnityScreenInterface, "keepDisplayOn"));
146- scoped_ptr<dbus::MessageWriter> message_writer;
147- message_writer.reset(new dbus::MessageWriter(method_call.get()));
148-
149- scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
150- method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
151- if (response) {
152- dbus::MessageReader message_reader(response.get());
153- if (!message_reader.PopInt32(&cookie_)) {
154- LOG(ERROR) << "Invalid response for screen blanking inhibition request: "
155- << response->ToString();
156- }
157- } else {
158- LOG(ERROR) << "Failed to inhibit screen blanking";
159- }
160+ ApplyBlockUnityScreenService();
161 } else {
162- NOTIMPLEMENTED();
163+ ApplyBlockFreedesktop();
164 }
165 }
166
167@@ -125,27 +117,121 @@
168
169 if (form_factor_ == oxide::FORM_FACTOR_PHONE ||
170 form_factor_ == oxide::FORM_FACTOR_TABLET) {
171- if (cookie_ != kInvalidCookie) {
172- DCHECK(bus_.get());
173- scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
174- kUnityScreenServiceName,
175- dbus::ObjectPath(kUnityScreenPath));
176- scoped_ptr<dbus::MethodCall> method_call;
177- method_call.reset(
178- new dbus::MethodCall(kUnityScreenInterface, "removeDisplayOnRequest"));
179- dbus::MessageWriter message_writer(method_call.get());
180- message_writer.AppendInt32(cookie_);
181- object_proxy->CallMethodAndBlock(
182- method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
183- cookie_ = kInvalidCookie;
184- }
185-
186- if (bus_.get()) {
187- bus_->ShutdownAndBlock();
188- bus_ = nullptr;
189- }
190- } else {
191- NOTIMPLEMENTED();
192+ RemoveBlockUnityScreenService();
193+ } else {
194+ RemoveBlockFreedesktop();
195+ }
196+}
197+
198+void PowerSaveBlocker::ApplyBlockUnityScreenService() {
199+ DCHECK(!bus_.get());
200+ dbus::Bus::Options options;
201+ options.bus_type = dbus::Bus::SYSTEM;
202+ options.connection_type = dbus::Bus::PRIVATE;
203+ bus_ = new dbus::Bus(options);
204+
205+ scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
206+ kUnityScreenServiceName,
207+ dbus::ObjectPath(kUnityScreenPath));
208+ scoped_ptr<dbus::MethodCall> method_call;
209+ method_call.reset(
210+ new dbus::MethodCall(kUnityScreenInterface, "keepDisplayOn"));
211+ scoped_ptr<dbus::MessageWriter> message_writer;
212+ message_writer.reset(new dbus::MessageWriter(method_call.get()));
213+
214+ scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
215+ method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
216+ if (response) {
217+ dbus::MessageReader message_reader(response.get());
218+ if (!message_reader.PopInt32(&unity_cookie_)) {
219+ LOG(ERROR) << "Invalid response for screen blanking inhibition request: "
220+ << response->ToString();
221+ }
222+ } else {
223+ LOG(ERROR) << "Failed to inhibit screen blanking";
224+ }
225+}
226+
227+void PowerSaveBlocker::RemoveBlockUnityScreenService() {
228+ if (unity_cookie_ != kInvalidCookie) {
229+ DCHECK(bus_.get());
230+ scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
231+ kUnityScreenServiceName,
232+ dbus::ObjectPath(kUnityScreenPath));
233+ scoped_ptr<dbus::MethodCall> method_call;
234+ method_call.reset(
235+ new dbus::MethodCall(kUnityScreenInterface, "removeDisplayOnRequest"));
236+ dbus::MessageWriter message_writer(method_call.get());
237+ message_writer.AppendInt32(unity_cookie_);
238+ object_proxy->CallMethodAndBlock(
239+ method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
240+ unity_cookie_ = kInvalidCookie;
241+ }
242+
243+ if (bus_.get()) {
244+ bus_->ShutdownAndBlock();
245+ bus_ = nullptr;
246+ }
247+}
248+
249+void PowerSaveBlocker::ApplyBlockFreedesktop() {
250+ std::string application_name =
251+ BrowserPlatformIntegration::GetInstance()->GetApplicationName();
252+ std::string description{kDefaultInhibitReason};
253+
254+ if (!description_.empty()) {
255+ description = description_;
256+ }
257+
258+ DCHECK(!bus_.get());
259+ dbus::Bus::Options options;
260+ options.bus_type = dbus::Bus::SESSION;
261+ options.connection_type = dbus::Bus::PRIVATE;
262+ bus_ = new dbus::Bus(options);
263+
264+ scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
265+ kFreeDesktopScreenSaverName,
266+ dbus::ObjectPath(kFreeDesktopScreenSaverPath));
267+ scoped_ptr<dbus::MethodCall> method_call;
268+ method_call.reset(
269+ new dbus::MethodCall(kFreeDestopScreenSaverInterface, "Inhibit"));
270+ scoped_ptr<dbus::MessageWriter> message_writer;
271+ message_writer.reset(new dbus::MessageWriter(method_call.get()));
272+ message_writer->AppendString(application_name);
273+ message_writer->AppendString(description);
274+
275+ scoped_ptr<dbus::Response> response(object_proxy->CallMethodAndBlock(
276+ method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT));
277+ if (response) {
278+ dbus::MessageReader message_reader(response.get());
279+ if (!message_reader.PopUint32(&freedesktop_cookie_)) {
280+ LOG(ERROR) << "Invalid response for screen blanking inhibition request: "
281+ << response->ToString();
282+ }
283+ } else {
284+ LOG(ERROR) << "Failed to inhibit screen blanking";
285+ }
286+}
287+
288+void PowerSaveBlocker::RemoveBlockFreedesktop() {
289+ if (freedesktop_cookie_ != uint32_t(kInvalidCookie)) {
290+ DCHECK(bus_.get());
291+ scoped_refptr<dbus::ObjectProxy> object_proxy = bus_->GetObjectProxy(
292+ kFreeDesktopScreenSaverName,
293+ dbus::ObjectPath(kFreeDesktopScreenSaverPath));
294+ scoped_ptr<dbus::MethodCall> method_call;
295+ method_call.reset(
296+ new dbus::MethodCall(kFreeDestopScreenSaverInterface, "UnInhibit"));
297+ dbus::MessageWriter message_writer(method_call.get());
298+ message_writer.AppendUint32(freedesktop_cookie_);
299+ object_proxy->CallMethodAndBlock(
300+ method_call.get(), dbus::ObjectProxy::TIMEOUT_USE_DEFAULT);
301+ freedesktop_cookie_ = kInvalidCookie;
302+ }
303+
304+ if (bus_.get()) {
305+ bus_->ShutdownAndBlock();
306+ bus_ = nullptr;
307 }
308 }
309
310@@ -153,23 +239,25 @@
311 BrowserPlatformIntegration::ApplicationState state =
312 BrowserPlatformIntegration::GetInstance()->GetApplicationState();
313 if (state != BrowserPlatformIntegration::APPLICATION_STATE_SUSPENDED &&
314- cookie_ == kInvalidCookie) {
315+ unity_cookie_ == kInvalidCookie) {
316 Init();
317 } else if (state == BrowserPlatformIntegration::APPLICATION_STATE_SUSPENDED &&
318- cookie_ != kInvalidCookie) {
319+ unity_cookie_ != kInvalidCookie) {
320 CleanUp();
321 }
322 }
323
324-PowerSaveBlocker::PowerSaveBlocker()
325+PowerSaveBlocker::PowerSaveBlocker(const std::string& description)
326 : form_factor_(oxide::GetFormFactorHint())
327- , cookie_(kInvalidCookie) {}
328+ , unity_cookie_(kInvalidCookie)
329+ , description_(description)
330+{}
331
332 content::PowerSaveBlockerOxideDelegate* CreatePowerSaveBlocker(
333 content::PowerSaveBlocker::PowerSaveBlockerType type,
334 content::PowerSaveBlocker::Reason reason,
335 const std::string& description) {
336- return new PowerSaveBlocker();
337+ return new PowerSaveBlocker(description);
338 }
339
340 } // namespace oxide

Subscribers

People subscribed via source and target branches