Chromium Code Reviews| 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..22a3ded8f33c3aab817ce0e8e497c888f046f8bf | 
| --- /dev/null | 
| +++ b/chrome/browser/extensions/syncable_extension_settings_storage.h | 
| @@ -0,0 +1,86 @@ | 
| +// 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 base::SupportsWeakPtr<SyncableExtensionSettingsStorage> { | 
| + 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; | 
| 
 
Ben Olmstead
2011/08/31 17:36:43
No need for virtual and OVERRIDE together, just OV
 
akalin
2011/08/31 21:12:51
Don't we always want 'virtual' for clarity?  Since
 
Ben Olmstead
2011/08/31 21:19:43
For some reason, I thought we didn't use the two t
 
not at google - send to devlin
2011/09/02 05:00:40
OVERRIDE and virtual are separate things, yes.
 
 | 
| + 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 ExtensionSettingSyncDataList& 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_ |