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