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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 syncer::SyncError SyncableSettingsStorage::OverwriteLocalSettingsWithSync( | 175 syncer::SyncError SyncableSettingsStorage::OverwriteLocalSettingsWithSync( |
176 const base::DictionaryValue& sync_state, | 176 const base::DictionaryValue& sync_state, |
177 const base::DictionaryValue& settings) { | 177 const base::DictionaryValue& settings) { |
178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
179 // Treat this as a list of changes to sync and use ProcessSyncChanges. | 179 // Treat this as a list of changes to sync and use ProcessSyncChanges. |
180 // This gives notifications etc for free. | 180 // This gives notifications etc for free. |
181 scoped_ptr<base::DictionaryValue> new_sync_state(sync_state.DeepCopy()); | 181 scoped_ptr<base::DictionaryValue> new_sync_state(sync_state.DeepCopy()); |
182 | 182 |
183 SettingSyncDataList changes; | 183 SettingSyncDataList changes; |
184 for (base::DictionaryValue::Iterator it(settings); !it.IsAtEnd(); it.Advance()
) { | 184 for (base::DictionaryValue::Iterator it(settings); !it.IsAtEnd(); it.Advance()
) { |
185 Value* orphaned_sync_value = NULL; | 185 scoped_ptr<Value> sync_value; |
186 if (new_sync_state->RemoveWithoutPathExpansion( | 186 if (new_sync_state->RemoveWithoutPathExpansion(it.key(), &sync_value)) { |
187 it.key(), &orphaned_sync_value)) { | |
188 scoped_ptr<Value> sync_value(orphaned_sync_value); | |
189 if (sync_value->Equals(&it.value())) { | 187 if (sync_value->Equals(&it.value())) { |
190 // Sync and local values are the same, no changes to send. | 188 // Sync and local values are the same, no changes to send. |
191 } else { | 189 } else { |
192 // Sync value is different, update local setting with new value. | 190 // Sync value is different, update local setting with new value. |
193 changes.push_back( | 191 changes.push_back( |
194 SettingSyncData( | 192 SettingSyncData( |
195 syncer::SyncChange::ACTION_UPDATE, | 193 syncer::SyncChange::ACTION_UPDATE, |
196 extension_id_, | 194 extension_id_, |
197 it.key(), | 195 it.key(), |
198 sync_value.Pass())); | 196 sync_value.Pass())); |
199 } | 197 } |
200 } else { | 198 } else { |
201 // Not synced, delete local setting. | 199 // Not synced, delete local setting. |
202 changes.push_back( | 200 changes.push_back( |
203 SettingSyncData( | 201 SettingSyncData( |
204 syncer::SyncChange::ACTION_DELETE, | 202 syncer::SyncChange::ACTION_DELETE, |
205 extension_id_, | 203 extension_id_, |
206 it.key(), | 204 it.key(), |
207 scoped_ptr<Value>(new base::DictionaryValue()))); | 205 scoped_ptr<Value>(new base::DictionaryValue()))); |
208 } | 206 } |
209 } | 207 } |
210 | 208 |
211 // Add all new settings to local settings. | 209 // Add all new settings to local settings. |
212 while (!new_sync_state->empty()) { | 210 while (!new_sync_state->empty()) { |
213 base::DictionaryValue::Iterator first_entry(*new_sync_state); | 211 base::DictionaryValue::Iterator first_entry(*new_sync_state); |
214 std::string key = first_entry.key(); | 212 std::string key = first_entry.key(); |
215 Value* value = NULL; | 213 scoped_ptr<Value> value; |
216 CHECK(new_sync_state->RemoveWithoutPathExpansion(key, &value)); | 214 CHECK(new_sync_state->RemoveWithoutPathExpansion(key, &value)); |
217 changes.push_back( | 215 changes.push_back( |
218 SettingSyncData( | 216 SettingSyncData( |
219 syncer::SyncChange::ACTION_ADD, | 217 syncer::SyncChange::ACTION_ADD, |
220 extension_id_, | 218 extension_id_, |
221 key, | 219 key, |
222 make_scoped_ptr(value))); | 220 value.Pass())); |
223 } | 221 } |
224 | 222 |
225 if (changes.empty()) | 223 if (changes.empty()) |
226 return syncer::SyncError(); | 224 return syncer::SyncError(); |
227 | 225 |
228 return ProcessSyncChanges(changes); | 226 return ProcessSyncChanges(changes); |
229 } | 227 } |
230 | 228 |
231 void SyncableSettingsStorage::StopSyncing() { | 229 void SyncableSettingsStorage::StopSyncing() { |
232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 230 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 syncer::SyncError::DATATYPE_ERROR, | 381 syncer::SyncError::DATATYPE_ERROR, |
384 std::string("Error pushing sync remove to local settings: ") + | 382 std::string("Error pushing sync remove to local settings: ") + |
385 result->error(), | 383 result->error(), |
386 sync_processor_->type()); | 384 sync_processor_->type()); |
387 } | 385 } |
388 changes->push_back(ValueStoreChange(key, old_value, NULL)); | 386 changes->push_back(ValueStoreChange(key, old_value, NULL)); |
389 return syncer::SyncError(); | 387 return syncer::SyncError(); |
390 } | 388 } |
391 | 389 |
392 } // namespace extensions | 390 } // namespace extensions |
OLD | NEW |