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

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

Issue 10780023: Change base::SystemMonitor's media device functions to take a type and string16 instead of a FilePa… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix cros Created 8 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <utility> 7 #include <utility>
8 8
9 #include "base/file_path.h"
10 #include "base/logging.h" 9 #include "base/logging.h"
11 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/stl_util.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/utf_string_conversions.h"
13 14
14 namespace base { 15 namespace base {
15 16
16 static SystemMonitor* g_system_monitor = NULL; 17 static SystemMonitor* g_system_monitor = NULL;
17 18
18 #if defined(ENABLE_BATTERY_MONITORING) 19 #if defined(ENABLE_BATTERY_MONITORING)
19 // The amount of time (in ms) to wait before running the initial 20 // The amount of time (in ms) to wait before running the initial
20 // battery check. 21 // battery check.
21 static int kDelayedBatteryCheckMs = 10 * 1000; 22 static int kDelayedBatteryCheckMs = 10 * 1000;
22 #endif // defined(ENABLE_BATTERY_MONITORING) 23 #endif // defined(ENABLE_BATTERY_MONITORING)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 NotifySuspend(); 80 NotifySuspend();
80 } 81 }
81 break; 82 break;
82 } 83 }
83 } 84 }
84 85
85 void SystemMonitor::ProcessDevicesChanged() { 86 void SystemMonitor::ProcessDevicesChanged() {
86 NotifyDevicesChanged(); 87 NotifyDevicesChanged();
87 } 88 }
88 89
89 void SystemMonitor::ProcessMediaDeviceAttached(const DeviceIdType& id, 90 void SystemMonitor::ProcessMediaDeviceAttached(
90 const std::string& name, 91 const std::string& id,
91 const FilePath& path) { 92 const string16& name,
92 media_device_map_.insert(std::make_pair(id, MakeTuple(id, name, path))); 93 MediaDeviceType type,
93 NotifyMediaDeviceAttached(id, name, path); 94 const FilePath::StringType& location) {
95 MediaDeviceInfo info(id, name, type, location);
96 if (ContainsKey(media_device_map_, id)) {
97 // This can happen if our unique id scheme fails. Ignore the incoming
98 // non-unique attachment.
99 return;
100 }
101 media_device_map_.insert(std::make_pair(id, info));
102 NotifyMediaDeviceAttached(id, name, type, location);
94 } 103 }
95 104
96 void SystemMonitor::ProcessMediaDeviceDetached(const DeviceIdType& id) { 105 void SystemMonitor::ProcessMediaDeviceDetached(const std::string& id) {
97 MediaDeviceMap::iterator it = media_device_map_.find(id); 106 MediaDeviceMap::iterator it = media_device_map_.find(id);
98 if (it != media_device_map_.end()) 107 if (it != media_device_map_.end())
99 media_device_map_.erase(it); 108 media_device_map_.erase(it);
100 NotifyMediaDeviceDetached(id); 109 NotifyMediaDeviceDetached(id);
101 } 110 }
102 111
103 std::vector<SystemMonitor::MediaDeviceInfo> 112 std::vector<SystemMonitor::MediaDeviceInfo>
104 SystemMonitor::GetAttachedMediaDevices() const { 113 SystemMonitor::GetAttachedMediaDevices() const {
105 std::vector<MediaDeviceInfo> results; 114 std::vector<MediaDeviceInfo> results;
106 for (MediaDeviceMap::const_iterator it = media_device_map_.begin(); 115 for (MediaDeviceMap::const_iterator it = media_device_map_.begin();
(...skipping 19 matching lines...) Expand all
126 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) { 135 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) {
127 devices_changed_observer_list_->RemoveObserver(obs); 136 devices_changed_observer_list_->RemoveObserver(obs);
128 } 137 }
129 138
130 void SystemMonitor::NotifyDevicesChanged() { 139 void SystemMonitor::NotifyDevicesChanged() {
131 DVLOG(1) << "DevicesChanged"; 140 DVLOG(1) << "DevicesChanged";
132 devices_changed_observer_list_->Notify( 141 devices_changed_observer_list_->Notify(
133 &DevicesChangedObserver::OnDevicesChanged); 142 &DevicesChangedObserver::OnDevicesChanged);
134 } 143 }
135 144
136 void SystemMonitor::NotifyMediaDeviceAttached(const DeviceIdType& id, 145 void SystemMonitor::NotifyMediaDeviceAttached(
137 const std::string& name, 146 const std::string& id,
138 const FilePath& path) { 147 const string16& name,
139 DVLOG(1) << "MediaDeviceAttached with name " << name << " and id " << id; 148 MediaDeviceType type,
149 const FilePath::StringType& location) {
150 DVLOG(1) << "MediaDeviceAttached with name " << UTF16ToUTF8(name)
151 << " and id " << id;
140 devices_changed_observer_list_->Notify( 152 devices_changed_observer_list_->Notify(
141 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, path); 153 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, type, location);
142 } 154 }
143 155
144 void SystemMonitor::NotifyMediaDeviceDetached(const DeviceIdType& id) { 156 void SystemMonitor::NotifyMediaDeviceDetached(const std::string& id) {
145 DVLOG(1) << "MediaDeviceDetached for id " << id; 157 DVLOG(1) << "MediaDeviceDetached for id " << id;
146 devices_changed_observer_list_->Notify( 158 devices_changed_observer_list_->Notify(
147 &DevicesChangedObserver::OnMediaDeviceDetached, id); 159 &DevicesChangedObserver::OnMediaDeviceDetached, id);
148 } 160 }
149 161
150 void SystemMonitor::NotifyPowerStateChange() { 162 void SystemMonitor::NotifyPowerStateChange() {
151 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") 163 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off")
152 << " battery"; 164 << " battery";
153 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, 165 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange,
154 BatteryPower()); 166 BatteryPower());
155 } 167 }
156 168
157 void SystemMonitor::NotifySuspend() { 169 void SystemMonitor::NotifySuspend() {
158 DVLOG(1) << "Power Suspending"; 170 DVLOG(1) << "Power Suspending";
159 power_observer_list_->Notify(&PowerObserver::OnSuspend); 171 power_observer_list_->Notify(&PowerObserver::OnSuspend);
160 } 172 }
161 173
162 void SystemMonitor::NotifyResume() { 174 void SystemMonitor::NotifyResume() {
163 DVLOG(1) << "Power Resuming"; 175 DVLOG(1) << "Power Resuming";
164 power_observer_list_->Notify(&PowerObserver::OnResume); 176 power_observer_list_->Notify(&PowerObserver::OnResume);
165 } 177 }
166 178
167 void SystemMonitor::BatteryCheck() { 179 void SystemMonitor::BatteryCheck() {
168 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); 180 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
169 } 181 }
170 182
171 } // namespace base 183 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698