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