Commit 38fdf074 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

Rewrite PowerSaveBlockerLinux [3/4]

* Renames power_save_blocker_x11.cc into power_save_blocker_linux.cc
* Made the power save blocker compatible with non-X11 linux, so ozone builds can
  use it.  This requires guarding X11-specific behavior behind #if
  defined(USE_X11).

BUG=1013812
TEST=Tested on GNOME and KDE environments
R=blundell

Change-Id: I7e23439bb9b7d7d961d1dc9f5a803ce7226b0706
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1926928
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#718422}
parent 3770b504
...@@ -27,7 +27,6 @@ source_set("power_save_blocker") { ...@@ -27,7 +27,6 @@ source_set("power_save_blocker") {
"power_save_blocker_mac.cc", "power_save_blocker_mac.cc",
"power_save_blocker_stub.cc", "power_save_blocker_stub.cc",
"power_save_blocker_win.cc", "power_save_blocker_win.cc",
"power_save_blocker_x11.cc",
] ]
public_deps = [ public_deps = [
...@@ -63,8 +62,8 @@ source_set("power_save_blocker") { ...@@ -63,8 +62,8 @@ source_set("power_save_blocker") {
sources -= [ "power_save_blocker_stub.cc" ] sources -= [ "power_save_blocker_stub.cc" ]
} }
if (is_chromeos || !use_x11 || !use_dbus) { if (!is_chromeos && use_x11 && use_dbus) {
sources -= [ "power_save_blocker_x11.cc" ] sources += [ "power_save_blocker_linux.cc" ]
} }
if (is_android) { if (is_android) {
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
#include "services/device/wake_lock/power_save_blocker/power_save_blocker.h" #include "services/device/wake_lock/power_save_blocker/power_save_blocker.h"
#include <X11/extensions/scrnsaver.h>
#include <stdint.h> #include <stdint.h>
#include <memory> #include <memory>
...@@ -25,7 +24,12 @@ ...@@ -25,7 +24,12 @@
#include "dbus/object_path.h" #include "dbus/object_path.h"
#include "dbus/object_proxy.h" #include "dbus/object_proxy.h"
#include "ui/gfx/switches.h" #include "ui/gfx/switches.h"
#include "ui/gfx/x/x11_types.h"
#if defined(USE_X11)
#include <X11/extensions/scrnsaver.h>
#include "ui/gfx/x/x11_types.h" // nogncheck
#endif
namespace device { namespace device {
...@@ -127,9 +131,10 @@ void GetDbusStringsForApi(DBusAPI api, ...@@ -127,9 +131,10 @@ void GetDbusStringsForApi(DBusAPI api,
NOTREACHED(); NOTREACHED();
} }
#if defined(USE_X11)
// Check whether the X11 Screen Saver Extension can be used to disable the // Check whether the X11 Screen Saver Extension can be used to disable the
// screen saver. Must be called on the UI thread. // screen saver. Must be called on the UI thread.
bool XSSAvailable() { bool X11ScreenSaverAvailable() {
// X Screen Saver isn't accessible in headless mode. // X Screen Saver isn't accessible in headless mode.
if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless)) if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kHeadless))
return false; return false;
...@@ -150,13 +155,14 @@ bool XSSAvailable() { ...@@ -150,13 +155,14 @@ bool XSSAvailable() {
// Wrapper for XScreenSaverSuspend. Checks whether the X11 Screen Saver // Wrapper for XScreenSaverSuspend. Checks whether the X11 Screen Saver
// Extension is available first. If it isn't, this is a no-op. Must be called // Extension is available first. If it isn't, this is a no-op. Must be called
// on the UI thread. // on the UI thread.
void XSSSuspendSet(bool suspend) { void X11ScreenSaverSuspendSet(bool suspend) {
if (!XSSAvailable()) if (!X11ScreenSaverAvailable())
return; return;
XDisplay* display = gfx::GetXDisplay(); XDisplay* display = gfx::GetXDisplay();
XScreenSaverSuspend(display, suspend); XScreenSaverSuspend(display, suspend);
} }
#endif
} // namespace } // namespace
...@@ -237,7 +243,10 @@ void PowerSaveBlocker::Delegate::Init() { ...@@ -237,7 +243,10 @@ void PowerSaveBlocker::Delegate::Init() {
FROM_HERE, base::BindOnce(&Delegate::ApplyBlock, this)); FROM_HERE, base::BindOnce(&Delegate::ApplyBlock, this));
} }
ui_task_runner_->PostTask(FROM_HERE, base::BindOnce(XSSSuspendSet, true)); #if defined(USE_X11)
ui_task_runner_->PostTask(FROM_HERE,
base::BindOnce(X11ScreenSaverSuspendSet, true));
#endif
} }
void PowerSaveBlocker::Delegate::CleanUp() { void PowerSaveBlocker::Delegate::CleanUp() {
...@@ -246,7 +255,10 @@ void PowerSaveBlocker::Delegate::CleanUp() { ...@@ -246,7 +255,10 @@ void PowerSaveBlocker::Delegate::CleanUp() {
FROM_HERE, base::BindOnce(&Delegate::RemoveBlock, this)); FROM_HERE, base::BindOnce(&Delegate::RemoveBlock, this));
} }
ui_task_runner_->PostTask(FROM_HERE, base::BindOnce(XSSSuspendSet, false)); #if defined(USE_X11)
ui_task_runner_->PostTask(FROM_HERE,
base::BindOnce(X11ScreenSaverSuspendSet, false));
#endif
} }
bool PowerSaveBlocker::Delegate::ShouldBlock() const { bool PowerSaveBlocker::Delegate::ShouldBlock() const {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment