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

Side by Side Diff: extensions/browser/api/storage/storage_frontend.cc

Issue 216513002: Replace DCHECK(BrowserThread::CurrentlyOn) with DCHECK_CURRENTLY_ON in extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "extensions/browser/api/storage/storage_frontend.h" 5 #include "extensions/browser/api/storage/storage_frontend.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const scoped_refptr<SettingsStorageFactory>& factory, 80 const scoped_refptr<SettingsStorageFactory>& factory,
81 BrowserContext* context) 81 BrowserContext* context)
82 : browser_context_(context) { 82 : browser_context_(context) {
83 Init(factory); 83 Init(factory);
84 } 84 }
85 85
86 void StorageFrontend::Init( 86 void StorageFrontend::Init(
87 const scoped_refptr<SettingsStorageFactory>& factory) { 87 const scoped_refptr<SettingsStorageFactory>& factory) {
88 observers_ = new SettingsObserverList(); 88 observers_ = new SettingsObserverList();
89 browser_context_observer_.reset(new DefaultObserver(browser_context_)); 89 browser_context_observer_.reset(new DefaultObserver(browser_context_));
90 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 90 DCHECK_CURRENTLY_ON(BrowserThread::UI);
91 DCHECK(!browser_context_->IsOffTheRecord()); 91 DCHECK(!browser_context_->IsOffTheRecord());
92 92
93 observers_->AddObserver(browser_context_observer_.get()); 93 observers_->AddObserver(browser_context_observer_.get());
94 94
95 caches_[settings_namespace::LOCAL] = 95 caches_[settings_namespace::LOCAL] =
96 new LocalValueStoreCache(factory, browser_context_->GetPath()); 96 new LocalValueStoreCache(factory, browser_context_->GetPath());
97 97
98 // Add any additional caches the embedder supports (for example, caches 98 // Add any additional caches the embedder supports (for example, caches
99 // for chrome.storage.managed and chrome.storage.sync). 99 // for chrome.storage.managed and chrome.storage.sync).
100 ExtensionsAPIClient::Get()->AddAdditionalValueStoreCaches( 100 ExtensionsAPIClient::Get()->AddAdditionalValueStoreCaches(
101 browser_context_, factory, observers_, &caches_); 101 browser_context_, factory, observers_, &caches_);
102 } 102 }
103 103
104 StorageFrontend::~StorageFrontend() { 104 StorageFrontend::~StorageFrontend() {
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 105 DCHECK_CURRENTLY_ON(BrowserThread::UI);
106 observers_->RemoveObserver(browser_context_observer_.get()); 106 observers_->RemoveObserver(browser_context_observer_.get());
107 for (CacheMap::iterator it = caches_.begin(); it != caches_.end(); ++it) { 107 for (CacheMap::iterator it = caches_.begin(); it != caches_.end(); ++it) {
108 ValueStoreCache* cache = it->second; 108 ValueStoreCache* cache = it->second;
109 cache->ShutdownOnUI(); 109 cache->ShutdownOnUI();
110 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, cache); 110 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, cache);
111 } 111 }
112 } 112 }
113 113
114 ValueStoreCache* StorageFrontend::GetValueStoreCache( 114 ValueStoreCache* StorageFrontend::GetValueStoreCache(
115 settings_namespace::Namespace settings_namespace) const { 115 settings_namespace::Namespace settings_namespace) const {
116 CacheMap::const_iterator it = caches_.find(settings_namespace); 116 CacheMap::const_iterator it = caches_.find(settings_namespace);
117 if (it != caches_.end()) 117 if (it != caches_.end())
118 return it->second; 118 return it->second;
119 return NULL; 119 return NULL;
120 } 120 }
121 121
122 bool StorageFrontend::IsStorageEnabled( 122 bool StorageFrontend::IsStorageEnabled(
123 settings_namespace::Namespace settings_namespace) const { 123 settings_namespace::Namespace settings_namespace) const {
124 return caches_.find(settings_namespace) != caches_.end(); 124 return caches_.find(settings_namespace) != caches_.end();
125 } 125 }
126 126
127 void StorageFrontend::RunWithStorage( 127 void StorageFrontend::RunWithStorage(
128 scoped_refptr<const Extension> extension, 128 scoped_refptr<const Extension> extension,
129 settings_namespace::Namespace settings_namespace, 129 settings_namespace::Namespace settings_namespace,
130 const ValueStoreCache::StorageCallback& callback) { 130 const ValueStoreCache::StorageCallback& callback) {
131 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 131 DCHECK_CURRENTLY_ON(BrowserThread::UI);
132 CHECK(extension.get()); 132 CHECK(extension.get());
133 133
134 ValueStoreCache* cache = caches_[settings_namespace]; 134 ValueStoreCache* cache = caches_[settings_namespace];
135 CHECK(cache); 135 CHECK(cache);
136 136
137 BrowserThread::PostTask( 137 BrowserThread::PostTask(
138 BrowserThread::FILE, FROM_HERE, 138 BrowserThread::FILE, FROM_HERE,
139 base::Bind(&ValueStoreCache::RunWithValueStoreForExtension, 139 base::Bind(&ValueStoreCache::RunWithValueStoreForExtension,
140 base::Unretained(cache), callback, extension)); 140 base::Unretained(cache), callback, extension));
141 } 141 }
142 142
143 void StorageFrontend::DeleteStorageSoon(const std::string& extension_id) { 143 void StorageFrontend::DeleteStorageSoon(const std::string& extension_id) {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 144 DCHECK_CURRENTLY_ON(BrowserThread::UI);
145 for (CacheMap::iterator it = caches_.begin(); it != caches_.end(); ++it) { 145 for (CacheMap::iterator it = caches_.begin(); it != caches_.end(); ++it) {
146 ValueStoreCache* cache = it->second; 146 ValueStoreCache* cache = it->second;
147 BrowserThread::PostTask( 147 BrowserThread::PostTask(
148 BrowserThread::FILE, FROM_HERE, 148 BrowserThread::FILE, FROM_HERE,
149 base::Bind(&ValueStoreCache::DeleteStorageSoon, 149 base::Bind(&ValueStoreCache::DeleteStorageSoon,
150 base::Unretained(cache), 150 base::Unretained(cache),
151 extension_id)); 151 extension_id));
152 } 152 }
153 } 153 }
154 154
155 scoped_refptr<SettingsObserverList> StorageFrontend::GetObservers() { 155 scoped_refptr<SettingsObserverList> StorageFrontend::GetObservers() {
156 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 156 DCHECK_CURRENTLY_ON(BrowserThread::UI);
157 return observers_; 157 return observers_;
158 } 158 }
159 159
160 void StorageFrontend::DisableStorageForTesting( 160 void StorageFrontend::DisableStorageForTesting(
161 settings_namespace::Namespace settings_namespace) { 161 settings_namespace::Namespace settings_namespace) {
162 CacheMap::iterator it = caches_.find(settings_namespace); 162 CacheMap::iterator it = caches_.find(settings_namespace);
163 if (it != caches_.end()) { 163 if (it != caches_.end()) {
164 ValueStoreCache* cache = it->second; 164 ValueStoreCache* cache = it->second;
165 cache->ShutdownOnUI(); 165 cache->ShutdownOnUI();
166 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, cache); 166 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, cache);
167 caches_.erase(it); 167 caches_.erase(it);
168 } 168 }
169 } 169 }
170 170
171 // BrowserContextKeyedAPI implementation. 171 // BrowserContextKeyedAPI implementation.
172 172
173 // static 173 // static
174 BrowserContextKeyedAPIFactory<StorageFrontend>* 174 BrowserContextKeyedAPIFactory<StorageFrontend>*
175 StorageFrontend::GetFactoryInstance() { 175 StorageFrontend::GetFactoryInstance() {
176 return g_factory.Pointer(); 176 return g_factory.Pointer();
177 } 177 }
178 178
179 // static 179 // static
180 const char* StorageFrontend::service_name() { return "StorageFrontend"; } 180 const char* StorageFrontend::service_name() { return "StorageFrontend"; }
181 181
182 } // namespace extensions 182 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/storage/local_value_store_cache.cc ('k') | extensions/browser/event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698