Chromium Code Reviews| Index: chrome/browser/chromeos/proxy_cros_settings_parser.cc |
| diff --git a/chrome/browser/chromeos/proxy_cros_settings_parser.cc b/chrome/browser/chromeos/proxy_cros_settings_parser.cc |
| index 72dd4964754e45a2cfc8f24df608e4c49d6eb091..87e25abfddac75e74917299a6e1fbe830b3c4914 100644 |
| --- a/chrome/browser/chromeos/proxy_cros_settings_parser.cc |
| +++ b/chrome/browser/chromeos/proxy_cros_settings_parser.cc |
| @@ -7,6 +7,7 @@ |
| #include <stdint.h> |
| #include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| #include "base/strings/string_util.h" |
| #include "base/values.h" |
| #include "chromeos/network/proxy/ui_proxy_config.h" |
| @@ -16,16 +17,18 @@ namespace chromeos { |
| namespace { |
| -base::Value* CreateServerHostValue(const UIProxyConfig::ManualProxy& proxy) { |
| - return proxy.server.is_valid() |
| - ? new base::Value(proxy.server.host_port_pair().host()) |
| - : NULL; |
| +std::unique_ptr<base::Value> CreateServerHostValue( |
| + const UIProxyConfig::ManualProxy& proxy) { |
| + return proxy.server.is_valid() ? base::MakeUnique<base::Value>( |
| + proxy.server.host_port_pair().host()) |
| + : nullptr; |
| } |
| -base::Value* CreateServerPortValue(const UIProxyConfig::ManualProxy& proxy) { |
| - return proxy.server.is_valid() |
| - ? new base::Value(proxy.server.host_port_pair().port()) |
| - : NULL; |
| +std::unique_ptr<base::Value> CreateServerPortValue( |
| + const UIProxyConfig::ManualProxy& proxy) { |
| + return proxy.server.is_valid() ? base::MakeUnique<base::Value>( |
| + proxy.server.host_port_pair().port()) |
| + : nullptr; |
| } |
| net::ProxyServer CreateProxyServer(std::string host, |
| @@ -284,7 +287,7 @@ bool GetProxyPrefValue(const std::string& network_guid, |
| UIProxyConfigService* config_service, |
| base::Value** out_value) { |
|
Daniel Erat
2017/03/23 14:21:30
nit: add a TODO to make this be a std::unique_ptr<
vabr (Chromium)
2017/03/23 22:43:50
Good point!
Done.
|
| std::string controlled_by; |
| - base::Value* data = NULL; |
| + std::unique_ptr<base::Value> data; |
| UIProxyConfig config; |
| config_service->GetProxyConfig(network_guid, &config); |
| @@ -292,7 +295,8 @@ bool GetProxyPrefValue(const std::string& network_guid, |
| // Only show pacurl for pac-script mode. |
| if (config.mode == UIProxyConfig::MODE_PAC_SCRIPT && |
| config.automatic_proxy.pac_url.is_valid()) { |
| - data = new base::Value(config.automatic_proxy.pac_url.spec()); |
| + data = |
| + base::MakeUnique<base::Value>(config.automatic_proxy.pac_url.spec()); |
| } |
| } else if (path == kProxySingleHttp) { |
| data = CreateServerHostValue(config.single_proxy); |
| @@ -305,12 +309,12 @@ bool GetProxyPrefValue(const std::string& network_guid, |
| } else if (path == kProxyType) { |
| if (config.mode == UIProxyConfig::MODE_AUTO_DETECT || |
| config.mode == UIProxyConfig::MODE_PAC_SCRIPT) { |
| - data = new base::Value(3); |
| + data = base::MakeUnique<base::Value>(3); |
| } else if (config.mode == UIProxyConfig::MODE_SINGLE_PROXY || |
| config.mode == UIProxyConfig::MODE_PROXY_PER_SCHEME) { |
| - data = new base::Value(2); |
| + data = base::MakeUnique<base::Value>(2); |
| } else { |
| - data = new base::Value(1); |
| + data = base::MakeUnique<base::Value>(1); |
| } |
| switch (config.state) { |
| case ProxyPrefs::CONFIG_POLICY: |
| @@ -328,9 +332,11 @@ bool GetProxyPrefValue(const std::string& network_guid, |
| break; |
| } |
| } else if (path == kProxySingle) { |
| - data = new base::Value(config.mode == UIProxyConfig::MODE_SINGLE_PROXY); |
| + data = base::MakeUnique<base::Value>(config.mode == |
| + UIProxyConfig::MODE_SINGLE_PROXY); |
| } else if (path == kProxyUsePacUrl) { |
| - data = new base::Value(config.mode == UIProxyConfig::MODE_PAC_SCRIPT); |
| + data = base::MakeUnique<base::Value>(config.mode == |
| + UIProxyConfig::MODE_PAC_SCRIPT); |
| } else if (path == kProxyFtpUrl) { |
| data = CreateServerHostValue(config.ftp_proxy); |
| } else if (path == kProxySocks) { |
| @@ -344,11 +350,11 @@ bool GetProxyPrefValue(const std::string& network_guid, |
| } else if (path == kProxySocksPort) { |
| data = CreateServerPortValue(config.socks_proxy); |
| } else if (path == kProxyIgnoreList) { |
| - base::ListValue* list = new base::ListValue(); |
| + auto list = base::MakeUnique<base::ListValue>(); |
| const auto& bypass_rules = config.bypass_rules.rules(); |
| for (const auto& rule : bypass_rules) |
| list->AppendString(rule->ToString()); |
| - data = list; |
| + data = std::move(list); |
| } else { |
| *out_value = NULL; |
| return false; |
| @@ -357,8 +363,8 @@ bool GetProxyPrefValue(const std::string& network_guid, |
| // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. |
| base::DictionaryValue* dict = new base::DictionaryValue; |
| if (!data) |
| - data = new base::Value(""); |
| - dict->Set("value", data); |
| + data = base::MakeUnique<base::Value>(base::Value::Type::STRING); |
| + dict->Set("value", std::move(data)); |
| if (path == kProxyType) { |
| if (!controlled_by.empty()) |
| dict->SetString("controlledBy", controlled_by); |