| 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 <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> |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "base/logging.h" | 25 #include "base/logging.h" |
| 26 #include "base/macros.h" | 26 #include "base/macros.h" |
| 27 #include "base/memory/ref_counted.h" | 27 #include "base/memory/ref_counted.h" |
| 28 #include "base/memory/singleton.h" | 28 #include "base/memory/singleton.h" |
| 29 #include "base/nix/xdg_util.h" | 29 #include "base/nix/xdg_util.h" |
| 30 #include "base/synchronization/lock.h" | 30 #include "base/synchronization/lock.h" |
| 31 #include "dbus/bus.h" | 31 #include "dbus/bus.h" |
| 32 #include "dbus/message.h" | 32 #include "dbus/message.h" |
| 33 #include "dbus/object_path.h" | 33 #include "dbus/object_path.h" |
| 34 #include "dbus/object_proxy.h" | 34 #include "dbus/object_proxy.h" |
| 35 #include "ui/gfx/switches.h" |
| 35 #include "ui/gfx/x/x11_types.h" | 36 #include "ui/gfx/x/x11_types.h" |
| 36 | 37 |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| 39 enum DBusAPI { | 40 enum DBusAPI { |
| 40 NO_API, // Disable. No supported API available. | 41 NO_API, // Disable. No supported API available. |
| 41 GNOME_API, // Use the GNOME API. (Supports more features.) | 42 GNOME_API, // Use the GNOME API. (Supports more features.) |
| 42 FREEDESKTOP_API, // Use the FreeDesktop API, for KDE4, KDE5, and XFCE. | 43 FREEDESKTOP_API, // Use the FreeDesktop API, for KDE4, KDE5, and XFCE. |
| 43 }; | 44 }; |
| 44 | 45 |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 int dummy; | 430 int dummy; |
| 430 if (DPMSQueryExtension(display, &dummy, &dummy) && DPMSCapable(display)) { | 431 if (DPMSQueryExtension(display, &dummy, &dummy) && DPMSCapable(display)) { |
| 431 CARD16 state; | 432 CARD16 state; |
| 432 DPMSInfo(display, &state, &enabled); | 433 DPMSInfo(display, &state, &enabled); |
| 433 } | 434 } |
| 434 return enabled; | 435 return enabled; |
| 435 } | 436 } |
| 436 | 437 |
| 437 bool PowerSaveBlocker::Delegate::XSSAvailable() { | 438 bool PowerSaveBlocker::Delegate::XSSAvailable() { |
| 438 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 439 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 440 // X Screen Saver isn't accessible in headless mode. |
| 441 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless)) |
| 442 return false; |
| 439 XDisplay* display = gfx::GetXDisplay(); | 443 XDisplay* display = gfx::GetXDisplay(); |
| 440 int dummy; | 444 int dummy; |
| 441 int major; | 445 int major; |
| 442 int minor; | 446 int minor; |
| 443 | 447 |
| 444 if (!XScreenSaverQueryExtension(display, &dummy, &dummy)) | 448 if (!XScreenSaverQueryExtension(display, &dummy, &dummy)) |
| 445 return false; | 449 return false; |
| 446 | 450 |
| 447 if (!XScreenSaverQueryVersion(display, &major, &minor)) | 451 if (!XScreenSaverQueryVersion(display, &major, &minor)) |
| 448 return false; | 452 return false; |
| 449 | 453 |
| 450 return major > 1 || (major == 1 && minor >= 1); | 454 return major > 1 || (major == 1 && minor >= 1); |
| 451 } | 455 } |
| 452 | 456 |
| 453 DBusAPI PowerSaveBlocker::Delegate::SelectAPI() { | 457 DBusAPI PowerSaveBlocker::Delegate::SelectAPI() { |
| 454 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 458 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 459 // Power saving APIs are not accessible in headless mode. |
| 460 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless)) |
| 461 return NO_API; |
| 455 std::unique_ptr<base::Environment> env(base::Environment::Create()); | 462 std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| 456 switch (base::nix::GetDesktopEnvironment(env.get())) { | 463 switch (base::nix::GetDesktopEnvironment(env.get())) { |
| 457 case base::nix::DESKTOP_ENVIRONMENT_GNOME: | 464 case base::nix::DESKTOP_ENVIRONMENT_GNOME: |
| 458 case base::nix::DESKTOP_ENVIRONMENT_UNITY: | 465 case base::nix::DESKTOP_ENVIRONMENT_UNITY: |
| 459 if (DPMSEnabled()) | 466 if (DPMSEnabled()) |
| 460 return GNOME_API; | 467 return GNOME_API; |
| 461 break; | 468 break; |
| 462 case base::nix::DESKTOP_ENVIRONMENT_XFCE: | 469 case base::nix::DESKTOP_ENVIRONMENT_XFCE: |
| 463 case base::nix::DESKTOP_ENVIRONMENT_KDE4: | 470 case base::nix::DESKTOP_ENVIRONMENT_KDE4: |
| 464 case base::nix::DESKTOP_ENVIRONMENT_KDE5: | 471 case base::nix::DESKTOP_ENVIRONMENT_KDE5: |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 496 } | 503 } |
| 497 } | 504 } |
| 498 | 505 |
| 499 PowerSaveBlocker::~PowerSaveBlocker() { | 506 PowerSaveBlocker::~PowerSaveBlocker() { |
| 500 delegate_->CleanUp(); | 507 delegate_->CleanUp(); |
| 501 if (freedesktop_suspend_delegate_) | 508 if (freedesktop_suspend_delegate_) |
| 502 freedesktop_suspend_delegate_->CleanUp(); | 509 freedesktop_suspend_delegate_->CleanUp(); |
| 503 } | 510 } |
| 504 | 511 |
| 505 } // namespace device | 512 } // namespace device |
| OLD | NEW |