summaryrefslogtreecommitdiffstats
path: root/extensions/browser/api
diff options
context:
space:
mode:
authorcmumford <cmumford@chromium.org>2016-03-24 13:35:27 -0700
committerCommit bot <commit-bot@chromium.org>2016-03-24 20:36:29 +0000
commit6ae8d465f961bb3c6fa9ed285d877710fb69ae12 (patch)
tree2ef3a31a1254b3d2bc9fa84f942f5a4be023ab4a /extensions/browser/api
parent7fad54c907e98f5c574cbf12420ab072eecf81ad (diff)
downloadchromium_src-6ae8d465f961bb3c6fa9ed285d877710fb69ae12.zip
chromium_src-6ae8d465f961bb3c6fa9ed285d877710fb69ae12.tar.gz
chromium_src-6ae8d465f961bb3c6fa9ed285d877710fb69ae12.tar.bz2
Extensions: Using common ValueStoreFactory for all value stores.
1. Introduce new ValueStoreFactory interface used for the creation of ValueStore's in all namespaces (local, sync, and managed), and for all types (extension and application). 2. Delete SettingsStorageFactory/LeveldbSettingsStorageFactory, and switched to ValueStoreFactory. 3. Created a new TestValueStoreFactory (for testing). This combines settings_sync_unittest.cc:TestingValueStoreFactory and ScopedSettingsStorageFactory. 4. ValueStoreFrontend::Backend always lazilily initializes using the ValueStoreFactory. This makes unnecessary StateStore's deferred initialization mechanism - which will be removed in an upcoming CL. 5. A new ValueStoreFactoryImpl to mint new ValueStore's for Chrome. This currently delegates to a new LegacyValueStoreFactory which creates new LeveldbValueStore. An upcoming CL will add a second delegated factory (currently called ProfileValueStoreFactory) to support a unified (per-profile) extensions database. 6. Removed memcheck suppression for SettingsStorageFactory as this class is now deleted (crbug.com/163922). BUG=453946,163922 Review URL: https://codereview.chromium.org/1803193002 Cr-Commit-Position: refs/heads/master@{#383137}
Diffstat (limited to 'extensions/browser/api')
-rw-r--r--extensions/browser/api/extensions_api_client.cc2
-rw-r--r--extensions/browser/api/extensions_api_client.h4
-rw-r--r--extensions/browser/api/storage/leveldb_settings_storage_factory.cc43
-rw-r--r--extensions/browser/api/storage/leveldb_settings_storage_factory.h28
-rw-r--r--extensions/browser/api/storage/local_value_store_cache.cc42
-rw-r--r--extensions/browser/api/storage/local_value_store_cache.h17
-rw-r--r--extensions/browser/api/storage/settings_quota_unittest.cc3
-rw-r--r--extensions/browser/api/storage/settings_storage_factory.h42
-rw-r--r--extensions/browser/api/storage/settings_storage_quota_enforcer.cc7
-rw-r--r--extensions/browser/api/storage/settings_storage_quota_enforcer.h4
-rw-r--r--extensions/browser/api/storage/settings_test_util.cc28
-rw-r--r--extensions/browser/api/storage/settings_test_util.h26
-rw-r--r--extensions/browser/api/storage/storage_api_unittest.cc9
-rw-r--r--extensions/browser/api/storage/storage_frontend.cc16
-rw-r--r--extensions/browser/api/storage/storage_frontend.h9
-rw-r--r--extensions/browser/api/storage/storage_frontend_unittest.cc9
16 files changed, 57 insertions, 232 deletions
diff --git a/extensions/browser/api/extensions_api_client.cc b/extensions/browser/api/extensions_api_client.cc
index 7eb174f..bfc08d3 100644
--- a/extensions/browser/api/extensions_api_client.cc
+++ b/extensions/browser/api/extensions_api_client.cc
@@ -28,7 +28,7 @@ ExtensionsAPIClient* ExtensionsAPIClient::Get() { return g_instance; }
void ExtensionsAPIClient::AddAdditionalValueStoreCaches(
content::BrowserContext* context,
- const scoped_refptr<SettingsStorageFactory>& factory,
+ const scoped_refptr<ValueStoreFactory>& factory,
const scoped_refptr<base::ObserverListThreadSafe<SettingsObserver>>&
observers,
std::map<settings_namespace::Namespace, ValueStoreCache*>* caches) {}
diff --git a/extensions/browser/api/extensions_api_client.h b/extensions/browser/api/extensions_api_client.h
index ca50ba8..d68174d 100644
--- a/extensions/browser/api/extensions_api_client.h
+++ b/extensions/browser/api/extensions_api_client.h
@@ -40,8 +40,8 @@ class MimeHandlerViewGuest;
class MimeHandlerViewGuestDelegate;
class RulesCacheDelegate;
class SettingsObserver;
-class SettingsStorageFactory;
class ValueStoreCache;
+class ValueStoreFactory;
class VirtualKeyboardDelegate;
class WebRequestEventRouterDelegate;
class WebViewGuest;
@@ -69,7 +69,7 @@ class ExtensionsAPIClient {
// to |caches|. By default adds nothing.
virtual void AddAdditionalValueStoreCaches(
content::BrowserContext* context,
- const scoped_refptr<SettingsStorageFactory>& factory,
+ const scoped_refptr<ValueStoreFactory>& factory,
const scoped_refptr<base::ObserverListThreadSafe<SettingsObserver>>&
observers,
std::map<settings_namespace::Namespace, ValueStoreCache*>* caches);
diff --git a/extensions/browser/api/storage/leveldb_settings_storage_factory.cc b/extensions/browser/api/storage/leveldb_settings_storage_factory.cc
deleted file mode 100644
index ef7d302..0000000
--- a/extensions/browser/api/storage/leveldb_settings_storage_factory.cc
+++ /dev/null
@@ -1,43 +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/leveldb_settings_storage_factory.h"
-
-#include "base/files/file_util.h"
-#include "base/logging.h"
-#include "extensions/browser/value_store/leveldb_value_store.h"
-
-namespace extensions {
-
-namespace {
-
-// Statistics are logged to UMA with this string as part of histogram name. They
-// can all be found under Extensions.Database.Open.<client>. Changing this needs
-// to synchronize with histograms.xml, AND will also become incompatible with
-// older browsers still reporting the previous values.
-const char kDatabaseUMAClientName[] = "Settings";
-
-base::FilePath GetDatabasePath(const base::FilePath& base_path,
- const std::string& extension_id) {
- return base_path.AppendASCII(extension_id);
-}
-
-} // namespace
-
-ValueStore* LeveldbSettingsStorageFactory::Create(
- const base::FilePath& base_path,
- const std::string& extension_id) {
- return new LeveldbValueStore(kDatabaseUMAClientName,
- GetDatabasePath(base_path, extension_id));
-}
-
-void LeveldbSettingsStorageFactory::DeleteDatabaseIfExists(
- const base::FilePath& base_path,
- const std::string& extension_id) {
- base::FilePath path = GetDatabasePath(base_path, extension_id);
- if (base::PathExists(path))
- base::DeleteFile(path, true /* recursive */);
-}
-
-} // namespace extensions
diff --git a/extensions/browser/api/storage/leveldb_settings_storage_factory.h b/extensions/browser/api/storage/leveldb_settings_storage_factory.h
deleted file mode 100644
index 6f9cc56..0000000
--- a/extensions/browser/api/storage/leveldb_settings_storage_factory.h
+++ /dev/null
@@ -1,28 +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_LEVELDB_SETTINGS_STORAGE_FACTORY_H_
-#define EXTENSIONS_BROWSER_API_STORAGE_LEVELDB_SETTINGS_STORAGE_FACTORY_H_
-
-#include "extensions/browser/api/storage/settings_storage_factory.h"
-
-namespace extensions {
-
-// Factory for creating LeveldbValueStore instances.
-class LeveldbSettingsStorageFactory : public SettingsStorageFactory {
- public:
- ValueStore* Create(const base::FilePath& base_path,
- const std::string& extension_id) override;
-
- void DeleteDatabaseIfExists(const base::FilePath& base_path,
- const std::string& extension_id) override;
-
- private:
- // SettingsStorageFactory is refcounted.
- ~LeveldbSettingsStorageFactory() override {}
-};
-
-} // namespace extensions
-
-#endif // EXTENSIONS_BROWSER_API_STORAGE_LEVELDB_SETTINGS_STORAGE_FACTORY_H_
diff --git a/extensions/browser/api/storage/local_value_store_cache.cc b/extensions/browser/api/storage/local_value_store_cache.cc
index 9c9ab15..920d130 100644
--- a/extensions/browser/api/storage/local_value_store_cache.cc
+++ b/extensions/browser/api/storage/local_value_store_cache.cc
@@ -8,18 +8,10 @@
#include <limits>
-#include "base/bind.h"
-#include "base/callback.h"
-#include "base/files/file_path.h"
#include "content/public/browser/browser_thread.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/browser/value_store/value_store_factory.h"
#include "extensions/common/api/storage.h"
-#include "extensions/common/constants.h"
-#include "extensions/common/extension.h"
-#include "extensions/common/permissions/api_permission.h"
#include "extensions/common/permissions/permissions_data.h"
using content::BrowserThread;
@@ -40,13 +32,8 @@ SettingsStorageQuotaEnforcer::Limits GetLocalQuotaLimits() {
} // namespace
LocalValueStoreCache::LocalValueStoreCache(
- const scoped_refptr<SettingsStorageFactory>& factory,
- const base::FilePath& profile_path)
- : storage_factory_(factory),
- extension_base_path_(
- profile_path.AppendASCII(kLocalExtensionSettingsDirectoryName)),
- app_base_path_(profile_path.AppendASCII(kLocalAppSettingsDirectoryName)),
- quota_(GetLocalQuotaLimits()) {
+ const scoped_refptr<ValueStoreFactory>& factory)
+ : storage_factory_(factory), quota_(GetLocalQuotaLimits()) {
DCHECK_CURRENTLY_ON(BrowserThread::UI);
}
@@ -59,7 +46,7 @@ void LocalValueStoreCache::RunWithValueStoreForExtension(
scoped_refptr<const Extension> extension) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
- ValueStore* storage = GetStorage(extension);
+ ValueStore* storage = GetStorage(extension.get());
// A neat way to implement unlimited storage; if the extension has the
// unlimited storage permission, force through all calls to Set().
@@ -75,21 +62,26 @@ void LocalValueStoreCache::RunWithValueStoreForExtension(
void LocalValueStoreCache::DeleteStorageSoon(const std::string& extension_id) {
DCHECK_CURRENTLY_ON(BrowserThread::FILE);
storage_map_.erase(extension_id);
- storage_factory_->DeleteDatabaseIfExists(app_base_path_, extension_id);
- storage_factory_->DeleteDatabaseIfExists(extension_base_path_, extension_id);
+ storage_factory_->DeleteSettings(settings_namespace::LOCAL,
+ ValueStoreFactory::ModelType::APP,
+ extension_id);
+ storage_factory_->DeleteSettings(settings_namespace::LOCAL,
+ ValueStoreFactory::ModelType::EXTENSION,
+ extension_id);
}
-ValueStore* LocalValueStoreCache::GetStorage(
- scoped_refptr<const Extension> extension) {
+ValueStore* LocalValueStoreCache::GetStorage(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_;
+ ValueStoreFactory::ModelType model_type =
+ extension->is_app() ? ValueStoreFactory::ModelType::APP
+ : ValueStoreFactory::ModelType::EXTENSION;
+ scoped_ptr<ValueStore> store = storage_factory_->CreateSettingsStore(
+ settings_namespace::LOCAL, model_type, extension->id());
linked_ptr<SettingsStorageQuotaEnforcer> storage(
- new SettingsStorageQuotaEnforcer(
- quota_, storage_factory_->Create(file_path, extension->id())));
+ new SettingsStorageQuotaEnforcer(quota_, std::move(store)));
DCHECK(storage.get());
storage_map_[extension->id()] = storage;
diff --git a/extensions/browser/api/storage/local_value_store_cache.h b/extensions/browser/api/storage/local_value_store_cache.h
index 6385ff1..c3303a5 100644
--- a/extensions/browser/api/storage/local_value_store_cache.h
+++ b/extensions/browser/api/storage/local_value_store_cache.h
@@ -6,7 +6,6 @@
#define EXTENSIONS_BROWSER_API_STORAGE_LOCAL_VALUE_STORE_CACHE_H_
#include "base/compiler_specific.h"
-#include "base/files/file_path.h"
#include "base/macros.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/ref_counted.h"
@@ -16,14 +15,14 @@
namespace extensions {
-class SettingsStorageFactory;
+class ValueStoreFactory;
// ValueStoreCache for the LOCAL namespace. It owns a backend for apps and
// another for extensions. Each backend takes care of persistence.
class LocalValueStoreCache : public ValueStoreCache {
public:
- LocalValueStoreCache(const scoped_refptr<SettingsStorageFactory>& factory,
- const base::FilePath& profile_path);
+ explicit LocalValueStoreCache(
+ const scoped_refptr<ValueStoreFactory>& factory);
~LocalValueStoreCache() override;
// ValueStoreCache implementation:
@@ -35,16 +34,10 @@ class LocalValueStoreCache : public ValueStoreCache {
private:
typedef std::map<std::string, linked_ptr<ValueStore> > StorageMap;
- ValueStore* GetStorage(scoped_refptr<const Extension> extension);
+ ValueStore* GetStorage(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_;
+ const scoped_refptr<ValueStoreFactory> storage_factory_;
// Quota limits (see SettingsStorageQuotaEnforcer).
const SettingsStorageQuotaEnforcer::Limits quota_;
diff --git a/extensions/browser/api/storage/settings_quota_unittest.cc b/extensions/browser/api/storage/settings_quota_unittest.cc
index c89669c..3681401 100644
--- a/extensions/browser/api/storage/settings_quota_unittest.cc
+++ b/extensions/browser/api/storage/settings_quota_unittest.cc
@@ -54,7 +54,8 @@ class ExtensionSettingsQuotaTest : public testing::Test {
ASSERT_TRUE(storage_.get() == NULL);
SettingsStorageQuotaEnforcer::Limits limits =
{ quota_bytes, quota_bytes_per_item, max_items };
- storage_.reset(new SettingsStorageQuotaEnforcer(limits, delegate_));
+ storage_.reset(
+ new SettingsStorageQuotaEnforcer(limits, make_scoped_ptr(delegate_)));
}
// Returns whether the settings in |storage_| and |delegate_| are the same as
diff --git a/extensions/browser/api/storage/settings_storage_factory.h b/extensions/browser/api/storage/settings_storage_factory.h
deleted file mode 100644
index 14f6187..0000000
--- a/extensions/browser/api/storage/settings_storage_factory.h
+++ /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.
-
-#ifndef EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_FACTORY_H_
-#define EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_FACTORY_H_
-
-#include <string>
-
-#include "base/files/file_path.h"
-#include "base/memory/ref_counted.h"
-
-class ValueStore;
-
-namespace extensions {
-
-// Factory for creating SettingStorage instances.
-//
-// Refcouted because it's just too messy to distribute these objects between
-// ValueStoreCache instances any other way.
-class SettingsStorageFactory
- : public base::RefCountedThreadSafe<SettingsStorageFactory> {
- public:
- // Creates a new ValueStore area for an extension under |base_path|.
- // Return NULL to indicate failure. Must be called on the FILE thread.
- virtual ValueStore* Create(const base::FilePath& base_path,
- const std::string& extension_id) = 0;
-
- // Deletes the database for the extension, if one exists.
- // Note: it is important to delete references to the database if any are
- // held, because ValueStores will create themselves if there is no file.
- virtual void DeleteDatabaseIfExists(const base::FilePath& base_path,
- const std::string& extension_id) = 0;
-
- protected:
- friend class base::RefCountedThreadSafe<SettingsStorageFactory>;
- virtual ~SettingsStorageFactory() {}
-};
-
-} // namespace extensions
-
-#endif // EXTENSIONS_BROWSER_API_STORAGE_SETTINGS_STORAGE_FACTORY_H_
diff --git a/extensions/browser/api/storage/settings_storage_quota_enforcer.cc b/extensions/browser/api/storage/settings_storage_quota_enforcer.cc
index 9a9e9b7..7d3703c 100644
--- a/extensions/browser/api/storage/settings_storage_quota_enforcer.cc
+++ b/extensions/browser/api/storage/settings_storage_quota_enforcer.cc
@@ -70,10 +70,11 @@ ValueStore::Status QuotaExceededError(Resource resource) {
} // namespace
-SettingsStorageQuotaEnforcer::SettingsStorageQuotaEnforcer(const Limits& limits,
- ValueStore* delegate)
+SettingsStorageQuotaEnforcer::SettingsStorageQuotaEnforcer(
+ const Limits& limits,
+ scoped_ptr<ValueStore> delegate)
: limits_(limits),
- delegate_(delegate),
+ delegate_(std::move(delegate)),
used_total_(0),
usage_calculated_(false) {}
diff --git a/extensions/browser/api/storage/settings_storage_quota_enforcer.h b/extensions/browser/api/storage/settings_storage_quota_enforcer.h
index 48a5e89..33de5b7 100644
--- a/extensions/browser/api/storage/settings_storage_quota_enforcer.h
+++ b/extensions/browser/api/storage/settings_storage_quota_enforcer.h
@@ -13,6 +13,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "extensions/browser/value_store/value_store.h"
@@ -33,7 +34,8 @@ class SettingsStorageQuotaEnforcer : public ValueStore {
size_t max_items;
};
- SettingsStorageQuotaEnforcer(const Limits& limits, ValueStore* delegate);
+ SettingsStorageQuotaEnforcer(const Limits& limits,
+ scoped_ptr<ValueStore> delegate);
~SettingsStorageQuotaEnforcer() override;
diff --git a/extensions/browser/api/storage/settings_test_util.cc b/extensions/browser/api/storage/settings_test_util.cc
index c3dc4a5..4442541 100644
--- a/extensions/browser/api/storage/settings_test_util.cc
+++ b/extensions/browser/api/storage/settings_test_util.cc
@@ -118,34 +118,6 @@ scoped_refptr<const Extension> AddExtensionWithIdAndPermissions(
return extension;
}
-// ScopedSettingsFactory
-
-ScopedSettingsStorageFactory::ScopedSettingsStorageFactory() {}
-
-ScopedSettingsStorageFactory::ScopedSettingsStorageFactory(
- const scoped_refptr<SettingsStorageFactory>& delegate)
- : delegate_(delegate) {}
-
-ScopedSettingsStorageFactory::~ScopedSettingsStorageFactory() {}
-
-void ScopedSettingsStorageFactory::Reset(
- const scoped_refptr<SettingsStorageFactory>& delegate) {
- delegate_ = delegate;
-}
-
-ValueStore* ScopedSettingsStorageFactory::Create(
- const base::FilePath& base_path,
- const std::string& extension_id) {
- DCHECK(delegate_.get());
- return delegate_->Create(base_path, extension_id);
-}
-
-void ScopedSettingsStorageFactory::DeleteDatabaseIfExists(
- const base::FilePath& base_path,
- const std::string& extension_id) {
- delegate_->DeleteDatabaseIfExists(base_path, extension_id);
-}
-
} // namespace settings_test_util
} // namespace extensions
diff --git a/extensions/browser/api/storage/settings_test_util.h b/extensions/browser/api/storage/settings_test_util.h
index 0b23f60..07a1d52 100644
--- a/extensions/browser/api/storage/settings_test_util.h
+++ b/extensions/browser/api/storage/settings_test_util.h
@@ -14,9 +14,9 @@
#include "base/memory/scoped_ptr.h"
#include "chrome/test/base/testing_profile.h"
#include "extensions/browser/api/storage/settings_namespace.h"
-#include "extensions/browser/api/storage/settings_storage_factory.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/mock_extension_system.h"
+#include "extensions/browser/value_store/value_store_factory.h"
#include "extensions/common/extension.h"
class ValueStore;
@@ -56,30 +56,6 @@ scoped_refptr<const Extension> AddExtensionWithIdAndPermissions(
Manifest::Type type,
const std::set<std::string>& permissions);
-// SettingsStorageFactory which acts as a wrapper for other factories.
-class ScopedSettingsStorageFactory : public SettingsStorageFactory {
- public:
- ScopedSettingsStorageFactory();
-
- explicit ScopedSettingsStorageFactory(
- const scoped_refptr<SettingsStorageFactory>& delegate);
-
- // Sets the delegate factory (equivalent to scoped_ptr::reset).
- void Reset(const scoped_refptr<SettingsStorageFactory>& delegate);
-
- // SettingsStorageFactory implementation.
- ValueStore* Create(const base::FilePath& base_path,
- const std::string& extension_id) override;
- void DeleteDatabaseIfExists(const base::FilePath& base_path,
- const std::string& extension_id) override;
-
- private:
- // SettingsStorageFactory is refcounted.
- ~ScopedSettingsStorageFactory() override;
-
- scoped_refptr<SettingsStorageFactory> delegate_;
-};
-
} // namespace settings_test_util
} // namespace extensions
diff --git a/extensions/browser/api/storage/storage_api_unittest.cc b/extensions/browser/api/storage/storage_api_unittest.cc
index f987db2..4a013db 100644
--- a/extensions/browser/api/storage/storage_api_unittest.cc
+++ b/extensions/browser/api/storage/storage_api_unittest.cc
@@ -9,7 +9,6 @@
#include "base/strings/stringprintf.h"
#include "content/public/test/test_browser_context.h"
#include "extensions/browser/api/extensions_api_client.h"
-#include "extensions/browser/api/storage/leveldb_settings_storage_factory.h"
#include "extensions/browser/api/storage/settings_storage_quota_enforcer.h"
#include "extensions/browser/api/storage/settings_test_util.h"
#include "extensions/browser/api/storage/storage_api.h"
@@ -20,6 +19,7 @@
#include "extensions/browser/test_extensions_browser_client.h"
#include "extensions/browser/value_store/leveldb_value_store.h"
#include "extensions/browser/value_store/value_store.h"
+#include "extensions/browser/value_store/value_store_factory_impl.h"
#include "extensions/common/manifest.h"
#include "extensions/common/test_util.h"
#include "third_party/leveldatabase/src/include/leveldb/db.h"
@@ -32,8 +32,9 @@ namespace {
// Caller owns the returned object.
scoped_ptr<KeyedService> CreateStorageFrontendForTesting(
content::BrowserContext* context) {
- return StorageFrontend::CreateForTesting(new LeveldbSettingsStorageFactory(),
- context);
+ scoped_refptr<ValueStoreFactory> factory =
+ new ValueStoreFactoryImpl(context->GetPath());
+ return StorageFrontend::CreateForTesting(factory, context);
}
scoped_ptr<KeyedService> BuildEventRouter(content::BrowserContext* context) {
@@ -105,6 +106,8 @@ TEST_F(StorageApiUnittest, RestoreCorruptedStorage) {
settings_namespace::LOCAL,
StorageFrontend::Get(browser_context()));
ASSERT_TRUE(store);
+ // TODO(cmumford): Modify test as this requires that the factory always
+ // creates instances of LeveldbValueStore.
SettingsStorageQuotaEnforcer* quota_store =
static_cast<SettingsStorageQuotaEnforcer*>(store);
LeveldbValueStore* leveldb_store =
diff --git a/extensions/browser/api/storage/storage_frontend.cc b/extensions/browser/api/storage/storage_frontend.cc
index 26d6ec8..911a492 100644
--- a/extensions/browser/api/storage/storage_frontend.cc
+++ b/extensions/browser/api/storage/storage_frontend.cc
@@ -16,10 +16,11 @@
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/browser/api/extensions_api_client.h"
-#include "extensions/browser/api/storage/leveldb_settings_storage_factory.h"
#include "extensions/browser/api/storage/local_value_store_cache.h"
#include "extensions/browser/event_router.h"
#include "extensions/browser/extension_registry.h"
+#include "extensions/browser/extension_system.h"
+#include "extensions/browser/value_store/value_store_factory.h"
#include "extensions/common/api/storage.h"
using content::BrowserContext;
@@ -69,25 +70,23 @@ StorageFrontend* StorageFrontend::Get(BrowserContext* context) {
// static
scoped_ptr<StorageFrontend> StorageFrontend::CreateForTesting(
- const scoped_refptr<SettingsStorageFactory>& storage_factory,
+ const scoped_refptr<ValueStoreFactory>& storage_factory,
BrowserContext* context) {
return make_scoped_ptr(new StorageFrontend(storage_factory, context));
}
StorageFrontend::StorageFrontend(BrowserContext* context)
- : browser_context_(context) {
- Init(new LeveldbSettingsStorageFactory());
+ : StorageFrontend(ExtensionSystem::Get(context)->store_factory(), context) {
}
StorageFrontend::StorageFrontend(
- const scoped_refptr<SettingsStorageFactory>& factory,
+ const scoped_refptr<ValueStoreFactory>& factory,
BrowserContext* context)
: browser_context_(context) {
Init(factory);
}
-void StorageFrontend::Init(
- const scoped_refptr<SettingsStorageFactory>& factory) {
+void StorageFrontend::Init(const scoped_refptr<ValueStoreFactory>& factory) {
TRACE_EVENT0("browser,startup", "StorageFrontend::Init")
SCOPED_UMA_HISTOGRAM_TIMER("Extensions.StorageFrontendInitTime");
@@ -98,8 +97,7 @@ void StorageFrontend::Init(
observers_->AddObserver(browser_context_observer_.get());
- caches_[settings_namespace::LOCAL] =
- new LocalValueStoreCache(factory, browser_context_->GetPath());
+ caches_[settings_namespace::LOCAL] = new LocalValueStoreCache(factory);
// Add any additional caches the embedder supports (for example, caches
// for chrome.storage.managed and chrome.storage.sync).
diff --git a/extensions/browser/api/storage/storage_frontend.h b/extensions/browser/api/storage/storage_frontend.h
index 372fd78..6d3427f 100644
--- a/extensions/browser/api/storage/storage_frontend.h
+++ b/extensions/browser/api/storage/storage_frontend.h
@@ -13,7 +13,6 @@
#include "base/memory/scoped_ptr.h"
#include "extensions/browser/api/storage/settings_namespace.h"
#include "extensions/browser/api/storage/settings_observer.h"
-#include "extensions/browser/api/storage/settings_storage_factory.h"
#include "extensions/browser/api/storage/value_store_cache.h"
#include "extensions/browser/browser_context_keyed_api_factory.h"
@@ -23,6 +22,8 @@ class BrowserContext;
namespace extensions {
+class ValueStoreFactory;
+
// The component of the Storage API which runs on the UI thread.
class StorageFrontend : public BrowserContextKeyedAPI {
public:
@@ -31,7 +32,7 @@ class StorageFrontend : public BrowserContextKeyedAPI {
// Creates with a specific |storage_factory|.
static scoped_ptr<StorageFrontend> CreateForTesting(
- const scoped_refptr<SettingsStorageFactory>& storage_factory,
+ const scoped_refptr<ValueStoreFactory>& storage_factory,
content::BrowserContext* context);
// Public so tests can create and delete their own instances.
@@ -74,10 +75,10 @@ class StorageFrontend : public BrowserContextKeyedAPI {
explicit StorageFrontend(content::BrowserContext* context);
// Constructor for tests.
- StorageFrontend(const scoped_refptr<SettingsStorageFactory>& storage_factory,
+ StorageFrontend(const scoped_refptr<ValueStoreFactory>& storage_factory,
content::BrowserContext* context);
- void Init(const scoped_refptr<SettingsStorageFactory>& storage_factory);
+ void Init(const scoped_refptr<ValueStoreFactory>& storage_factory);
// The (non-incognito) browser context this Frontend belongs to.
content::BrowserContext* const browser_context_;
diff --git a/extensions/browser/api/storage/storage_frontend_unittest.cc b/extensions/browser/api/storage/storage_frontend_unittest.cc
index a434a3c..5995ceb 100644
--- a/extensions/browser/api/storage/storage_frontend_unittest.cc
+++ b/extensions/browser/api/storage/storage_frontend_unittest.cc
@@ -12,12 +12,12 @@
#include "content/public/test/test_browser_context.h"
#include "content/public/test/test_browser_thread.h"
#include "extensions/browser/api/extensions_api_client.h"
-#include "extensions/browser/api/storage/leveldb_settings_storage_factory.h"
#include "extensions/browser/api/storage/settings_namespace.h"
#include "extensions/browser/api/storage/settings_test_util.h"
#include "extensions/browser/api/storage/storage_frontend.h"
#include "extensions/browser/extensions_test.h"
#include "extensions/browser/value_store/value_store.h"
+#include "extensions/browser/value_store/value_store_factory_impl.h"
#include "testing/gtest/include/gtest/gtest.h"
using content::BrowserThread;
@@ -40,13 +40,13 @@ const ValueStore::WriteOptions DEFAULTS = ValueStore::DEFAULTS;
class ExtensionSettingsFrontendTest : public ExtensionsTest {
public:
ExtensionSettingsFrontendTest()
- : storage_factory_(new util::ScopedSettingsStorageFactory()),
- ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
+ : ui_thread_(BrowserThread::UI, base::MessageLoop::current()),
file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {}
void SetUp() override {
ExtensionsTest::SetUp();
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ storage_factory_ = new ValueStoreFactoryImpl(temp_dir_.path());
ResetFrontend();
}
@@ -59,14 +59,13 @@ class ExtensionSettingsFrontendTest : public ExtensionsTest {
protected:
void ResetFrontend() {
- storage_factory_->Reset(new LeveldbSettingsStorageFactory());
frontend_ =
StorageFrontend::CreateForTesting(storage_factory_, browser_context());
}
base::ScopedTempDir temp_dir_;
scoped_ptr<StorageFrontend> frontend_;
- scoped_refptr<util::ScopedSettingsStorageFactory> storage_factory_;
+ scoped_refptr<ValueStoreFactoryImpl> storage_factory_;
private:
base::MessageLoop message_loop_;