Chromium Code Reviews| 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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 | 51 |
| 52 // List of migrated preference name pairs. If a preference is migrated | 52 // List of migrated preference name pairs. If a preference is migrated |
| 53 // (meaning renamed) adding the old and new preference names here will ensure | 53 // (meaning renamed) adding the old and new preference names here will ensure |
| 54 // that the sync engine knows how to deal with the synced values coming in | 54 // that the sync engine knows how to deal with the synced values coming in |
| 55 // with the old name. Preference migration itself doesn't happen here. It may | 55 // with the old name. Preference migration itself doesn't happen here. It may |
| 56 // happen in session_startup_pref.cc. | 56 // happen in session_startup_pref.cc. |
| 57 const struct MigratedPreferences { | 57 const struct MigratedPreferences { |
| 58 const char* const old_name; | 58 const char* const old_name; |
| 59 const char* const new_name; | 59 const char* const new_name; |
| 60 } kMigratedPreferences[] = { | 60 } kMigratedPreferences[] = { |
| 61 { prefs::kURLsToRestoreOnStartupOld, prefs::kURLsToRestoreOnStartup }, | 61 // arraysize macro does not supports empty arrays, so we use a sentinel |
| 62 // value when there are no migrated preferences. | |
| 63 { NULL, NULL }, | |
|
gab
2015/08/24 21:48:45
+zea: Think we should keep this around or simply g
Nicolas Zea
2015/08/25 17:10:30
I'd rather get rid of it personally. If someone do
sdefresne
2015/08/26 16:00:56
Done.
| |
| 62 }; | 64 }; |
| 63 | 65 |
| 64 std::string GetOldMigratedPreferenceName(const char* preference_name) { | 66 std::string GetOldMigratedPreferenceName(const char* preference_name) { |
| 65 for (size_t i = 0; i < arraysize(kMigratedPreferences); ++i) { | 67 for (size_t i = 0; i < arraysize(kMigratedPreferences); ++i) { |
| 66 if (!strcmp(kMigratedPreferences[i].new_name, preference_name)) | 68 if (kMigratedPreferences[i].new_name && |
| 69 !strcmp(kMigratedPreferences[i].new_name, preference_name)) { | |
| 70 DCHECK(kMigratedPreferences[i].old_name); | |
| 67 return kMigratedPreferences[i].old_name; | 71 return kMigratedPreferences[i].old_name; |
| 72 } | |
| 68 } | 73 } |
| 69 return std::string(); | 74 return std::string(); |
| 70 } | 75 } |
| 71 | 76 |
| 72 std::string GetNewMigratedPreferenceName(const char* old_preference_name) { | 77 std::string GetNewMigratedPreferenceName(const char* old_preference_name) { |
| 73 for (size_t i = 0; i < arraysize(kMigratedPreferences); ++i) { | 78 for (size_t i = 0; i < arraysize(kMigratedPreferences); ++i) { |
| 74 if (!strcmp(kMigratedPreferences[i].old_name, old_preference_name)) | 79 if (kMigratedPreferences[i].old_name && |
| 80 !strcmp(kMigratedPreferences[i].old_name, old_preference_name)) { | |
| 81 DCHECK(kMigratedPreferences[i].new_name); | |
| 75 return kMigratedPreferences[i].new_name; | 82 return kMigratedPreferences[i].new_name; |
| 83 } | |
| 76 } | 84 } |
| 77 return std::string(); | 85 return std::string(); |
| 78 } | 86 } |
| 79 | 87 |
| 80 } // namespace | 88 } // namespace |
| 81 | 89 |
| 82 PrefModelAssociator::PrefModelAssociator(syncer::ModelType type) | 90 PrefModelAssociator::PrefModelAssociator(syncer::ModelType type) |
| 83 : models_associated_(false), | 91 : models_associated_(false), |
| 84 processing_syncer_changes_(false), | 92 processing_syncer_changes_(false), |
| 85 pref_service_(NULL), | 93 pref_service_(NULL), |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 sync_error_factory_.reset(); | 319 sync_error_factory_.reset(); |
| 312 pref_service_->OnIsSyncingChanged(); | 320 pref_service_->OnIsSyncingChanged(); |
| 313 } | 321 } |
| 314 | 322 |
| 315 scoped_ptr<base::Value> PrefModelAssociator::MergePreference( | 323 scoped_ptr<base::Value> PrefModelAssociator::MergePreference( |
| 316 const std::string& name, | 324 const std::string& name, |
| 317 const base::Value& local_value, | 325 const base::Value& local_value, |
| 318 const base::Value& server_value) { | 326 const base::Value& server_value) { |
| 319 // This function special cases preferences individually, so don't attempt | 327 // This function special cases preferences individually, so don't attempt |
| 320 // to merge for all migrated values. | 328 // to merge for all migrated values. |
| 321 if (name == prefs::kURLsToRestoreOnStartup || | 329 if (name == prefs::kURLsToRestoreOnStartup) { |
| 322 name == prefs::kURLsToRestoreOnStartupOld) { | |
| 323 return make_scoped_ptr(MergeListValues(local_value, server_value)); | 330 return make_scoped_ptr(MergeListValues(local_value, server_value)); |
| 324 } | 331 } |
| 325 | 332 |
| 326 content_settings::WebsiteSettingsRegistry* registry = | 333 content_settings::WebsiteSettingsRegistry* registry = |
| 327 content_settings::WebsiteSettingsRegistry::GetInstance(); | 334 content_settings::WebsiteSettingsRegistry::GetInstance(); |
| 328 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { | 335 for (int i = 0; i < CONTENT_SETTINGS_NUM_TYPES; ++i) { |
| 329 ContentSettingsType type = static_cast<ContentSettingsType>(i); | 336 ContentSettingsType type = static_cast<ContentSettingsType>(i); |
| 330 if (registry->Get(type)->pref_name() == name) | 337 if (registry->Get(type)->pref_name() == name) |
| 331 return make_scoped_ptr(MergeDictionaryValues(local_value, server_value)); | 338 return make_scoped_ptr(MergeDictionaryValues(local_value, server_value)); |
| 332 } | 339 } |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 649 void PrefModelAssociator::NotifySyncedPrefObservers(const std::string& path, | 656 void PrefModelAssociator::NotifySyncedPrefObservers(const std::string& path, |
| 650 bool from_sync) const { | 657 bool from_sync) const { |
| 651 SyncedPrefObserverMap::const_iterator observer_iter = | 658 SyncedPrefObserverMap::const_iterator observer_iter = |
| 652 synced_pref_observers_.find(path); | 659 synced_pref_observers_.find(path); |
| 653 if (observer_iter == synced_pref_observers_.end()) | 660 if (observer_iter == synced_pref_observers_.end()) |
| 654 return; | 661 return; |
| 655 SyncedPrefObserverList* observers = observer_iter->second; | 662 SyncedPrefObserverList* observers = observer_iter->second; |
| 656 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, | 663 FOR_EACH_OBSERVER(SyncedPrefObserver, *observers, |
| 657 OnSyncedPrefChanged(path, from_sync)); | 664 OnSyncedPrefChanged(path, from_sync)); |
| 658 } | 665 } |
| OLD | NEW |