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 if (initialized_) { | 65 if (initialized_) { |
vandebo (ex-Chrome)
2013/05/31 18:05:03
Add a check that this is only called from a single
Greg Billock
2013/06/01 01:48:46
There's a note in the header. I think I tried a ch
vandebo (ex-Chrome)
2013/06/01 15:47:24
I think you can use base/threading/thread_checker.
Greg Billock
2013/06/03 15:30:57
Added. We'll see if the bots complain.
| |
66 if (!callback.is_null()) | 66 if (!callback.is_null()) |
67 callback.Run(); | 67 callback.Run(); |
68 return; | 68 return; |
69 } | 69 } |
70 | 70 |
71 if (!callback.is_null()) { | 71 if (!callback.is_null()) { |
72 on_initialize_callbacks_.push_back(callback); | 72 on_initialize_callbacks_.push_back(callback); |
73 } | 73 } |
74 | 74 |
75 if (initializing_) | |
76 return; | |
77 | |
78 initializing_ = true; | |
75 Init(); | 79 Init(); |
76 } | 80 } |
77 | 81 |
78 bool StorageMonitor::IsInitialized() { | 82 bool StorageMonitor::IsInitialized() { |
79 return initialized_; | 83 return initialized_; |
80 } | 84 } |
81 | 85 |
82 void StorageMonitor::AddObserver(RemovableStorageObserver* obs) { | 86 void StorageMonitor::AddObserver(RemovableStorageObserver* obs) { |
83 observer_list_->AddObserver(obs); | 87 observer_list_->AddObserver(obs); |
84 } | 88 } |
(...skipping 16 matching lines...) Expand all Loading... | |
101 void StorageMonitor::EjectDevice( | 105 void StorageMonitor::EjectDevice( |
102 const std::string& device_id, | 106 const std::string& device_id, |
103 base::Callback<void(EjectStatus)> callback) { | 107 base::Callback<void(EjectStatus)> callback) { |
104 // Platform-specific implementations will override this method to | 108 // Platform-specific implementations will override this method to |
105 // perform actual device ejection. | 109 // perform actual device ejection. |
106 callback.Run(EJECT_FAILURE); | 110 callback.Run(EJECT_FAILURE); |
107 } | 111 } |
108 | 112 |
109 StorageMonitor::StorageMonitor() | 113 StorageMonitor::StorageMonitor() |
110 : observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()), | 114 : observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()), |
115 initializing_(false), | |
111 initialized_(false), | 116 initialized_(false), |
112 transient_device_ids_(new TransientDeviceIds) { | 117 transient_device_ids_(new TransientDeviceIds) { |
113 receiver_.reset(new ReceiverImpl(this)); | 118 receiver_.reset(new ReceiverImpl(this)); |
114 | 119 |
115 DCHECK(!g_storage_monitor); | 120 DCHECK(!g_storage_monitor); |
116 g_storage_monitor = this; | 121 g_storage_monitor = this; |
117 } | 122 } |
118 | 123 |
119 StorageMonitor::~StorageMonitor() { | 124 StorageMonitor::~StorageMonitor() { |
120 g_storage_monitor = NULL; | 125 g_storage_monitor = NULL; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
166 info = it->second; | 171 info = it->second; |
167 storage_map_.erase(it); | 172 storage_map_.erase(it); |
168 } | 173 } |
169 | 174 |
170 DVLOG(1) << "RemovableStorageDetached for id " << id; | 175 DVLOG(1) << "RemovableStorageDetached for id " << id; |
171 observer_list_->Notify( | 176 observer_list_->Notify( |
172 &RemovableStorageObserver::OnRemovableStorageDetached, info); | 177 &RemovableStorageObserver::OnRemovableStorageDetached, info); |
173 } | 178 } |
174 | 179 |
175 } // namespace chrome | 180 } // namespace chrome |
OLD | NEW |