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/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/storage_monitor/removable_storage_observer.h" | 10 #include "chrome/browser/storage_monitor/removable_storage_observer.h" |
10 #include "chrome/browser/storage_monitor/transient_device_ids.h" | 11 #include "chrome/browser/storage_monitor/transient_device_ids.h" |
11 | 12 |
12 namespace chrome { | 13 namespace chrome { |
13 | 14 |
14 static StorageMonitor* g_storage_monitor = NULL; | |
15 | |
16 StorageMonitor::Receiver::~Receiver() { | 15 StorageMonitor::Receiver::~Receiver() { |
17 } | 16 } |
18 | 17 |
19 class StorageMonitor::ReceiverImpl : public StorageMonitor::Receiver { | 18 class StorageMonitor::ReceiverImpl : public StorageMonitor::Receiver { |
20 public: | 19 public: |
21 explicit ReceiverImpl(StorageMonitor* notifications) | 20 explicit ReceiverImpl(StorageMonitor* notifications) |
22 : notifications_(notifications) {} | 21 : notifications_(notifications) {} |
23 | 22 |
24 virtual ~ReceiverImpl() {} | 23 virtual ~ReceiverImpl() {} |
25 | 24 |
(...skipping 13 matching lines...) Expand all Loading... |
39 | 38 |
40 void StorageMonitor::ReceiverImpl::ProcessDetach(const std::string& id) { | 39 void StorageMonitor::ReceiverImpl::ProcessDetach(const std::string& id) { |
41 notifications_->ProcessDetach(id); | 40 notifications_->ProcessDetach(id); |
42 } | 41 } |
43 | 42 |
44 void StorageMonitor::ReceiverImpl::MarkInitialized() { | 43 void StorageMonitor::ReceiverImpl::MarkInitialized() { |
45 notifications_->MarkInitialized(); | 44 notifications_->MarkInitialized(); |
46 } | 45 } |
47 | 46 |
48 StorageMonitor* StorageMonitor::GetInstance() { | 47 StorageMonitor* StorageMonitor::GetInstance() { |
49 return g_storage_monitor; | 48 if (g_browser_process) |
| 49 return g_browser_process->storage_monitor(); |
| 50 |
| 51 return NULL; |
50 } | 52 } |
51 | 53 |
52 std::vector<StorageInfo> StorageMonitor::GetAllAvailableStorages() const { | 54 std::vector<StorageInfo> StorageMonitor::GetAllAvailableStorages() const { |
53 std::vector<StorageInfo> results; | 55 std::vector<StorageInfo> results; |
54 | 56 |
55 base::AutoLock lock(storage_lock_); | 57 base::AutoLock lock(storage_lock_); |
56 for (StorageMap::const_iterator it = storage_map_.begin(); | 58 for (StorageMap::const_iterator it = storage_map_.begin(); |
57 it != storage_map_.end(); | 59 it != storage_map_.end(); |
58 ++it) { | 60 ++it) { |
59 results.push_back(it->second); | 61 results.push_back(it->second); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 // perform actual device ejection. | 112 // perform actual device ejection. |
111 callback.Run(EJECT_FAILURE); | 113 callback.Run(EJECT_FAILURE); |
112 } | 114 } |
113 | 115 |
114 StorageMonitor::StorageMonitor() | 116 StorageMonitor::StorageMonitor() |
115 : observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()), | 117 : observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()), |
116 initializing_(false), | 118 initializing_(false), |
117 initialized_(false), | 119 initialized_(false), |
118 transient_device_ids_(new TransientDeviceIds) { | 120 transient_device_ids_(new TransientDeviceIds) { |
119 receiver_.reset(new ReceiverImpl(this)); | 121 receiver_.reset(new ReceiverImpl(this)); |
120 | |
121 DCHECK(!g_storage_monitor); | |
122 g_storage_monitor = this; | |
123 } | 122 } |
124 | 123 |
125 StorageMonitor::~StorageMonitor() { | 124 StorageMonitor::~StorageMonitor() { |
126 g_storage_monitor = NULL; | |
127 } | |
128 | |
129 // static | |
130 void StorageMonitor::RemoveSingletonForTesting() { | |
131 g_storage_monitor = NULL; | |
132 } | 125 } |
133 | 126 |
134 StorageMonitor::Receiver* StorageMonitor::receiver() const { | 127 StorageMonitor::Receiver* StorageMonitor::receiver() const { |
135 return receiver_.get(); | 128 return receiver_.get(); |
136 } | 129 } |
137 | 130 |
138 void StorageMonitor::MarkInitialized() { | 131 void StorageMonitor::MarkInitialized() { |
139 initialized_ = true; | 132 initialized_ = true; |
140 for (std::vector<base::Closure>::iterator iter = | 133 for (std::vector<base::Closure>::iterator iter = |
141 on_initialize_callbacks_.begin(); | 134 on_initialize_callbacks_.begin(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 } | 169 } |
177 | 170 |
178 DVLOG(1) << "StorageDetached for id " << id; | 171 DVLOG(1) << "StorageDetached for id " << id; |
179 if (StorageInfo::IsRemovableDevice(info.device_id())) { | 172 if (StorageInfo::IsRemovableDevice(info.device_id())) { |
180 observer_list_->Notify( | 173 observer_list_->Notify( |
181 &RemovableStorageObserver::OnRemovableStorageDetached, info); | 174 &RemovableStorageObserver::OnRemovableStorageDetached, info); |
182 } | 175 } |
183 } | 176 } |
184 | 177 |
185 } // namespace chrome | 178 } // namespace chrome |
OLD | NEW |