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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 base::AutoLock lock(storage_lock_); | 55 base::AutoLock lock(storage_lock_); |
56 for (RemovableStorageMap::const_iterator it = storage_map_.begin(); | 56 for (RemovableStorageMap::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()); | |
Lei Zhang
2013/06/03 20:17:13
Isn't this always the UI thread?
Greg Billock
2013/06/03 22:33:02
Not in tests.
| |
65 if (initialized_) { | 66 if (initialized_) { |
66 if (!callback.is_null()) | 67 if (!callback.is_null()) |
67 callback.Run(); | 68 callback.Run(); |
68 return; | 69 return; |
69 } | 70 } |
70 | 71 |
71 if (!callback.is_null()) { | 72 if (!callback.is_null()) { |
72 on_initialize_callbacks_.push_back(callback); | 73 on_initialize_callbacks_.push_back(callback); |
73 } | 74 } |
74 | 75 |
76 if (initializing_) | |
77 return; | |
78 | |
79 initializing_ = true; | |
75 Init(); | 80 Init(); |
76 } | 81 } |
77 | 82 |
78 bool StorageMonitor::IsInitialized() { | 83 bool StorageMonitor::IsInitialized() { |
79 return initialized_; | 84 return initialized_; |
80 } | 85 } |
81 | 86 |
82 void StorageMonitor::AddObserver(RemovableStorageObserver* obs) { | 87 void StorageMonitor::AddObserver(RemovableStorageObserver* obs) { |
83 observer_list_->AddObserver(obs); | 88 observer_list_->AddObserver(obs); |
84 } | 89 } |
(...skipping 16 matching lines...) Expand all Loading... | |
101 void StorageMonitor::EjectDevice( | 106 void StorageMonitor::EjectDevice( |
102 const std::string& device_id, | 107 const std::string& device_id, |
103 base::Callback<void(EjectStatus)> callback) { | 108 base::Callback<void(EjectStatus)> callback) { |
104 // Platform-specific implementations will override this method to | 109 // Platform-specific implementations will override this method to |
105 // perform actual device ejection. | 110 // perform actual device ejection. |
106 callback.Run(EJECT_FAILURE); | 111 callback.Run(EJECT_FAILURE); |
107 } | 112 } |
108 | 113 |
109 StorageMonitor::StorageMonitor() | 114 StorageMonitor::StorageMonitor() |
110 : observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()), | 115 : observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()), |
116 initializing_(false), | |
111 initialized_(false), | 117 initialized_(false), |
112 transient_device_ids_(new TransientDeviceIds) { | 118 transient_device_ids_(new TransientDeviceIds) { |
113 receiver_.reset(new ReceiverImpl(this)); | 119 receiver_.reset(new ReceiverImpl(this)); |
114 | 120 |
115 DCHECK(!g_storage_monitor); | 121 DCHECK(!g_storage_monitor); |
116 g_storage_monitor = this; | 122 g_storage_monitor = this; |
117 } | 123 } |
118 | 124 |
119 StorageMonitor::~StorageMonitor() { | 125 StorageMonitor::~StorageMonitor() { |
120 g_storage_monitor = NULL; | 126 g_storage_monitor = NULL; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 info = it->second; | 172 info = it->second; |
167 storage_map_.erase(it); | 173 storage_map_.erase(it); |
168 } | 174 } |
169 | 175 |
170 DVLOG(1) << "RemovableStorageDetached for id " << id; | 176 DVLOG(1) << "RemovableStorageDetached for id " << id; |
171 observer_list_->Notify( | 177 observer_list_->Notify( |
172 &RemovableStorageObserver::OnRemovableStorageDetached, info); | 178 &RemovableStorageObserver::OnRemovableStorageDetached, info); |
173 } | 179 } |
174 | 180 |
175 } // namespace chrome | 181 } // namespace chrome |
OLD | NEW |