Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(135)

Side by Side Diff: device/power_save_blocker/power_save_blocker_x11.cc

Issue 2075153002: Reland of 'Move content/browser/power_save_blocker to //device/power_save_blocker' (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing libs for component mac Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « device/power_save_blocker/power_save_blocker_win.cc ('k') | device/test/run_all_unittests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <X11/Xlib.h> 5 #include <X11/Xlib.h>
6 #include <X11/extensions/dpms.h> 6 #include <X11/extensions/dpms.h>
7 #include <X11/extensions/scrnsaver.h> 7 #include <X11/extensions/scrnsaver.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "content/browser/power_save_blocker_impl.h" 12 #include "device/power_save_blocker/power_save_blocker_impl.h"
13 // Xlib #defines Status, but we can't have that for some of our headers. 13 // Xlib #defines Status, but we can't have that for some of our headers.
14 #ifdef Status 14 #ifdef Status
15 #undef Status 15 #undef Status
16 #endif 16 #endif
17 17
18 #include "base/bind.h" 18 #include "base/bind.h"
19 #include "base/callback.h" 19 #include "base/callback.h"
20 #include "base/command_line.h" 20 #include "base/command_line.h"
21 #include "base/environment.h" 21 #include "base/environment.h"
22 #include "base/files/file_path.h" 22 #include "base/files/file_path.h"
(...skipping 15 matching lines...) Expand all
38 enum DBusAPI { 38 enum DBusAPI {
39 NO_API, // Disable. No supported API available. 39 NO_API, // Disable. No supported API available.
40 GNOME_API, // Use the GNOME API. (Supports more features.) 40 GNOME_API, // Use the GNOME API. (Supports more features.)
41 FREEDESKTOP_API, // Use the FreeDesktop API, for KDE4, KDE5, and XFCE. 41 FREEDESKTOP_API, // Use the FreeDesktop API, for KDE4, KDE5, and XFCE.
42 }; 42 };
43 43
44 // Inhibit flags defined in the org.gnome.SessionManager interface. 44 // Inhibit flags defined in the org.gnome.SessionManager interface.
45 // Can be OR'd together and passed as argument to the Inhibit() method 45 // Can be OR'd together and passed as argument to the Inhibit() method
46 // to specify which power management features we want to suspend. 46 // to specify which power management features we want to suspend.
47 enum GnomeAPIInhibitFlags { 47 enum GnomeAPIInhibitFlags {
48 INHIBIT_LOGOUT = 1, 48 INHIBIT_LOGOUT = 1,
49 INHIBIT_SWITCH_USER = 2, 49 INHIBIT_SWITCH_USER = 2,
50 INHIBIT_SUSPEND_SESSION = 4, 50 INHIBIT_SUSPEND_SESSION = 4,
51 INHIBIT_MARK_SESSION_IDLE = 8 51 INHIBIT_MARK_SESSION_IDLE = 8
52 }; 52 };
53 53
54 const char kGnomeAPIServiceName[] = "org.gnome.SessionManager"; 54 const char kGnomeAPIServiceName[] = "org.gnome.SessionManager";
55 const char kGnomeAPIInterfaceName[] = "org.gnome.SessionManager"; 55 const char kGnomeAPIInterfaceName[] = "org.gnome.SessionManager";
56 const char kGnomeAPIObjectPath[] = "/org/gnome/SessionManager"; 56 const char kGnomeAPIObjectPath[] = "/org/gnome/SessionManager";
57 57
58 const char kFreeDesktopAPIPowerServiceName[] = 58 const char kFreeDesktopAPIPowerServiceName[] =
59 "org.freedesktop.PowerManagement"; 59 "org.freedesktop.PowerManagement";
60 const char kFreeDesktopAPIPowerInterfaceName[] = 60 const char kFreeDesktopAPIPowerInterfaceName[] =
61 "org.freedesktop.PowerManagement.Inhibit"; 61 "org.freedesktop.PowerManagement.Inhibit";
62 const char kFreeDesktopAPIPowerObjectPath[] = 62 const char kFreeDesktopAPIPowerObjectPath[] =
63 "/org/freedesktop/PowerManagement/Inhibit"; 63 "/org/freedesktop/PowerManagement/Inhibit";
64 64
65 const char kFreeDesktopAPIScreenServiceName[] = "org.freedesktop.ScreenSaver"; 65 const char kFreeDesktopAPIScreenServiceName[] = "org.freedesktop.ScreenSaver";
66 const char kFreeDesktopAPIScreenInterfaceName[] = "org.freedesktop.ScreenSaver"; 66 const char kFreeDesktopAPIScreenInterfaceName[] = "org.freedesktop.ScreenSaver";
67 const char kFreeDesktopAPIScreenObjectPath[] = "/org/freedesktop/ScreenSaver"; 67 const char kFreeDesktopAPIScreenObjectPath[] = "/org/freedesktop/ScreenSaver";
68 68
69 } // namespace 69 } // namespace
70 70
71 namespace content { 71 namespace device {
72 72
73 class PowerSaveBlockerImpl::Delegate 73 class PowerSaveBlockerImpl::Delegate
74 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> { 74 : public base::RefCountedThreadSafe<PowerSaveBlockerImpl::Delegate> {
75 public: 75 public:
76 // Picks an appropriate D-Bus API to use based on the desktop environment. 76 // Picks an appropriate D-Bus API to use based on the desktop environment.
77 Delegate(PowerSaveBlockerType type, 77 Delegate(PowerSaveBlockerType type,
78 const std::string& description, 78 const std::string& description,
79 bool freedesktop_only, 79 bool freedesktop_only,
80 scoped_refptr<base::SequencedTaskRunner> ui_task_runner, 80 scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
81 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner); 81 scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 scoped_refptr<dbus::ObjectProxy> object_proxy; 249 scoped_refptr<dbus::ObjectProxy> object_proxy;
250 std::unique_ptr<dbus::MethodCall> method_call; 250 std::unique_ptr<dbus::MethodCall> method_call;
251 std::unique_ptr<dbus::MessageWriter> message_writer; 251 std::unique_ptr<dbus::MessageWriter> message_writer;
252 252
253 switch (api_) { 253 switch (api_) {
254 case NO_API: 254 case NO_API:
255 NOTREACHED(); // We should never call this method with this value. 255 NOTREACHED(); // We should never call this method with this value.
256 return; 256 return;
257 case GNOME_API: 257 case GNOME_API:
258 object_proxy = bus_->GetObjectProxy( 258 object_proxy = bus_->GetObjectProxy(
259 kGnomeAPIServiceName, 259 kGnomeAPIServiceName, dbus::ObjectPath(kGnomeAPIObjectPath));
260 dbus::ObjectPath(kGnomeAPIObjectPath));
261 method_call.reset( 260 method_call.reset(
262 new dbus::MethodCall(kGnomeAPIInterfaceName, "Inhibit")); 261 new dbus::MethodCall(kGnomeAPIInterfaceName, "Inhibit"));
263 message_writer.reset(new dbus::MessageWriter(method_call.get())); 262 message_writer.reset(new dbus::MessageWriter(method_call.get()));
264 // The arguments of the method are: 263 // The arguments of the method are:
265 // app_id: The application identifier 264 // app_id: The application identifier
266 // toplevel_xid: The toplevel X window identifier 265 // toplevel_xid: The toplevel X window identifier
267 // reason: The reason for the inhibit 266 // reason: The reason for the inhibit
268 // flags: Flags that spefify what should be inhibited 267 // flags: Flags that spefify what should be inhibited
269 message_writer->AppendString( 268 message_writer->AppendString(
270 base::CommandLine::ForCurrentProcess()->GetProgram().value()); 269 base::CommandLine::ForCurrentProcess()->GetProgram().value());
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 358
360 scoped_refptr<dbus::ObjectProxy> object_proxy; 359 scoped_refptr<dbus::ObjectProxy> object_proxy;
361 std::unique_ptr<dbus::MethodCall> method_call; 360 std::unique_ptr<dbus::MethodCall> method_call;
362 361
363 switch (api_) { 362 switch (api_) {
364 case NO_API: 363 case NO_API:
365 NOTREACHED(); // We should never call this method with this value. 364 NOTREACHED(); // We should never call this method with this value.
366 return; 365 return;
367 case GNOME_API: 366 case GNOME_API:
368 object_proxy = bus_->GetObjectProxy( 367 object_proxy = bus_->GetObjectProxy(
369 kGnomeAPIServiceName, 368 kGnomeAPIServiceName, dbus::ObjectPath(kGnomeAPIObjectPath));
370 dbus::ObjectPath(kGnomeAPIObjectPath));
371 method_call.reset( 369 method_call.reset(
372 new dbus::MethodCall(kGnomeAPIInterfaceName, "Uninhibit")); 370 new dbus::MethodCall(kGnomeAPIInterfaceName, "Uninhibit"));
373 break; 371 break;
374 case FREEDESKTOP_API: 372 case FREEDESKTOP_API:
375 switch (type_) { 373 switch (type_) {
376 case kPowerSaveBlockPreventDisplaySleep: 374 case kPowerSaveBlockPreventDisplaySleep:
377 object_proxy = bus_->GetObjectProxy( 375 object_proxy = bus_->GetObjectProxy(
378 kFreeDesktopAPIScreenServiceName, 376 kFreeDesktopAPIScreenServiceName,
379 dbus::ObjectPath(kFreeDesktopAPIScreenObjectPath)); 377 dbus::ObjectPath(kFreeDesktopAPIScreenObjectPath));
380 method_call.reset(new dbus::MethodCall( 378 method_call.reset(new dbus::MethodCall(
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 freedesktop_suspend_delegate_->Init(); 496 freedesktop_suspend_delegate_->Init();
499 } 497 }
500 } 498 }
501 499
502 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { 500 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() {
503 delegate_->CleanUp(); 501 delegate_->CleanUp();
504 if (freedesktop_suspend_delegate_) 502 if (freedesktop_suspend_delegate_)
505 freedesktop_suspend_delegate_->CleanUp(); 503 freedesktop_suspend_delegate_->CleanUp();
506 } 504 }
507 505
508 } // namespace content 506 } // namespace device
OLDNEW
« no previous file with comments | « device/power_save_blocker/power_save_blocker_win.cc ('k') | device/test/run_all_unittests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698