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

Side by Side Diff: base/system_monitor/system_monitor.cc

Issue 8523021: Send WM_DEVICECHANGE message through SystemMonitor (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase Created 9 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « base/system_monitor/system_monitor.h ('k') | base/system_monitor/system_monitor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/system_monitor/system_monitor.h" 5 #include "base/system_monitor/system_monitor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 static SystemMonitor* g_system_monitor = NULL; 13 static SystemMonitor* g_system_monitor = NULL;
14 14
15 #if defined(ENABLE_BATTERY_MONITORING) 15 #if defined(ENABLE_BATTERY_MONITORING)
16 // The amount of time (in ms) to wait before running the initial 16 // The amount of time (in ms) to wait before running the initial
17 // battery check. 17 // battery check.
18 static int kDelayedBatteryCheckMs = 10 * 1000; 18 static int kDelayedBatteryCheckMs = 10 * 1000;
19 #endif // defined(ENABLE_BATTERY_MONITORING) 19 #endif // defined(ENABLE_BATTERY_MONITORING)
20 20
21 SystemMonitor::SystemMonitor() 21 SystemMonitor::SystemMonitor()
22 : observer_list_(new ObserverListThreadSafe<PowerObserver>()), 22 : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()),
23 devices_changed_observer_list_(
24 new ObserverListThreadSafe<DevicesChangedObserver>()),
23 battery_in_use_(false), 25 battery_in_use_(false),
24 suspended_(false) { 26 suspended_(false) {
25 DCHECK(!g_system_monitor); 27 DCHECK(!g_system_monitor);
26 g_system_monitor = this; 28 g_system_monitor = this;
27 29
28 DCHECK(MessageLoop::current()); 30 DCHECK(MessageLoop::current());
29 #if defined(ENABLE_BATTERY_MONITORING) 31 #if defined(ENABLE_BATTERY_MONITORING)
30 delayed_battery_check_.Start(FROM_HERE, 32 delayed_battery_check_.Start(FROM_HERE,
31 base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this, 33 base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this,
32 &SystemMonitor::BatteryCheck); 34 &SystemMonitor::BatteryCheck);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 break; 72 break;
71 case SUSPEND_EVENT: 73 case SUSPEND_EVENT:
72 if (!suspended_) { 74 if (!suspended_) {
73 suspended_ = true; 75 suspended_ = true;
74 NotifySuspend(); 76 NotifySuspend();
75 } 77 }
76 break; 78 break;
77 } 79 }
78 } 80 }
79 81
80 void SystemMonitor::AddObserver(PowerObserver* obs) { 82 void SystemMonitor::ProcessDevicesChanged() {
81 observer_list_->AddObserver(obs); 83 NotifyDevicesChanged();
82 } 84 }
83 85
84 void SystemMonitor::RemoveObserver(PowerObserver* obs) { 86 void SystemMonitor::AddPowerObserver(PowerObserver* obs) {
85 observer_list_->RemoveObserver(obs); 87 power_observer_list_->AddObserver(obs);
88 }
89
90 void SystemMonitor::RemovePowerObserver(PowerObserver* obs) {
91 power_observer_list_->RemoveObserver(obs);
92 }
93
94 void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) {
95 devices_changed_observer_list_->AddObserver(obs);
96 }
97
98 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) {
99 devices_changed_observer_list_->RemoveObserver(obs);
100 }
101
102 void SystemMonitor::NotifyDevicesChanged() {
103 DVLOG(1) << "DevicesChanged";
104 devices_changed_observer_list_->Notify(
105 &DevicesChangedObserver::OnDevicesChanged);
86 } 106 }
87 107
88 void SystemMonitor::NotifyPowerStateChange() { 108 void SystemMonitor::NotifyPowerStateChange() {
89 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") 109 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off")
90 << " battery"; 110 << " battery";
91 observer_list_->Notify(&PowerObserver::OnPowerStateChange, BatteryPower()); 111 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange,
112 BatteryPower());
92 } 113 }
93 114
94 void SystemMonitor::NotifySuspend() { 115 void SystemMonitor::NotifySuspend() {
95 DVLOG(1) << "Power Suspending"; 116 DVLOG(1) << "Power Suspending";
96 observer_list_->Notify(&PowerObserver::OnSuspend); 117 power_observer_list_->Notify(&PowerObserver::OnSuspend);
97 } 118 }
98 119
99 void SystemMonitor::NotifyResume() { 120 void SystemMonitor::NotifyResume() {
100 DVLOG(1) << "Power Resuming"; 121 DVLOG(1) << "Power Resuming";
101 observer_list_->Notify(&PowerObserver::OnResume); 122 power_observer_list_->Notify(&PowerObserver::OnResume);
102 } 123 }
103 124
104 void SystemMonitor::BatteryCheck() { 125 void SystemMonitor::BatteryCheck() {
105 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); 126 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
106 } 127 }
107 128
108 } // namespace base 129 } // namespace base
OLDNEW
« no previous file with comments | « base/system_monitor/system_monitor.h ('k') | base/system_monitor/system_monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698