OLD | NEW |
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 "content/browser/power_save_blocker.h" | 5 #include "content/browser/power_save_blocker.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/environment.h" | 11 #include "base/environment.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/message_loop_proxy.h" | 17 #include "base/message_loop_proxy.h" |
18 #include "base/nix/xdg_util.h" | 18 #include "base/nix/xdg_util.h" |
19 #include "base/threading/platform_thread.h" | 19 #include "base/threading/platform_thread.h" |
20 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
21 #include "dbus/bus.h" | 21 #include "dbus/bus.h" |
22 #include "dbus/message.h" | 22 #include "dbus/message.h" |
| 23 #include "dbus/object_path.h" |
23 #include "dbus/object_proxy.h" | 24 #include "dbus/object_proxy.h" |
24 | 25 |
25 using content::BrowserThread; | 26 using content::BrowserThread; |
26 | 27 |
27 namespace { | 28 namespace { |
28 | 29 |
29 // This class is used to inhibit Power Management on Linux systems | 30 // This class is used to inhibit Power Management on Linux systems |
30 // using D-Bus interfaces. Mainly, there are two interfaces that | 31 // using D-Bus interfaces. Mainly, there are two interfaces that |
31 // make this possible. | 32 // make this possible. |
32 // org.freedesktop.PowerManagement[.Inhibit] is considered to be | 33 // org.freedesktop.PowerManagement[.Inhibit] is considered to be |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 return; | 130 return; |
130 } | 131 } |
131 } else if ((pending_inhibit_call_ && !postponed_uninhibit_call_) || | 132 } else if ((pending_inhibit_call_ && !postponed_uninhibit_call_) || |
132 inhibit_cookie_ > 0) { | 133 inhibit_cookie_ > 0) { |
133 return; | 134 return; |
134 } | 135 } |
135 | 136 |
136 scoped_refptr<dbus::ObjectProxy> object_proxy = | 137 scoped_refptr<dbus::ObjectProxy> object_proxy = |
137 DBusPowerSaveBlocker::GetInstance()->bus()->GetObjectProxy( | 138 DBusPowerSaveBlocker::GetInstance()->bus()->GetObjectProxy( |
138 "org.freedesktop.PowerManagement", | 139 "org.freedesktop.PowerManagement", |
139 "/org/freedesktop/PowerManagement/Inhibit"); | 140 dbus::ObjectPath("/org/freedesktop/PowerManagement/Inhibit")); |
140 dbus::MethodCall method_call("org.freedesktop.PowerManagement.Inhibit", | 141 dbus::MethodCall method_call("org.freedesktop.PowerManagement.Inhibit", |
141 "Inhibit"); | 142 "Inhibit"); |
142 dbus::MessageWriter message_writer(&method_call); | 143 dbus::MessageWriter message_writer(&method_call); |
143 base::Callback<void(dbus::Response*)> bus_callback; | 144 base::Callback<void(dbus::Response*)> bus_callback; |
144 | 145 |
145 switch (type) { | 146 switch (type) { |
146 case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: | 147 case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: |
147 case PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep: | 148 case PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep: |
148 // The org.freedesktop.PowerManagement.Inhibit interface offers only one | 149 // The org.freedesktop.PowerManagement.Inhibit interface offers only one |
149 // Inhibit() method, that temporarily disables all power management | 150 // Inhibit() method, that temporarily disables all power management |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 // we make an uninhibit request to cancel it now. | 278 // we make an uninhibit request to cancel it now. |
278 if (type != PowerSaveBlocker::kPowerSaveBlockPreventNone && | 279 if (type != PowerSaveBlocker::kPowerSaveBlockPreventNone && |
279 pending_inhibit_calls_ == 0 && | 280 pending_inhibit_calls_ == 0 && |
280 inhibit_cookie_ > 0) { | 281 inhibit_cookie_ > 0) { |
281 ApplyBlock(PowerSaveBlocker::kPowerSaveBlockPreventNone); | 282 ApplyBlock(PowerSaveBlocker::kPowerSaveBlockPreventNone); |
282 } | 283 } |
283 | 284 |
284 scoped_refptr<dbus::ObjectProxy> object_proxy = | 285 scoped_refptr<dbus::ObjectProxy> object_proxy = |
285 DBusPowerSaveBlocker::GetInstance()->bus()->GetObjectProxy( | 286 DBusPowerSaveBlocker::GetInstance()->bus()->GetObjectProxy( |
286 "org.gnome.SessionManager", | 287 "org.gnome.SessionManager", |
287 "/org/gnome/SessionManager"); | 288 dbus::ObjectPath("/org/gnome/SessionManager")); |
288 dbus::MethodCall method_call("org.gnome.SessionManager", "Inhibit"); | 289 dbus::MethodCall method_call("org.gnome.SessionManager", "Inhibit"); |
289 dbus::MessageWriter message_writer(&method_call); | 290 dbus::MessageWriter message_writer(&method_call); |
290 base::Callback<void(dbus::Response*)> bus_callback; | 291 base::Callback<void(dbus::Response*)> bus_callback; |
291 | 292 |
292 unsigned int flags = 0; | 293 unsigned int flags = 0; |
293 switch (type) { | 294 switch (type) { |
294 case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: | 295 case PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep: |
295 flags |= kInhibitMarkSessionAsIdle; | 296 flags |= kInhibitMarkSessionAsIdle; |
296 break; | 297 break; |
297 case PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep: | 298 case PowerSaveBlocker::kPowerSaveBlockPreventSystemSleep: |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 } | 457 } |
457 | 458 |
458 } // namespace | 459 } // namespace |
459 | 460 |
460 // Called only from UI thread. | 461 // Called only from UI thread. |
461 // static | 462 // static |
462 void PowerSaveBlocker::ApplyBlock(PowerSaveBlockerType type) { | 463 void PowerSaveBlocker::ApplyBlock(PowerSaveBlockerType type) { |
463 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 464 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
464 DBusPowerSaveBlocker::GetInstance()->ApplyBlock(type); | 465 DBusPowerSaveBlocker::GetInstance()->ApplyBlock(type); |
465 } | 466 } |
OLD | NEW |