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..b17fdf5f964180ef83fdda20c47255c50f26bb21 |
--- /dev/null |
+++ b/chrome/browser/extensions/syncable_extension_settings_storage.h |
@@ -0,0 +1,88 @@ |
+// 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_settings_sync_data.h" |
+#include "chrome/browser/sync/api/syncable_service.h" |
+#include "chrome/browser/sync/api/sync_change.h" |
+ |
+// XXX repro/investigate sqlite crash. |
+// XXX rename Push to Send? |
+// ... RemoveFromSyncCallback -> SendRemoveToSyncCallback? |
+ |
+// Decorates an ExtensionSettingsStorage with sync behaviour. |
+class SyncableExtensionSettingsStorage : public ExtensionSettingsStorage { |
+ public: |
+ // Bundles the sync dependencies for sync-related callbacks. Since sync may |
+ // be disabled at any time, and therefore the sync processor and synced keys |
+ // made invalid, callbacks must only be passed weak references to them. |
+ // Public for anonymous namespace access. |
+ class SyncDeps : public base::SupportsWeakPtr<SyncDeps> { |
+ public: |
+ // Ownership of processor NOT taken. |
+ explicit SyncDeps(SyncChangeProcessor* processor); |
+ virtual ~SyncDeps(); |
+ |
+ SyncChangeProcessor* processor() { return processor_; } |
+ std::set<std::string>* keys() { return &keys_; } |
+ |
+ private: |
+ // Sync's SyncChange handler. All changes are pushed through this. |
+ SyncChangeProcessor* processor_; |
+ |
+ // Keys of settings that have been synced. Track in order to correctly |
+ // send an ACTION_ADD or ACTION_UPDATE to the processor on Set(). |
+ std::set<std::string> keys_; |
+ }; |
+ |
+ explicit SyncableExtensionSettingsStorage( |
+ std::string extension_id, |
+ // Ownership taken. |
+ ExtensionSettingsStorage* delegate); |
+ |
+ // ExtensionSettingsStorage implementation. |
+ virtual void Get(const std::string& key, Callback* callback) OVERRIDE; |
+ virtual void Get(const ListValue& keys, Callback* callback) OVERRIDE; |
+ virtual void Get(Callback* callback) OVERRIDE; |
+ virtual void Set( |
+ const std::string& key, const Value& value, Callback* callback) OVERRIDE; |
+ virtual void Set(const DictionaryValue& values, Callback* callback) OVERRIDE; |
+ virtual void Remove(const std::string& key, Callback* callback) OVERRIDE; |
+ virtual void Remove(const ListValue& keys, Callback* callback) OVERRIDE; |
+ virtual void Clear(Callback *callback) OVERRIDE; |
+ virtual void DeleteSoon() OVERRIDE; |
+ |
+ // Sync-related methods. |
+ void StartSyncing( |
+ const DictionaryValue& sync_state, |
+ // Guaranteed non-NULL. Ownership NOT taken. |
+ SyncChangeProcessor* sync_processor); |
+ void StopSyncing(); |
+ void ProcessSyncChanges(const ExtensionSettingsSyncDataList& sync_changes); |
+ |
+ private: |
+ // Deleted from DeleteSoon(). |
+ virtual ~SyncableExtensionSettingsStorage(); |
+ |
+ // Id of the extension these settings are for. |
+ std::string extension_id_; |
+ |
+ // Decorated storage. Deleted in DeleteSoon(). |
+ ExtensionSettingsStorage* delegate_; |
+ |
+ // Weak sync dependencies. Non-NULL while sync enabled (between calls to |
+ // MergeDataAndStartSyncing and StopSyncing), NULL at other times. |
+ SyncDeps* sync_deps_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(SyncableExtensionSettingsStorage); |
+}; |
+ |
+#endif // CHROME_BROWSER_EXTENSIONS_SYNCABLE_EXTENSION_SETTINGS_STORAGE_H_ |