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