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

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

Issue 14556015: [Media Galleries] Lazily initialize the storage monitor. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Switch approaches Created 7 years, 7 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/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"
11 #include "content/public/browser/browser_thread.h"
11 12
12 namespace chrome { 13 namespace chrome {
13 14
14 static StorageMonitor* g_storage_monitor = NULL; 15 static StorageMonitor* g_storage_monitor = NULL;
15 16
16 StorageMonitor::Receiver::~Receiver() { 17 StorageMonitor::Receiver::~Receiver() {
17 } 18 }
18 19
19 class StorageMonitor::ReceiverImpl : public StorageMonitor::Receiver { 20 class StorageMonitor::ReceiverImpl : public StorageMonitor::Receiver {
20 public: 21 public:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 base::AutoLock lock(storage_lock_); 56 base::AutoLock lock(storage_lock_);
56 for (RemovableStorageMap::const_iterator it = storage_map_.begin(); 57 for (RemovableStorageMap::const_iterator it = storage_map_.begin();
57 it != storage_map_.end(); 58 it != storage_map_.end();
58 ++it) { 59 ++it) {
59 results.push_back(it->second); 60 results.push_back(it->second);
60 } 61 }
61 return results; 62 return results;
62 } 63 }
63 64
64 void StorageMonitor::Initialize(base::Closure callback) { 65 void StorageMonitor::Initialize(base::Closure callback) {
66 //DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
67
65 if (initialized_) { 68 if (initialized_) {
66 if (!callback.is_null()) 69 if (!callback.is_null())
67 callback.Run(); 70 callback.Run();
68 return; 71 return;
69 } 72 }
70 73
71 if (!callback.is_null()) { 74 if (!callback.is_null()) {
72 on_initialize_callbacks_.push_back(callback); 75 on_initialize_callbacks_.push_back(callback);
73 } 76 }
74 77
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // static 126 // static
124 void StorageMonitor::RemoveSingletonForTesting() { 127 void StorageMonitor::RemoveSingletonForTesting() {
125 g_storage_monitor = NULL; 128 g_storage_monitor = NULL;
126 } 129 }
127 130
128 StorageMonitor::Receiver* StorageMonitor::receiver() const { 131 StorageMonitor::Receiver* StorageMonitor::receiver() const {
129 return receiver_.get(); 132 return receiver_.get();
130 } 133 }
131 134
132 void StorageMonitor::MarkInitialized() { 135 void StorageMonitor::MarkInitialized() {
136 //DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
137
133 initialized_ = true; 138 initialized_ = true;
134 for (std::vector<base::Closure>::iterator iter = 139 for (std::vector<base::Closure>::iterator iter =
135 on_initialize_callbacks_.begin(); 140 on_initialize_callbacks_.begin();
136 iter != on_initialize_callbacks_.end(); ++iter) { 141 iter != on_initialize_callbacks_.end(); ++iter) {
137 iter->Run(); 142 iter->Run();
138 } 143 }
139 on_initialize_callbacks_.clear(); 144 on_initialize_callbacks_.clear();
140 } 145 }
141 146
142 void StorageMonitor::ProcessAttach(const StorageInfo& info) { 147 void StorageMonitor::ProcessAttach(const StorageInfo& info) {
(...skipping 23 matching lines...) Expand all
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698