| 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 "chrome/browser/storage_monitor/storage_monitor.h" | 5 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 6 | 6 |
| 7 #include "base/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/storage_monitor/removable_storage_observer.h" | 9 #include "chrome/browser/storage_monitor/removable_storage_observer.h" |
| 10 #include "chrome/browser/storage_monitor/transient_device_ids.h" | 10 #include "chrome/browser/storage_monitor/transient_device_ids.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 } | 42 } |
| 43 | 43 |
| 44 void StorageMonitor::ReceiverImpl::MarkInitialized() { | 44 void StorageMonitor::ReceiverImpl::MarkInitialized() { |
| 45 notifications_->MarkInitialized(); | 45 notifications_->MarkInitialized(); |
| 46 } | 46 } |
| 47 | 47 |
| 48 StorageMonitor* StorageMonitor::GetInstance() { | 48 StorageMonitor* StorageMonitor::GetInstance() { |
| 49 return g_storage_monitor; | 49 return g_storage_monitor; |
| 50 } | 50 } |
| 51 | 51 |
| 52 std::vector<StorageInfo> StorageMonitor::GetAttachedStorage() const { | 52 std::vector<StorageInfo> StorageMonitor::GetAllAvailableStorages() const { |
| 53 std::vector<StorageInfo> results; | 53 std::vector<StorageInfo> results; |
| 54 | 54 |
| 55 base::AutoLock lock(storage_lock_); | 55 base::AutoLock lock(storage_lock_); |
| 56 for (RemovableStorageMap::const_iterator it = storage_map_.begin(); | 56 for (AllAvailableStorageMap::const_iterator it = storage_map_.begin(); |
| 57 it != storage_map_.end(); | 57 it != storage_map_.end(); |
| 58 ++it) { | 58 ++it) { |
| 59 results.push_back(it->second); | 59 results.push_back(it->second); |
| 60 } | 60 } |
| 61 return results; | 61 return results; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void StorageMonitor::Initialize(base::Closure callback) { | 64 void StorageMonitor::Initialize(base::Closure callback) { |
| 65 if (initialized_) { | 65 if (initialized_) { |
| 66 if (!callback.is_null()) | 66 if (!callback.is_null()) |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 if (ContainsKey(storage_map_, info.device_id())) { | 145 if (ContainsKey(storage_map_, info.device_id())) { |
| 146 // This can happen if our unique id scheme fails. Ignore the incoming | 146 // This can happen if our unique id scheme fails. Ignore the incoming |
| 147 // non-unique attachment. | 147 // non-unique attachment. |
| 148 return; | 148 return; |
| 149 } | 149 } |
| 150 storage_map_.insert(std::make_pair(info.device_id(), info)); | 150 storage_map_.insert(std::make_pair(info.device_id(), info)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 DVLOG(1) << "RemovableStorageAttached with name " << UTF16ToUTF8(info.name()) | 153 DVLOG(1) << "RemovableStorageAttached with name " << UTF16ToUTF8(info.name()) |
| 154 << " and id " << info.device_id(); | 154 << " and id " << info.device_id(); |
| 155 observer_list_->Notify( | 155 if (StorageInfo::IsRemovableDevice(info.device_id())) |
| 156 &RemovableStorageObserver::OnRemovableStorageAttached, info); | 156 observer_list_->Notify( |
| 157 &RemovableStorageObserver::OnRemovableStorageAttached, info); |
| 157 } | 158 } |
| 158 | 159 |
| 159 void StorageMonitor::ProcessDetach(const std::string& id) { | 160 void StorageMonitor::ProcessDetach(const std::string& id) { |
| 160 StorageInfo info; | 161 StorageInfo info; |
| 161 { | 162 { |
| 162 base::AutoLock lock(storage_lock_); | 163 base::AutoLock lock(storage_lock_); |
| 163 RemovableStorageMap::iterator it = storage_map_.find(id); | 164 AllAvailableStorageMap::iterator it = storage_map_.find(id); |
| 164 if (it == storage_map_.end()) | 165 if (it == storage_map_.end()) |
| 165 return; | 166 return; |
| 166 info = it->second; | 167 info = it->second; |
| 167 storage_map_.erase(it); | 168 storage_map_.erase(it); |
| 168 } | 169 } |
| 169 | 170 |
| 170 DVLOG(1) << "RemovableStorageDetached for id " << id; | 171 DVLOG(1) << "RemovableStorageDetached for id " << id; |
| 171 observer_list_->Notify( | 172 observer_list_->Notify( |
| 172 &RemovableStorageObserver::OnRemovableStorageDetached, info); | 173 &RemovableStorageObserver::OnRemovableStorageDetached, info); |
| 173 } | 174 } |
| 174 | 175 |
| 175 } // namespace chrome | 176 } // namespace chrome |
| OLD | NEW |