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

Unified Diff: chrome/browser/extensions/api/storage/local_value_store_cache.cc

Issue 184043031: Split up extensions storage API implementations for sync and local storage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: split sync_or_local Created 6 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/storage/local_value_store_cache.cc
diff --git a/chrome/browser/extensions/api/storage/sync_or_local_value_store_cache.cc b/chrome/browser/extensions/api/storage/local_value_store_cache.cc
similarity index 43%
copy from chrome/browser/extensions/api/storage/sync_or_local_value_store_cache.cc
copy to chrome/browser/extensions/api/storage/local_value_store_cache.cc
index 9ff1175bc728be18c84db4c226feba7720610e0c..014b385d36ef3d38098a0552c997167fd5b61892 100644
--- a/chrome/browser/extensions/api/storage/sync_or_local_value_store_cache.cc
+++ b/chrome/browser/extensions/api/storage/local_value_store_cache.cc
@@ -2,18 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/extensions/api/storage/sync_or_local_value_store_cache.h"
+#include "chrome/browser/extensions/api/storage/local_value_store_cache.h"
+
+#include <limits>
#include "base/bind.h"
#include "base/callback.h"
#include "base/files/file_path.h"
-#include "base/sequenced_task_runner.h"
#include "chrome/browser/extensions/api/storage/local_storage_backend.h"
-#include "chrome/browser/extensions/api/storage/settings_frontend.h"
+#include "chrome/browser/extensions/api/storage/settings_storage_factory.h"
#include "chrome/browser/extensions/api/storage/settings_storage_quota_enforcer.h"
-#include "chrome/browser/extensions/api/storage/sync_storage_backend.h"
#include "chrome/browser/extensions/api/storage/weak_unlimited_settings_storage.h"
-#include "chrome/browser/sync/glue/sync_start_util.h"
+#include "chrome/common/extensions/api/storage.h"
#include "content/public/browser/browser_thread.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
@@ -23,51 +23,44 @@ using content::BrowserThread;
namespace extensions {
-SyncOrLocalValueStoreCache::SyncOrLocalValueStoreCache(
- settings_namespace::Namespace settings_namespace,
+namespace {
+
+// Returns the quota limit for local storage, taken from the schema in
+// chrome/common/extensions/api/storage.json.
+SettingsStorageQuotaEnforcer::Limits GetLocalQuotaLimits() {
+ SettingsStorageQuotaEnforcer::Limits limits = {
+ static_cast<size_t>(api::storage::local::QUOTA_BYTES),
+ std::numeric_limits<size_t>::max(),
+ std::numeric_limits<size_t>::max()
+ };
+ return limits;
+}
+
+} // namespace
+
+LocalValueStoreCache::LocalValueStoreCache(
const scoped_refptr<SettingsStorageFactory>& factory,
- const SettingsStorageQuotaEnforcer::Limits& quota,
- const scoped_refptr<SettingsObserverList>& observers,
- const base::FilePath& profile_path)
- : settings_namespace_(settings_namespace), initialized_(false) {
+ const base::FilePath& profile_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- DCHECK(settings_namespace_ == settings_namespace::LOCAL ||
- settings_namespace_ == settings_namespace::SYNC);
// 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(&SyncOrLocalValueStoreCache::InitOnFileThread,
+ base::Bind(&LocalValueStoreCache::InitOnFileThread,
base::Unretained(this),
- factory, quota, observers, profile_path));
-}
-
-SyncOrLocalValueStoreCache::~SyncOrLocalValueStoreCache() {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
+ factory, profile_path));
}
-syncer::SyncableService* SyncOrLocalValueStoreCache::GetSyncableService(
- syncer::ModelType type) const {
+LocalValueStoreCache::~LocalValueStoreCache() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- DCHECK(initialized_);
- switch (type) {
- case syncer::APP_SETTINGS:
- return app_backend_->GetAsSyncableService();
- case syncer::EXTENSION_SETTINGS:
- return extension_backend_->GetAsSyncableService();
- default:
- NOTREACHED();
- return NULL;
- }
}
-void SyncOrLocalValueStoreCache::RunWithValueStoreForExtension(
+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();
@@ -78,11 +71,7 @@ void SyncOrLocalValueStoreCache::RunWithValueStoreForExtension(
// same way that writes from sync ignore quota).
// But only if it's local storage (bad stuff would happen if sync'ed
Devlin 2014/03/05 19:02:55 you can take out the stuff about sync'ed storage i
James Cook 2014/03/05 23:14:28 Done.
// storage is allowed to be unlimited).
- bool is_unlimited =
- settings_namespace_ == settings_namespace::LOCAL &&
- extension->HasAPIPermission(APIPermission::kUnlimitedStorage);
-
- if (is_unlimited) {
+ if (extension->HasAPIPermission(APIPermission::kUnlimitedStorage)) {
WeakUnlimitedSettingsStorage unlimited_storage(storage);
callback.Run(&unlimited_storage);
} else {
@@ -90,53 +79,24 @@ void SyncOrLocalValueStoreCache::RunWithValueStoreForExtension(
}
}
-void SyncOrLocalValueStoreCache::DeleteStorageSoon(
- const std::string& extension_id) {
+void LocalValueStoreCache::DeleteStorageSoon(const std::string& extension_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- DCHECK(initialized_);
app_backend_->DeleteStorage(extension_id);
Devlin 2014/03/05 19:02:55 that DCHECK(initialized_) made sure we don't deref
James Cook 2014/03/05 23:14:28 Done.
extension_backend_->DeleteStorage(extension_id);
}
-void SyncOrLocalValueStoreCache::InitOnFileThread(
+void LocalValueStoreCache::InitOnFileThread(
const scoped_refptr<SettingsStorageFactory>& factory,
- const SettingsStorageQuotaEnforcer::Limits& quota,
- const scoped_refptr<SettingsObserverList>& observers,
const base::FilePath& profile_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
Devlin 2014/03/05 19:02:55 DCHECK(!initialized_) was useful here, too, IMO.
James Cook 2014/03/05 23:14:28 Done.
- DCHECK(!initialized_);
- switch (settings_namespace_) {
- case settings_namespace::LOCAL:
- app_backend_.reset(new LocalStorageBackend(
- factory,
- profile_path.AppendASCII(kLocalAppSettingsDirectoryName),
- quota));
- extension_backend_.reset(new LocalStorageBackend(
- factory,
- profile_path.AppendASCII(kLocalExtensionSettingsDirectoryName),
- quota));
- break;
- case settings_namespace::SYNC:
- app_backend_.reset(new SyncStorageBackend(
- factory,
- profile_path.AppendASCII(kSyncAppSettingsDirectoryName),
- quota,
- observers,
- syncer::APP_SETTINGS,
- sync_start_util::GetFlareForSyncableService(profile_path)));
- extension_backend_.reset(new SyncStorageBackend(
- factory,
- profile_path.AppendASCII(kSyncExtensionSettingsDirectoryName),
- quota,
- observers,
- syncer::EXTENSION_SETTINGS,
- sync_start_util::GetFlareForSyncableService(profile_path)));
- break;
- default:
- NOTREACHED();
- }
-
- initialized_ = true;
+ app_backend_.reset(new LocalStorageBackend(
+ factory,
+ profile_path.AppendASCII(kLocalAppSettingsDirectoryName),
+ GetLocalQuotaLimits()));
+ extension_backend_.reset(new LocalStorageBackend(
+ factory,
+ profile_path.AppendASCII(kLocalExtensionSettingsDirectoryName),
+ GetLocalQuotaLimits()));
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698