| OLD | NEW |
| 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/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 : device_id(id), | 32 : device_id(id), |
| 33 name(device_name), | 33 name(device_name), |
| 34 location(device_location) { | 34 location(device_location) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 SystemMonitor::SystemMonitor() | 37 SystemMonitor::SystemMonitor() |
| 38 : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()), | 38 : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()), |
| 39 devices_changed_observer_list_( | 39 devices_changed_observer_list_( |
| 40 new ObserverListThreadSafe<DevicesChangedObserver>()), | 40 new ObserverListThreadSafe<DevicesChangedObserver>()), |
| 41 battery_in_use_(false), | 41 battery_in_use_(false), |
| 42 suspended_(false) { | 42 suspended_(false), |
| 43 free_space_delegate_(NULL) { |
| 43 DCHECK(!g_system_monitor); | 44 DCHECK(!g_system_monitor); |
| 44 g_system_monitor = this; | 45 g_system_monitor = this; |
| 45 | 46 |
| 46 DCHECK(MessageLoop::current()); | 47 DCHECK(MessageLoop::current()); |
| 47 #if defined(ENABLE_BATTERY_MONITORING) | 48 #if defined(ENABLE_BATTERY_MONITORING) |
| 48 delayed_battery_check_.Start(FROM_HERE, | 49 delayed_battery_check_.Start(FROM_HERE, |
| 49 base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this, | 50 base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this, |
| 50 &SystemMonitor::BatteryCheck); | 51 &SystemMonitor::BatteryCheck); |
| 51 #endif // defined(ENABLE_BATTERY_MONITORING) | 52 #endif // defined(ENABLE_BATTERY_MONITORING) |
| 52 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 115 } |
| 115 | 116 |
| 116 void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) { | 117 void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) { |
| 117 RemovableStorageMap::iterator it = removable_storage_map_.find(id); | 118 RemovableStorageMap::iterator it = removable_storage_map_.find(id); |
| 118 if (it == removable_storage_map_.end()) | 119 if (it == removable_storage_map_.end()) |
| 119 return; | 120 return; |
| 120 removable_storage_map_.erase(it); | 121 removable_storage_map_.erase(it); |
| 121 NotifyRemovableStorageDetached(id); | 122 NotifyRemovableStorageDetached(id); |
| 122 } | 123 } |
| 123 | 124 |
| 125 void SystemMonitor::ProcessStorageFreeSpaceChanged( |
| 126 const FilePath::StringType& path) { |
| 127 DVLOG(1) << "Free Space Changing"; |
| 128 devices_changed_observer_list_->Notify( |
| 129 &DevicesChangedObserver::OnStorageFreeSpaceChanged, path); |
| 130 } |
| 131 |
| 132 bool SystemMonitor::StartWatchingStorage(const FilePath::StringType& path) { |
| 133 if (!free_space_delegate_) |
| 134 return false; |
| 135 |
| 136 // Try to start watching if the first one is requested. |
| 137 if (watched_storages_.find(path) == watched_storages_.end() && |
| 138 !free_space_delegate_->StartWatchingStorage(path)) { |
| 139 return false; |
| 140 } |
| 141 |
| 142 // The free space watcher has been started for the storage identifed by |
| 143 // |path|. |
| 144 watched_storages_.insert(path); |
| 145 return true; |
| 146 } |
| 147 |
| 148 bool SystemMonitor::StopWatchingStorage(const FilePath::StringType& path) { |
| 149 if (!free_space_delegate_) |
| 150 return false; |
| 151 |
| 152 watched_storages_.erase(path); |
| 153 |
| 154 // Try to stop watching when the last one is erased. |
| 155 if (watched_storages_.find(path) == watched_storages_.end() && |
| 156 !free_space_delegate_->StopWatchingStorage(path)) |
| 157 return false; |
| 158 |
| 159 return true; |
| 160 } |
| 161 |
| 124 std::vector<SystemMonitor::RemovableStorageInfo> | 162 std::vector<SystemMonitor::RemovableStorageInfo> |
| 125 SystemMonitor::GetAttachedRemovableStorage() const { | 163 SystemMonitor::GetAttachedRemovableStorage() const { |
| 126 std::vector<RemovableStorageInfo> results; | 164 std::vector<RemovableStorageInfo> results; |
| 127 for (RemovableStorageMap::const_iterator it = removable_storage_map_.begin(); | 165 for (RemovableStorageMap::const_iterator it = removable_storage_map_.begin(); |
| 128 it != removable_storage_map_.end(); | 166 it != removable_storage_map_.end(); |
| 129 ++it) { | 167 ++it) { |
| 130 results.push_back(it->second); | 168 results.push_back(it->second); |
| 131 } | 169 } |
| 132 return results; | 170 return results; |
| 133 } | 171 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 void SystemMonitor::NotifyResume() { | 223 void SystemMonitor::NotifyResume() { |
| 186 DVLOG(1) << "Power Resuming"; | 224 DVLOG(1) << "Power Resuming"; |
| 187 power_observer_list_->Notify(&PowerObserver::OnResume); | 225 power_observer_list_->Notify(&PowerObserver::OnResume); |
| 188 } | 226 } |
| 189 | 227 |
| 190 void SystemMonitor::BatteryCheck() { | 228 void SystemMonitor::BatteryCheck() { |
| 191 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 229 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
| 192 } | 230 } |
| 193 | 231 |
| 194 } // namespace base | 232 } // namespace base |
| OLD | NEW |