| 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_impl.h" | |
| 6 | |
| 7 #include <X11/Xlib.h> | 5 #include <X11/Xlib.h> |
| 8 #include <stdint.h> | |
| 9 #include <X11/extensions/dpms.h> | 6 #include <X11/extensions/dpms.h> |
| 10 #include <X11/extensions/scrnsaver.h> | 7 #include <X11/extensions/scrnsaver.h> |
| 8 #include <stdint.h> |
| 9 |
| 10 #include <memory> |
| 11 |
| 12 #include "content/browser/power_save_blocker_impl.h" |
| 11 // 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. |
| 12 #ifdef Status | 14 #ifdef Status |
| 13 #undef Status | 15 #undef Status |
| 14 #endif | 16 #endif |
| 15 | 17 |
| 16 #include "base/bind.h" | 18 #include "base/bind.h" |
| 17 #include "base/callback.h" | 19 #include "base/callback.h" |
| 18 #include "base/command_line.h" | 20 #include "base/command_line.h" |
| 19 #include "base/environment.h" | 21 #include "base/environment.h" |
| 20 #include "base/files/file_path.h" | 22 #include "base/files/file_path.h" |
| 21 #include "base/logging.h" | 23 #include "base/logging.h" |
| 22 #include "base/macros.h" | 24 #include "base/macros.h" |
| 23 #include "base/memory/ref_counted.h" | 25 #include "base/memory/ref_counted.h" |
| 24 #include "base/memory/scoped_ptr.h" | |
| 25 #include "base/memory/singleton.h" | 26 #include "base/memory/singleton.h" |
| 26 #include "base/nix/xdg_util.h" | 27 #include "base/nix/xdg_util.h" |
| 27 #include "base/synchronization/lock.h" | 28 #include "base/synchronization/lock.h" |
| 28 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 29 #include "dbus/bus.h" | 30 #include "dbus/bus.h" |
| 30 #include "dbus/message.h" | 31 #include "dbus/message.h" |
| 31 #include "dbus/object_path.h" | 32 #include "dbus/object_path.h" |
| 32 #include "dbus/object_proxy.h" | 33 #include "dbus/object_proxy.h" |
| 33 #include "ui/gfx/x/x11_types.h" | 34 #include "ui/gfx/x/x11_types.h" |
| 34 | 35 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 230 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 230 DCHECK(!bus_); // ApplyBlock() should only be called once. | 231 DCHECK(!bus_); // ApplyBlock() should only be called once. |
| 231 DCHECK(!block_inflight_); | 232 DCHECK(!block_inflight_); |
| 232 | 233 |
| 233 dbus::Bus::Options options; | 234 dbus::Bus::Options options; |
| 234 options.bus_type = dbus::Bus::SESSION; | 235 options.bus_type = dbus::Bus::SESSION; |
| 235 options.connection_type = dbus::Bus::PRIVATE; | 236 options.connection_type = dbus::Bus::PRIVATE; |
| 236 bus_ = new dbus::Bus(options); | 237 bus_ = new dbus::Bus(options); |
| 237 | 238 |
| 238 scoped_refptr<dbus::ObjectProxy> object_proxy; | 239 scoped_refptr<dbus::ObjectProxy> object_proxy; |
| 239 scoped_ptr<dbus::MethodCall> method_call; | 240 std::unique_ptr<dbus::MethodCall> method_call; |
| 240 scoped_ptr<dbus::MessageWriter> message_writer; | 241 std::unique_ptr<dbus::MessageWriter> message_writer; |
| 241 | 242 |
| 242 switch (api_) { | 243 switch (api_) { |
| 243 case NO_API: | 244 case NO_API: |
| 244 NOTREACHED(); // We should never call this method with this value. | 245 NOTREACHED(); // We should never call this method with this value. |
| 245 return; | 246 return; |
| 246 case GNOME_API: | 247 case GNOME_API: |
| 247 object_proxy = bus_->GetObjectProxy( | 248 object_proxy = bus_->GetObjectProxy( |
| 248 kGnomeAPIServiceName, | 249 kGnomeAPIServiceName, |
| 249 dbus::ObjectPath(kGnomeAPIObjectPath)); | 250 dbus::ObjectPath(kGnomeAPIObjectPath)); |
| 250 method_call.reset( | 251 method_call.reset( |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 341 |
| 341 if (block_inflight_) { | 342 if (block_inflight_) { |
| 342 DCHECK(!enqueue_unblock_); | 343 DCHECK(!enqueue_unblock_); |
| 343 // Can't call RemoveBlock until ApplyBlock's async operation has | 344 // Can't call RemoveBlock until ApplyBlock's async operation has |
| 344 // finished. Enqueue it for execution once ApplyBlock is done. | 345 // finished. Enqueue it for execution once ApplyBlock is done. |
| 345 enqueue_unblock_ = true; | 346 enqueue_unblock_ = true; |
| 346 return; | 347 return; |
| 347 } | 348 } |
| 348 | 349 |
| 349 scoped_refptr<dbus::ObjectProxy> object_proxy; | 350 scoped_refptr<dbus::ObjectProxy> object_proxy; |
| 350 scoped_ptr<dbus::MethodCall> method_call; | 351 std::unique_ptr<dbus::MethodCall> method_call; |
| 351 | 352 |
| 352 switch (api_) { | 353 switch (api_) { |
| 353 case NO_API: | 354 case NO_API: |
| 354 NOTREACHED(); // We should never call this method with this value. | 355 NOTREACHED(); // We should never call this method with this value. |
| 355 return; | 356 return; |
| 356 case GNOME_API: | 357 case GNOME_API: |
| 357 object_proxy = bus_->GetObjectProxy( | 358 object_proxy = bus_->GetObjectProxy( |
| 358 kGnomeAPIServiceName, | 359 kGnomeAPIServiceName, |
| 359 dbus::ObjectPath(kGnomeAPIObjectPath)); | 360 dbus::ObjectPath(kGnomeAPIObjectPath)); |
| 360 method_call.reset( | 361 method_call.reset( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 | 442 |
| 442 if (!XScreenSaverQueryVersion(display, &major, &minor)) | 443 if (!XScreenSaverQueryVersion(display, &major, &minor)) |
| 443 return false; | 444 return false; |
| 444 | 445 |
| 445 return major > 1 || (major == 1 && minor >= 1); | 446 return major > 1 || (major == 1 && minor >= 1); |
| 446 } | 447 } |
| 447 | 448 |
| 448 // static | 449 // static |
| 449 DBusAPI PowerSaveBlockerImpl::Delegate::SelectAPI() { | 450 DBusAPI PowerSaveBlockerImpl::Delegate::SelectAPI() { |
| 450 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 451 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 451 scoped_ptr<base::Environment> env(base::Environment::Create()); | 452 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 452 switch (base::nix::GetDesktopEnvironment(env.get())) { | 453 switch (base::nix::GetDesktopEnvironment(env.get())) { |
| 453 case base::nix::DESKTOP_ENVIRONMENT_GNOME: | 454 case base::nix::DESKTOP_ENVIRONMENT_GNOME: |
| 454 case base::nix::DESKTOP_ENVIRONMENT_UNITY: | 455 case base::nix::DESKTOP_ENVIRONMENT_UNITY: |
| 455 if (DPMSEnabled()) | 456 if (DPMSEnabled()) |
| 456 return GNOME_API; | 457 return GNOME_API; |
| 457 break; | 458 break; |
| 458 case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 459 case base::nix::DESKTOP_ENVIRONMENT_XFCE: |
| 459 case base::nix::DESKTOP_ENVIRONMENT_KDE4: | 460 case base::nix::DESKTOP_ENVIRONMENT_KDE4: |
| 460 case base::nix::DESKTOP_ENVIRONMENT_KDE5: | 461 case base::nix::DESKTOP_ENVIRONMENT_KDE5: |
| 461 if (DPMSEnabled()) | 462 if (DPMSEnabled()) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 483 } | 484 } |
| 484 } | 485 } |
| 485 | 486 |
| 486 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { | 487 PowerSaveBlockerImpl::~PowerSaveBlockerImpl() { |
| 487 delegate_->CleanUp(); | 488 delegate_->CleanUp(); |
| 488 if (freedesktop_suspend_delegate_) | 489 if (freedesktop_suspend_delegate_) |
| 489 freedesktop_suspend_delegate_->CleanUp(); | 490 freedesktop_suspend_delegate_->CleanUp(); |
| 490 } | 491 } |
| 491 | 492 |
| 492 } // namespace content | 493 } // namespace content |
| OLD | NEW |