Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(552)

Side by Side Diff: chrome/browser/storage_monitor/storage_monitor.cc

Issue 16703025: [StorageMonitor] Move StorageMonitor ownership to BrowserProcessImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 return g_browser_process->storage_monitor();
50 } 49 }
51 50
52 std::vector<StorageInfo> StorageMonitor::GetAllAvailableStorages() const { 51 std::vector<StorageInfo> StorageMonitor::GetAllAvailableStorages() const {
53 std::vector<StorageInfo> results; 52 std::vector<StorageInfo> results;
54 53
55 base::AutoLock lock(storage_lock_); 54 base::AutoLock lock(storage_lock_);
56 for (StorageMap::const_iterator it = storage_map_.begin(); 55 for (StorageMap::const_iterator it = storage_map_.begin();
57 it != storage_map_.end(); 56 it != storage_map_.end();
58 ++it) { 57 ++it) {
59 results.push_back(it->second); 58 results.push_back(it->second);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // perform actual device ejection. 109 // perform actual device ejection.
111 callback.Run(EJECT_FAILURE); 110 callback.Run(EJECT_FAILURE);
112 } 111 }
113 112
114 StorageMonitor::StorageMonitor() 113 StorageMonitor::StorageMonitor()
115 : observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()), 114 : observer_list_(new ObserverListThreadSafe<RemovableStorageObserver>()),
116 initializing_(false), 115 initializing_(false),
117 initialized_(false), 116 initialized_(false),
118 transient_device_ids_(new TransientDeviceIds) { 117 transient_device_ids_(new TransientDeviceIds) {
119 receiver_.reset(new ReceiverImpl(this)); 118 receiver_.reset(new ReceiverImpl(this));
120
121 DCHECK(!g_storage_monitor);
122 g_storage_monitor = this;
123 } 119 }
124 120
125 StorageMonitor::~StorageMonitor() { 121 StorageMonitor::~StorageMonitor() {
126 g_storage_monitor = NULL;
127 }
128
129 // static
130 void StorageMonitor::RemoveSingletonForTesting() {
131 g_storage_monitor = NULL;
132 } 122 }
133 123
134 StorageMonitor::Receiver* StorageMonitor::receiver() const { 124 StorageMonitor::Receiver* StorageMonitor::receiver() const {
135 return receiver_.get(); 125 return receiver_.get();
136 } 126 }
137 127
138 void StorageMonitor::MarkInitialized() { 128 void StorageMonitor::MarkInitialized() {
139 initialized_ = true; 129 initialized_ = true;
140 for (std::vector<base::Closure>::iterator iter = 130 for (std::vector<base::Closure>::iterator iter =
141 on_initialize_callbacks_.begin(); 131 on_initialize_callbacks_.begin();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 166 }
177 167
178 DVLOG(1) << "RemovableStorageDetached for id " << id; 168 DVLOG(1) << "RemovableStorageDetached for id " << id;
179 if (StorageInfo::IsRemovableDevice(info.device_id())) { 169 if (StorageInfo::IsRemovableDevice(info.device_id())) {
180 observer_list_->Notify( 170 observer_list_->Notify(
181 &RemovableStorageObserver::OnRemovableStorageDetached, info); 171 &RemovableStorageObserver::OnRemovableStorageDetached, info);
182 } 172 }
183 } 173 }
184 174
185 } // namespace chrome 175 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698