Chromium Code Reviews| 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/system_monitor/removable_storage_notifications.h" | 5 #include "chrome/browser/system_monitor/removable_storage_notifications.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/system_monitor/removable_storage_observer.h" | 9 #include "chrome/browser/system_monitor/removable_storage_observer.h" |
| 10 #include "chrome/browser/system_monitor/transient_device_ids.h" | |
| 10 | 11 |
| 11 namespace chrome { | 12 namespace chrome { |
| 12 | 13 |
| 13 static RemovableStorageNotifications* | 14 static RemovableStorageNotifications* |
| 14 g_removable_storage_notifications = NULL; | 15 g_removable_storage_notifications = NULL; |
| 15 | 16 |
| 16 RemovableStorageNotifications::StorageInfo::StorageInfo() { | 17 RemovableStorageNotifications::StorageInfo::StorageInfo() { |
| 17 } | 18 } |
| 18 | 19 |
| 19 RemovableStorageNotifications::StorageInfo::StorageInfo( | 20 RemovableStorageNotifications::StorageInfo::StorageInfo( |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 const base::FilePath::StringType& location) { | 53 const base::FilePath::StringType& location) { |
| 53 notifications_->ProcessAttach( | 54 notifications_->ProcessAttach( |
| 54 RemovableStorageNotifications::StorageInfo(id, name, location)); | 55 RemovableStorageNotifications::StorageInfo(id, name, location)); |
| 55 } | 56 } |
| 56 | 57 |
| 57 void RemovableStorageNotifications::ReceiverImpl::ProcessDetach( | 58 void RemovableStorageNotifications::ReceiverImpl::ProcessDetach( |
| 58 const std::string& id) { | 59 const std::string& id) { |
| 59 notifications_->ProcessDetach(id); | 60 notifications_->ProcessDetach(id); |
| 60 } | 61 } |
| 61 | 62 |
| 63 RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() { | |
| 64 return g_removable_storage_notifications; | |
|
Greg Billock
2013/02/08 17:54:53
Why move these above the constructor?
vandebo (ex-Chrome)
2013/02/09 00:49:16
Definition order should match declaration order.
| |
| 65 } | |
| 66 | |
| 67 std::vector<RemovableStorageNotifications::StorageInfo> | |
| 68 RemovableStorageNotifications::GetAttachedStorage() const { | |
| 69 std::vector<StorageInfo> results; | |
| 70 | |
| 71 base::AutoLock lock(storage_lock_); | |
| 72 for (RemovableStorageMap::const_iterator it = storage_map_.begin(); | |
| 73 it != storage_map_.end(); | |
| 74 ++it) { | |
| 75 results.push_back(it->second); | |
| 76 } | |
| 77 return results; | |
| 78 } | |
| 79 | |
| 80 void RemovableStorageNotifications::AddObserver(RemovableStorageObserver* obs) { | |
| 81 observer_list_->AddObserver(obs); | |
| 82 } | |
| 83 | |
| 84 void RemovableStorageNotifications::RemoveObserver( | |
| 85 RemovableStorageObserver* obs) { | |
| 86 observer_list_->RemoveObserver(obs); | |
| 87 } | |
| 88 | |
| 89 TransientDeviceIds* | |
| 90 RemovableStorageNotifications::transient_device_ids() const { | |
| 91 return transient_device_ids_.get(); | |
| 92 } | |
| 93 | |
| 62 RemovableStorageNotifications::RemovableStorageNotifications() | 94 RemovableStorageNotifications::RemovableStorageNotifications() |
| 63 : observer_list_( | 95 : observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()), |
| 64 new ObserverListThreadSafe<RemovableStorageObserver>()) { | 96 transient_device_ids_(new TransientDeviceIds) { |
| 65 receiver_.reset(new ReceiverImpl(this)); | 97 receiver_.reset(new ReceiverImpl(this)); |
| 66 | 98 |
| 67 DCHECK(!g_removable_storage_notifications); | 99 DCHECK(!g_removable_storage_notifications); |
| 68 g_removable_storage_notifications = this; | 100 g_removable_storage_notifications = this; |
| 69 } | 101 } |
| 70 | 102 |
| 71 RemovableStorageNotifications::~RemovableStorageNotifications() { | 103 RemovableStorageNotifications::~RemovableStorageNotifications() { |
| 72 DCHECK_EQ(this, g_removable_storage_notifications); | 104 DCHECK_EQ(this, g_removable_storage_notifications); |
| 73 g_removable_storage_notifications = NULL; | 105 g_removable_storage_notifications = NULL; |
| 74 } | 106 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 105 return; | 137 return; |
| 106 info = it->second; | 138 info = it->second; |
| 107 storage_map_.erase(it); | 139 storage_map_.erase(it); |
| 108 } | 140 } |
| 109 | 141 |
| 110 DVLOG(1) << "RemovableStorageDetached for id " << id; | 142 DVLOG(1) << "RemovableStorageDetached for id " << id; |
| 111 observer_list_->Notify( | 143 observer_list_->Notify( |
| 112 &RemovableStorageObserver::OnRemovableStorageDetached, info); | 144 &RemovableStorageObserver::OnRemovableStorageDetached, info); |
| 113 } | 145 } |
| 114 | 146 |
| 115 std::vector<RemovableStorageNotifications::StorageInfo> | |
| 116 RemovableStorageNotifications::GetAttachedStorage() const { | |
| 117 std::vector<StorageInfo> results; | |
| 118 | |
| 119 base::AutoLock lock(storage_lock_); | |
| 120 for (RemovableStorageMap::const_iterator it = storage_map_.begin(); | |
| 121 it != storage_map_.end(); | |
| 122 ++it) { | |
| 123 results.push_back(it->second); | |
| 124 } | |
| 125 return results; | |
| 126 } | |
| 127 | |
| 128 void RemovableStorageNotifications::AddObserver(RemovableStorageObserver* obs) { | |
| 129 observer_list_->AddObserver(obs); | |
| 130 } | |
| 131 | |
| 132 void RemovableStorageNotifications::RemoveObserver( | |
| 133 RemovableStorageObserver* obs) { | |
| 134 observer_list_->RemoveObserver(obs); | |
| 135 } | |
| 136 | |
| 137 RemovableStorageNotifications* RemovableStorageNotifications::GetInstance() { | |
| 138 return g_removable_storage_notifications; | |
| 139 } | |
| 140 | |
| 141 } // namespace chrome | 147 } // namespace chrome |
| OLD | NEW |