| 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/observer_list_threadsafe.h" |
| 14 #include "base/task.h" | 14 #include "base/task.h" |
| 15 #include "chrome/browser/extensions/extension_settings_observer.h" | 15 #include "chrome/browser/extensions/extension_settings_observer.h" |
| 16 #include "chrome/browser/extensions/syncable_extension_settings_storage.h" | 16 #include "chrome/browser/extensions/syncable_extension_settings_storage.h" |
| 17 #include "chrome/browser/sync/api/syncable_service.h" | 17 #include "chrome/browser/sync/api/syncable_service.h" |
| 18 | 18 |
| 19 // Manages ExtensionSettingsStorage objects for extensions, including routing | 19 // Manages ExtensionSettingsStorage objects for extensions, including routing |
| 20 // changes from sync to them. | 20 // changes from sync to them. |
| 21 // Lives entirely on the FILE thread. | 21 // Lives entirely on the FILE thread. |
| 22 class ExtensionSettingsBackend : public SyncableService { | 22 class ExtensionSettingsBackend : public SyncableService { |
| 23 public: | 23 public: |
| 24 // |base_path| is the base of the extension settings directory, so the | 24 // |base_path| is the base of the extension settings directory, so the |
| 25 // databases will be at base_path/extension_id. | 25 // databases will be at base_path/extension_id. |
| 26 // |observers| is the list of observers to settings changes. | 26 // |observers| is the list of observers to settings changes. |
| 27 explicit ExtensionSettingsBackend( | 27 explicit ExtensionSettingsBackend( |
| 28 const FilePath& base_path, | 28 const FilePath& base_path, |
| 29 const scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> >& | 29 const scoped_refptr<ExtensionSettingsObserverList>& observers); |
| 30 observers); | |
| 31 | 30 |
| 32 virtual ~ExtensionSettingsBackend(); | 31 virtual ~ExtensionSettingsBackend(); |
| 33 | 32 |
| 34 // Gets a weak reference to the storage area for a given extension. | 33 // Gets a weak reference to the storage area for a given extension. |
| 35 // Must be run on the FILE thread. | 34 // Must be run on the FILE thread. |
| 36 // | 35 // |
| 37 // By default this will be an ExtensionSettingsLeveldbStorage, but on | 36 // By default this will be an ExtensionSettingsLeveldbStorage, but on |
| 38 // failure to create a leveldb instance will fall back to | 37 // failure to create a leveldb instance will fall back to |
| 39 // InMemoryExtensionSettingsStorage. | 38 // InMemoryExtensionSettingsStorage. |
| 40 ExtensionSettingsStorage* GetStorage( | 39 ExtensionSettingsStorage* GetStorage( |
| 41 const std::string& extension_id) const; | 40 const std::string& extension_id) const; |
| 42 | 41 |
| 43 // Deletes all setting data for an extension. Call on the FILE thread. | 42 // Deletes all setting data for an extension. Call on the FILE thread. |
| 44 void DeleteExtensionData(const std::string& extension_id); | 43 void DeleteStorage(const std::string& extension_id); |
| 45 | 44 |
| 46 // Sends a change event to the observer list. |profile| is the profile which | 45 // Sends a change event to the observer list. |profile| is the profile which |
| 47 // generated the change. Must be called on the FILE thread. | 46 // generated the change. Must be called on the FILE thread. |
| 48 void TriggerOnSettingsChanged( | 47 void TriggerOnSettingsChanged( |
| 49 Profile* profile, | 48 Profile* profile, |
| 50 const std::string& extension_id, | 49 const std::string& extension_id, |
| 51 const ExtensionSettingChanges& changes) const; | 50 const ExtensionSettingChanges& changes) const; |
| 52 | 51 |
| 53 // SyncableService implementation. | 52 // SyncableService implementation. |
| 54 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | 53 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 const std::string& extension_id, const DictionaryValue& sync_data) const; | 70 const std::string& extension_id, const DictionaryValue& sync_data) const; |
| 72 | 71 |
| 73 // Gets all extension IDs known to extension settings. This may not be all | 72 // Gets all extension IDs known to extension settings. This may not be all |
| 74 // installed extensions. | 73 // installed extensions. |
| 75 std::set<std::string> GetKnownExtensionIDs() const; | 74 std::set<std::string> GetKnownExtensionIDs() const; |
| 76 | 75 |
| 77 // The base file path to create any leveldb databases at. | 76 // The base file path to create any leveldb databases at. |
| 78 const FilePath base_path_; | 77 const FilePath base_path_; |
| 79 | 78 |
| 80 // The list of observers to settings changes. | 79 // The list of observers to settings changes. |
| 81 const scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > | 80 const scoped_refptr<ExtensionSettingsObserverList> observers_; |
| 82 observers_; | |
| 83 | 81 |
| 84 // A cache of ExtensionSettingsStorage objects that have already been created. | 82 // A cache of ExtensionSettingsStorage objects that have already been created. |
| 85 // Ensure that there is only ever one created per extension. | 83 // Ensure that there is only ever one created per extension. |
| 86 typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> > | 84 typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> > |
| 87 StorageObjMap; | 85 StorageObjMap; |
| 88 mutable StorageObjMap storage_objs_; | 86 mutable StorageObjMap storage_objs_; |
| 89 | 87 |
| 88 // Current sync model type. Will be UNSPECIFIED if sync hasn't been enabled |
| 89 // yet, and either EXTENSION_SETTINGS or APP_SETTINGS if it has been. |
| 90 syncable::ModelType sync_type_; |
| 91 |
| 90 // Current sync processor, if any. | 92 // Current sync processor, if any. |
| 91 SyncChangeProcessor* sync_processor_; | 93 SyncChangeProcessor* sync_processor_; |
| 92 | 94 |
| 93 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsBackend); | 95 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsBackend); |
| 94 }; | 96 }; |
| 95 | 97 |
| 96 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ | 98 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ |
| OLD | NEW |