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

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: with util fix 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,
22 const SettingsStorageQuotaEnforcer::Limits& quota, 23 const SettingsStorageQuotaEnforcer::Limits& quota,
23 const scoped_refptr<SettingsObserverList>& observers) 24 const scoped_refptr<SettingsObserverList>& observers)
24 : storage_factory_(storage_factory), 25 : storage_factory_(storage_factory),
25 base_path_(base_path), 26 base_path_(base_path),
26 quota_(quota), 27 quota_(quota),
27 observers_(observers), 28 observers_(observers),
28 sync_type_(syncer::UNSPECIFIED) { 29 sync_type_(sync_type) {
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
31 DCHECK(sync_type_ == syncer::EXTENSION_SETTINGS ||
32 sync_type_ == syncer::APP_SETTINGS);
30 } 33 }
31 34
32 SettingsBackend::~SettingsBackend() { 35 SettingsBackend::~SettingsBackend() {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
34 } 37 }
35 38
36 ValueStore* SettingsBackend::GetStorage( 39 ValueStore* SettingsBackend::GetStorage(
37 const std::string& extension_id) const { 40 const std::string& extension_id) const {
38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
39 DictionaryValue empty; 42 DictionaryValue empty;
(...skipping 23 matching lines...) Expand all
63 storage)); 66 storage));
64 storage_objs_[extension_id] = syncable_storage; 67 storage_objs_[extension_id] = syncable_storage;
65 68
66 if (sync_processor_.get()) { 69 if (sync_processor_.get()) {
67 syncer::SyncError error = 70 syncer::SyncError error =
68 syncable_storage->StartSyncing( 71 syncable_storage->StartSyncing(
69 sync_data, 72 sync_data,
70 CreateSettingsSyncProcessor(extension_id).Pass()); 73 CreateSettingsSyncProcessor(extension_id).Pass());
71 if (error.IsSet()) 74 if (error.IsSet())
72 syncable_storage.get()->StopSyncing(); 75 syncable_storage.get()->StopSyncing();
76 } else {
77 flare_.Run(sync_type_);
not at google - send to devlin 2013/05/20 18:00:04 what does this actually do? will it call MergeData
tim (not reviewing) 2013/05/20 18:21:15 Done.
73 } 78 }
74 79
75 return syncable_storage.get(); 80 return syncable_storage.get();
76 } 81 }
77 82
78 void SettingsBackend::DeleteStorage(const std::string& extension_id) { 83 void SettingsBackend::DeleteStorage(const std::string& extension_id) {
79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
80 85
81 // Clear settings when the extension is uninstalled. Leveldb implementations 86 // Clear settings when the extension is uninstalled. Leveldb implementations
82 // will also delete the database from disk when the object is destroyed as a 87 // will also delete the database from disk when the object is destroyed as a
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 maybe_settings->error(); 160 maybe_settings->error();
156 continue; 161 continue;
157 } 162 }
158 AddAllSyncData(*it, *maybe_settings->settings().get(), 163 AddAllSyncData(*it, *maybe_settings->settings().get(),
159 type, &all_sync_data); 164 type, &all_sync_data);
160 } 165 }
161 166
162 return all_sync_data; 167 return all_sync_data;
163 } 168 }
164 169
170 void SettingsBackend::InjectStartSyncFlare(
171 const syncer::SyncableService::StartSyncFlare& flare) {
172 flare_ = flare;
173 }
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