| 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" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/chrome_notification_types.h" | 16 #include "chrome/browser/chrome_notification_types.h" |
| 17 #include "chrome/browser/prefs/pref_service_syncable.h" | 17 #include "chrome/browser/prefs/pref_service_syncable.h" |
| 18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 19 #include "components/content_settings/core/browser/content_settings_pref_provide
r.h" | 19 #include "components/content_settings/core/browser/website_settings_registry.h" |
| 20 #include "sync/api/sync_change.h" | 20 #include "sync/api/sync_change.h" |
| 21 #include "sync/api/sync_error_factory.h" | 21 #include "sync/api/sync_error_factory.h" |
| 22 #include "sync/protocol/preference_specifics.pb.h" | 22 #include "sync/protocol/preference_specifics.pb.h" |
| 23 #include "sync/protocol/sync.pb.h" | 23 #include "sync/protocol/sync.pb.h" |
| 24 | 24 |
| 25 using syncer::PREFERENCES; | 25 using syncer::PREFERENCES; |
| 26 using syncer::PRIORITY_PREFERENCES; | 26 using syncer::PRIORITY_PREFERENCES; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 | 314 |
| 315 scoped_ptr<base::Value> PrefModelAssociator::MergePreference( | 315 scoped_ptr<base::Value> PrefModelAssociator::MergePreference( |
| 316 const std::string& name, | 316 const std::string& name, |
| 317 const base::Value& local_value, | 317 const base::Value& local_value, |
| 318 const base::Value& server_value) { | 318 const base::Value& server_value) { |
| 319 // This function special cases preferences individually, so don't attempt | 319 // This function special cases preferences individually, so don't attempt |
| 320 // to merge for all migrated values. | 320 // to merge for all migrated values. |
| 321 if (name == prefs::kURLsToRestoreOnStartup || | 321 if (name == prefs::kURLsToRestoreOnStartup || |
| 322 name == prefs::kURLsToRestoreOnStartupOld) { | 322 name == prefs::kURLsToRestoreOnStartupOld) { |
| 323 return scoped_ptr<base::Value>( | 323 return make_scoped_ptr(MergeListValues(local_value, server_value)); |
| 324 MergeListValues(local_value, server_value)).Pass(); | |
| 325 } | 324 } |
| 326 | 325 |
| 327 if (content_settings::PrefProvider::IsContentSettingsExceptionsPref(name)) { | 326 content_settings::WebsiteSettingsRegistry* registry = |
| 328 return scoped_ptr<base::Value>( | 327 content_settings::WebsiteSettingsRegistry::GetInstance(); |
| 329 MergeDictionaryValues(local_value, server_value)).Pass(); | 328 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 329 ContentSettingsType type = static_cast<ContentSettingsType>(i); |
| 330 if (registry->Get(type)->pref_name() == name) |
| 331 return make_scoped_ptr(MergeDictionaryValues(local_value, server_value)); |
| 330 } | 332 } |
| 331 | 333 |
| 332 // If this is not a specially handled preference, server wins. | 334 // If this is not a specially handled preference, server wins. |
| 333 return scoped_ptr<base::Value>(server_value.DeepCopy()).Pass(); | 335 return make_scoped_ptr(server_value.DeepCopy()); |
| 334 } | 336 } |
| 335 | 337 |
| 336 bool PrefModelAssociator::CreatePrefSyncData( | 338 bool PrefModelAssociator::CreatePrefSyncData( |
| 337 const std::string& name, | 339 const std::string& name, |
| 338 const base::Value& value, | 340 const base::Value& value, |
| 339 syncer::SyncData* sync_data) const { | 341 syncer::SyncData* sync_data) const { |
| 340 if (value.IsType(base::Value::TYPE_NULL)) { | 342 if (value.IsType(base::Value::TYPE_NULL)) { |
| 341 LOG(ERROR) << "Attempting to sync a null pref value for " << name; | 343 LOG(ERROR) << "Attempting to sync a null pref value for " << name; |
| 342 return false; | 344 return false; |
| 343 } | 345 } |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 void PrefModelAssociator::NotifySyncedPrefObservers(const std::string& path, | 649 void PrefModelAssociator::NotifySyncedPrefObservers(const std::string& path, |
| 648 bool from_sync) const { | 650 bool from_sync) const { |
| 649 SyncedPrefObserverMap::const_iterator observer_iter = | 651 SyncedPrefObserverMap::const_iterator observer_iter = |
| 650 synced_pref_observers_.find(path); | 652 synced_pref_observers_.find(path); |
| 651 if (observer_iter == synced_pref_observers_.end()) | 653 if (observer_iter == synced_pref_observers_.end()) |
| 652 return; | 654 return; |
| 653 SyncedPrefObserverList* observers = observer_iter->second; | 655 SyncedPrefObserverList* observers = observer_iter->second; |
| 654 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, | 656 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, |
| 655 OnSyncedPrefChanged(path, from_sync)); | 657 OnSyncedPrefChanged(path, from_sync)); |
| 656 } | 658 } |
| OLD | NEW |