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

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: Sync to tip. Latest comments. 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..b6f87d81470ec1cde6e98ee2f1becb13648f0272 100644
--- a/chrome/browser/extensions/extension_settings.h
+++ b/chrome/browser/extensions/extension_settings.h
@@ -6,23 +6,32 @@
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_H_
#pragma once
+#include "base/compiler_specific.h"
#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 entirely 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.
explicit ExtensionSettings(const FilePath& base_path);
+ virtual ~ExtensionSettings();
+
// 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 +41,60 @@ 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();
+ // 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;
- // Creates a storage area of a given type, optionally wrapped in a cache.
- // Returns NULL if creation fails.
- ExtensionSettingsStorage* CreateStorage(
+ // 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