OLD | NEW |
1 // Copyright (c) 2012 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/file_path.h" | |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
10 #include "base/time.h" | 9 #include "base/time.h" |
11 | 10 |
12 namespace base { | 11 namespace base { |
13 | 12 |
14 static SystemMonitor* g_system_monitor = NULL; | 13 static SystemMonitor* g_system_monitor = NULL; |
15 | 14 |
16 #if defined(ENABLE_BATTERY_MONITORING) | 15 #if defined(ENABLE_BATTERY_MONITORING) |
17 // 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 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 NotifySuspend(); | 76 NotifySuspend(); |
78 } | 77 } |
79 break; | 78 break; |
80 } | 79 } |
81 } | 80 } |
82 | 81 |
83 void SystemMonitor::ProcessDevicesChanged() { | 82 void SystemMonitor::ProcessDevicesChanged() { |
84 NotifyDevicesChanged(); | 83 NotifyDevicesChanged(); |
85 } | 84 } |
86 | 85 |
87 void SystemMonitor::ProcessMediaDeviceAttached(const DeviceIdType& id, | |
88 const std::string& name, | |
89 const FilePath& path) { | |
90 NotifyMediaDeviceAttached(id, name, path); | |
91 } | |
92 | |
93 void SystemMonitor::ProcessMediaDeviceDetached(const DeviceIdType& id) { | |
94 NotifyMediaDeviceDetached(id); | |
95 } | |
96 | |
97 void SystemMonitor::AddPowerObserver(PowerObserver* obs) { | 86 void SystemMonitor::AddPowerObserver(PowerObserver* obs) { |
98 power_observer_list_->AddObserver(obs); | 87 power_observer_list_->AddObserver(obs); |
99 } | 88 } |
100 | 89 |
101 void SystemMonitor::RemovePowerObserver(PowerObserver* obs) { | 90 void SystemMonitor::RemovePowerObserver(PowerObserver* obs) { |
102 power_observer_list_->RemoveObserver(obs); | 91 power_observer_list_->RemoveObserver(obs); |
103 } | 92 } |
104 | 93 |
105 void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) { | 94 void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) { |
106 devices_changed_observer_list_->AddObserver(obs); | 95 devices_changed_observer_list_->AddObserver(obs); |
107 } | 96 } |
108 | 97 |
109 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) { | 98 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) { |
110 devices_changed_observer_list_->RemoveObserver(obs); | 99 devices_changed_observer_list_->RemoveObserver(obs); |
111 } | 100 } |
112 | 101 |
113 void SystemMonitor::NotifyDevicesChanged() { | 102 void SystemMonitor::NotifyDevicesChanged() { |
114 DVLOG(1) << "DevicesChanged"; | 103 DVLOG(1) << "DevicesChanged"; |
115 devices_changed_observer_list_->Notify( | 104 devices_changed_observer_list_->Notify( |
116 &DevicesChangedObserver::OnDevicesChanged); | 105 &DevicesChangedObserver::OnDevicesChanged); |
117 } | 106 } |
118 | 107 |
119 void SystemMonitor::NotifyMediaDeviceAttached(const DeviceIdType& id, | |
120 const std::string& name, | |
121 const FilePath& path) { | |
122 DVLOG(1) << "MediaDeviceAttached with name " << name << " and id " << id; | |
123 devices_changed_observer_list_->Notify( | |
124 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, path); | |
125 } | |
126 | |
127 void SystemMonitor::NotifyMediaDeviceDetached(const DeviceIdType& id) { | |
128 DVLOG(1) << "MediaDeviceDetached for id " << id; | |
129 devices_changed_observer_list_->Notify( | |
130 &DevicesChangedObserver::OnMediaDeviceDetached, id); | |
131 } | |
132 | |
133 void SystemMonitor::NotifyPowerStateChange() { | 108 void SystemMonitor::NotifyPowerStateChange() { |
134 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") | 109 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") |
135 << " battery"; | 110 << " battery"; |
136 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, | 111 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, |
137 BatteryPower()); | 112 BatteryPower()); |
138 } | 113 } |
139 | 114 |
140 void SystemMonitor::NotifySuspend() { | 115 void SystemMonitor::NotifySuspend() { |
141 DVLOG(1) << "Power Suspending"; | 116 DVLOG(1) << "Power Suspending"; |
142 power_observer_list_->Notify(&PowerObserver::OnSuspend); | 117 power_observer_list_->Notify(&PowerObserver::OnSuspend); |
143 } | 118 } |
144 | 119 |
145 void SystemMonitor::NotifyResume() { | 120 void SystemMonitor::NotifyResume() { |
146 DVLOG(1) << "Power Resuming"; | 121 DVLOG(1) << "Power Resuming"; |
147 power_observer_list_->Notify(&PowerObserver::OnResume); | 122 power_observer_list_->Notify(&PowerObserver::OnResume); |
148 } | 123 } |
149 | 124 |
150 void SystemMonitor::BatteryCheck() { | 125 void SystemMonitor::BatteryCheck() { |
151 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 126 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
152 } | 127 } |
153 | 128 |
154 } // namespace base | 129 } // namespace base |
OLD | NEW |