Refactor WebsiteSettings to operate on a SecurityInfo
[chromium-blink-merge.git] / chrome / browser / prefs / chrome_pref_model_associator_client.cc
blobcb2c3fefd494564511fa18ef21c6f006e10012c5
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/prefs/chrome_pref_model_associator_client.h"
7 #include "base/memory/singleton.h"
8 #include "chrome/common/pref_names.h"
9 #include "components/content_settings/core/browser/website_settings_info.h"
10 #include "components/content_settings/core/browser/website_settings_registry.h"
12 namespace {
13 // List of migrated preference name pairs. If a preference is migrated
14 // (meaning renamed) adding the old and new preference names here will ensure
15 // that the sync engine knows how to deal with the synced values coming in
16 // with the old name. Preference migration itself doesn't happen here. It may
17 // happen in session_startup_pref.cc.
18 const struct MigratedPreferences {
19 const char* const old_name;
20 const char* const new_name;
21 } kMigratedPreferences[] = {
22 {prefs::kURLsToRestoreOnStartupOld, prefs::kURLsToRestoreOnStartup},
24 } // namespace
26 // static
27 ChromePrefModelAssociatorClient*
28 ChromePrefModelAssociatorClient::GetInstance() {
29 return base::Singleton<ChromePrefModelAssociatorClient>::get();
32 ChromePrefModelAssociatorClient::ChromePrefModelAssociatorClient() {}
34 ChromePrefModelAssociatorClient::~ChromePrefModelAssociatorClient() {}
36 bool ChromePrefModelAssociatorClient::IsMergeableListPreference(
37 const std::string& pref_name) const {
38 return pref_name == prefs::kURLsToRestoreOnStartup;
41 bool ChromePrefModelAssociatorClient::IsMergeableDictionaryPreference(
42 const std::string& pref_name) const {
43 const content_settings::WebsiteSettingsRegistry& registry =
44 *content_settings::WebsiteSettingsRegistry::GetInstance();
45 for (const content_settings::WebsiteSettingsInfo* info : registry) {
46 if (info->pref_name() == pref_name)
47 return true;
49 return false;
52 bool ChromePrefModelAssociatorClient::IsMigratedPreference(
53 const std::string& new_pref_name,
54 std::string* old_pref_name) const {
55 for (size_t i = 0; i < arraysize(kMigratedPreferences); ++i) {
56 if (new_pref_name == kMigratedPreferences[i].new_name) {
57 old_pref_name->assign(kMigratedPreferences[i].old_name);
58 return true;
61 return false;
64 bool ChromePrefModelAssociatorClient::IsOldMigratedPreference(
65 const std::string& old_pref_name,
66 std::string* new_pref_name) const {
67 for (size_t i = 0; i < arraysize(kMigratedPreferences); ++i) {
68 if (old_pref_name == kMigratedPreferences[i].old_name) {
69 new_pref_name->assign(kMigratedPreferences[i].new_name);
70 return true;
73 return false;