| 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/prefs/pref_model_associator.h" | 5 #include "chrome/browser/prefs/pref_model_associator.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 9 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 VLOG(1) << "Associating preference " << pref_name; | 41 VLOG(1) << "Associating preference " << pref_name; |
| 42 | 42 |
| 43 base::JSONReader reader; | 43 base::JSONReader reader; |
| 44 if (sync_pref.IsValid()) { | 44 if (sync_pref.IsValid()) { |
| 45 // The server has a value for the preference, we have to reconcile it with | 45 // The server has a value for the preference, we have to reconcile it with |
| 46 // ours. | 46 // ours. |
| 47 const sync_pb::PreferenceSpecifics& preference = | 47 const sync_pb::PreferenceSpecifics& preference = |
| 48 sync_pref.GetSpecifics().preference(); | 48 sync_pref.GetSpecifics().preference(); |
| 49 DCHECK_EQ(pref->name(), preference.name()); | 49 DCHECK_EQ(pref->name(), preference.name()); |
| 50 | 50 |
| 51 scoped_ptr<Value> value( | 51 scoped_ptr<Value> value(reader.ReadToValue(preference.value())); |
| 52 reader.JsonToValue(preference.value(), false, false)); | |
| 53 if (!value.get()) { | 52 if (!value.get()) { |
| 54 LOG(ERROR) << "Failed to deserialize preference value: " | 53 LOG(ERROR) << "Failed to deserialize preference value: " |
| 55 << reader.GetErrorMessage(); | 54 << reader.GetErrorMessage(); |
| 56 return; | 55 return; |
| 57 } | 56 } |
| 58 | 57 |
| 59 // Merge the server value of this preference with the local value. | 58 // Merge the server value of this preference with the local value. |
| 60 scoped_ptr<Value> new_value(MergePreference(*pref, *value)); | 59 scoped_ptr<Value> new_value(MergePreference(*pref, *value)); |
| 61 | 60 |
| 62 // Update the local preference based on what we got from the | 61 // Update the local preference based on what we got from the |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 synced_preferences_.insert(name); | 342 synced_preferences_.insert(name); |
| 344 } | 343 } |
| 345 } | 344 } |
| 346 return SyncError(); | 345 return SyncError(); |
| 347 } | 346 } |
| 348 | 347 |
| 349 Value* PrefModelAssociator::ReadPreferenceSpecifics( | 348 Value* PrefModelAssociator::ReadPreferenceSpecifics( |
| 350 const sync_pb::PreferenceSpecifics& preference, | 349 const sync_pb::PreferenceSpecifics& preference, |
| 351 std::string* name) { | 350 std::string* name) { |
| 352 base::JSONReader reader; | 351 base::JSONReader reader; |
| 353 scoped_ptr<Value> value(reader.JsonToValue(preference.value(), false, false)); | 352 scoped_ptr<Value> value(reader.ReadToValue(preference.value())); |
| 354 if (!value.get()) { | 353 if (!value.get()) { |
| 355 std::string err = "Failed to deserialize preference value: " + | 354 std::string err = "Failed to deserialize preference value: " + |
| 356 reader.GetErrorMessage(); | 355 reader.GetErrorMessage(); |
| 357 LOG(ERROR) << err; | 356 LOG(ERROR) << err; |
| 358 return NULL; | 357 return NULL; |
| 359 } | 358 } |
| 360 *name = preference.name(); | 359 *name = preference.name(); |
| 361 return value.release(); | 360 return value.release(); |
| 362 } | 361 } |
| 363 | 362 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 } | 422 } |
| 424 | 423 |
| 425 SyncError error = | 424 SyncError error = |
| 426 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 425 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
| 427 } | 426 } |
| 428 | 427 |
| 429 void PrefModelAssociator::SetPrefService(PrefService* pref_service) { | 428 void PrefModelAssociator::SetPrefService(PrefService* pref_service) { |
| 430 DCHECK(pref_service_ == NULL); | 429 DCHECK(pref_service_ == NULL); |
| 431 pref_service_ = pref_service; | 430 pref_service_ = pref_service; |
| 432 } | 431 } |
| OLD | NEW |