OLD | NEW |
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 <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "extensions/browser/api/storage/settings_storage_factory.h" | 13 #include "extensions/browser/api/storage/settings_storage_factory.h" |
14 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" | 14 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" |
15 #include "extensions/browser/api/storage/weak_unlimited_settings_storage.h" | 15 #include "extensions/browser/api/storage/weak_unlimited_settings_storage.h" |
16 #include "extensions/browser/value_store/value_store.h" | 16 #include "extensions/browser/value_store/value_store.h" |
17 #include "extensions/common/api/storage.h" | 17 #include "extensions/common/api/storage.h" |
18 #include "extensions/common/constants.h" | 18 #include "extensions/common/constants.h" |
19 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
20 #include "extensions/common/permissions/api_permission.h" | 20 #include "extensions/common/permissions/api_permission.h" |
| 21 #include "extensions/common/permissions/permissions_data.h" |
21 | 22 |
22 using content::BrowserThread; | 23 using content::BrowserThread; |
23 | 24 |
24 namespace extensions { | 25 namespace extensions { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 // Returns the quota limit for local storage, taken from the schema in | 29 // Returns the quota limit for local storage, taken from the schema in |
29 // extensions/common/api/storage.json. | 30 // extensions/common/api/storage.json. |
30 SettingsStorageQuotaEnforcer::Limits GetLocalQuotaLimits() { | 31 SettingsStorageQuotaEnforcer::Limits GetLocalQuotaLimits() { |
(...skipping 24 matching lines...) Expand all Loading... |
55 | 56 |
56 void LocalValueStoreCache::RunWithValueStoreForExtension( | 57 void LocalValueStoreCache::RunWithValueStoreForExtension( |
57 const StorageCallback& callback, | 58 const StorageCallback& callback, |
58 scoped_refptr<const Extension> extension) { | 59 scoped_refptr<const Extension> extension) { |
59 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 60 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
60 | 61 |
61 ValueStore* storage = GetStorage(extension); | 62 ValueStore* storage = GetStorage(extension); |
62 | 63 |
63 // A neat way to implement unlimited storage; if the extension has the | 64 // A neat way to implement unlimited storage; if the extension has the |
64 // unlimited storage permission, force through all calls to Set(). | 65 // unlimited storage permission, force through all calls to Set(). |
65 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) { | 66 if (extension->permissions_data()->HasAPIPermission( |
| 67 APIPermission::kUnlimitedStorage)) { |
66 WeakUnlimitedSettingsStorage unlimited_storage(storage); | 68 WeakUnlimitedSettingsStorage unlimited_storage(storage); |
67 callback.Run(&unlimited_storage); | 69 callback.Run(&unlimited_storage); |
68 } else { | 70 } else { |
69 callback.Run(storage); | 71 callback.Run(storage); |
70 } | 72 } |
71 } | 73 } |
72 | 74 |
73 void LocalValueStoreCache::DeleteStorageSoon(const std::string& extension_id) { | 75 void LocalValueStoreCache::DeleteStorageSoon(const std::string& extension_id) { |
74 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 76 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
75 storage_map_.erase(extension_id); | 77 storage_map_.erase(extension_id); |
(...skipping 11 matching lines...) Expand all Loading... |
87 extension->is_app() ? app_base_path_ : extension_base_path_; | 89 extension->is_app() ? app_base_path_ : extension_base_path_; |
88 linked_ptr<SettingsStorageQuotaEnforcer> storage( | 90 linked_ptr<SettingsStorageQuotaEnforcer> storage( |
89 new SettingsStorageQuotaEnforcer( | 91 new SettingsStorageQuotaEnforcer( |
90 quota_, storage_factory_->Create(file_path, extension->id()))); | 92 quota_, storage_factory_->Create(file_path, extension->id()))); |
91 DCHECK(storage.get()); | 93 DCHECK(storage.get()); |
92 storage_map_[extension->id()] = storage; | 94 storage_map_[extension->id()] = storage; |
93 return storage.get(); | 95 return storage.get(); |
94 } | 96 } |
95 | 97 |
96 } // namespace extensions | 98 } // namespace extensions |
OLD | NEW |