Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(824)

Unified Diff: chrome/browser/chromeos/proxy_cros_settings_parser.cc

Issue 2765363004: Stop passing raw pointers to DictionaryValue::Set, part 2 (Closed)
Patch Set: Fix comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/chromeos/policy/remote_commands/device_command_screenshot_job_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..be6d08fefc4689a5ecc195d6971e3397b2498875 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,
@@ -279,12 +282,14 @@ void SetProxyPrefValue(const std::string& network_guid,
config_service->SetProxyConfig(network_guid, config);
}
+// TODO(crbug.com/697817): Change |out_value| to be
+// std::unique_ptr<base::Value>*.
bool GetProxyPrefValue(const std::string& network_guid,
const std::string& path,
UIProxyConfigService* config_service,
base::Value** out_value) {
std::string controlled_by;
- base::Value* data = NULL;
+ std::unique_ptr<base::Value> data;
UIProxyConfig config;
config_service->GetProxyConfig(network_guid, &config);
@@ -292,7 +297,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 +311,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 +334,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 +352,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 +365,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);
« no previous file with comments | « chrome/browser/chromeos/policy/remote_commands/device_command_screenshot_job_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698