| Index: chrome/browser/extensions/extension_settings.h
|
| diff --git a/chrome/browser/extensions/extension_settings.h b/chrome/browser/extensions/extension_settings.h
|
| index 1510a537457b89050466ff81819cbd9dad4d8124..209a858c272a3ad422f21e50b876e511f86fdbe0 100644
|
| --- a/chrome/browser/extensions/extension_settings.h
|
| +++ b/chrome/browser/extensions/extension_settings.h
|
| @@ -8,21 +8,31 @@
|
|
|
| #include "base/file_path.h"
|
| #include "base/memory/ref_counted.h"
|
| -#include "chrome/browser/extensions/extension_settings_storage.h"
|
| +#include "chrome/browser/extensions/extension_service.h"
|
| +#include "chrome/browser/extensions/syncable_extension_settings_storage.h"
|
| +#include "chrome/browser/sync/api/syncable_service.h"
|
|
|
| -// Manages ExtensionSettingsStorage objects for extensions.
|
| -class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> {
|
| +// Manages ExtensionSettingsStorage objects for extensions, including routing
|
| +// changes from sync to them.
|
| +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);
|
|
|
| + // Sets the current ExtensionService, required for GetAllSyncData.
|
| + // Ownership NOT taken.
|
| + void SetExtensionService(ExtensionServiceInterface* extension_service);
|
| +
|
| // Gets a weak reference to the storage area for a given extension.
|
| // Must be run on the FILE thread.
|
| //
|
| // By default this will be of a cached LEVELDB storage, but on failure to
|
| // create a leveldb instance will fall back to cached NOOP storage.
|
| - ExtensionSettingsStorage* GetStorage(const std::string& extension_id);
|
| + ExtensionSettingsStorage* GetStorage(
|
| + const std::string& extension_id) const;
|
|
|
| // Gets a weak reference to the storage area for a given extension, with a
|
| // specific type and whether it should be wrapped in a cache.
|
| @@ -32,25 +42,72 @@ class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> {
|
| ExtensionSettingsStorage* GetStorageForTesting(
|
| ExtensionSettingsStorage::Type type,
|
| bool cached,
|
| - const std::string& extension_id);
|
| + const std::string& extension_id) const;
|
| +
|
| + // 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>;
|
| virtual ~ExtensionSettings();
|
|
|
| - // Creates a storage area of a given type, optionally wrapped in a cache.
|
| - // Returns NULL if creation fails.
|
| - ExtensionSettingsStorage* CreateStorage(
|
| + // Gets a weak reference to the storage area for a given extension,
|
| + // initializing sync with some initial data if sync enabled.
|
| + //
|
| + // By default this will be of a cached LEVELDB storage, but on failure to
|
| + // create a leveldb instance will fall back to cached NOOP storage.
|
| + SyncableExtensionSettingsStorage* GetOrCreateStorageWithSyncData(
|
| + const std::string& extension_id, const DictionaryValue& sync_data) const;
|
| +
|
| + // If a storage area exists in the cache, returns the cached storage area.
|
| + // Otherwise tries to create one using CreateAndInitStorage.
|
| + SyncableExtensionSettingsStorage* GetOrCreateAndInitStorage(
|
| + ExtensionSettingsStorage::Type type,
|
| + bool cached,
|
| const std::string& extension_id,
|
| + const DictionaryValue& initial_sync_data) const;
|
| +
|
| + // Creates a storage area of a given type, optionally wrapped in a cache.
|
| + // Returns NULL if creation fails. Otherwise, adds the new storage area to
|
| + // the cache and initializes sync if sync is enabled.
|
| + SyncableExtensionSettingsStorage* CreateAndInitStorage(
|
| ExtensionSettingsStorage::Type type,
|
| - bool cached);
|
| + bool cached,
|
| + const std::string& extension_id,
|
| + const DictionaryValue& initial_sync_data) const;
|
| +
|
| + // Delegates for MergeDataAndStartSyncing and ProcessSyncChanges that return
|
| + // void so that they can be bound to Callbacks.
|
| + void MergeDataAndStartSyncing2(
|
| + syncable::ModelType type,
|
| + const SyncDataList& initial_sync_data,
|
| + SyncChangeProcessor* sync_processor);
|
| + void ProcessSyncChanges2(
|
| + const tracked_objects::Location& from_here,
|
| + const SyncChangeList& change_list);
|
|
|
| // 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_;
|
| + mutable
|
| + std::map<std::string, SyncableExtensionSettingsStorage*> storage_objs_;
|
| +
|
| + // Current extension service. Needed in order to list all extensions when
|
| + // getting all settings for GetAllSyncData().
|
| + const ExtensionServiceInterface* extension_service_;
|
| +
|
| + // Current sync processor, if any.
|
| + SyncChangeProcessor* sync_processor_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(ExtensionSettings);
|
| };
|
|
|