| 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..c481626d9b6d572dc8a383b7bd092dce00c73595 100644
|
| --- a/chrome/browser/extensions/extension_settings.h
|
| +++ b/chrome/browser/extensions/extension_settings.h
|
| @@ -7,22 +7,37 @@
|
| #pragma once
|
|
|
| #include "base/file_path.h"
|
| +#include "base/memory/linked_ptr.h"
|
| #include "base/memory/ref_counted.h"
|
| -#include "chrome/browser/extensions/extension_settings_storage.h"
|
| +#include "base/task.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.
|
| +// Lives on the FILE thread, so all methods (apart from the constructor, but
|
| +// including the destructor) must be called on the FILE thread.
|
| +class ExtensionSettings
|
| + : public base::RefCountedThreadSafe<
|
| + ExtensionSettings, BrowserThread::DeleteOnFileThread>,
|
| + 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 +47,68 @@ 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>;
|
| + friend struct BrowserThread::DeleteOnThread<BrowserThread::FILE>;
|
| + friend class DeleteTask<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;
|
| +
|
| + // Appends the sync data from a list of Extensions to a given list.
|
| + void AppendAllSyncData(
|
| + SyncDataList* sync_data, const ExtensionList& extensions) const;
|
|
|
| // The base file path to create any leveldb databases at.
|
| - const FilePath base_path_;
|
| + const FilePath const 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_;
|
| + typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> >
|
| + StorageObjMap;
|
| + mutable StorageObjMap 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);
|
| };
|
|
|