OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/sync/glue/preference_model_associator.h" | 5 #include "chrome/browser/sync/glue/preference_model_associator.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 LOG(ERROR) << "Failed to deserialize preference value: " | 66 LOG(ERROR) << "Failed to deserialize preference value: " |
67 << reader.GetErrorMessage(); | 67 << reader.GetErrorMessage(); |
68 return false; | 68 return false; |
69 } | 69 } |
70 | 70 |
71 // Merge the server value of this preference with the local value. | 71 // Merge the server value of this preference with the local value. |
72 scoped_ptr<Value> new_value(MergePreference(*pref, *value)); | 72 scoped_ptr<Value> new_value(MergePreference(*pref, *value)); |
73 | 73 |
74 // Update the local preference based on what we got from the | 74 // Update the local preference based on what we got from the |
75 // sync server. | 75 // sync server. |
76 if (!pref->GetValue()->Equals(new_value.get())) | 76 if (new_value->IsType(Value::TYPE_NULL)) { |
| 77 pref_service->ClearPref(pref_name.c_str()); |
| 78 } else if (!new_value->IsType(pref->GetType())) { |
| 79 LOG(WARNING) << "Synced value for " << preference.name() |
| 80 << " is of type " << new_value->GetType() |
| 81 << " which doesn't match pref type " << pref->GetType(); |
| 82 } else if (!pref->GetValue()->Equals(new_value.get())) { |
77 pref_service->Set(pref_name.c_str(), *new_value); | 83 pref_service->Set(pref_name.c_str(), *new_value); |
| 84 } |
78 | 85 |
79 AfterUpdateOperations(pref_name); | 86 AfterUpdateOperations(pref_name); |
80 | 87 |
81 // If the merge resulted in an updated value, write it back to | 88 // If the merge resulted in an updated value, write it back to |
82 // the sync node. | 89 // the sync node. |
83 if (!value->Equals(new_value.get()) && | 90 if (!value->Equals(new_value.get()) && |
84 !WritePreferenceToNode(pref->name(), *new_value, &node)) | 91 !WritePreferenceToNode(pref->name(), *new_value, &node)) |
85 return false; | 92 return false; |
86 } | 93 } |
87 Associate(pref, node.GetId()); | 94 Associate(pref, node.GetId()); |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 // notification to update the UI. | 320 // notification to update the UI. |
314 if (0 == pref_name.compare(prefs::kShowBookmarkBar)) { | 321 if (0 == pref_name.compare(prefs::kShowBookmarkBar)) { |
315 NotificationService::current()->Notify( | 322 NotificationService::current()->Notify( |
316 NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 323 NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
317 Source<PreferenceModelAssociator>(this), | 324 Source<PreferenceModelAssociator>(this), |
318 NotificationService::NoDetails()); | 325 NotificationService::NoDetails()); |
319 } | 326 } |
320 } | 327 } |
321 | 328 |
322 } // namespace browser_sync | 329 } // namespace browser_sync |
OLD | NEW |