Commit 9b564109 authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Chromium LUCI CQ

[net] Prepare //net/proxy_resolution/win for base::string16 switch

This change prepares //net/proxy_resolution/win for the switch of
base::string16 to std::u16string.

Bug: 911896
Change-Id: If58c61761969fa355bea533d87b70e393951c7c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2642146
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Reviewed-by: default avatarMatt Menke <mmenke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845647}
parent 7ac76697
...@@ -68,21 +68,22 @@ bool GetProxyServerFromWinHttpResultEntry( ...@@ -68,21 +68,22 @@ bool GetProxyServerFromWinHttpResultEntry(
DCHECK(!!result_entry.pwszProxy); DCHECK(!!result_entry.pwszProxy);
DCHECK(wcslen(result_entry.pwszProxy) > 0); DCHECK(wcslen(result_entry.pwszProxy) > 0);
base::string16 host_wide(result_entry.pwszProxy, std::wstring host_wide(result_entry.pwszProxy,
wcslen(result_entry.pwszProxy)); wcslen(result_entry.pwszProxy));
if (!base::IsStringASCII(host_wide)) { if (!base::IsStringASCII(host_wide)) {
const int kInitialBufferSize = 256; const int kInitialBufferSize = 256;
url::RawCanonOutputT<base::char16, kInitialBufferSize> punycode_output; url::RawCanonOutputT<base::char16, kInitialBufferSize> punycode_output;
if (!url::IDNToASCII(host_wide.data(), host_wide.length(), if (!url::IDNToASCII(base::as_u16cstr(host_wide), host_wide.length(),
&punycode_output)) &punycode_output))
return false; return false;
host_wide.assign(punycode_output.data(), punycode_output.length()); host_wide.assign(base::as_wcstr(punycode_output.data()),
punycode_output.length());
} }
// At this point the string in |host_wide| is ASCII. // At this point the string in |host_wide| is ASCII.
std::string host; std::string host;
if (!base::UTF16ToUTF8(host_wide.data(), host_wide.length(), &host)) if (!base::WideToUTF8(host_wide.data(), host_wide.length(), &host))
return false; return false;
HostPortPair host_and_port(host, result_entry.ProxyPort); HostPortPair host_and_port(host, result_entry.ProxyPort);
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/threading/sequenced_task_runner_handle.h" #include "base/threading/sequenced_task_runner_handle.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
...@@ -38,10 +37,10 @@ namespace { ...@@ -38,10 +37,10 @@ namespace {
constexpr char kUrl[] = "https://example.test:8080/"; constexpr char kUrl[] = "https://example.test:8080/";
void CopySettingToIEProxyConfigString(const base::string16& setting, void CopySettingToIEProxyConfigString(const std::wstring& setting,
LPWSTR* ie_proxy_config_string) { LPWSTR* ie_proxy_config_string) {
*ie_proxy_config_string = static_cast<LPWSTR>( *ie_proxy_config_string = static_cast<LPWSTR>(
GlobalAlloc(GPTR, sizeof(base::char16) * (setting.length() + 1))); GlobalAlloc(GPTR, sizeof(wchar_t) * (setting.length() + 1)));
memcpy(*ie_proxy_config_string, setting.data(), memcpy(*ie_proxy_config_string, setting.data(),
sizeof(wchar_t) * setting.length()); sizeof(wchar_t) * setting.length());
} }
...@@ -150,9 +149,9 @@ class MockWinHttpAPIWrapper : public WinHttpAPIWrapper { ...@@ -150,9 +149,9 @@ class MockWinHttpAPIWrapper : public WinHttpAPIWrapper {
get_ie_proxy_config_success_ = get_ie_proxy_config_success; get_ie_proxy_config_success_ = get_ie_proxy_config_success;
} }
void set_ie_proxy_config(bool is_autoproxy_enabled, void set_ie_proxy_config(bool is_autoproxy_enabled,
const base::string16& pac_url, const std::wstring& pac_url,
const base::string16& proxy, const std::wstring& proxy,
const base::string16& proxy_bypass) { const std::wstring& proxy_bypass) {
is_autoproxy_enabled_ = is_autoproxy_enabled; is_autoproxy_enabled_ = is_autoproxy_enabled;
pac_url_ = pac_url; pac_url_ = pac_url;
proxy_ = proxy; proxy_ = proxy;
...@@ -306,7 +305,7 @@ class MockWinHttpAPIWrapper : public WinHttpAPIWrapper { ...@@ -306,7 +305,7 @@ class MockWinHttpAPIWrapper : public WinHttpAPIWrapper {
break; break;
} }
base::string16 proxy_host(proxy_server.host_port_pair().host().begin(), std::wstring proxy_host(proxy_server.host_port_pair().host().begin(),
proxy_server.host_port_pair().host().end()); proxy_server.host_port_pair().host().end());
proxy_list_.push_back(proxy_host); proxy_list_.push_back(proxy_host);
...@@ -384,11 +383,11 @@ class MockWinHttpAPIWrapper : public WinHttpAPIWrapper { ...@@ -384,11 +383,11 @@ class MockWinHttpAPIWrapper : public WinHttpAPIWrapper {
DWORD callback_status_ = WINHTTP_CALLBACK_STATUS_GETPROXYFORURL_COMPLETE; DWORD callback_status_ = WINHTTP_CALLBACK_STATUS_GETPROXYFORURL_COMPLETE;
std::unique_ptr<WINHTTP_ASYNC_RESULT> callback_info_; std::unique_ptr<WINHTTP_ASYNC_RESULT> callback_info_;
bool is_autoproxy_enabled_ = false; bool is_autoproxy_enabled_ = false;
base::string16 pac_url_; std::wstring pac_url_;
base::string16 proxy_; std::wstring proxy_;
base::string16 proxy_bypass_; std::wstring proxy_bypass_;
WINHTTP_PROXY_RESULT proxy_result_ = {0}; WINHTTP_PROXY_RESULT proxy_result_ = {0};
std::vector<base::string16> proxy_list_; std::vector<std::wstring> proxy_list_;
// Data used internally in the mock to function and validate its own behavior. // Data used internally in the mock to function and validate its own behavior.
bool did_call_open_ = false; bool did_call_open_ = false;
...@@ -521,19 +520,19 @@ class WindowsSystemProxyResolverTest : public TestWithTaskEnvironment { ...@@ -521,19 +520,19 @@ class WindowsSystemProxyResolverTest : public TestWithTaskEnvironment {
ProxyList proxy_list; ProxyList proxy_list;
AddHTTPSProxyToResults(&proxy_list); AddHTTPSProxyToResults(&proxy_list);
base::string16 pac_url; std::wstring pac_url;
if (proxy_config.has_pac_url()) if (proxy_config.has_pac_url())
pac_url = base::UTF8ToUTF16(proxy_config.pac_url().spec()); pac_url = base::UTF8ToWide(proxy_config.pac_url().spec());
base::string16 proxy; std::wstring proxy;
if (!proxy_config.proxy_rules().single_proxies.IsEmpty()) if (!proxy_config.proxy_rules().single_proxies.IsEmpty())
proxy = base::UTF8ToUTF16( proxy = base::UTF8ToWide(
proxy_config.proxy_rules().single_proxies.ToPacString()); proxy_config.proxy_rules().single_proxies.ToPacString());
base::string16 proxy_bypass; std::wstring proxy_bypass;
if (!proxy_config.proxy_rules().bypass_rules.ToString().empty()) if (!proxy_config.proxy_rules().bypass_rules.ToString().empty())
proxy_bypass = proxy_bypass =
base::UTF8ToUTF16(proxy_config.proxy_rules().bypass_rules.ToString()); base::UTF8ToWide(proxy_config.proxy_rules().bypass_rules.ToString());
winhttp_api_wrapper_->set_ie_proxy_config(proxy_config.auto_detect(), winhttp_api_wrapper_->set_ie_proxy_config(proxy_config.auto_detect(),
pac_url, proxy, proxy_bypass); pac_url, proxy, proxy_bypass);
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
#include "net/proxy_resolution/win/winhttp_api_wrapper.h" #include "net/proxy_resolution/win/winhttp_api_wrapper.h"
#include <string>
#include <utility> #include <utility>
#include "base/check_op.h" #include "base/check_op.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string16.h"
#include "net/proxy_resolution/win/winhttp_proxy_resolver_functions.h" #include "net/proxy_resolution/win/winhttp_proxy_resolver_functions.h"
namespace net { namespace net {
...@@ -81,7 +81,7 @@ bool WinHttpAPIWrapper::CallWinHttpGetProxyForUrlEx( ...@@ -81,7 +81,7 @@ bool WinHttpAPIWrapper::CallWinHttpGetProxyForUrlEx(
const std::string& url, const std::string& url,
WINHTTP_AUTOPROXY_OPTIONS* autoproxy_options, WINHTTP_AUTOPROXY_OPTIONS* autoproxy_options,
DWORD_PTR context) { DWORD_PTR context) {
const base::string16 wide_url(url.begin(), url.end()); const std::wstring wide_url(url.begin(), url.end());
// TODO(https://crbug.com/1032820): Upgrade to WinHttpGetProxyForUrlEx2() // TODO(https://crbug.com/1032820): Upgrade to WinHttpGetProxyForUrlEx2()
// if there is a clear reason to do so. // if there is a clear reason to do so.
const DWORD result = const DWORD result =
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment