| 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 (StorageMap::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 DCHECK(thread_checker_.CalledOnValidThread()); | 65 DCHECK(thread_checker_.CalledOnValidThread()); |
| 66 if (initialized_) { | 66 if (initialized_) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if (ContainsKey(storage_map_, info.device_id())) { | 151 if (ContainsKey(storage_map_, info.device_id())) { |
| 152 // This can happen if our unique id scheme fails. Ignore the incoming | 152 // This can happen if our unique id scheme fails. Ignore the incoming |
| 153 // non-unique attachment. | 153 // non-unique attachment. |
| 154 return; | 154 return; |
| 155 } | 155 } |
| 156 storage_map_.insert(std::make_pair(info.device_id(), info)); | 156 storage_map_.insert(std::make_pair(info.device_id(), info)); |
| 157 } | 157 } |
| 158 | 158 |
| 159 DVLOG(1) << "RemovableStorageAttached with name " << UTF16ToUTF8(info.name()) | 159 DVLOG(1) << "RemovableStorageAttached with name " << UTF16ToUTF8(info.name()) |
| 160 << " and id " << info.device_id(); | 160 << " and id " << info.device_id(); |
| 161 observer_list_->Notify( | 161 if (StorageInfo::IsRemovableDevice(info.device_id())) { |
| 162 &RemovableStorageObserver::OnRemovableStorageAttached, info); | 162 observer_list_->Notify( |
| 163 &RemovableStorageObserver::OnRemovableStorageAttached, info); |
| 164 } |
| 163 } | 165 } |
| 164 | 166 |
| 165 void StorageMonitor::ProcessDetach(const std::string& id) { | 167 void StorageMonitor::ProcessDetach(const std::string& id) { |
| 166 StorageInfo info; | 168 StorageInfo info; |
| 167 { | 169 { |
| 168 base::AutoLock lock(storage_lock_); | 170 base::AutoLock lock(storage_lock_); |
| 169 RemovableStorageMap::iterator it = storage_map_.find(id); | 171 StorageMap::iterator it = storage_map_.find(id); |
| 170 if (it == storage_map_.end()) | 172 if (it == storage_map_.end()) |
| 171 return; | 173 return; |
| 172 info = it->second; | 174 info = it->second; |
| 173 storage_map_.erase(it); | 175 storage_map_.erase(it); |
| 174 } | 176 } |
| 175 | 177 |
| 176 DVLOG(1) << "RemovableStorageDetached for id " << id; | 178 DVLOG(1) << "RemovableStorageDetached for id " << id; |
| 177 observer_list_->Notify( | 179 if (StorageInfo::IsRemovableDevice(info.device_id())) { |
| 178 &RemovableStorageObserver::OnRemovableStorageDetached, info); | 180 observer_list_->Notify( |
| 181 &RemovableStorageObserver::OnRemovableStorageDetached, info); |
| 182 } |
| 179 } | 183 } |
| 180 | 184 |
| 181 } // namespace chrome | 185 } // namespace chrome |
| OLD | NEW |