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