| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| 11 #include "base/memory/linked_ptr.h" | 11 #include "base/memory/linked_ptr.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/observer_list_threadsafe.h" |
| 13 #include "base/task.h" | 14 #include "base/task.h" |
| 15 #include "chrome/browser/extensions/extension_settings_observer.h" |
| 14 #include "chrome/browser/extensions/syncable_extension_settings_storage.h" | 16 #include "chrome/browser/extensions/syncable_extension_settings_storage.h" |
| 15 #include "chrome/browser/sync/api/syncable_service.h" | 17 #include "chrome/browser/sync/api/syncable_service.h" |
| 16 | 18 |
| 17 // Manages ExtensionSettingsStorage objects for extensions, including routing | 19 // Manages ExtensionSettingsStorage objects for extensions, including routing |
| 18 // changes from sync to them. | 20 // changes from sync to them. |
| 19 // Lives entirely on the FILE thread. | 21 // Lives entirely on the FILE thread. |
| 20 class ExtensionSettingsBackend : public SyncableService { | 22 class ExtensionSettingsBackend : public SyncableService { |
| 21 public: | 23 public: |
| 22 // File path is the base of the extension settings directory. | 24 // |base_path| is the base of the extension settings directory, so the |
| 23 // The databases will be at base_path/extension_id. | 25 // databases will be at base_path/extension_id. |
| 24 explicit ExtensionSettingsBackend(const FilePath& base_path); | 26 // |observers| is the list of observers to settings changes. |
| 27 explicit ExtensionSettingsBackend( |
| 28 const FilePath& base_path, |
| 29 const scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> >& |
| 30 observers); |
| 25 | 31 |
| 26 virtual ~ExtensionSettingsBackend(); | 32 virtual ~ExtensionSettingsBackend(); |
| 27 | 33 |
| 28 // Gets a weak reference to the storage area for a given extension. | 34 // Gets a weak reference to the storage area for a given extension. |
| 29 // Must be run on the FILE thread. | 35 // Must be run on the FILE thread. |
| 30 // | 36 // |
| 31 // By default this will be an ExtensionSettingsLeveldbStorage, but on | 37 // By default this will be an ExtensionSettingsLeveldbStorage, but on |
| 32 // failure to create a leveldb instance will fall back to | 38 // failure to create a leveldb instance will fall back to |
| 33 // InMemoryExtensionSettingsStorage. | 39 // InMemoryExtensionSettingsStorage. |
| 34 ExtensionSettingsStorage* GetStorage( | 40 ExtensionSettingsStorage* GetStorage( |
| 35 const std::string& extension_id) const; | 41 const std::string& extension_id) const; |
| 36 | 42 |
| 37 // Deletes all setting data for an extension. Call on the FILE thread. | 43 // Deletes all setting data for an extension. Call on the FILE thread. |
| 38 void DeleteExtensionData(const std::string& extension_id); | 44 void DeleteExtensionData(const std::string& extension_id); |
| 39 | 45 |
| 46 // Sends a change event to the observer list. |profile| is the profile which |
| 47 // generated the change. Must be called on the FILE thread. |
| 48 void TriggerOnSettingsChanged( |
| 49 Profile* profile, |
| 50 const std::string& extension_id, |
| 51 const ExtensionSettingsChanges& changes) const; |
| 52 |
| 40 // SyncableService implementation. | 53 // SyncableService implementation. |
| 41 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | 54 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; |
| 42 virtual SyncError MergeDataAndStartSyncing( | 55 virtual SyncError MergeDataAndStartSyncing( |
| 43 syncable::ModelType type, | 56 syncable::ModelType type, |
| 44 const SyncDataList& initial_sync_data, | 57 const SyncDataList& initial_sync_data, |
| 45 SyncChangeProcessor* sync_processor) OVERRIDE; | 58 SyncChangeProcessor* sync_processor) OVERRIDE; |
| 46 virtual SyncError ProcessSyncChanges( | 59 virtual SyncError ProcessSyncChanges( |
| 47 const tracked_objects::Location& from_here, | 60 const tracked_objects::Location& from_here, |
| 48 const SyncChangeList& change_list) OVERRIDE; | 61 const SyncChangeList& change_list) OVERRIDE; |
| 49 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; | 62 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; |
| 50 | 63 |
| 51 private: | 64 private: |
| 52 // Gets a weak reference to the storage area for a given extension, | 65 // Gets a weak reference to the storage area for a given extension, |
| 53 // initializing sync with some initial data if sync enabled. | 66 // initializing sync with some initial data if sync enabled. |
| 54 // | 67 // |
| 55 // By default this will be of a cached LEVELDB storage, but on failure to | 68 // By default this will be of a cached LEVELDB storage, but on failure to |
| 56 // create a leveldb instance will fall back to cached NOOP storage. | 69 // create a leveldb instance will fall back to cached NOOP storage. |
| 57 SyncableExtensionSettingsStorage* GetOrCreateStorageWithSyncData( | 70 SyncableExtensionSettingsStorage* GetOrCreateStorageWithSyncData( |
| 58 const std::string& extension_id, const DictionaryValue& sync_data) const; | 71 const std::string& extension_id, const DictionaryValue& sync_data) const; |
| 59 | 72 |
| 60 // Gets all extension IDs known to extension settings. This may not be all | 73 // Gets all extension IDs known to extension settings. This may not be all |
| 61 // installed extensions. | 74 // installed extensions. |
| 62 std::set<std::string> GetKnownExtensionIDs() const; | 75 std::set<std::string> GetKnownExtensionIDs() const; |
| 63 | 76 |
| 64 // The base file path to create any leveldb databases at. | 77 // The base file path to create any leveldb databases at. |
| 65 const FilePath base_path_; | 78 const FilePath base_path_; |
| 66 | 79 |
| 80 // The list of observers to settings changes. |
| 81 const scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > |
| 82 observers_; |
| 83 |
| 67 // A cache of ExtensionSettingsStorage objects that have already been created. | 84 // A cache of ExtensionSettingsStorage objects that have already been created. |
| 68 // Ensure that there is only ever one created per extension. | 85 // Ensure that there is only ever one created per extension. |
| 69 typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> > | 86 typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> > |
| 70 StorageObjMap; | 87 StorageObjMap; |
| 71 mutable StorageObjMap storage_objs_; | 88 mutable StorageObjMap storage_objs_; |
| 72 | 89 |
| 73 // Current sync processor, if any. | 90 // Current sync processor, if any. |
| 74 SyncChangeProcessor* sync_processor_; | 91 SyncChangeProcessor* sync_processor_; |
| 75 | 92 |
| 76 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsBackend); | 93 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsBackend); |
| 77 }; | 94 }; |
| 78 | 95 |
| 79 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ | 96 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ |
| OLD | NEW |