| Index: chrome/browser/extensions/extension_settings.h
|
| diff --git a/chrome/browser/extensions/extension_settings.h b/chrome/browser/extensions/extension_settings.h
|
| index 1f297daa927266631b4712ab9cf190ae8068edfa..bf86c37b9718aa006733421175892104aa2cbde8 100644
|
| --- a/chrome/browser/extensions/extension_settings.h
|
| +++ b/chrome/browser/extensions/extension_settings.h
|
| @@ -7,50 +7,73 @@
|
| #pragma once
|
|
|
| #include "base/callback.h"
|
| +#include "base/compiler_specific.h"
|
| #include "base/file_path.h"
|
| #include "base/memory/ref_counted.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "base/values.h"
|
| #include "chrome/browser/extensions/extension_settings_storage.h"
|
| -
|
| -// Manages ExtensionSettingsStorage objects for extensions.
|
| -class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> {
|
| +#include "chrome/browser/extensions/extension_settings.h"
|
| +#include "chrome/browser/extensions/extension_settings_storage.h"
|
| +#include "chrome/browser/extensions/extension_setting_sync_data.h"
|
| +#include "chrome/browser/extensions/syncable_extension_settings_storage.h"
|
| +#include "chrome/browser/sync/api/syncable_service.h"
|
| +#include "chrome/browser/sync/api/sync_data.h"
|
| +#include "chrome/browser/sync/api/sync_change.h"
|
| +
|
| +// Manages ExtensionSettingsStorage objects and routes sync events to their
|
| +// target storage objects.
|
| +class ExtensionSettings
|
| + : public base::RefCountedThreadSafe<ExtensionSettings>,
|
| + public SyncableService {
|
| public:
|
| // File path is the base of the extension settings directory.
|
| // The databases will be at base_path/extension_id.
|
| explicit ExtensionSettings(const FilePath& base_path);
|
|
|
| // Callback from the GetStorage() methods.
|
| - typedef base::Callback<void(ExtensionSettingsStorage*)> Callback;
|
| + typedef base::Callback<void(SyncableExtensionSettingsStorage*)> Callback;
|
|
|
| - // Gets the storage area for a given extension. Only valid for the duration
|
| - // of the callback.
|
| - // By default this will be of a cached LEVELDB storage, but on failure to
|
| + // Gets a sync-enabled storage area for a given extension. Only valid for
|
| + // the duration of the callback.
|
| + // By default this will be a cached LEVELDB storage area, but on failure to
|
| // create a leveldb instance will fall back to cached NOOP storage.
|
| // Callbacks will happen asynchronously regardless of whether they need to go
|
| // to the FILE thread, but will always be called on the UI thread.
|
| void GetStorage(const std::string& extension_id, const Callback& callback);
|
|
|
| - // Gets a storage area for a given extension with a specific type.
|
| - // and whether it should be wrapped in a cache.
|
| - // Use this for testing; if the given type fails to be created (e.g. if
|
| - // leveldb creation fails) then a DCHECK will fail.
|
| - // Callback objects will be deleted when used.
|
| + // Gets a sync-endabled storage area for a given extension with a specific
|
| + // type. Use this for testing; if the given type fails to be created (e.g.
|
| + // if leveldb creation fails) then a DCHECK will fail.
|
| void GetStorageForTesting(
|
| ExtensionSettingsStorage::Type type,
|
| bool cached,
|
| const std::string& extension_id,
|
| const Callback& callback);
|
|
|
| + // SyncableService implementation.
|
| + virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE;
|
| + virtual SyncError MergeDataAndStartSyncing(
|
| + syncable::ModelType type,
|
| + const SyncDataList& initial_sync_data,
|
| + SyncChangeProcessor* sync_processor) OVERRIDE;
|
| + virtual SyncError ProcessSyncChanges(
|
| + const tracked_objects::Location& from_here,
|
| + const SyncChangeList& change_list) OVERRIDE;
|
| + virtual void StopSyncing(syncable::ModelType type) OVERRIDE;
|
| +
|
| private:
|
| friend class base::RefCountedThreadSafe<ExtensionSettings>;
|
| - ~ExtensionSettings();
|
| + virtual ~ExtensionSettings();
|
|
|
| - // Attempts to get and callback with an existing storage area. Returns
|
| - // whether storage existed and the callback run.
|
| + // Attempts to get an existing storage area, and runs a Callback if
|
| + // successful. Returns whether storage existed and the callback run.
|
| bool GetExistingStorage(
|
| const std::string& extension_id, const Callback& callback);
|
|
|
| // Runs a Callback with a storage argument, then deletes the callback.
|
| - void RunWithStorage(Callback* callback, ExtensionSettingsStorage* storage);
|
| + void RunWithStorage(
|
| + Callback* callback, SyncableExtensionSettingsStorage* storage);
|
|
|
| // Starts the process of creation of a storage area.
|
| // Must be run on the UI thread.
|
| @@ -71,9 +94,9 @@ class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> {
|
| bool cached,
|
| const Callback& callback);
|
|
|
| - // Creates a storage area of a given type, optionally wrapped in a cache.
|
| - // Returns NULL if creation fails.
|
| - ExtensionSettingsStorage* CreateStorage(
|
| + // Creates a sync-enabled storage area of a given type, optionally wrapped in
|
| + // a cache. Returns NULL if creation fails.
|
| + SyncableExtensionSettingsStorage* CreateStorage(
|
| const std::string& extension_id,
|
| ExtensionSettingsStorage::Type type,
|
| bool cached);
|
| @@ -82,15 +105,36 @@ class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> {
|
| // Must be run on the UI thread.
|
| void EndCreationOfStorage(
|
| const std::string& extension_id,
|
| - ExtensionSettingsStorage* storage,
|
| + SyncableExtensionSettingsStorage* storage,
|
| const Callback& callback);
|
|
|
| + // Start syncing some extension settings.
|
| + void StartSyncingStorage(
|
| + const std::string& extension_id,
|
| + SyncableExtensionSettingsStorage* storage);
|
| +
|
| + // Stop syncing some extension settings.
|
| + void StopSyncingStorage(ExtensionSettingsStorage* storage);
|
| +
|
| + // Asserts that there is no sync data for a storage area.
|
| + void AssertNoSyncData(
|
| + const std::string& extension_id,
|
| + SyncableExtensionSettingsStorage* storage);
|
| +
|
| // The base file path to create any leveldb databases at.
|
| const FilePath base_path_;
|
|
|
| // A cache of ExtensionSettingsStorage objects that have already been created.
|
| // Ensure that there is only ever one created per extension.
|
| - std::map<std::string, ExtensionSettingsStorage*> storage_objs_;
|
| + std::map<std::string, SyncableExtensionSettingsStorage*> storage_objs_;
|
| +
|
| + // Sync change processor for sync.
|
| + SyncChangeProcessor* sync_processor_;
|
| +
|
| + // Initial settings received from sync that haven't been merged into their
|
| + // respective storage areas. Populated in MergeDataAndStartSyncing and
|
| + // depopulated in StartSyncingStorage.
|
| + std::map<std::string, DictionaryValue*> unmerged_sync_data_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ExtensionSettings);
|
| };
|
|
|