| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "net/proxy/proxy_resolver_v8.h" | 32 #include "net/proxy/proxy_resolver_v8.h" |
| 33 #include "net/proxy/sync_host_resolver_bridge.h" | 33 #include "net/proxy/sync_host_resolver_bridge.h" |
| 34 #include "net/url_request/url_request_context.h" | 34 #include "net/url_request/url_request_context.h" |
| 35 | 35 |
| 36 using base::TimeDelta; | 36 using base::TimeDelta; |
| 37 using base::TimeTicks; | 37 using base::TimeTicks; |
| 38 | 38 |
| 39 namespace net { | 39 namespace net { |
| 40 | 40 |
| 41 static const size_t kMaxNumNetLogEntries = 100; | 41 static const size_t kMaxNumNetLogEntries = 100; |
| 42 static const size_t kDefaultNumPacThreads = 4; |
| 42 | 43 |
| 43 // Config getter that fails every time. | 44 // Config getter that fails every time. |
| 44 class ProxyConfigServiceNull : public ProxyConfigService { | 45 class ProxyConfigServiceNull : public ProxyConfigService { |
| 45 public: | 46 public: |
| 46 // ProxyConfigService implementation: | 47 // ProxyConfigService implementation: |
| 47 virtual int GetProxyConfig(ProxyConfig* config) { | 48 virtual int GetProxyConfig(ProxyConfig* config) { |
| 48 return ERR_NOT_IMPLEMENTED; | 49 return ERR_NOT_IMPLEMENTED; |
| 49 } | 50 } |
| 50 }; | 51 }; |
| 51 | 52 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 ALLOW_THIS_IN_INITIALIZER_LIST(init_proxy_resolver_callback_( | 258 ALLOW_THIS_IN_INITIALIZER_LIST(init_proxy_resolver_callback_( |
| 258 this, &ProxyService::OnInitProxyResolverComplete)), | 259 this, &ProxyService::OnInitProxyResolverComplete)), |
| 259 net_log_(net_log) { | 260 net_log_(net_log) { |
| 260 NetworkChangeNotifier::AddObserver(this); | 261 NetworkChangeNotifier::AddObserver(this); |
| 261 } | 262 } |
| 262 | 263 |
| 263 // static | 264 // static |
| 264 ProxyService* ProxyService::Create( | 265 ProxyService* ProxyService::Create( |
| 265 ProxyConfigService* proxy_config_service, | 266 ProxyConfigService* proxy_config_service, |
| 266 bool use_v8_resolver, | 267 bool use_v8_resolver, |
| 268 size_t num_pac_threads, |
| 267 URLRequestContext* url_request_context, | 269 URLRequestContext* url_request_context, |
| 268 NetLog* net_log, | 270 NetLog* net_log, |
| 269 MessageLoop* io_loop) { | 271 MessageLoop* io_loop) { |
| 272 if (num_pac_threads == 0) |
| 273 num_pac_threads = kDefaultNumPacThreads; |
| 270 | 274 |
| 271 ProxyResolverFactory* sync_resolver_factory; | 275 ProxyResolverFactory* sync_resolver_factory; |
| 272 if (use_v8_resolver) { | 276 if (use_v8_resolver) { |
| 273 sync_resolver_factory = | 277 sync_resolver_factory = |
| 274 new ProxyResolverFactoryForV8( | 278 new ProxyResolverFactoryForV8( |
| 275 url_request_context->host_resolver(), | 279 url_request_context->host_resolver(), |
| 276 io_loop); | 280 io_loop); |
| 277 } else { | 281 } else { |
| 278 sync_resolver_factory = new ProxyResolverFactoryForNonV8(); | 282 sync_resolver_factory = new ProxyResolverFactoryForNonV8(); |
| 279 } | 283 } |
| 280 | 284 |
| 281 const size_t kMaxNumResolverThreads = 1u; | |
| 282 ProxyResolver* proxy_resolver = | 285 ProxyResolver* proxy_resolver = |
| 283 new MultiThreadedProxyResolver(sync_resolver_factory, | 286 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads); |
| 284 kMaxNumResolverThreads); | |
| 285 | 287 |
| 286 ProxyService* proxy_service = | 288 ProxyService* proxy_service = |
| 287 new ProxyService(proxy_config_service, proxy_resolver, net_log); | 289 new ProxyService(proxy_config_service, proxy_resolver, net_log); |
| 288 | 290 |
| 289 if (proxy_resolver->expects_pac_bytes()) { | 291 if (proxy_resolver->expects_pac_bytes()) { |
| 290 // Configure PAC script downloads to be issued using |url_request_context|. | 292 // Configure PAC script downloads to be issued using |url_request_context|. |
| 291 DCHECK(url_request_context); | 293 DCHECK(url_request_context); |
| 292 proxy_service->SetProxyScriptFetcher( | 294 proxy_service->SetProxyScriptFetcher( |
| 293 ProxyScriptFetcher::Create(url_request_context)); | 295 ProxyScriptFetcher::Create(url_request_context)); |
| 294 } | 296 } |
| 295 | 297 |
| 296 return proxy_service; | 298 return proxy_service; |
| 297 } | 299 } |
| 298 | 300 |
| 299 // static | 301 // static |
| 300 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { | 302 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { |
| 301 return Create(new ProxyConfigServiceFixed(pc), false, NULL, NULL, NULL); | 303 // TODO(eroman): This isn't quite right, won't work if |pc| specifies |
| 304 // a PAC script. |
| 305 return Create(new ProxyConfigServiceFixed(pc), false, 0, NULL, NULL, NULL); |
| 302 } | 306 } |
| 303 | 307 |
| 304 // static | 308 // static |
| 305 ProxyService* ProxyService::CreateNull() { | 309 ProxyService* ProxyService::CreateNull() { |
| 306 // Use a configuration fetcher and proxy resolver which always fail. | 310 // Use a configuration fetcher and proxy resolver which always fail. |
| 307 return new ProxyService(new ProxyConfigServiceNull, new ProxyResolverNull, | 311 return new ProxyService(new ProxyConfigServiceNull, new ProxyResolverNull, |
| 308 NULL); | 312 NULL); |
| 309 } | 313 } |
| 310 | 314 |
| 311 int ProxyService::ResolveProxy(const GURL& raw_url, | 315 int ProxyService::ResolveProxy(const GURL& raw_url, |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 OnCompletion(result_); | 760 OnCompletion(result_); |
| 757 } | 761 } |
| 758 } | 762 } |
| 759 | 763 |
| 760 void SyncProxyServiceHelper::OnCompletion(int rv) { | 764 void SyncProxyServiceHelper::OnCompletion(int rv) { |
| 761 result_ = rv; | 765 result_ = rv; |
| 762 event_.Signal(); | 766 event_.Signal(); |
| 763 } | 767 } |
| 764 | 768 |
| 765 } // namespace net | 769 } // namespace net |
| OLD | NEW |