OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/proxy_service_factory.h" | 5 #include "chrome/browser/net/proxy_service_factory.h" |
6 | 6 |
| 7 #include <stddef.h> |
| 8 #include <string> |
| 9 #include <utility> |
| 10 |
| 11 #include "base/command_line.h" |
| 12 #include "base/metrics/field_trial.h" |
| 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/threading/thread.h" |
7 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/io_thread.h" |
| 18 #include "chrome/browser/net/chrome_mojo_proxy_resolver_factory.h" |
| 19 #include "chrome/common/chrome_switches.h" |
8 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | 20 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" |
9 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/common/content_switches.h" |
| 23 #include "net/proxy/dhcp_proxy_script_fetcher_factory.h" |
10 #include "net/proxy/proxy_config_service.h" | 24 #include "net/proxy/proxy_config_service.h" |
| 25 #include "net/proxy/proxy_script_fetcher_impl.h" |
11 #include "net/proxy/proxy_service.h" | 26 #include "net/proxy/proxy_service.h" |
| 27 #include "net/proxy/proxy_service_mojo.h" |
| 28 #include "net/url_request/url_request_context.h" |
12 | 29 |
13 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
| 31 #include "chromeos/network/dhcp_proxy_script_fetcher_chromeos.h" |
14 #include "chromeos/network/proxy/proxy_config_service_impl.h" | 32 #include "chromeos/network/proxy/proxy_config_service_impl.h" |
15 #endif // defined(OS_CHROMEOS) | 33 #endif // defined(OS_CHROMEOS) |
16 | 34 |
17 using content::BrowserThread; | 35 using content::BrowserThread; |
18 | 36 |
19 // static | 37 // static |
20 std::unique_ptr<net::ProxyConfigService> | 38 std::unique_ptr<net::ProxyConfigService> |
21 ProxyServiceFactory::CreateProxyConfigService(PrefProxyConfigTracker* tracker) { | 39 ProxyServiceFactory::CreateProxyConfigService(PrefProxyConfigTracker* tracker) { |
22 // The linux gconf-based proxy settings getter relies on being initialized | 40 // The linux gconf-based proxy settings getter relies on being initialized |
23 // from the UI thread. | 41 // from the UI thread. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 #if defined(OS_CHROMEOS) | 81 #if defined(OS_CHROMEOS) |
64 return new chromeos::ProxyConfigServiceImpl( | 82 return new chromeos::ProxyConfigServiceImpl( |
65 nullptr, local_state_prefs, | 83 nullptr, local_state_prefs, |
66 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 84 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
67 #else | 85 #else |
68 return new PrefProxyConfigTrackerImpl( | 86 return new PrefProxyConfigTrackerImpl( |
69 local_state_prefs, | 87 local_state_prefs, |
70 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); | 88 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)); |
71 #endif // defined(OS_CHROMEOS) | 89 #endif // defined(OS_CHROMEOS) |
72 } | 90 } |
| 91 |
| 92 // static |
| 93 std::unique_ptr<net::ProxyService> ProxyServiceFactory::CreateProxyService( |
| 94 net::NetLog* net_log, |
| 95 net::URLRequestContext* context, |
| 96 net::NetworkDelegate* network_delegate, |
| 97 std::unique_ptr<net::ProxyConfigService> proxy_config_service, |
| 98 const base::CommandLine& command_line, |
| 99 bool quick_check_enabled, |
| 100 bool pac_https_url_stripping_enabled) { |
| 101 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 102 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); |
| 103 // TODO(eroman): Figure out why this doesn't work in single-process mode. |
| 104 // Should be possible now that a private isolate is used. |
| 105 // http://crbug.com/474654 |
| 106 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { |
| 107 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; |
| 108 use_v8 = false; // Fallback to non-v8 implementation. |
| 109 } |
| 110 |
| 111 std::unique_ptr<net::ProxyService> proxy_service; |
| 112 if (use_v8) { |
| 113 std::unique_ptr<net::DhcpProxyScriptFetcher> dhcp_proxy_script_fetcher; |
| 114 #if defined(OS_CHROMEOS) |
| 115 dhcp_proxy_script_fetcher.reset( |
| 116 new chromeos::DhcpProxyScriptFetcherChromeos(context)); |
| 117 #else |
| 118 net::DhcpProxyScriptFetcherFactory dhcp_factory; |
| 119 dhcp_proxy_script_fetcher = dhcp_factory.Create(context); |
| 120 #endif |
| 121 |
| 122 proxy_service = net::CreateProxyServiceUsingMojoFactory( |
| 123 ChromeMojoProxyResolverFactory::GetInstance(), |
| 124 std::move(proxy_config_service), |
| 125 new net::ProxyScriptFetcherImpl(context), |
| 126 std::move(dhcp_proxy_script_fetcher), context->host_resolver(), net_log, |
| 127 network_delegate); |
| 128 } else { |
| 129 proxy_service = net::ProxyService::CreateUsingSystemProxyResolver( |
| 130 std::move(proxy_config_service), net_log); |
| 131 } |
| 132 |
| 133 proxy_service->set_quick_check_enabled(quick_check_enabled); |
| 134 proxy_service->set_sanitize_url_policy( |
| 135 pac_https_url_stripping_enabled |
| 136 ? net::ProxyService::SanitizeUrlPolicy::SAFE |
| 137 : net::ProxyService::SanitizeUrlPolicy::UNSAFE); |
| 138 |
| 139 return proxy_service; |
| 140 } |
OLD | NEW |