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/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_value_serializer.h" | 9 #include "base/json/json_value_serializer.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 if (new_value->IsType(Value::TYPE_NULL)) { | 75 if (new_value->IsType(Value::TYPE_NULL)) { |
76 pref_service_->ClearPref(pref_name.c_str()); | 76 pref_service_->ClearPref(pref_name.c_str()); |
77 } else if (!new_value->IsType(pref->GetType())) { | 77 } else if (!new_value->IsType(pref->GetType())) { |
78 LOG(WARNING) << "Synced value for " << preference.name() | 78 LOG(WARNING) << "Synced value for " << preference.name() |
79 << " is of type " << new_value->GetType() | 79 << " is of type " << new_value->GetType() |
80 << " which doesn't match pref type " << pref->GetType(); | 80 << " which doesn't match pref type " << pref->GetType(); |
81 } else if (!pref->GetValue()->Equals(new_value.get())) { | 81 } else if (!pref->GetValue()->Equals(new_value.get())) { |
82 pref_service_->Set(pref_name.c_str(), *new_value); | 82 pref_service_->Set(pref_name.c_str(), *new_value); |
83 } | 83 } |
84 | 84 |
85 SendUpdateNotificationsIfNecessary(pref_name); | |
86 | |
87 // If the merge resulted in an updated value, inform the syncer. | 85 // If the merge resulted in an updated value, inform the syncer. |
88 if (!value->Equals(new_value.get())) { | 86 if (!value->Equals(new_value.get())) { |
89 SyncData sync_data; | 87 SyncData sync_data; |
90 if (!CreatePrefSyncData(pref->name(), *new_value, &sync_data)) { | 88 if (!CreatePrefSyncData(pref->name(), *new_value, &sync_data)) { |
91 LOG(ERROR) << "Failed to update preference."; | 89 LOG(ERROR) << "Failed to update preference."; |
92 return; | 90 return; |
93 } | 91 } |
94 sync_changes->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); | 92 sync_changes->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); |
95 } | 93 } |
96 } else if (pref->IsUserControlled()) { | 94 } else if (pref->IsUserControlled()) { |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 264 } |
267 // Note that for all other types we want to preserve the "to" | 265 // Note that for all other types we want to preserve the "to" |
268 // values so we do nothing here. | 266 // values so we do nothing here. |
269 } else { | 267 } else { |
270 result->SetWithoutPathExpansion(*key, from_value->DeepCopy()); | 268 result->SetWithoutPathExpansion(*key, from_value->DeepCopy()); |
271 } | 269 } |
272 } | 270 } |
273 return result; | 271 return result; |
274 } | 272 } |
275 | 273 |
276 void PrefModelAssociator::SendUpdateNotificationsIfNecessary( | |
277 const std::string& pref_name) { | |
278 // The bookmark bar visibility preference requires a special | |
279 // notification to update the UI. | |
280 if (0 == pref_name.compare(prefs::kShowBookmarkBar)) { | |
281 NotificationService::current()->Notify( | |
282 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | |
283 Source<PrefModelAssociator>(this), | |
284 NotificationService::NoDetails()); | |
285 } | |
286 } | |
287 | |
288 // Note: This will build a model of all preferences registered as syncable | 274 // Note: This will build a model of all preferences registered as syncable |
289 // with user controlled data. We do not track any information for preferences | 275 // with user controlled data. We do not track any information for preferences |
290 // not registered locally as syncable and do not inform the syncer of | 276 // not registered locally as syncable and do not inform the syncer of |
291 // non-user controlled preferences. | 277 // non-user controlled preferences. |
292 SyncDataList PrefModelAssociator::GetAllSyncData(syncable::ModelType type) | 278 SyncDataList PrefModelAssociator::GetAllSyncData(syncable::ModelType type) |
293 const { | 279 const { |
294 DCHECK_EQ(PREFERENCES, type); | 280 DCHECK_EQ(PREFERENCES, type); |
295 SyncDataList current_data; | 281 SyncDataList current_data; |
296 for (PreferenceSet::const_iterator iter = synced_preferences_.begin(); | 282 for (PreferenceSet::const_iterator iter = synced_preferences_.begin(); |
297 iter != synced_preferences_.end(); | 283 iter != synced_preferences_.end(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 344 |
359 // This will only modify the user controlled value store, which takes | 345 // This will only modify the user controlled value store, which takes |
360 // priority over the default value but is ignored if the preference is | 346 // priority over the default value but is ignored if the preference is |
361 // policy controlled. | 347 // policy controlled. |
362 pref_service_->Set(pref_name, *value); | 348 pref_service_->Set(pref_name, *value); |
363 | 349 |
364 // Keep track of any newly synced preferences. | 350 // Keep track of any newly synced preferences. |
365 if (iter->change_type() == SyncChange::ACTION_ADD) { | 351 if (iter->change_type() == SyncChange::ACTION_ADD) { |
366 synced_preferences_.insert(name); | 352 synced_preferences_.insert(name); |
367 } | 353 } |
368 | |
369 SendUpdateNotificationsIfNecessary(name); | |
370 } | 354 } |
371 return SyncError(); | 355 return SyncError(); |
372 } | 356 } |
373 | 357 |
374 Value* PrefModelAssociator::ReadPreferenceSpecifics( | 358 Value* PrefModelAssociator::ReadPreferenceSpecifics( |
375 const sync_pb::PreferenceSpecifics& preference, | 359 const sync_pb::PreferenceSpecifics& preference, |
376 std::string* name) { | 360 std::string* name) { |
377 base::JSONReader reader; | 361 base::JSONReader reader; |
378 scoped_ptr<Value> value(reader.JsonToValue(preference.value(), false, false)); | 362 scoped_ptr<Value> value(reader.JsonToValue(preference.value(), false, false)); |
379 if (!value.get()) { | 363 if (!value.get()) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 return; | 425 return; |
442 } | 426 } |
443 changes.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); | 427 changes.push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); |
444 } | 428 } |
445 | 429 |
446 SyncError error = | 430 SyncError error = |
447 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); | 431 sync_processor_->ProcessSyncChanges(FROM_HERE, changes); |
448 if (error.IsSet()) | 432 if (error.IsSet()) |
449 StopSyncing(PREFERENCES); | 433 StopSyncing(PREFERENCES); |
450 } | 434 } |
OLD | NEW |