| OLD | NEW |
| 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/syncable_settings_storage.h" | 5 #include "chrome/browser/extensions/api/storage/syncable_settings_storage.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/api/storage/settings_namespace.h" | 7 #include "chrome/browser/extensions/api/storage/settings_namespace.h" |
| 8 #include "chrome/browser/extensions/api/storage/settings_sync_processor.h" | 8 #include "chrome/browser/extensions/api/storage/settings_sync_processor.h" |
| 9 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" | 9 #include "chrome/browser/extensions/api/storage/settings_sync_util.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 134 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 135 DCHECK(!sync_processor_.get()); | 135 DCHECK(!sync_processor_.get()); |
| 136 | 136 |
| 137 sync_processor_ = sync_processor.Pass(); | 137 sync_processor_ = sync_processor.Pass(); |
| 138 sync_processor_->Init(sync_state); | 138 sync_processor_->Init(sync_state); |
| 139 | 139 |
| 140 ReadResult maybe_settings = delegate_->Get(); | 140 ReadResult maybe_settings = delegate_->Get(); |
| 141 if (maybe_settings->HasError()) { | 141 if (maybe_settings->HasError()) { |
| 142 return syncer::SyncError( | 142 return syncer::SyncError( |
| 143 FROM_HERE, | 143 FROM_HERE, |
| 144 syncer::SyncError::DATATYPE_ERROR, |
| 144 std::string("Failed to get settings: ") + maybe_settings->error(), | 145 std::string("Failed to get settings: ") + maybe_settings->error(), |
| 145 sync_processor_->type()); | 146 sync_processor_->type()); |
| 146 } | 147 } |
| 147 | 148 |
| 148 const base::DictionaryValue& settings = *maybe_settings->settings().get(); | 149 const base::DictionaryValue& settings = *maybe_settings->settings().get(); |
| 149 if (sync_state.empty()) | 150 if (sync_state.empty()) |
| 150 return SendLocalSettingsToSync(settings); | 151 return SendLocalSettingsToSync(settings); |
| 151 else | 152 else |
| 152 return OverwriteLocalSettingsWithSync(sync_state, settings); | 153 return OverwriteLocalSettingsWithSync(sync_state, settings); |
| 153 } | 154 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 234 } |
| 234 | 235 |
| 235 syncer::SyncError SyncableSettingsStorage::ProcessSyncChanges( | 236 syncer::SyncError SyncableSettingsStorage::ProcessSyncChanges( |
| 236 const SettingSyncDataList& sync_changes) { | 237 const SettingSyncDataList& sync_changes) { |
| 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 238 DCHECK(!sync_changes.empty()) << "No sync changes for " << extension_id_; | 239 DCHECK(!sync_changes.empty()) << "No sync changes for " << extension_id_; |
| 239 | 240 |
| 240 if (!sync_processor_.get()) { | 241 if (!sync_processor_.get()) { |
| 241 return syncer::SyncError( | 242 return syncer::SyncError( |
| 242 FROM_HERE, | 243 FROM_HERE, |
| 244 syncer::SyncError::DATATYPE_ERROR, |
| 243 std::string("Sync is inactive for ") + extension_id_, | 245 std::string("Sync is inactive for ") + extension_id_, |
| 244 syncer::UNSPECIFIED); | 246 syncer::UNSPECIFIED); |
| 245 } | 247 } |
| 246 | 248 |
| 247 std::vector<syncer::SyncError> errors; | 249 std::vector<syncer::SyncError> errors; |
| 248 ValueStoreChangeList changes; | 250 ValueStoreChangeList changes; |
| 249 | 251 |
| 250 for (SettingSyncDataList::const_iterator it = sync_changes.begin(); | 252 for (SettingSyncDataList::const_iterator it = sync_changes.begin(); |
| 251 it != sync_changes.end(); ++it) { | 253 it != sync_changes.end(); ++it) { |
| 252 DCHECK_EQ(extension_id_, it->extension_id()); | 254 DCHECK_EQ(extension_id_, it->extension_id()); |
| 253 | 255 |
| 254 const std::string& key = it->key(); | 256 const std::string& key = it->key(); |
| 255 const Value& value = it->value(); | 257 const Value& value = it->value(); |
| 256 | 258 |
| 257 scoped_ptr<Value> current_value; | 259 scoped_ptr<Value> current_value; |
| 258 { | 260 { |
| 259 ReadResult maybe_settings = Get(it->key()); | 261 ReadResult maybe_settings = Get(it->key()); |
| 260 if (maybe_settings->HasError()) { | 262 if (maybe_settings->HasError()) { |
| 261 errors.push_back(syncer::SyncError( | 263 errors.push_back(syncer::SyncError( |
| 262 FROM_HERE, | 264 FROM_HERE, |
| 265 syncer::SyncError::DATATYPE_ERROR, |
| 263 std::string("Error getting current sync state for ") + | 266 std::string("Error getting current sync state for ") + |
| 264 extension_id_ + "/" + key + ": " + maybe_settings->error(), | 267 extension_id_ + "/" + key + ": " + maybe_settings->error(), |
| 265 sync_processor_->type())); | 268 sync_processor_->type())); |
| 266 continue; | 269 continue; |
| 267 } | 270 } |
| 268 Value* value = NULL; | 271 Value* value = NULL; |
| 269 if (maybe_settings->settings()->GetWithoutPathExpansion(key, &value)) { | 272 if (maybe_settings->settings()->GetWithoutPathExpansion(key, &value)) { |
| 270 current_value.reset(value->DeepCopy()); | 273 current_value.reset(value->DeepCopy()); |
| 271 } | 274 } |
| 272 } | 275 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 | 335 |
| 333 syncer::SyncError SyncableSettingsStorage::OnSyncAdd( | 336 syncer::SyncError SyncableSettingsStorage::OnSyncAdd( |
| 334 const std::string& key, | 337 const std::string& key, |
| 335 Value* new_value, | 338 Value* new_value, |
| 336 ValueStoreChangeList* changes) { | 339 ValueStoreChangeList* changes) { |
| 337 DCHECK(new_value); | 340 DCHECK(new_value); |
| 338 WriteResult result = delegate_->Set(IGNORE_QUOTA, key, *new_value); | 341 WriteResult result = delegate_->Set(IGNORE_QUOTA, key, *new_value); |
| 339 if (result->HasError()) { | 342 if (result->HasError()) { |
| 340 return syncer::SyncError( | 343 return syncer::SyncError( |
| 341 FROM_HERE, | 344 FROM_HERE, |
| 345 syncer::SyncError::DATATYPE_ERROR, |
| 342 std::string("Error pushing sync add to local settings: ") + | 346 std::string("Error pushing sync add to local settings: ") + |
| 343 result->error(), | 347 result->error(), |
| 344 sync_processor_->type()); | 348 sync_processor_->type()); |
| 345 } | 349 } |
| 346 changes->push_back(ValueStoreChange(key, NULL, new_value)); | 350 changes->push_back(ValueStoreChange(key, NULL, new_value)); |
| 347 return syncer::SyncError(); | 351 return syncer::SyncError(); |
| 348 } | 352 } |
| 349 | 353 |
| 350 syncer::SyncError SyncableSettingsStorage::OnSyncUpdate( | 354 syncer::SyncError SyncableSettingsStorage::OnSyncUpdate( |
| 351 const std::string& key, | 355 const std::string& key, |
| 352 Value* old_value, | 356 Value* old_value, |
| 353 Value* new_value, | 357 Value* new_value, |
| 354 ValueStoreChangeList* changes) { | 358 ValueStoreChangeList* changes) { |
| 355 DCHECK(old_value); | 359 DCHECK(old_value); |
| 356 DCHECK(new_value); | 360 DCHECK(new_value); |
| 357 WriteResult result = delegate_->Set(IGNORE_QUOTA, key, *new_value); | 361 WriteResult result = delegate_->Set(IGNORE_QUOTA, key, *new_value); |
| 358 if (result->HasError()) { | 362 if (result->HasError()) { |
| 359 return syncer::SyncError( | 363 return syncer::SyncError( |
| 360 FROM_HERE, | 364 FROM_HERE, |
| 365 syncer::SyncError::DATATYPE_ERROR, |
| 361 std::string("Error pushing sync update to local settings: ") + | 366 std::string("Error pushing sync update to local settings: ") + |
| 362 result->error(), | 367 result->error(), |
| 363 sync_processor_->type()); | 368 sync_processor_->type()); |
| 364 } | 369 } |
| 365 changes->push_back(ValueStoreChange(key, old_value, new_value)); | 370 changes->push_back(ValueStoreChange(key, old_value, new_value)); |
| 366 return syncer::SyncError(); | 371 return syncer::SyncError(); |
| 367 } | 372 } |
| 368 | 373 |
| 369 syncer::SyncError SyncableSettingsStorage::OnSyncDelete( | 374 syncer::SyncError SyncableSettingsStorage::OnSyncDelete( |
| 370 const std::string& key, | 375 const std::string& key, |
| 371 Value* old_value, | 376 Value* old_value, |
| 372 ValueStoreChangeList* changes) { | 377 ValueStoreChangeList* changes) { |
| 373 DCHECK(old_value); | 378 DCHECK(old_value); |
| 374 WriteResult result = delegate_->Remove(key); | 379 WriteResult result = delegate_->Remove(key); |
| 375 if (result->HasError()) { | 380 if (result->HasError()) { |
| 376 return syncer::SyncError( | 381 return syncer::SyncError( |
| 377 FROM_HERE, | 382 FROM_HERE, |
| 383 syncer::SyncError::DATATYPE_ERROR, |
| 378 std::string("Error pushing sync remove to local settings: ") + | 384 std::string("Error pushing sync remove to local settings: ") + |
| 379 result->error(), | 385 result->error(), |
| 380 sync_processor_->type()); | 386 sync_processor_->type()); |
| 381 } | 387 } |
| 382 changes->push_back(ValueStoreChange(key, old_value, NULL)); | 388 changes->push_back(ValueStoreChange(key, old_value, NULL)); |
| 383 return syncer::SyncError(); | 389 return syncer::SyncError(); |
| 384 } | 390 } |
| 385 | 391 |
| 386 } // namespace extensions | 392 } // namespace extensions |
| OLD | NEW |