| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_BACKEND_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_BACKEND_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 #include <string> | |
| 11 | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/file_path.h" | |
| 14 #include "base/memory/linked_ptr.h" | |
| 15 #include "base/memory/ref_counted.h" | |
| 16 #include "base/memory/scoped_ptr.h" | |
| 17 #include "chrome/browser/extensions/settings/settings_observer.h" | |
| 18 #include "chrome/browser/extensions/settings/settings_storage_factory.h" | |
| 19 #include "chrome/browser/extensions/settings/settings_storage_quota_enforcer.h" | |
| 20 #include "sync/api/syncable_service.h" | |
| 21 | |
| 22 namespace syncer { | |
| 23 class SyncErrorFactory; | |
| 24 } | |
| 25 | |
| 26 namespace extensions { | |
| 27 | |
| 28 class SettingsSyncProcessor; | |
| 29 class SyncableSettingsStorage; | |
| 30 | |
| 31 // Manages ValueStore objects for extensions, including routing | |
| 32 // changes from sync to them. | |
| 33 // Lives entirely on the FILE thread. | |
| 34 class SettingsBackend : public syncer::SyncableService { | |
| 35 public: | |
| 36 // |storage_factory| is use to create leveldb storage areas. | |
| 37 // |base_path| is the base of the extension settings directory, so the | |
| 38 // databases will be at base_path/extension_id. | |
| 39 // |observers| is the list of observers to settings changes. | |
| 40 SettingsBackend( | |
| 41 const scoped_refptr<SettingsStorageFactory>& storage_factory, | |
| 42 const FilePath& base_path, | |
| 43 const SettingsStorageQuotaEnforcer::Limits& quota, | |
| 44 const scoped_refptr<SettingsObserverList>& observers); | |
| 45 | |
| 46 virtual ~SettingsBackend(); | |
| 47 | |
| 48 // Gets a weak reference to the storage area for |extension_id|. | |
| 49 // Must be run on the FILE thread. | |
| 50 ValueStore* GetStorage(const std::string& extension_id) const; | |
| 51 | |
| 52 // Deletes all setting data for an extension. Call on the FILE thread. | |
| 53 void DeleteStorage(const std::string& extension_id); | |
| 54 | |
| 55 // syncer::SyncableService implementation. | |
| 56 virtual syncer::SyncDataList GetAllSyncData( | |
| 57 syncer::ModelType type) const OVERRIDE; | |
| 58 virtual syncer::SyncMergeResult MergeDataAndStartSyncing( | |
| 59 syncer::ModelType type, | |
| 60 const syncer::SyncDataList& initial_sync_data, | |
| 61 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, | |
| 62 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) OVERRIDE; | |
| 63 virtual syncer::SyncError ProcessSyncChanges( | |
| 64 const tracked_objects::Location& from_here, | |
| 65 const syncer::SyncChangeList& change_list) OVERRIDE; | |
| 66 virtual void StopSyncing(syncer::ModelType type) OVERRIDE; | |
| 67 | |
| 68 private: | |
| 69 // Gets a weak reference to the storage area for a given extension, | |
| 70 // initializing sync with some initial data if sync enabled. | |
| 71 SyncableSettingsStorage* GetOrCreateStorageWithSyncData( | |
| 72 const std::string& extension_id, | |
| 73 const DictionaryValue& sync_data) const; | |
| 74 | |
| 75 // Gets all extension IDs known to extension settings. This may not be all | |
| 76 // installed extensions. | |
| 77 std::set<std::string> GetKnownExtensionIDs() const; | |
| 78 | |
| 79 // Creates a new SettingsSyncProcessor for an extension. | |
| 80 scoped_ptr<SettingsSyncProcessor> CreateSettingsSyncProcessor( | |
| 81 const std::string& extension_id) const; | |
| 82 | |
| 83 // The Factory to use for creating leveldb storage areas. | |
| 84 const scoped_refptr<SettingsStorageFactory> storage_factory_; | |
| 85 | |
| 86 // The base file path to create any leveldb databases at. | |
| 87 const FilePath base_path_; | |
| 88 | |
| 89 // Quota limits (see SettingsStorageQuotaEnforcer). | |
| 90 const SettingsStorageQuotaEnforcer::Limits quota_; | |
| 91 | |
| 92 // The list of observers to settings changes. | |
| 93 const scoped_refptr<SettingsObserverList> observers_; | |
| 94 | |
| 95 // A cache of ValueStore objects that have already been created. | |
| 96 // Ensure that there is only ever one created per extension. | |
| 97 typedef std::map<std::string, linked_ptr<SyncableSettingsStorage> > | |
| 98 StorageObjMap; | |
| 99 mutable StorageObjMap storage_objs_; | |
| 100 | |
| 101 // Current sync model type. Will be UNSPECIFIED if sync hasn't been enabled | |
| 102 // yet, and either SETTINGS or APP_SETTINGS if it has been. | |
| 103 syncer::ModelType sync_type_; | |
| 104 | |
| 105 // Current sync processor, if any. | |
| 106 scoped_ptr<syncer::SyncChangeProcessor> sync_processor_; | |
| 107 | |
| 108 // Current sync error handler if any. | |
| 109 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory_; | |
| 110 | |
| 111 DISALLOW_COPY_AND_ASSIGN(SettingsBackend); | |
| 112 }; | |
| 113 | |
| 114 } // namespace extensions | |
| 115 | |
| 116 #endif // CHROME_BROWSER_EXTENSIONS_SETTINGS_SETTINGS_BACKEND_H_ | |
| OLD | NEW |