| 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 "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/extensions/api/storage/settings_namespace.h" | 8 #include "chrome/browser/extensions/api/storage/settings_namespace.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" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 ValueStore::WriteResult SyncableSettingsStorage::Clear() { | 115 ValueStore::WriteResult SyncableSettingsStorage::Clear() { |
| 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 116 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 117 WriteResult result = delegate_->Clear(); | 117 WriteResult result = delegate_->Clear(); |
| 118 if (result->HasError()) { | 118 if (result->HasError()) { |
| 119 return result.Pass(); | 119 return result.Pass(); |
| 120 } | 120 } |
| 121 SyncResultIfEnabled(result); | 121 SyncResultIfEnabled(result); |
| 122 return result.Pass(); | 122 return result.Pass(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool SyncableSettingsStorage::Restore() { |
| 126 // If we're syncing, stop - we don't want to push the deletion of any data. |
| 127 // At next startup, when we start up the sync service, we'll get back any |
| 128 // data which was stored intact on Sync. |
| 129 // TODO (rdevlin.cronin): Investigate if there's a way we can trigger |
| 130 // MergeDataAndStartSyncing() to immediately get back any data we can, |
| 131 // and continue syncing. |
| 132 StopSyncing(); |
| 133 return delegate_->Restore(); |
| 134 } |
| 135 |
| 136 bool SyncableSettingsStorage::RestoreKey(const std::string& key) { |
| 137 // If we're syncing, stop - we don't want to push the deletion of any data. |
| 138 // At next startup, when we start up the sync service, we'll get back any |
| 139 // data which was stored intact on Sync. |
| 140 // TODO (rdevlin.cronin): Investigate if there's a way we can trigger |
| 141 // MergeDataAndStartSyncing() to immediately get back any data we can, |
| 142 // and continue syncing. |
| 143 StopSyncing(); |
| 144 return delegate_->RestoreKey(key); |
| 145 } |
| 146 |
| 125 void SyncableSettingsStorage::SyncResultIfEnabled( | 147 void SyncableSettingsStorage::SyncResultIfEnabled( |
| 126 const ValueStore::WriteResult& result) { | 148 const ValueStore::WriteResult& result) { |
| 127 if (result->changes().empty()) | 149 if (result->changes().empty()) |
| 128 return; | 150 return; |
| 129 | 151 |
| 130 if (sync_processor_.get()) { | 152 if (sync_processor_.get()) { |
| 131 syncer::SyncError error = sync_processor_->SendChanges(result->changes()); | 153 syncer::SyncError error = sync_processor_->SendChanges(result->changes()); |
| 132 if (error.IsSet()) | 154 if (error.IsSet()) |
| 133 StopSyncing(); | 155 StopSyncing(); |
| 134 } else { | 156 } else { |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 syncer::SyncError::DATATYPE_ERROR, | 416 syncer::SyncError::DATATYPE_ERROR, |
| 395 base::StringPrintf("Error pushing sync remove to local settings: %s", | 417 base::StringPrintf("Error pushing sync remove to local settings: %s", |
| 396 result->error().message.c_str()), | 418 result->error().message.c_str()), |
| 397 sync_processor_->type()); | 419 sync_processor_->type()); |
| 398 } | 420 } |
| 399 changes->push_back(ValueStoreChange(key, old_value, NULL)); | 421 changes->push_back(ValueStoreChange(key, old_value, NULL)); |
| 400 return syncer::SyncError(); | 422 return syncer::SyncError(); |
| 401 } | 423 } |
| 402 | 424 |
| 403 } // namespace extensions | 425 } // namespace extensions |
| OLD | NEW |