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

Unified Diff: content/common/power_monitor_client.cc

Issue 17074009: Created multi-process-friendly PowerMonitor interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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/common/power_monitor_client.cc
diff --git a/content/common/power_monitor_client.cc b/content/common/power_monitor_client.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f841af1e14618fcdc03332391526cec5a5bda8ee
--- /dev/null
+++ b/content/common/power_monitor_client.cc
@@ -0,0 +1,49 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/common/power_monitor_client.h"
+
+namespace content {
+
+static PowerMonitorClient* g_power_monitor_client = NULL;
Ken Russell (switch to Gerrit) 2013/06/24 22:54:38 This and PowerMonitorClient::Get() should use base
+
+PowerMonitorClient::PowerMonitorClient()
+ : observers_(new ObserverListThreadSafe<base::PowerObserver>()),
+ battery_in_use_(false) {
+ DCHECK(!g_power_monitor_client);
+ g_power_monitor_client = this;
+}
+
+PowerMonitorClient::~PowerMonitorClient() {
+ DCHECK_EQ(this, g_power_monitor_client);
+ g_power_monitor_client = NULL;
+}
+
+// static
+PowerMonitorClient* PowerMonitorClient::Get() {
+ return g_power_monitor_client;
+}
+
+void PowerMonitorClient::AddObserver(base::PowerObserver* obs) {
+ observers_->AddObserver(obs);
+}
+
+void PowerMonitorClient::RemoveObserver(base::PowerObserver* obs) {
+ observers_->RemoveObserver(obs);
+}
+
+void PowerMonitorClient::NotifyPowerStateChange(bool battery_in_use) {
+ battery_in_use_ = battery_in_use;
+ observers_->Notify(&base::PowerObserver::OnPowerStateChange, battery_in_use);
+}
+
+void PowerMonitorClient::NotifySuspend() {
+ observers_->Notify(&base::PowerObserver::OnSuspend);
+}
+
+void PowerMonitorClient::NotifyResume() {
+ observers_->Notify(&base::PowerObserver::OnResume);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698