| 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" |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 LocalValueStoreCache::LocalValueStoreCache( | 41 LocalValueStoreCache::LocalValueStoreCache( |
| 42 const scoped_refptr<SettingsStorageFactory>& factory, | 42 const scoped_refptr<SettingsStorageFactory>& factory, |
| 43 const base::FilePath& profile_path) | 43 const base::FilePath& profile_path) |
| 44 : storage_factory_(factory), | 44 : storage_factory_(factory), |
| 45 extension_base_path_( | 45 extension_base_path_( |
| 46 profile_path.AppendASCII(kLocalExtensionSettingsDirectoryName)), | 46 profile_path.AppendASCII(kLocalExtensionSettingsDirectoryName)), |
| 47 app_base_path_(profile_path.AppendASCII(kLocalAppSettingsDirectoryName)), | 47 app_base_path_(profile_path.AppendASCII(kLocalAppSettingsDirectoryName)), |
| 48 quota_(GetLocalQuotaLimits()) { | 48 quota_(GetLocalQuotaLimits()) { |
| 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 49 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 50 } | 50 } |
| 51 | 51 |
| 52 LocalValueStoreCache::~LocalValueStoreCache() { | 52 LocalValueStoreCache::~LocalValueStoreCache() { |
| 53 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 53 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void LocalValueStoreCache::RunWithValueStoreForExtension( | 56 void LocalValueStoreCache::RunWithValueStoreForExtension( |
| 57 const StorageCallback& callback, | 57 const StorageCallback& callback, |
| 58 scoped_refptr<const Extension> extension) { | 58 scoped_refptr<const Extension> extension) { |
| 59 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 59 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 60 | 60 |
| 61 ValueStore* storage = GetStorage(extension); | 61 ValueStore* storage = GetStorage(extension); |
| 62 | 62 |
| 63 // A neat way to implement unlimited storage; if the extension has the | 63 // A neat way to implement unlimited storage; if the extension has the |
| 64 // unlimited storage permission, force through all calls to Set(). | 64 // unlimited storage permission, force through all calls to Set(). |
| 65 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) { | 65 if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) { |
| 66 WeakUnlimitedSettingsStorage unlimited_storage(storage); | 66 WeakUnlimitedSettingsStorage unlimited_storage(storage); |
| 67 callback.Run(&unlimited_storage); | 67 callback.Run(&unlimited_storage); |
| 68 } else { | 68 } else { |
| 69 callback.Run(storage); | 69 callback.Run(storage); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 void LocalValueStoreCache::DeleteStorageSoon(const std::string& extension_id) { | 73 void LocalValueStoreCache::DeleteStorageSoon(const std::string& extension_id) { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 74 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 75 storage_map_.erase(extension_id); | 75 storage_map_.erase(extension_id); |
| 76 storage_factory_->DeleteDatabaseIfExists(app_base_path_, extension_id); | 76 storage_factory_->DeleteDatabaseIfExists(app_base_path_, extension_id); |
| 77 storage_factory_->DeleteDatabaseIfExists(extension_base_path_, extension_id); | 77 storage_factory_->DeleteDatabaseIfExists(extension_base_path_, extension_id); |
| 78 } | 78 } |
| 79 | 79 |
| 80 ValueStore* LocalValueStoreCache::GetStorage( | 80 ValueStore* LocalValueStoreCache::GetStorage( |
| 81 scoped_refptr<const Extension> extension) { | 81 scoped_refptr<const Extension> extension) { |
| 82 StorageMap::iterator iter = storage_map_.find(extension->id()); | 82 StorageMap::iterator iter = storage_map_.find(extension->id()); |
| 83 if (iter != storage_map_.end()) | 83 if (iter != storage_map_.end()) |
| 84 return iter->second.get(); | 84 return iter->second.get(); |
| 85 | 85 |
| 86 const base::FilePath& file_path = | 86 const base::FilePath& file_path = |
| 87 extension->is_app() ? app_base_path_ : extension_base_path_; | 87 extension->is_app() ? app_base_path_ : extension_base_path_; |
| 88 linked_ptr<SettingsStorageQuotaEnforcer> storage( | 88 linked_ptr<SettingsStorageQuotaEnforcer> storage( |
| 89 new SettingsStorageQuotaEnforcer( | 89 new SettingsStorageQuotaEnforcer( |
| 90 quota_, storage_factory_->Create(file_path, extension->id()))); | 90 quota_, storage_factory_->Create(file_path, extension->id()))); |
| 91 DCHECK(storage.get()); | 91 DCHECK(storage.get()); |
| 92 storage_map_[extension->id()] = storage; | 92 storage_map_[extension->id()] = storage; |
| 93 return storage.get(); | 93 return storage.get(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace extensions | 96 } // namespace extensions |
| OLD | NEW |