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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 scoped_ptr<base::Value>( |
324 MergeListValues(local_value, server_value)).Pass(); | 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 scoped_ptr<base::Value>( | |
Bernhard Bauer
2015/07/29 10:12:38
Can you use make_scoped_ptr()?
raymes
2015/07/30 05:25:03
Done.
| |
333 MergeDictionaryValues(local_value, server_value)) | |
334 .Pass(); | |
Bernhard Bauer
2015/07/29 10:12:38
The .Pass() is only necessary to pass ownership fr
raymes
2015/07/30 05:25:03
Thanks - I wasn't really thinking about this as I
| |
335 } | |
330 } | 336 } |
331 | 337 |
332 // If this is not a specially handled preference, server wins. | 338 // If this is not a specially handled preference, server wins. |
333 return scoped_ptr<base::Value>(server_value.DeepCopy()).Pass(); | 339 return scoped_ptr<base::Value>(server_value.DeepCopy()).Pass(); |
Bernhard Bauer
2015/07/29 10:12:38
Same here.
raymes
2015/07/30 05:25:03
Done.
| |
334 } | 340 } |
335 | 341 |
336 bool PrefModelAssociator::CreatePrefSyncData( | 342 bool PrefModelAssociator::CreatePrefSyncData( |
337 const std::string& name, | 343 const std::string& name, |
338 const base::Value& value, | 344 const base::Value& value, |
339 syncer::SyncData* sync_data) const { | 345 syncer::SyncData* sync_data) const { |
340 if (value.IsType(base::Value::TYPE_NULL)) { | 346 if (value.IsType(base::Value::TYPE_NULL)) { |
341 LOG(ERROR) << "Attempting to sync a null pref value for " << name; | 347 LOG(ERROR) << "Attempting to sync a null pref value for " << name; |
342 return false; | 348 return false; |
343 } | 349 } |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
647 void PrefModelAssociator::NotifySyncedPrefObservers(const std::string& path, | 653 void PrefModelAssociator::NotifySyncedPrefObservers(const std::string& path, |
648 bool from_sync) const { | 654 bool from_sync) const { |
649 SyncedPrefObserverMap::const_iterator observer_iter = | 655 SyncedPrefObserverMap::const_iterator observer_iter = |
650 synced_pref_observers_.find(path); | 656 synced_pref_observers_.find(path); |
651 if (observer_iter == synced_pref_observers_.end()) | 657 if (observer_iter == synced_pref_observers_.end()) |
652 return; | 658 return; |
653 SyncedPrefObserverList* observers = observer_iter->second; | 659 SyncedPrefObserverList* observers = observer_iter->second; |
654 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, | 660 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, |
655 OnSyncedPrefChanged(path, from_sync)); | 661 OnSyncedPrefChanged(path, from_sync)); |
656 } | 662 } |
OLD | NEW |