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

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

Issue 2965153002: Migrate Extensions code to Task Scheduler API (Closed)
Patch Set: Self review Created 3 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 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/local_value_store_cache.h" 5 #include "extensions/browser/api/storage/local_value_store_cache.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
11 #include "content/public/browser/browser_thread.h" 11 #include "content/public/browser/browser_thread.h"
12 #include "extensions/browser/api/storage/backend_task_runner.h"
12 #include "extensions/browser/api/storage/weak_unlimited_settings_storage.h" 13 #include "extensions/browser/api/storage/weak_unlimited_settings_storage.h"
13 #include "extensions/browser/value_store/value_store_factory.h" 14 #include "extensions/browser/value_store/value_store_factory.h"
14 #include "extensions/common/api/storage.h" 15 #include "extensions/common/api/storage.h"
15 #include "extensions/common/extension.h" 16 #include "extensions/common/extension.h"
16 #include "extensions/common/permissions/permissions_data.h" 17 #include "extensions/common/permissions/permissions_data.h"
17 18
18 using content::BrowserThread; 19 using content::BrowserThread;
19 20
20 namespace extensions { 21 namespace extensions {
21 22
(...skipping 10 matching lines...) Expand all
32 33
33 } // namespace 34 } // namespace
34 35
35 LocalValueStoreCache::LocalValueStoreCache( 36 LocalValueStoreCache::LocalValueStoreCache(
36 const scoped_refptr<ValueStoreFactory>& factory) 37 const scoped_refptr<ValueStoreFactory>& factory)
37 : storage_factory_(factory), quota_(GetLocalQuotaLimits()) { 38 : storage_factory_(factory), quota_(GetLocalQuotaLimits()) {
38 DCHECK_CURRENTLY_ON(BrowserThread::UI); 39 DCHECK_CURRENTLY_ON(BrowserThread::UI);
39 } 40 }
40 41
41 LocalValueStoreCache::~LocalValueStoreCache() { 42 LocalValueStoreCache::~LocalValueStoreCache() {
42 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 43 DCHECK(IsOnBackendSequence());
43 } 44 }
44 45
45 void LocalValueStoreCache::RunWithValueStoreForExtension( 46 void LocalValueStoreCache::RunWithValueStoreForExtension(
46 const StorageCallback& callback, 47 const StorageCallback& callback,
47 scoped_refptr<const Extension> extension) { 48 scoped_refptr<const Extension> extension) {
48 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 49 DCHECK(IsOnBackendSequence());
49 50
50 ValueStore* storage = GetStorage(extension.get()); 51 ValueStore* storage = GetStorage(extension.get());
51 52
52 // A neat way to implement unlimited storage; if the extension has the 53 // A neat way to implement unlimited storage; if the extension has the
53 // unlimited storage permission, force through all calls to Set(). 54 // unlimited storage permission, force through all calls to Set().
54 if (extension->permissions_data()->HasAPIPermission( 55 if (extension->permissions_data()->HasAPIPermission(
55 APIPermission::kUnlimitedStorage)) { 56 APIPermission::kUnlimitedStorage)) {
56 WeakUnlimitedSettingsStorage unlimited_storage(storage); 57 WeakUnlimitedSettingsStorage unlimited_storage(storage);
57 callback.Run(&unlimited_storage); 58 callback.Run(&unlimited_storage);
58 } else { 59 } else {
59 callback.Run(storage); 60 callback.Run(storage);
60 } 61 }
61 } 62 }
62 63
63 void LocalValueStoreCache::DeleteStorageSoon(const std::string& extension_id) { 64 void LocalValueStoreCache::DeleteStorageSoon(const std::string& extension_id) {
64 DCHECK_CURRENTLY_ON(BrowserThread::FILE); 65 DCHECK(IsOnBackendSequence());
65 storage_map_.erase(extension_id); 66 storage_map_.erase(extension_id);
66 storage_factory_->DeleteSettings(settings_namespace::LOCAL, 67 storage_factory_->DeleteSettings(settings_namespace::LOCAL,
67 ValueStoreFactory::ModelType::APP, 68 ValueStoreFactory::ModelType::APP,
68 extension_id); 69 extension_id);
69 storage_factory_->DeleteSettings(settings_namespace::LOCAL, 70 storage_factory_->DeleteSettings(settings_namespace::LOCAL,
70 ValueStoreFactory::ModelType::EXTENSION, 71 ValueStoreFactory::ModelType::EXTENSION,
71 extension_id); 72 extension_id);
72 } 73 }
73 74
74 ValueStore* LocalValueStoreCache::GetStorage(const Extension* extension) { 75 ValueStore* LocalValueStoreCache::GetStorage(const Extension* extension) {
75 StorageMap::iterator iter = storage_map_.find(extension->id()); 76 StorageMap::iterator iter = storage_map_.find(extension->id());
76 if (iter != storage_map_.end()) 77 if (iter != storage_map_.end())
77 return iter->second.get(); 78 return iter->second.get();
78 79
79 ValueStoreFactory::ModelType model_type = 80 ValueStoreFactory::ModelType model_type =
80 extension->is_app() ? ValueStoreFactory::ModelType::APP 81 extension->is_app() ? ValueStoreFactory::ModelType::APP
81 : ValueStoreFactory::ModelType::EXTENSION; 82 : ValueStoreFactory::ModelType::EXTENSION;
82 std::unique_ptr<ValueStore> store = storage_factory_->CreateSettingsStore( 83 std::unique_ptr<ValueStore> store = storage_factory_->CreateSettingsStore(
83 settings_namespace::LOCAL, model_type, extension->id()); 84 settings_namespace::LOCAL, model_type, extension->id());
84 std::unique_ptr<SettingsStorageQuotaEnforcer> storage( 85 std::unique_ptr<SettingsStorageQuotaEnforcer> storage(
85 new SettingsStorageQuotaEnforcer(quota_, std::move(store))); 86 new SettingsStorageQuotaEnforcer(quota_, std::move(store)));
86 DCHECK(storage.get()); 87 DCHECK(storage.get());
87 88
88 ValueStore* storage_ptr = storage.get(); 89 ValueStore* storage_ptr = storage.get();
89 storage_map_[extension->id()] = std::move(storage); 90 storage_map_[extension->id()] = std::move(storage);
90 return storage_ptr; 91 return storage_ptr;
91 } 92 }
92 93
93 } // namespace extensions 94 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698