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

Unified Diff: chrome/browser/extensions/syncable_extension_settings_storage.h

Issue 7977018: Enable sync for the settings from the Extension Settings API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix race condition in ExtensionSettingsUIWrapper::Core Created 9 years, 3 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/syncable_extension_settings_storage.h
diff --git a/chrome/browser/extensions/syncable_extension_settings_storage.h b/chrome/browser/extensions/syncable_extension_settings_storage.h
new file mode 100644
index 0000000000000000000000000000000000000000..3232eb4dc9e1af62788f0914635e3458433014f8
--- /dev/null
+++ b/chrome/browser/extensions/syncable_extension_settings_storage.h
@@ -0,0 +1,79 @@
+// Copyright (c) 2011 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 CHROME_BROWSER_EXTENSIONS_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_
+#define CHROME_BROWSER_EXTENSIONS_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "base/memory/weak_ptr.h"
+#include "base/values.h"
+#include "chrome/browser/extensions/extension_settings_storage.h"
+#include "chrome/browser/extensions/extension_setting_sync_data.h"
+#include "chrome/browser/sync/api/syncable_service.h"
+#include "chrome/browser/sync/api/sync_change.h"
+
+// Decorates an ExtensionSettingsStorage with sync behaviour.
+class SyncableExtensionSettingsStorage : public ExtensionSettingsStorage {
+ public:
+ explicit SyncableExtensionSettingsStorage(
+ std::string extension_id,
+ // Ownership taken.
+ ExtensionSettingsStorage* delegate);
+
+ virtual ~SyncableExtensionSettingsStorage();
+
+ // ExtensionSettingsStorage implementation.
+ virtual Result Get(const std::string& key) OVERRIDE;
+ virtual Result Get(const std::vector<std::string>& keys) OVERRIDE;
+ virtual Result Get() OVERRIDE;
+ virtual Result Set(const std::string& key, const Value& value) OVERRIDE;
+ virtual Result Set(const DictionaryValue& settings) OVERRIDE;
+ virtual Result Remove(const std::string& key) OVERRIDE;
+ virtual Result Remove(const std::vector<std::string>& keys) OVERRIDE;
+ virtual Result Clear() OVERRIDE;
+
+ // Sync-related methods, analogous to those on SyncableService (handled by
+ // ExtensionSettings).
+ SyncError StartSyncing(
+ const DictionaryValue& sync_state,
+ // Must NOT be NULL. Ownership NOT taken.
+ SyncChangeProcessor* sync_processor);
+ void StopSyncing();
+ std::vector<SyncError> ProcessSyncChanges(
+ const ExtensionSettingSyncDataList& sync_changes);
+
+ private:
+ // Either adds to sync or send updates to sync for some settings.
+ // Whether they're adds or updates depends on the state of synced_keys_.
+ void SendAddsOrUpdatesToSync(const DictionaryValue& settings);
+
+ // Sends deletes to sync for some settings.
+ void SendDeletesToSync(const std::vector<std::string>& keys);
+
+ // Sends all local settings to sync (synced settings assumed to be empty).
+ SyncError SendLocalSettingsToSync(
+ const DictionaryValue& settings);
+
+ // Overwrites local state with sync state.
+ SyncError OverwriteLocalSettingsWithSync(
+ const DictionaryValue& sync_state, const DictionaryValue& settings);
+
+ // Id of the extension these settings are for.
+ std::string const extension_id_;
+
+ // Storage area to sync.
+ const scoped_ptr<ExtensionSettingsStorage> delegate_;
+
+ // Sync processor. Non-NULL while sync is enabled (between calls to
+ // StartSyncing and StopSyncing).
+ SyncChangeProcessor* sync_processor_;
+
+ // Keys of the settings that are currently being synced.
+ std::set<std::string> synced_keys_;
+
+ DISALLOW_COPY_AND_ASSIGN(SyncableExtensionSettingsStorage);
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_

Powered by Google App Engine
This is Rietveld 408576698