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 | |
147 void SyncableSettingsStorage::SyncResultIfEnabled( | 125 void SyncableSettingsStorage::SyncResultIfEnabled( |
148 const ValueStore::WriteResult& result) { | 126 const ValueStore::WriteResult& result) { |
149 if (result->changes().empty()) | 127 if (result->changes().empty()) |
150 return; | 128 return; |
151 | 129 |
152 if (sync_processor_.get()) { | 130 if (sync_processor_.get()) { |
153 syncer::SyncError error = sync_processor_->SendChanges(result->changes()); | 131 syncer::SyncError error = sync_processor_->SendChanges(result->changes()); |
154 if (error.IsSet()) | 132 if (error.IsSet()) |
155 StopSyncing(); | 133 StopSyncing(); |
156 } else { | 134 } else { |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 syncer::SyncError::DATATYPE_ERROR, | 394 syncer::SyncError::DATATYPE_ERROR, |
417 base::StringPrintf("Error pushing sync remove to local settings: %s", | 395 base::StringPrintf("Error pushing sync remove to local settings: %s", |
418 result->error().message.c_str()), | 396 result->error().message.c_str()), |
419 sync_processor_->type()); | 397 sync_processor_->type()); |
420 } | 398 } |
421 changes->push_back(ValueStoreChange(key, old_value, NULL)); | 399 changes->push_back(ValueStoreChange(key, old_value, NULL)); |
422 return syncer::SyncError(); | 400 return syncer::SyncError(); |
423 } | 401 } |
424 | 402 |
425 } // namespace extensions | 403 } // namespace extensions |
OLD | NEW |