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

Unified Diff: chrome/browser/extensions/api/storage/sync_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: rebase (split_sync) Created 6 years, 9 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/sync_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/sync_value_store_cache.cc
similarity index 44%
rename from chrome/browser/extensions/api/storage/sync_or_local_value_store_cache.cc
rename to chrome/browser/extensions/api/storage/sync_value_store_cache.cc
index 9ff1175bc728be18c84db4c226feba7720610e0c..2c50a5283a897feaa99a483a380ca2609a46c52b 100644
--- a/chrome/browser/extensions/api/storage/sync_or_local_value_store_cache.cc
+++ b/chrome/browser/extensions/api/storage/sync_value_store_cache.cc
@@ -1,57 +1,67 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// 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 "chrome/browser/extensions/api/storage/sync_or_local_value_store_cache.h"
+#include "chrome/browser/extensions/api/storage/sync_value_store_cache.h"
#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_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"
-#include "extensions/common/permissions/api_permission.h"
using content::BrowserThread;
namespace extensions {
-SyncOrLocalValueStoreCache::SyncOrLocalValueStoreCache(
- settings_namespace::Namespace settings_namespace,
+namespace {
+
+// Returns the quota limit for sync storage, taken from the schema in
+// chrome/common/extensions/api/storage.json.
+SettingsStorageQuotaEnforcer::Limits GetSyncQuotaLimits() {
+ SettingsStorageQuotaEnforcer::Limits limits = {
+ static_cast<size_t>(api::storage::sync::QUOTA_BYTES),
+ static_cast<size_t>(api::storage::sync::QUOTA_BYTES_PER_ITEM),
+ static_cast<size_t>(api::storage::sync::MAX_ITEMS)
+ };
+ return limits;
+}
+
+} // namespace
+
+SyncValueStoreCache::SyncValueStoreCache(
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) {
+ : initialized_(false) {
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(&SyncValueStoreCache::InitOnFileThread,
base::Unretained(this),
- factory, quota, observers, profile_path));
+ factory, observers, profile_path));
}
-SyncOrLocalValueStoreCache::~SyncOrLocalValueStoreCache() {
+SyncValueStoreCache::~SyncValueStoreCache() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
}
-syncer::SyncableService* SyncOrLocalValueStoreCache::GetSyncableService(
+syncer::SyncableService* SyncValueStoreCache::GetSyncableService(
syncer::ModelType type) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
DCHECK(initialized_);
+
switch (type) {
case syncer::APP_SETTINGS:
return app_backend_->GetAsSyncableService();
@@ -63,79 +73,42 @@ syncer::SyncableService* SyncOrLocalValueStoreCache::GetSyncableService(
}
}
-void SyncOrLocalValueStoreCache::RunWithValueStoreForExtension(
+void SyncValueStoreCache::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());
-
- // A neat way to implement unlimited storage; if the extension has the
- // unlimited storage permission, force through all calls to Set() (in the
- // same way that writes from sync ignore quota).
- // But only if it's local storage (bad stuff would happen if sync'ed
- // storage is allowed to be unlimited).
- bool is_unlimited =
- settings_namespace_ == settings_namespace::LOCAL &&
- extension->HasAPIPermission(APIPermission::kUnlimitedStorage);
-
- if (is_unlimited) {
- WeakUnlimitedSettingsStorage unlimited_storage(storage);
- callback.Run(&unlimited_storage);
- } else {
- callback.Run(storage);
- }
+ callback.Run(backend->GetStorage(extension->id()));
}
-void SyncOrLocalValueStoreCache::DeleteStorageSoon(
- const std::string& extension_id) {
+void SyncValueStoreCache::DeleteStorageSoon(const std::string& extension_id) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
- DCHECK(initialized_);
app_backend_->DeleteStorage(extension_id);
extension_backend_->DeleteStorage(extension_id);
}
-void SyncOrLocalValueStoreCache::InitOnFileThread(
+void SyncValueStoreCache::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));
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();
- }
-
+ app_backend_.reset(new SyncStorageBackend(
+ factory,
+ profile_path.AppendASCII(kSyncAppSettingsDirectoryName),
+ GetSyncQuotaLimits(),
+ observers,
+ syncer::APP_SETTINGS,
+ sync_start_util::GetFlareForSyncableService(profile_path)));
+ extension_backend_.reset(new SyncStorageBackend(
+ factory,
+ profile_path.AppendASCII(kSyncExtensionSettingsDirectoryName),
+ GetSyncQuotaLimits(),
+ observers,
+ syncer::EXTENSION_SETTINGS,
+ sync_start_util::GetFlareForSyncableService(profile_path)));
initialized_ = true;
}

Powered by Google App Engine
This is Rietveld 408576698