diff options
author | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 19:07:33 +0000 |
---|---|---|
committer | rdevlin.cronin@chromium.org <rdevlin.cronin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-03-12 19:07:33 +0000 |
commit | ad1265b445744c060bf521b28ffd7c717e9d4088 (patch) | |
tree | 4089edfd228ffa86a57b1e1f33363884cb9f5000 /extensions/browser/api | |
parent | 80ba60d9f03d0b4397de2ba4e5f7bfeedcf640e7 (diff) | |
download | chromium_src-ad1265b445744c060bf521b28ffd7c717e9d4088.zip chromium_src-ad1265b445744c060bf521b28ffd7c717e9d4088.tar.gz chromium_src-ad1265b445744c060bf521b28ffd7c717e9d4088.tar.bz2 |
Remove SettingsBackend
Combine LocalStorageBackend and LocalValueStoreCache.
Remove SettingsBackend.
Sadly, SyncStorageBackend still exists. It's significantly more tangled than
the local version, because we also keep apps/extensions separate when we sync
them.
BUG=351412
Review URL: https://codereview.chromium.org/193133002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@256594 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'extensions/browser/api')
8 files changed, 46 insertions, 245 deletions
diff --git a/extensions/browser/api/storage/local_storage_backend.cc b/extensions/browser/api/storage/local_storage_backend.cc deleted file mode 100644 index 5340a5a..0000000 --- a/extensions/browser/api/storage/local_storage_backend.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "extensions/browser/api/storage/local_storage_backend.h" - -#include "base/file_util.h" -#include "extensions/browser/api/storage/settings_storage_factory.h" - -namespace extensions { - -LocalStorageBackend::LocalStorageBackend( - const scoped_refptr<SettingsStorageFactory>& storage_factory, - const base::FilePath& base_path, - const SettingsStorageQuotaEnforcer::Limits& quota) - : SettingsBackend(storage_factory, base_path, quota) {} - -LocalStorageBackend::~LocalStorageBackend() {} - -ValueStore* LocalStorageBackend::GetStorage(const std::string& extension_id) { - StorageMap::iterator iter = storage_map_.find(extension_id); - if (iter != storage_map_.end()) - return iter->second.get(); - - linked_ptr<SettingsStorageQuotaEnforcer> storage( - CreateStorageForExtension(extension_id).release()); - storage_map_[extension_id] = storage; - return storage.get(); -} - -void LocalStorageBackend::DeleteStorage(const std::string& extension_id) { - // Clear settings when the extension is uninstalled. - storage_map_.erase(extension_id); - storage_factory()->DeleteDatabaseIfExists(base_path(), extension_id); -} - -} // namespace extensions diff --git a/extensions/browser/api/storage/local_storage_backend.h b/extensions/browser/api/storage/local_storage_backend.h deleted file mode 100644 index 812e1ee..0000000 --- a/extensions/browser/api/storage/local_storage_backend.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef EXTENSIONS_BROWSER_API_STORAGE_LOCAL_STORAGE_BACKEND_H_ -#define EXTENSIONS_BROWSER_API_STORAGE_LOCAL_STORAGE_BACKEND_H_ - -#include <map> -#include <string> - -#include "base/memory/linked_ptr.h" -#include "base/memory/ref_counted.h" -#include "extensions/browser/api/storage/settings_backend.h" -#include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" - -namespace base { -class FilePath; -} - -class ValueStore; - -namespace extensions { -class SettingStorageFactory; - -class LocalStorageBackend : public SettingsBackend { - public: - LocalStorageBackend( - const scoped_refptr<SettingsStorageFactory>& storage_factory, - const base::FilePath& base_path, - const SettingsStorageQuotaEnforcer::Limits& quota); - virtual ~LocalStorageBackend(); - - // SettingsBackend implementation. - virtual ValueStore* GetStorage(const std::string& extension_id) OVERRIDE; - virtual void DeleteStorage(const std::string& extension_id) OVERRIDE; - - private: - typedef std::map<std::string, linked_ptr<ValueStore> > StorageMap; - - StorageMap storage_map_; - - DISALLOW_COPY_AND_ASSIGN(LocalStorageBackend); -}; - -} // namespace extensions - -#endif // EXTENSIONS_BROWSER_API_STORAGE_LOCAL_STORAGE_BACKEND_H_ diff --git a/extensions/browser/api/storage/local_value_store_cache.cc b/extensions/browser/api/storage/local_value_store_cache.cc index a8d3afba..7c7ce58 100644 --- a/extensions/browser/api/storage/local_value_store_cache.cc +++ b/extensions/browser/api/storage/local_value_store_cache.cc @@ -11,10 +11,10 @@ #include "base/files/file_path.h" #include "chrome/common/extensions/api/storage.h" #include "content/public/browser/browser_thread.h" -#include "extensions/browser/api/storage/local_storage_backend.h" #include "extensions/browser/api/storage/settings_storage_factory.h" #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" #include "extensions/browser/api/storage/weak_unlimited_settings_storage.h" +#include "extensions/browser/value_store/value_store.h" #include "extensions/common/constants.h" #include "extensions/common/extension.h" #include "extensions/common/permissions/api_permission.h" @@ -41,17 +41,12 @@ SettingsStorageQuotaEnforcer::Limits GetLocalQuotaLimits() { LocalValueStoreCache::LocalValueStoreCache( const scoped_refptr<SettingsStorageFactory>& factory, const base::FilePath& profile_path) - : initialized_(false) { + : storage_factory_(factory), + extension_base_path_( + profile_path.AppendASCII(kLocalExtensionSettingsDirectoryName)), + app_base_path_(profile_path.AppendASCII(kLocalAppSettingsDirectoryName)), + quota_(GetLocalQuotaLimits()) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - - // This post is safe since the destructor can only be invoked from the - // same message loop, and any potential post of a deletion task must come - // after the constructor returns. - BrowserThread::PostTask( - BrowserThread::FILE, FROM_HERE, - base::Bind(&LocalValueStoreCache::InitOnFileThread, - base::Unretained(this), - factory, profile_path)); } LocalValueStoreCache::~LocalValueStoreCache() { @@ -62,11 +57,8 @@ void LocalValueStoreCache::RunWithValueStoreForExtension( const StorageCallback& callback, scoped_refptr<const Extension> extension) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - DCHECK(initialized_); - SettingsBackend* backend = - extension->is_app() ? app_backend_.get() : extension_backend_.get(); - ValueStore* storage = backend->GetStorage(extension->id()); + ValueStore* storage = GetStorage(extension); // A neat way to implement unlimited storage; if the extension has the // unlimited storage permission, force through all calls to Set(). @@ -80,25 +72,25 @@ void LocalValueStoreCache::RunWithValueStoreForExtension( void LocalValueStoreCache::DeleteStorageSoon(const std::string& extension_id) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - DCHECK(initialized_); - app_backend_->DeleteStorage(extension_id); - extension_backend_->DeleteStorage(extension_id); + storage_map_.erase(extension_id); + storage_factory_->DeleteDatabaseIfExists(app_base_path_, extension_id); + storage_factory_->DeleteDatabaseIfExists(extension_base_path_, extension_id); } -void LocalValueStoreCache::InitOnFileThread( - const scoped_refptr<SettingsStorageFactory>& factory, - const base::FilePath& profile_path) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - DCHECK(!initialized_); - app_backend_.reset(new LocalStorageBackend( - factory, - profile_path.AppendASCII(kLocalAppSettingsDirectoryName), - GetLocalQuotaLimits())); - extension_backend_.reset(new LocalStorageBackend( - factory, - profile_path.AppendASCII(kLocalExtensionSettingsDirectoryName), - GetLocalQuotaLimits())); - initialized_ = true; +ValueStore* LocalValueStoreCache::GetStorage( + scoped_refptr<const Extension> extension) { + StorageMap::iterator iter = storage_map_.find(extension->id()); + if (iter != storage_map_.end()) + return iter->second.get(); + + const base::FilePath& file_path = + extension->is_app() ? app_base_path_ : extension_base_path_; + linked_ptr<SettingsStorageQuotaEnforcer> storage( + new SettingsStorageQuotaEnforcer( + quota_, storage_factory_->Create(file_path, extension->id()))); + DCHECK(storage.get()); + storage_map_[extension->id()] = storage; + return storage.get(); } } // namespace extensions diff --git a/extensions/browser/api/storage/local_value_store_cache.h b/extensions/browser/api/storage/local_value_store_cache.h index ee5b9fc..834b4006 100644 --- a/extensions/browser/api/storage/local_value_store_cache.h +++ b/extensions/browser/api/storage/local_value_store_cache.h @@ -7,17 +7,15 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/files/file_path.h" +#include "base/memory/linked_ptr.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" #include "extensions/browser/api/storage/value_store_cache.h" -namespace base { -class FilePath; -} - namespace extensions { -class SettingsBackend; class SettingsStorageFactory; // ValueStoreCache for the LOCAL namespace. It owns a backend for apps and @@ -35,12 +33,24 @@ class LocalValueStoreCache : public ValueStoreCache { virtual void DeleteStorageSoon(const std::string& extension_id) OVERRIDE; private: - void InitOnFileThread(const scoped_refptr<SettingsStorageFactory>& factory, - const base::FilePath& profile_path); + typedef std::map<std::string, linked_ptr<ValueStore> > StorageMap; + + ValueStore* GetStorage(scoped_refptr<const Extension> extension); + + // The Factory to use for creating new ValueStores. + const scoped_refptr<SettingsStorageFactory> storage_factory_; + + // The base path to use for extensions when creating new ValueStores. + const base::FilePath extension_base_path_; + + // The base path to use for apps when creating new ValueStores. + const base::FilePath app_base_path_; + + // Quota limits (see SettingsStorageQuotaEnforcer). + const SettingsStorageQuotaEnforcer::Limits quota_; - bool initialized_; - scoped_ptr<SettingsBackend> app_backend_; - scoped_ptr<SettingsBackend> extension_backend_; + // The collection of ValueStores for local storage. + StorageMap storage_map_; DISALLOW_COPY_AND_ASSIGN(LocalValueStoreCache); }; diff --git a/extensions/browser/api/storage/settings_backend.cc b/extensions/browser/api/storage/settings_backend.cc deleted file mode 100644 index 072636e..0000000 --- a/extensions/browser/api/storage/settings_backend.cc +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "extensions/browser/api/storage/settings_backend.h" - -#include "base/logging.h" -#include "content/public/browser/browser_thread.h" -#include "extensions/browser/api/storage/settings_storage_factory.h" - -using content::BrowserThread; - -namespace extensions { - -SettingsBackend::SettingsBackend( - const scoped_refptr<SettingsStorageFactory>& storage_factory, - const base::FilePath& base_path, - const SettingsStorageQuotaEnforcer::Limits& quota) - : storage_factory_(storage_factory), base_path_(base_path), quota_(quota) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); -} - -SettingsBackend::~SettingsBackend() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); -} - -syncer::SyncableService* SettingsBackend::GetAsSyncableService() { - NOTREACHED(); - return NULL; -} - -scoped_ptr<SettingsStorageQuotaEnforcer> -SettingsBackend::CreateStorageForExtension( - const std::string& extension_id) const { - scoped_ptr<SettingsStorageQuotaEnforcer> storage( - new SettingsStorageQuotaEnforcer( - quota(), storage_factory()->Create(base_path(), extension_id))); - DCHECK(storage.get()); - return storage.Pass(); -} - -} // namespace extensions diff --git a/extensions/browser/api/storage/settings_backend.h b/extensions/browser/api/storage/settings_backend.h deleted file mode 100644 index bf5812c..0000000 --- a/extensions/browser/api/storage/settings_backend.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_BACKEND_H_ -#define EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_BACKEND_H_ - -#include <string> - -#include "base/files/file_path.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" - -namespace syncer { -class SyncableService; -} - -class ValueStore; - -namespace extensions { -class SettingsStorageFactory; - -// Performs work for the storage API on the FILE thread. -class SettingsBackend { - public: - SettingsBackend(const scoped_refptr<SettingsStorageFactory>& storage_factory, - const base::FilePath& base_path, - const SettingsStorageQuotaEnforcer::Limits& quota); - virtual ~SettingsBackend(); - - // Gets a weak reference to the storage area for |extension_id|. - // Must be run on the FILE thread. - virtual ValueStore* GetStorage(const std::string& extension_id) = 0; - - // Deletes all setting data for an extension. Call on the FILE thread. - virtual void DeleteStorage(const std::string& extension_id) = 0; - - // A slight hack so we can get a SyncableService from a SettingsBackend if - // it's actually a SyncStorageBackend. If called on a LocalStorageBackend, - // this asserts and returns null. - virtual syncer::SyncableService* GetAsSyncableService(); - - SettingsStorageFactory* storage_factory() const { - return storage_factory_.get(); - } - const base::FilePath& base_path() const { return base_path_; } - const SettingsStorageQuotaEnforcer::Limits& quota() const { return quota_; } - - protected: - // Creates a ValueStore decorated with quota-enforcing behavior (the default - // for both sync and local stores). If the database is corrupt, - // SettingsStorageQuotaEnforcer will try and restore it as part of the - // initialization process (by necessity, since we need to read the database to - // calculate the storage). - scoped_ptr<SettingsStorageQuotaEnforcer> CreateStorageForExtension( - const std::string& extension_id) const; - - private: - // The Factory to use for creating new ValueStores. - const scoped_refptr<SettingsStorageFactory> storage_factory_; - - // The base file path to use when creating new ValueStores. - const base::FilePath base_path_; - - // Quota limits (see SettingsStorageQuotaEnforcer). - const SettingsStorageQuotaEnforcer::Limits quota_; - - DISALLOW_COPY_AND_ASSIGN(SettingsBackend); -}; - -} // namespace extensions - -#endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_BACKEND_H_ diff --git a/extensions/browser/api/storage/settings_frontend.h b/extensions/browser/api/storage/settings_frontend.h index 5b73e2d..ffb13e7 100644 --- a/extensions/browser/api/storage/settings_frontend.h +++ b/extensions/browser/api/storage/settings_frontend.h @@ -22,8 +22,7 @@ class BrowserContext; namespace extensions { -// The component of extension settings which runs on the UI thread, as opposed -// to SettingsBackend which lives on the FILE thread. +// The component of extension settings which runs on the UI thread. class SettingsFrontend : public BrowserContextKeyedAPI { public: // Returns the current instance for |context|. diff --git a/extensions/browser/api/storage/settings_storage_factory.h b/extensions/browser/api/storage/settings_storage_factory.h index 613bc2f..14f6187 100644 --- a/extensions/browser/api/storage/settings_storage_factory.h +++ b/extensions/browser/api/storage/settings_storage_factory.h @@ -17,7 +17,7 @@ namespace extensions { // Factory for creating SettingStorage instances. // // Refcouted because it's just too messy to distribute these objects between -// SettingsBackend instances any other way. +// ValueStoreCache instances any other way. class SettingsStorageFactory : public base::RefCountedThreadSafe<SettingsStorageFactory> { public: |