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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/profiler/scoped_tracker.h" | 8 #include "base/profiler/scoped_tracker.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 // TODO(michaeln): Remove ScopedTracker below once crbug.com/454983 is fixed. | 98 // TODO(michaeln): Remove ScopedTracker below once crbug.com/454983 is fixed. |
99 tracked_objects::ScopedTracker tracking_profile( | 99 tracked_objects::ScopedTracker tracking_profile( |
100 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 100 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
101 "454983 ProxyServiceFactory::CreateProxyService")); | 101 "454983 ProxyServiceFactory::CreateProxyService")); |
102 | 102 |
103 #if defined(OS_IOS) | 103 #if defined(OS_IOS) |
104 bool use_v8 = false; | 104 bool use_v8 = false; |
105 #else | 105 #else |
106 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); | 106 bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); |
107 if (use_v8 && command_line.HasSwitch(switches::kSingleProcess)) { | |
108 // See the note about V8 multithreading in net/proxy/proxy_resolver_v8.h | |
109 // to understand why we have this limitation. | |
110 LOG(ERROR) << "Cannot use V8 Proxy resolver in single process mode."; | |
111 use_v8 = false; // Fallback to non-v8 implementation. | |
112 } | |
113 #endif // defined(OS_IOS) | 107 #endif // defined(OS_IOS) |
114 | 108 |
115 size_t num_pac_threads = 0u; // Use default number of threads. | 109 size_t num_pac_threads = 0u; // Use default number of threads. |
116 | 110 |
117 // Check the command line for an override on the number of proxy resolver | 111 // Check the command line for an override on the number of proxy resolver |
118 // threads to use. | 112 // threads to use. |
119 if (command_line.HasSwitch(switches::kNumPacThreads)) { | 113 if (command_line.HasSwitch(switches::kNumPacThreads)) { |
120 std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads); | 114 std::string s = command_line.GetSwitchValueASCII(switches::kNumPacThreads); |
121 | 115 |
122 // Parse the switch (it should be a positive integer formatted as decimal). | 116 // Parse the switch (it should be a positive integer formatted as decimal). |
123 int n; | 117 int n; |
124 if (base::StringToInt(s, &n) && n > 0) { | 118 if (base::StringToInt(s, &n) && n > 0) { |
125 num_pac_threads = static_cast<size_t>(n); | 119 num_pac_threads = static_cast<size_t>(n); |
126 } else { | 120 } else { |
127 LOG(ERROR) << "Invalid switch for number of PAC threads: " << s; | 121 LOG(ERROR) << "Invalid switch for number of PAC threads: " << s; |
128 } | 122 } |
129 } | 123 } |
130 | 124 |
131 net::ProxyService* proxy_service = NULL; | 125 net::ProxyService* proxy_service = NULL; |
132 if (use_v8) { | 126 if (use_v8) { |
133 #if defined(OS_IOS) | 127 #if defined(OS_IOS) |
134 NOTREACHED(); | 128 NOTREACHED(); |
135 #else | 129 #else |
136 net::ProxyResolverV8::EnsureIsolateCreated(); | |
137 | |
138 net::DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher; | 130 net::DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher; |
139 #if defined(OS_CHROMEOS) | 131 #if defined(OS_CHROMEOS) |
140 dhcp_proxy_script_fetcher = | 132 dhcp_proxy_script_fetcher = |
141 new chromeos::DhcpProxyScriptFetcherChromeos(context); | 133 new chromeos::DhcpProxyScriptFetcherChromeos(context); |
142 #else | 134 #else |
143 net::DhcpProxyScriptFetcherFactory dhcp_factory; | 135 net::DhcpProxyScriptFetcherFactory dhcp_factory; |
144 dhcp_proxy_script_fetcher = dhcp_factory.Create(context); | 136 dhcp_proxy_script_fetcher = dhcp_factory.Create(context); |
145 #endif | 137 #endif |
146 | 138 |
147 proxy_service = net::CreateProxyServiceUsingV8ProxyResolver( | 139 proxy_service = net::CreateProxyServiceUsingV8ProxyResolver( |
148 proxy_config_service, | 140 proxy_config_service, |
149 new net::ProxyScriptFetcherImpl(context), | 141 new net::ProxyScriptFetcherImpl(context), |
150 dhcp_proxy_script_fetcher, | 142 dhcp_proxy_script_fetcher, |
151 context->host_resolver(), | 143 context->host_resolver(), |
152 net_log, | 144 net_log, |
153 network_delegate); | 145 network_delegate); |
154 #endif // defined(OS_IOS) | 146 #endif // defined(OS_IOS) |
155 } else { | 147 } else { |
156 proxy_service = net::ProxyService::CreateUsingSystemProxyResolver( | 148 proxy_service = net::ProxyService::CreateUsingSystemProxyResolver( |
157 proxy_config_service, | 149 proxy_config_service, |
158 num_pac_threads, | 150 num_pac_threads, |
159 net_log); | 151 net_log); |
160 } | 152 } |
161 | 153 |
162 proxy_service->set_quick_check_enabled(quick_check_enabled); | 154 proxy_service->set_quick_check_enabled(quick_check_enabled); |
163 | 155 |
164 return proxy_service; | 156 return proxy_service; |
165 } | 157 } |
OLD | NEW |