Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(805)

Unified Diff: content/browser/power_save_blocker_linux.cc

Issue 11784016: chromeos: Block system suspend while uploading files to Drive (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: PowerSaveBlocker is a pure interface Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/power_save_blocker_linux.cc
diff --git a/content/browser/power_save_blocker_linux.cc b/content/browser/power_save_blocker_linux.cc
index 2ebf7bed5267b0e608cd88b21cc8810edf759038..533c3f3592c34d9fe150da1180142a05801b10e0 100644
--- a/content/browser/power_save_blocker_linux.cc
+++ b/content/browser/power_save_blocker_linux.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/power_save_blocker.h"
+#include "content/public/browser/power_save_blocker.h"
#include <X11/Xlib.h>
#include <X11/extensions/dpms.h>
@@ -35,6 +35,8 @@
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
+namespace content {
+
namespace {
enum DBusAPI {
@@ -63,12 +65,22 @@ const char kFreeDesktopAPIInterfaceName[] =
const char kFreeDesktopAPIObjectPath[] =
"/org/freedesktop/PowerManagement/Inhibit";
-} // anonymous namespace
+class PowerSaveBlockerLinux : public PowerSaveBlocker {
+ public:
+ PowerSaveBlockerLinux(PowerSaveBlockerType type, const std::string& reason);
+ virtual ~PowerSaveBlockerLinux();
+
+ private:
+ class Delegate;
-namespace content {
+ // A second object with different lifetime than the RAII container.
+ scoped_refptr<Delegate> delegate_;
-class PowerSaveBlocker::Delegate
- : public base::RefCountedThreadSafe<PowerSaveBlocker::Delegate> {
+ DISALLOW_COPY_AND_ASSIGN(PowerSaveBlockerLinux);
+};
+
+class PowerSaveBlockerLinux::Delegate
+ : public base::RefCountedThreadSafe<PowerSaveBlockerLinux::Delegate> {
public:
// Picks an appropriate D-Bus API to use based on the desktop environment.
Delegate(PowerSaveBlockerType type, const std::string& reason);
@@ -128,7 +140,7 @@ class PowerSaveBlocker::Delegate
DISALLOW_COPY_AND_ASSIGN(Delegate);
};
-PowerSaveBlocker::Delegate::Delegate(PowerSaveBlockerType type,
+PowerSaveBlockerLinux::Delegate::Delegate(PowerSaveBlockerType type,
const std::string& reason)
: type_(type),
reason_(reason),
@@ -139,7 +151,7 @@ PowerSaveBlocker::Delegate::Delegate(PowerSaveBlockerType type,
// object yet. We'll do it later in ApplyBlock(), on the FILE thread.
}
-void PowerSaveBlocker::Delegate::Init() {
+void PowerSaveBlockerLinux::Delegate::Init() {
base::AutoLock lock(lock_);
DCHECK(!enqueue_apply_);
enqueue_apply_ = true;
@@ -147,7 +159,7 @@ void PowerSaveBlocker::Delegate::Init() {
base::Bind(&Delegate::InitOnUIThread, this));
}
-void PowerSaveBlocker::Delegate::CleanUp() {
+void PowerSaveBlockerLinux::Delegate::CleanUp() {
base::AutoLock lock(lock_);
if (enqueue_apply_) {
// If a call to ApplyBlock() has not yet been enqueued because we are still
@@ -160,7 +172,7 @@ void PowerSaveBlocker::Delegate::CleanUp() {
}
}
-void PowerSaveBlocker::Delegate::InitOnUIThread() {
+void PowerSaveBlockerLinux::Delegate::InitOnUIThread() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
base::AutoLock lock(lock_);
api_ = SelectAPI();
@@ -174,7 +186,7 @@ void PowerSaveBlocker::Delegate::InitOnUIThread() {
enqueue_apply_ = false;
}
-void PowerSaveBlocker::Delegate::ApplyBlock(DBusAPI api) {
+void PowerSaveBlockerLinux::Delegate::ApplyBlock(DBusAPI api) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
DCHECK(!bus_.get()); // ApplyBlock() should only be called once.
@@ -254,7 +266,7 @@ void PowerSaveBlocker::Delegate::ApplyBlock(DBusAPI api) {
}
}
-void PowerSaveBlocker::Delegate::RemoveBlock(DBusAPI api) {
+void PowerSaveBlockerLinux::Delegate::RemoveBlock(DBusAPI api) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
DCHECK(bus_.get()); // RemoveBlock() should only be called once.
@@ -296,7 +308,7 @@ void PowerSaveBlocker::Delegate::RemoveBlock(DBusAPI api) {
}
// static
-bool PowerSaveBlocker::Delegate::DPMSEnabled() {
+bool PowerSaveBlockerLinux::Delegate::DPMSEnabled() {
Display* display = base::MessagePumpForUI::GetDefaultXDisplay();
BOOL enabled = false;
int dummy;
@@ -308,7 +320,7 @@ bool PowerSaveBlocker::Delegate::DPMSEnabled() {
}
// static
-DBusAPI PowerSaveBlocker::Delegate::SelectAPI() {
+DBusAPI PowerSaveBlockerLinux::Delegate::SelectAPI() {
scoped_ptr<base::Environment> env(base::Environment::Create());
switch (base::nix::GetDesktopEnvironment(env.get())) {
case base::nix::DESKTOP_ENVIRONMENT_GNOME:
@@ -329,14 +341,23 @@ DBusAPI PowerSaveBlocker::Delegate::SelectAPI() {
return NO_API;
}
-PowerSaveBlocker::PowerSaveBlocker(
+PowerSaveBlockerLinux::PowerSaveBlockerLinux(
PowerSaveBlockerType type, const std::string& reason)
: delegate_(new Delegate(type, reason)) {
delegate_->Init();
}
-PowerSaveBlocker::~PowerSaveBlocker() {
+PowerSaveBlockerLinux::~PowerSaveBlockerLinux() {
delegate_->CleanUp();
}
+} // namespace
+
+// static
+scoped_ptr<PowerSaveBlocker> PowerSaveBlocker::Create(
+ PowerSaveBlockerType type,
+ const std::string& reason) {
+ return scoped_ptr<PowerSaveBlocker>(new PowerSaveBlockerLinux(type, reason));
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698