Chromium Code Reviews| 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..c4efaa6f7e0c2584d36cd80dd1b4ada183ec7207 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 |
|
akalin
2011/09/15 19:56:44
Say that this lives on the FILE thread, and all me
not at google - send to devlin
2011/09/16 05:18:59
Done.
|
| + : public base::RefCountedThreadSafe<ExtensionSettings>, |
|
akalin
2011/09/15 19:56:44
since this lives on the FILE thread only, shouldn'
not at google - send to devlin
2011/09/16 05:18:59
It seemed easiest to do the RefCountedThreadSafe w
akalin
2011/09/16 15:36:40
See earlier rant about lifetime management. This
not at google - send to devlin
2011/09/19 07:10:46
See previous comment.
|
| + 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); |
|
akalin
2011/09/15 19:56:44
Prefer to make this a constructor arg, since it'll
not at google - send to devlin
2011/09/16 05:18:59
Can't make it a ctor argument unfortunately becaus
akalin
2011/09/16 15:36:40
Ugh. Maybe add a comment? Although if ExtensionS
not at google - send to devlin
2011/09/19 07:10:46
Don't need this any more.
|
| + |
| // 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,66 @@ 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; |
| + |
| + // 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_; |
| // 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); |
| }; |