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. 4 5 #include "chrome/browser/prefs/chrome_pref_model_associator_client.h" 6 7 #include <cstdint> 8 9 #include "base/memory/singleton.h" 10 #include "chrome/common/pref_names.h" 11 #include "components/content_settings/core/browser/website_settings_info.h" 12 #include "components/content_settings/core/browser/website_settings_registry.h" 13 14 // static 15 ChromePrefModelAssociatorClient* GetInstance()16ChromePrefModelAssociatorClient::GetInstance() { 17 return base::Singleton<ChromePrefModelAssociatorClient>::get(); 18 } 19 ChromePrefModelAssociatorClient()20ChromePrefModelAssociatorClient::ChromePrefModelAssociatorClient() {} 21 ~ChromePrefModelAssociatorClient()22ChromePrefModelAssociatorClient::~ChromePrefModelAssociatorClient() {} 23 IsMergeableListPreference(const std::string & pref_name) const24bool ChromePrefModelAssociatorClient::IsMergeableListPreference( 25 const std::string& pref_name) const { 26 return pref_name == prefs::kURLsToRestoreOnStartup; 27 } 28 IsMergeableDictionaryPreference(const std::string & pref_name) const29bool ChromePrefModelAssociatorClient::IsMergeableDictionaryPreference( 30 const std::string& pref_name) const { 31 const content_settings::WebsiteSettingsRegistry& registry = 32 *content_settings::WebsiteSettingsRegistry::GetInstance(); 33 for (const content_settings::WebsiteSettingsInfo* info : registry) { 34 if (info->pref_name() == pref_name) 35 return true; 36 } 37 return false; 38 } 39 40 std::unique_ptr<base::Value> MaybeMergePreferenceValues(const std::string & pref_name,const base::Value & local_value,const base::Value & server_value) const41ChromePrefModelAssociatorClient::MaybeMergePreferenceValues( 42 const std::string& pref_name, 43 const base::Value& local_value, 44 const base::Value& server_value) const { 45 if (pref_name == prefs::kNetworkEasterEggHighScore) { 46 uint32_t local_high_score; 47 if (!local_value.GetAsInteger(reinterpret_cast<int*>(&local_high_score))) 48 return nullptr; 49 uint32_t server_high_score; 50 if (!server_value.GetAsInteger(reinterpret_cast<int*>(&server_high_score))) 51 return nullptr; 52 return std::make_unique<base::Value>( 53 static_cast<int>(std::max(local_high_score, server_high_score))); 54 } 55 56 return nullptr; 57 } 58