diff options
Diffstat (limited to 'chromium/components/proxy_config')
4 files changed, 49 insertions, 42 deletions
diff --git a/chromium/components/proxy_config/pref_proxy_config_tracker_impl.cc b/chromium/components/proxy_config/pref_proxy_config_tracker_impl.cc index a7ffcb86b3a..f8077aa9032 100644 --- a/chromium/components/proxy_config/pref_proxy_config_tracker_impl.cc +++ b/chromium/components/proxy_config/pref_proxy_config_tracker_impl.cc @@ -6,6 +6,9 @@ #include <stddef.h> +#include <memory> +#include <utility> + #include "base/bind.h" #include "base/location.h" #include "base/single_thread_task_runner.h" @@ -205,19 +208,19 @@ net::ProxyConfigService::ConfigAvailability // static void PrefProxyConfigTrackerImpl::RegisterPrefs(PrefRegistrySimple* registry) { - base::DictionaryValue* default_settings = + std::unique_ptr<base::DictionaryValue> default_settings = ProxyConfigDictionary::CreateSystem(); registry->RegisterDictionaryPref(proxy_config::prefs::kProxy, - default_settings); + std::move(default_settings)); } // static void PrefProxyConfigTrackerImpl::RegisterProfilePrefs( user_prefs::PrefRegistrySyncable* pref_service) { - base::DictionaryValue* default_settings = + std::unique_ptr<base::DictionaryValue> default_settings = ProxyConfigDictionary::CreateSystem(); pref_service->RegisterDictionaryPref(proxy_config::prefs::kProxy, - default_settings); + std::move(default_settings)); pref_service->RegisterBooleanPref(proxy_config::prefs::kUseSharedProxies, false); } @@ -237,7 +240,7 @@ ProxyPrefs::ConfigState PrefProxyConfigTrackerImpl::ReadPrefConfig( const base::DictionaryValue* dict = pref_service->GetDictionary(proxy_config::prefs::kProxy); DCHECK(dict); - ProxyConfigDictionary proxy_dict(dict); + ProxyConfigDictionary proxy_dict(dict->CreateDeepCopy()); if (PrefConfigToNetConfig(proxy_dict, config)) { if (!pref->IsUserModifiable() || pref->HasUserSetting()) { diff --git a/chromium/components/proxy_config/proxy_config_dictionary.cc b/chromium/components/proxy_config/proxy_config_dictionary.cc index 1251ae68442..a55133c71be 100644 --- a/chromium/components/proxy_config/proxy_config_dictionary.cc +++ b/chromium/components/proxy_config/proxy_config_dictionary.cc @@ -4,7 +4,10 @@ #include "components/proxy_config/proxy_config_dictionary.h" +#include <utility> + #include "base/logging.h" +#include "base/memory/ptr_util.h" #include "base/values.h" #include "net/proxy/proxy_config.h" @@ -29,9 +32,9 @@ const char kProxyBypassList[] = "bypass_list"; } // namespace -ProxyConfigDictionary::ProxyConfigDictionary(const base::DictionaryValue* dict) - : dict_(dict->DeepCopy()) { -} +ProxyConfigDictionary::ProxyConfigDictionary( + std::unique_ptr<base::DictionaryValue> dict) + : dict_(std::move(dict)) {} ProxyConfigDictionary::~ProxyConfigDictionary() {} @@ -70,7 +73,7 @@ const base::DictionaryValue& ProxyConfigDictionary::GetDictionary() const { } // static -base::DictionaryValue* ProxyConfigDictionary::CreateDirect() { +std::unique_ptr<base::DictionaryValue> ProxyConfigDictionary::CreateDirect() { return CreateDictionary(ProxyPrefs::MODE_DIRECT, std::string(), false, @@ -79,7 +82,8 @@ base::DictionaryValue* ProxyConfigDictionary::CreateDirect() { } // static -base::DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() { +std::unique_ptr<base::DictionaryValue> +ProxyConfigDictionary::CreateAutoDetect() { return CreateDictionary(ProxyPrefs::MODE_AUTO_DETECT, std::string(), false, @@ -88,7 +92,7 @@ base::DictionaryValue* ProxyConfigDictionary::CreateAutoDetect() { } // static -base::DictionaryValue* ProxyConfigDictionary::CreatePacScript( +std::unique_ptr<base::DictionaryValue> ProxyConfigDictionary::CreatePacScript( const std::string& pac_url, bool pac_mandatory) { return CreateDictionary(ProxyPrefs::MODE_PAC_SCRIPT, @@ -99,9 +103,9 @@ base::DictionaryValue* ProxyConfigDictionary::CreatePacScript( } // static -base::DictionaryValue* ProxyConfigDictionary::CreateFixedServers( - const std::string& proxy_server, - const std::string& bypass_list) { +std::unique_ptr<base::DictionaryValue> +ProxyConfigDictionary::CreateFixedServers(const std::string& proxy_server, + const std::string& bypass_list) { if (!proxy_server.empty()) { return CreateDictionary(ProxyPrefs::MODE_FIXED_SERVERS, std::string(), @@ -114,7 +118,7 @@ base::DictionaryValue* ProxyConfigDictionary::CreateFixedServers( } // static -base::DictionaryValue* ProxyConfigDictionary::CreateSystem() { +std::unique_ptr<base::DictionaryValue> ProxyConfigDictionary::CreateSystem() { return CreateDictionary(ProxyPrefs::MODE_SYSTEM, std::string(), false, @@ -123,13 +127,13 @@ base::DictionaryValue* ProxyConfigDictionary::CreateSystem() { } // static -base::DictionaryValue* ProxyConfigDictionary::CreateDictionary( +std::unique_ptr<base::DictionaryValue> ProxyConfigDictionary::CreateDictionary( ProxyPrefs::ProxyMode mode, const std::string& pac_url, bool pac_mandatory, const std::string& proxy_server, const std::string& bypass_list) { - base::DictionaryValue* dict = new base::DictionaryValue(); + auto dict = base::MakeUnique<base::DictionaryValue>(); dict->SetString(kProxyMode, ProxyModeToString(mode)); if (!pac_url.empty()) { dict->SetString(kProxyPacUrl, pac_url); diff --git a/chromium/components/proxy_config/proxy_config_dictionary.h b/chromium/components/proxy_config/proxy_config_dictionary.h index 1faa121a392..ed7a936f1b3 100644 --- a/chromium/components/proxy_config/proxy_config_dictionary.h +++ b/chromium/components/proxy_config/proxy_config_dictionary.h @@ -31,8 +31,7 @@ class ProxyServer; // See proxy_config_dictionary.cc for the structure of the respective strings. class PROXY_CONFIG_EXPORT ProxyConfigDictionary { public: - // Creates a deep copy of |dict| and leaves ownership to caller. - explicit ProxyConfigDictionary(const base::DictionaryValue* dict); + explicit ProxyConfigDictionary(std::unique_ptr<base::DictionaryValue> dict); ~ProxyConfigDictionary(); bool GetMode(ProxyPrefs::ProxyMode* out) const; @@ -44,14 +43,15 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary { const base::DictionaryValue& GetDictionary() const; - static base::DictionaryValue* CreateDirect(); - static base::DictionaryValue* CreateAutoDetect(); - static base::DictionaryValue* CreatePacScript(const std::string& pac_url, - bool pac_mandatory); - static base::DictionaryValue* CreateFixedServers( + static std::unique_ptr<base::DictionaryValue> CreateDirect(); + static std::unique_ptr<base::DictionaryValue> CreateAutoDetect(); + static std::unique_ptr<base::DictionaryValue> CreatePacScript( + const std::string& pac_url, + bool pac_mandatory); + static std::unique_ptr<base::DictionaryValue> CreateFixedServers( const std::string& proxy_server, const std::string& bypass_list); - static base::DictionaryValue* CreateSystem(); + static std::unique_ptr<base::DictionaryValue> CreateSystem(); // Encodes the proxy server as "<url-scheme>=<proxy-scheme>://<proxy>". // Used to generate the |proxy_server| arg for CreateFixedServers(). @@ -60,7 +60,7 @@ class PROXY_CONFIG_EXPORT ProxyConfigDictionary { std::string* spec); private: - static base::DictionaryValue* CreateDictionary( + static std::unique_ptr<base::DictionaryValue> CreateDictionary( ProxyPrefs::ProxyMode mode, const std::string& pac_url, bool pac_mandatory, diff --git a/chromium/components/proxy_config/proxy_config_dictionary_unittest.cc b/chromium/components/proxy_config/proxy_config_dictionary_unittest.cc index 33f5364c14b..e7047223aac 100644 --- a/chromium/components/proxy_config/proxy_config_dictionary_unittest.cc +++ b/chromium/components/proxy_config/proxy_config_dictionary_unittest.cc @@ -6,6 +6,7 @@ #include <memory> #include <string> +#include <utility> #include "base/values.h" #include "testing/gtest/include/gtest/gtest.h" @@ -18,9 +19,9 @@ struct ProxyConfigHolder { }; TEST(ProxyConfigDictionaryTest, CreateDirect) { - std::unique_ptr<base::DictionaryValue> dict_value( - ProxyConfigDictionary::CreateDirect()); - ProxyConfigDictionary dict(dict_value.get()); + std::unique_ptr<base::DictionaryValue> dict_value = + ProxyConfigDictionary::CreateDirect(); + ProxyConfigDictionary dict(std::move(dict_value)); ProxyConfigHolder h; ASSERT_TRUE(dict.GetMode(&h.mode)); @@ -31,9 +32,9 @@ TEST(ProxyConfigDictionaryTest, CreateDirect) { } TEST(ProxyConfigDictionaryTest, CreateAutoDetect) { - std::unique_ptr<base::DictionaryValue> dict_value( - ProxyConfigDictionary::CreateAutoDetect()); - ProxyConfigDictionary dict(dict_value.get()); + std::unique_ptr<base::DictionaryValue> dict_value = + ProxyConfigDictionary::CreateAutoDetect(); + ProxyConfigDictionary dict(std::move(dict_value)); ProxyConfigHolder h; ASSERT_TRUE(dict.GetMode(&h.mode)); @@ -44,9 +45,9 @@ TEST(ProxyConfigDictionaryTest, CreateAutoDetect) { } TEST(ProxyConfigDictionaryTest, CreatePacScript) { - std::unique_ptr<base::DictionaryValue> dict_value( - ProxyConfigDictionary::CreatePacScript("pac", false)); - ProxyConfigDictionary dict(dict_value.get()); + std::unique_ptr<base::DictionaryValue> dict_value = + ProxyConfigDictionary::CreatePacScript("pac", false); + ProxyConfigDictionary dict(std::move(dict_value)); ProxyConfigHolder h; ASSERT_TRUE(dict.GetMode(&h.mode)); @@ -58,10 +59,9 @@ TEST(ProxyConfigDictionaryTest, CreatePacScript) { } TEST(ProxyConfigDictionaryTest, CreateFixedServers) { - std::unique_ptr<base::DictionaryValue> dict_value( - ProxyConfigDictionary::CreateFixedServers("http://1.2.3.4", - "http://foo")); - ProxyConfigDictionary dict(dict_value.get()); + std::unique_ptr<base::DictionaryValue> dict_value = + ProxyConfigDictionary::CreateFixedServers("http://1.2.3.4", "http://foo"); + ProxyConfigDictionary dict(std::move(dict_value)); ProxyConfigHolder h; ASSERT_TRUE(dict.GetMode(&h.mode)); @@ -74,9 +74,9 @@ TEST(ProxyConfigDictionaryTest, CreateFixedServers) { } TEST(ProxyConfigDictionaryTest, CreateSystem) { - std::unique_ptr<base::DictionaryValue> dict_value( - ProxyConfigDictionary::CreateSystem()); - ProxyConfigDictionary dict(dict_value.get()); + std::unique_ptr<base::DictionaryValue> dict_value = + ProxyConfigDictionary::CreateSystem(); + ProxyConfigDictionary dict(std::move(dict_value)); ProxyConfigHolder h; ASSERT_TRUE(dict.GetMode(&h.mode)); |