| 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 >& |
| 30 observers); | 30 observers); |
| 31 | 31 |
| 32 virtual ~ExtensionSettingsBackend(); | 32 virtual ~ExtensionSettingsBackend(); |
| 33 | 33 |
| 34 // 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. |
| 35 // Must be run on the FILE thread. | 35 // Must be run on the FILE thread. |
| 36 // | 36 // |
| 37 // By default this will be an ExtensionSettingsLeveldbStorage, but on | 37 // By default this will be an ExtensionSettingsLeveldbStorage, but on |
| 38 // failure to create a leveldb instance will fall back to | 38 // failure to create a leveldb instance will fall back to |
| 39 // InMemoryExtensionSettingsStorage. | 39 // InMemoryExtensionSettingsStorage. |
| 40 ExtensionSettingsStorage* GetStorage( | 40 ExtensionSettingsStorage* GetStorage( |
| 41 const std::string& extension_id) const; | 41 const std::string& extension_id) const; |
| 42 | 42 |
| 43 // 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. |
| 44 void DeleteExtensionData(const std::string& extension_id); | 44 void DeleteStorage(const std::string& extension_id); |
| 45 | 45 |
| 46 // Sends a change event to the observer list. |profile| is the profile which | 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. | 47 // generated the change. Must be called on the FILE thread. |
| 48 void TriggerOnSettingsChanged( | 48 void TriggerOnSettingsChanged( |
| 49 Profile* profile, | 49 Profile* profile, |
| 50 const std::string& extension_id, | 50 const std::string& extension_id, |
| 51 const ExtensionSettingChanges& changes) const; | 51 const ExtensionSettingChanges& changes) const; |
| 52 | 52 |
| 53 // SyncableService implementation. | 53 // SyncableService implementation. |
| 54 virtual SyncDataList GetAllSyncData(syncable::ModelType type) const OVERRIDE; | 54 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; | 71 const std::string& extension_id, const DictionaryValue& sync_data) const; |
| 72 | 72 |
| 73 // 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 |
| 74 // installed extensions. | 74 // installed extensions. |
| 75 std::set<std::string> GetKnownExtensionIDs() const; | 75 std::set<std::string> GetKnownExtensionIDs() const; |
| 76 | 76 |
| 77 // The base file path to create any leveldb databases at. | 77 // The base file path to create any leveldb databases at. |
| 78 const FilePath base_path_; | 78 const FilePath base_path_; |
| 79 | 79 |
| 80 // The list of observers to settings changes. | 80 // The list of observers to settings changes. |
| 81 const scoped_refptr<ObserverListThreadSafe<ExtensionSettingsObserver> > | 81 const scoped_refptr<ExtensionSettingsObserverList> observers_; |
| 82 observers_; | |
| 83 | 82 |
| 84 // A cache of ExtensionSettingsStorage objects that have already been created. | 83 // A cache of ExtensionSettingsStorage objects that have already been created. |
| 85 // Ensure that there is only ever one created per extension. | 84 // Ensure that there is only ever one created per extension. |
| 86 typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> > | 85 typedef std::map<std::string, linked_ptr<SyncableExtensionSettingsStorage> > |
| 87 StorageObjMap; | 86 StorageObjMap; |
| 88 mutable StorageObjMap storage_objs_; | 87 mutable StorageObjMap storage_objs_; |
| 89 | 88 |
| 89 // Current sync model type. Will be UNSPECIFIED if sync hasn't been enabled |
| 90 // yet, and either EXTENSION_SETTINGS or APP_SETTINGS if it has been. |
| 91 syncable::ModelType sync_type_; |
| 92 |
| 90 // Current sync processor, if any. | 93 // Current sync processor, if any. |
| 91 SyncChangeProcessor* sync_processor_; | 94 SyncChangeProcessor* sync_processor_; |
| 92 | 95 |
| 93 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsBackend); | 96 DISALLOW_COPY_AND_ASSIGN(ExtensionSettingsBackend); |
| 94 }; | 97 }; |
| 95 | 98 |
| 96 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ | 99 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SETTINGS_BACKEND_H_ |
| OLD | NEW |