Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1175)

Unified Diff: chrome/browser/extensions/extension_settings.h

Issue 7775008: Enable sync for the settings from the Extension Settings API. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Comments, GCC compile fix Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..42f9baad4c64b324831f2267d61027cabbe31f33 100644
--- a/chrome/browser/extensions/extension_settings.h
+++ b/chrome/browser/extensions/extension_settings.h
@@ -7,11 +7,17 @@
#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/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
akalin 2011/09/20 14:53:11 remove parenthesized clause
not at google - send to devlin 2011/09/21 00:20:14 Done.
+// including the destructor) must be called on the FILE thread.
+class ExtensionSettings : public SyncableService {
public:
// File path is the base of the extension settings directory.
// The databases will be at base_path/extension_id.
@@ -22,7 +28,8 @@ class ExtensionSettings : public base::RefCountedThreadSafe<ExtensionSettings> {
//
// 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 +39,64 @@ 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;
akalin 2011/09/20 14:53:11 #include base/compiler_specific.h
not at google - send to devlin 2011/09/21 00:20:14 Done.
+ 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>;
+ // Must be destroyed on the FILE thread.
+ friend class DeleteTask<ExtensionSettings>;
akalin 2011/09/20 14:53:11 no need for this anymore. Just make the destructo
not at google - send to devlin 2011/09/21 00:20:14 Done.
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;
+
+ // Gets all extension IDs known to extension settings. This may not be all
+ // installed extensions.
+ std::set<std::string> GetKnownExtensionIDs() 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_;
+ typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> >
+ StorageObjMap;
+ mutable StorageObjMap storage_objs_;
+
+ // Current sync processor, if any.
+ SyncChangeProcessor* sync_processor_;
DISALLOW_COPY_AND_ASSIGN(ExtensionSettings);
};

Powered by Google App Engine
This is Rietveld 408576698