Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/syncable_extension_settings_storage.h" | 5 #include "chrome/browser/extensions/syncable_extension_settings_storage.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "chrome/browser/extensions/extension_settings_sync_util.h" | 8 #include "chrome/browser/extensions/extension_settings_sync_util.h" |
| 9 #include "chrome/browser/sync/api/sync_data.h" | 9 #include "chrome/browser/sync/api/sync_data.h" |
| 10 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h" | 10 #include "chrome/browser/sync/protocol/extension_setting_specifics.pb.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 const DictionaryValue& sync_state, const DictionaryValue& settings) { | 170 const DictionaryValue& sync_state, const DictionaryValue& settings) { |
| 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 172 // Treat this as a list of changes to sync and use ProcessSyncChanges. | 172 // Treat this as a list of changes to sync and use ProcessSyncChanges. |
| 173 // This gives notifications etc for free. | 173 // This gives notifications etc for free. |
| 174 scoped_ptr<DictionaryValue> new_sync_state(sync_state.DeepCopy()); | 174 scoped_ptr<DictionaryValue> new_sync_state(sync_state.DeepCopy()); |
| 175 | 175 |
| 176 ExtensionSettingSyncDataList changes; | 176 ExtensionSettingSyncDataList changes; |
| 177 for (DictionaryValue::key_iterator it = settings.begin_keys(); | 177 for (DictionaryValue::key_iterator it = settings.begin_keys(); |
| 178 it != settings.end_keys(); ++it) { | 178 it != settings.end_keys(); ++it) { |
| 179 Value* sync_value = NULL; | 179 Value* sync_value = NULL; |
| 180 if (new_sync_state->RemoveWithoutPathExpansion(*it, &sync_value)) { | 180 if (new_sync_state->RemoveWithoutPathExpansion(*it, &sync_value)) { |
|
akalin
2011/09/22 01:36:52
i'd feel better if a scoped_ptr was involved someh
not at google - send to devlin
2011/09/22 02:31:13
Yeah there are several options, it's just so damn
| |
| 181 Value* local_value = NULL; | 181 Value* local_value = NULL; |
| 182 settings.GetWithoutPathExpansion(*it, &local_value); | 182 settings.GetWithoutPathExpansion(*it, &local_value); |
| 183 if (!local_value->Equals(sync_value)) { | 183 if (!local_value->Equals(sync_value)) { |
| 184 // Sync value is different, update local setting with new value. | 184 // Sync value is different, update local setting with new value. |
| 185 changes.push_back( | 185 changes.push_back( |
| 186 ExtensionSettingSyncData( | 186 ExtensionSettingSyncData( |
| 187 SyncChange::ACTION_UPDATE, extension_id_, *it, sync_value)); | 187 SyncChange::ACTION_UPDATE, extension_id_, *it, sync_value)); |
| 188 } else { | |
| 189 // Values are the same, no change needed. | |
| 190 delete sync_value; | |
| 188 } | 191 } |
| 189 } else { | 192 } else { |
| 190 // Not synced, delete local setting. | 193 // Not synced, delete local setting. |
| 191 changes.push_back( | 194 changes.push_back( |
| 192 ExtensionSettingSyncData( | 195 ExtensionSettingSyncData( |
| 193 SyncChange::ACTION_DELETE, | 196 SyncChange::ACTION_DELETE, |
| 194 extension_id_, | 197 extension_id_, |
| 195 *it, | 198 *it, |
| 196 new DictionaryValue())); | 199 new DictionaryValue())); |
| 197 } | 200 } |
| 198 } | 201 } |
| 199 | 202 |
| 200 // Add all new settings to local settings. | 203 // Add all new settings to local settings. |
| 201 while (!new_sync_state->empty()) { | 204 while (!new_sync_state->empty()) { |
| 202 std::string key = *new_sync_state->begin_keys(); | 205 std::string key = *new_sync_state->begin_keys(); |
| 203 Value* value; | 206 Value* value; |
|
akalin
2011/09/22 01:36:52
since you're modifying this file:
Value* value =
not at google - send to devlin
2011/09/22 02:31:13
Ok. Though I think it's fine to assume that Remov
| |
| 204 new_sync_state->RemoveWithoutPathExpansion(key, &value); | 207 new_sync_state->RemoveWithoutPathExpansion(key, &value); |
| 205 changes.push_back( | 208 changes.push_back( |
| 206 ExtensionSettingSyncData( | 209 ExtensionSettingSyncData( |
| 207 SyncChange::ACTION_ADD, extension_id_, key, value)); | 210 SyncChange::ACTION_ADD, extension_id_, key, value)); |
| 208 } | 211 } |
| 209 | 212 |
| 210 if (changes.empty()) { | 213 if (changes.empty()) { |
| 211 return SyncError(); | 214 return SyncError(); |
| 212 } | 215 } |
| 213 | 216 |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 if (error.IsSet()) { | 335 if (error.IsSet()) { |
| 333 LOG(WARNING) << "Failed to send changes to sync: " << error.message(); | 336 LOG(WARNING) << "Failed to send changes to sync: " << error.message(); |
| 334 return; | 337 return; |
| 335 } | 338 } |
| 336 | 339 |
| 337 for (std::vector<std::string>::const_iterator it = keys.begin(); | 340 for (std::vector<std::string>::const_iterator it = keys.begin(); |
| 338 it != keys.end(); ++it) { | 341 it != keys.end(); ++it) { |
| 339 synced_keys_.erase(*it); | 342 synced_keys_.erase(*it); |
| 340 } | 343 } |
| 341 } | 344 } |
| OLD | NEW |