Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Side by Side Diff: chrome/browser/extensions/api/storage/settings_backend.cc

Issue 15404005: sync: deferred initialization support for app/extension settings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 #include "chrome/browser/extensions/api/storage/settings_backend.h" 5 #include "chrome/browser/extensions/api/storage/settings_backend.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "chrome/browser/extensions/api/storage/settings_sync_processor.h" 9 #include "chrome/browser/extensions/api/storage/settings_sync_processor.h"
10 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" 10 #include "chrome/browser/extensions/api/storage/settings_sync_util.h"
11 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" 11 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h"
12 #include "content/public/browser/browser_thread.h" 12 #include "content/public/browser/browser_thread.h"
13 #include "sync/api/sync_error_factory.h" 13 #include "sync/api/sync_error_factory.h"
14 14
15 using content::BrowserThread; 15 using content::BrowserThread;
16 16
17 namespace extensions { 17 namespace extensions {
18 18
19 SettingsBackend::SettingsBackend( 19 SettingsBackend::SettingsBackend(
20 const scoped_refptr<SettingsStorageFactory>& storage_factory, 20 const scoped_refptr<SettingsStorageFactory>& storage_factory,
21 const base::FilePath& base_path, 21 const base::FilePath& base_path,
22 syncer::ModelType sync_type,
23 const syncer::SyncableService::StartSyncFlare& flare,
22 const SettingsStorageQuotaEnforcer::Limits& quota, 24 const SettingsStorageQuotaEnforcer::Limits& quota,
23 const scoped_refptr<SettingsObserverList>& observers) 25 const scoped_refptr<SettingsObserverList>& observers)
24 : storage_factory_(storage_factory), 26 : storage_factory_(storage_factory),
25 base_path_(base_path), 27 base_path_(base_path),
26 quota_(quota), 28 quota_(quota),
27 observers_(observers), 29 observers_(observers),
28 sync_type_(syncer::UNSPECIFIED) { 30 sync_type_(sync_type),
31 flare_(flare) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
33 DCHECK(sync_type_ == syncer::EXTENSION_SETTINGS ||
34 sync_type_ == syncer::APP_SETTINGS);
30 } 35 }
31 36
32 SettingsBackend::~SettingsBackend() { 37 SettingsBackend::~SettingsBackend() {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
34 } 39 }
35 40
36 ValueStore* SettingsBackend::GetStorage( 41 ValueStore* SettingsBackend::GetStorage(
37 const std::string& extension_id) const { 42 const std::string& extension_id) const {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 43 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
39 DictionaryValue empty; 44 DictionaryValue empty;
(...skipping 23 matching lines...) Expand all
63 storage)); 68 storage));
64 storage_objs_[extension_id] = syncable_storage; 69 storage_objs_[extension_id] = syncable_storage;
65 70
66 if (sync_processor_.get()) { 71 if (sync_processor_.get()) {
67 syncer::SyncError error = 72 syncer::SyncError error =
68 syncable_storage->StartSyncing( 73 syncable_storage->StartSyncing(
69 sync_data, 74 sync_data,
70 CreateSettingsSyncProcessor(extension_id).Pass()); 75 CreateSettingsSyncProcessor(extension_id).Pass());
71 if (error.IsSet()) 76 if (error.IsSet())
72 syncable_storage.get()->StopSyncing(); 77 syncable_storage.get()->StopSyncing();
78 } else {
79 // Tell sync to try and start soon, because syncable changes to sync_type_
80 // have started happening. This will cause sync to call us back
81 // asynchronously via MergeDataAndStartSyncing as soon as possible.
82 flare_.Run(sync_type_);
73 } 83 }
74 84
75 return syncable_storage.get(); 85 return syncable_storage.get();
76 } 86 }
77 87
78 void SettingsBackend::DeleteStorage(const std::string& extension_id) { 88 void SettingsBackend::DeleteStorage(const std::string& extension_id) {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 89 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
80 90
81 // Clear settings when the extension is uninstalled. Leveldb implementations 91 // Clear settings when the extension is uninstalled. Leveldb implementations
82 // will also delete the database from disk when the object is destroyed as a 92 // will also delete the database from disk when the object is destroyed as a
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 171
162 return all_sync_data; 172 return all_sync_data;
163 } 173 }
164 174
165 syncer::SyncMergeResult SettingsBackend::MergeDataAndStartSyncing( 175 syncer::SyncMergeResult SettingsBackend::MergeDataAndStartSyncing(
166 syncer::ModelType type, 176 syncer::ModelType type,
167 const syncer::SyncDataList& initial_sync_data, 177 const syncer::SyncDataList& initial_sync_data,
168 scoped_ptr<syncer::SyncChangeProcessor> sync_processor, 178 scoped_ptr<syncer::SyncChangeProcessor> sync_processor,
169 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) { 179 scoped_ptr<syncer::SyncErrorFactory> sync_error_factory) {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
171 DCHECK(type == syncer::EXTENSION_SETTINGS || 181 DCHECK_EQ(sync_type_, type);
172 type == syncer::APP_SETTINGS);
173 DCHECK_EQ(sync_type_, syncer::UNSPECIFIED);
174 DCHECK(!sync_processor_.get()); 182 DCHECK(!sync_processor_.get());
175 DCHECK(sync_processor.get()); 183 DCHECK(sync_processor.get());
176 DCHECK(sync_error_factory.get()); 184 DCHECK(sync_error_factory.get());
177 185
178 sync_type_ = type;
179 sync_processor_ = sync_processor.Pass(); 186 sync_processor_ = sync_processor.Pass();
180 sync_error_factory_ = sync_error_factory.Pass(); 187 sync_error_factory_ = sync_error_factory.Pass();
181 188
182 // Group the initial sync data by extension id. 189 // Group the initial sync data by extension id.
183 std::map<std::string, linked_ptr<DictionaryValue> > grouped_sync_data; 190 std::map<std::string, linked_ptr<DictionaryValue> > grouped_sync_data;
184 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin(); 191 for (syncer::SyncDataList::const_iterator it = initial_sync_data.begin();
185 it != initial_sync_data.end(); ++it) { 192 it != initial_sync_data.end(); ++it) {
186 SettingSyncData data(*it); 193 SettingSyncData data(*it);
187 linked_ptr<DictionaryValue> sync_data = 194 linked_ptr<DictionaryValue> sync_data =
188 grouped_sync_data[data.extension_id()]; 195 grouped_sync_data[data.extension_id()];
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 storage->StopSyncing(); 260 storage->StopSyncing();
254 } 261 }
255 262
256 return syncer::SyncError(); 263 return syncer::SyncError();
257 } 264 }
258 265
259 void SettingsBackend::StopSyncing(syncer::ModelType type) { 266 void SettingsBackend::StopSyncing(syncer::ModelType type) {
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 267 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
261 DCHECK(type == syncer::EXTENSION_SETTINGS || 268 DCHECK(type == syncer::EXTENSION_SETTINGS ||
262 type == syncer::APP_SETTINGS); 269 type == syncer::APP_SETTINGS);
263 DCHECK(sync_type_ == type || sync_type_ == syncer::UNSPECIFIED); 270 DCHECK_EQ(sync_type_, type);
264 271
265 for (StorageObjMap::iterator it = storage_objs_.begin(); 272 for (StorageObjMap::iterator it = storage_objs_.begin();
266 it != storage_objs_.end(); ++it) { 273 it != storage_objs_.end(); ++it) {
267 // Some storage areas may have already stopped syncing if they had areas 274 // Some storage areas may have already stopped syncing if they had areas
268 // and syncing was disabled, but StopSyncing is safe to call multiple times. 275 // and syncing was disabled, but StopSyncing is safe to call multiple times.
269 it->second->StopSyncing(); 276 it->second->StopSyncing();
270 } 277 }
271 278
272 sync_type_ = syncer::UNSPECIFIED;
273 sync_processor_.reset(); 279 sync_processor_.reset();
274 sync_error_factory_.reset(); 280 sync_error_factory_.reset();
275 } 281 }
276 282
277 scoped_ptr<SettingsSyncProcessor> SettingsBackend::CreateSettingsSyncProcessor( 283 scoped_ptr<SettingsSyncProcessor> SettingsBackend::CreateSettingsSyncProcessor(
278 const std::string& extension_id) const { 284 const std::string& extension_id) const {
279 CHECK(sync_processor_.get()); 285 CHECK(sync_processor_.get());
280 return scoped_ptr<SettingsSyncProcessor>( 286 return scoped_ptr<SettingsSyncProcessor>(
281 new SettingsSyncProcessor(extension_id, 287 new SettingsSyncProcessor(extension_id,
282 sync_type_, 288 sync_type_,
283 sync_processor_.get())); 289 sync_processor_.get()));
284 } 290 }
285 291
286 } // namespace extensions 292 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698