Chromium Code Reviews| 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 // Reference taken. | |
| 30 ObserverListThreadSafe<ExtensionSettingsObserver>* observers); | |
|
akalin
2011/10/07 21:06:23
pass a const ref to scoped_refptr
not at google - send to devlin
2011/10/10 01:00:16
Done.
| |
| 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 |
| 43 // Sends a change event to the observer list. |profile| is the profile which | |
| 44 // generated the change. Must be called on the FILE thread. | |
| 45 void TriggerOnSettingsChanged( | |
| 46 Profile* profile, | |
| 47 const std::string& extension_id, | |
| 48 const std::string& event_json); | |
| 49 | |
| 37 // SyncableService implementation. | 50 // SyncableService implementation. |
| 38 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | 51 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; |
| 39 virtual SyncError MergeDataAndStartSyncing( | 52 virtual SyncError MergeDataAndStartSyncing( |
| 40 syncable::ModelType type, | 53 syncable::ModelType type, |
| 41 const SyncDataList& initial_sync_data, | 54 const SyncDataList& initial_sync_data, |
| 42 SyncChangeProcessor* sync_processor) OVERRIDE; | 55 SyncChangeProcessor* sync_processor) OVERRIDE; |
| 43 virtual SyncError ProcessSyncChanges( | 56 virtual SyncError ProcessSyncChanges( |
| 44 const tracked_objects::Location& from_here, | 57 const tracked_objects::Location& from_here, |
| 45 const SyncChangeList& change_list) OVERRIDE; | 58 const SyncChangeList& change_list) OVERRIDE; |
| 46 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; | 59 virtual void StopSyncing(syncable::ModelType type) OVERRIDE; |
| 47 | 60 |
| 48 private: | 61 private: |
| 49 // Gets a weak reference to the storage area for a given extension, | 62 // Gets a weak reference to the storage area for a given extension, |
| 50 // initializing sync with some initial data if sync enabled. | 63 // initializing sync with some initial data if sync enabled. |
| 51 // | 64 // |
| 52 // By default this will be of a cached LEVELDB storage, but on failure to | 65 // By default this will be of a cached LEVELDB storage, but on failure to |
| 53 // create a leveldb instance will fall back to cached NOOP storage. | 66 // create a leveldb instance will fall back to cached NOOP storage. |
| 54 SyncableExtensionSettingsStorage* GetOrCreateStorageWithSyncData( | 67 SyncableExtensionSettingsStorage* GetOrCreateStorageWithSyncData( |
| 55 const std::string& extension_id, const DictionaryValue& sync_data) const; | 68 const std::string& extension_id, const DictionaryValue& sync_data) const; |
| 56 | 69 |
| 57 // Gets all extension IDs known to extension settings. This may not be all | 70 // Gets all extension IDs known to extension settings. This may not be all |
| 58 // installed extensions. | 71 // installed extensions. |
| 59 std::set<std::string> GetKnownExtensionIDs() const; | 72 std::set<std::string> GetKnownExtensionIDs() const; |
| 60 | 73 |
| 61 // The base file path to create any leveldb databases at. | 74 // The base file path to create any leveldb databases at. |
| 62 const FilePath base_path_; | 75 const FilePath base_path_; |
| 63 | 76 |
| 77 // The list of observers to settings changes. | |
| 78 scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > observers_; | |
| 79 | |
| 64 // A cache of ExtensionSettingsStorage objects that have already been created. | 80 // A cache of ExtensionSettingsStorage objects that have already been created. |
| 65 // Ensure that there is only ever one created per extension. | 81 // Ensure that there is only ever one created per extension. |
| 66 typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> > | 82 typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> > |
| 67 StorageObjMap; | 83 StorageObjMap; |
| 68 mutable StorageObjMap storage_objs_; | 84 mutable StorageObjMap storage_objs_; |
| 69 | 85 |
| 70 // Current sync processor, if any. | 86 // Current sync processor, if any. |
| 71 SyncChangeProcessor* sync_processor_; | 87 SyncChangeProcessor* sync_processor_; |
| 72 | 88 |
| 73 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsBackend); | 89 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsBackend); |
| 74 }; | 90 }; |
| 75 | 91 |
| 76 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ | 92 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ |
| OLD | NEW |