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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 | 186 |
187 private: | 187 private: |
188 HostResolver* const async_host_resolver_; | 188 HostResolver* const async_host_resolver_; |
189 MessageLoop* io_loop_; | 189 MessageLoop* io_loop_; |
190 | 190 |
191 // Thread-safe wrapper around a non-threadsafe NetLog implementation. This | 191 // Thread-safe wrapper around a non-threadsafe NetLog implementation. This |
192 // enables the proxy resolver to emit log messages from the PAC thread. | 192 // enables the proxy resolver to emit log messages from the PAC thread. |
193 scoped_ptr<ForwardingNetLog> forwarding_net_log_; | 193 scoped_ptr<ForwardingNetLog> forwarding_net_log_; |
194 }; | 194 }; |
195 | 195 |
196 // Creates ProxyResolvers using a non-V8 implementation. | 196 // Creates ProxyResolvers using a platform-specific implementation. |
197 class ProxyResolverFactoryForNonV8 : public ProxyResolverFactory { | 197 class ProxyResolverFactoryForSystem : public ProxyResolverFactory { |
198 public: | 198 public: |
199 ProxyResolverFactoryForNonV8() | 199 ProxyResolverFactoryForSystem() |
200 : ProxyResolverFactory(false /*expects_pac_bytes*/) {} | 200 : ProxyResolverFactory(false /*expects_pac_bytes*/) {} |
201 | 201 |
202 virtual ProxyResolver* CreateProxyResolver() { | 202 virtual ProxyResolver* CreateProxyResolver() { |
| 203 DCHECK(IsSupported()); |
203 #if defined(OS_WIN) | 204 #if defined(OS_WIN) |
204 return new ProxyResolverWinHttp(); | 205 return new ProxyResolverWinHttp(); |
205 #elif defined(OS_MACOSX) | 206 #elif defined(OS_MACOSX) |
206 return new ProxyResolverMac(); | 207 return new ProxyResolverMac(); |
207 #else | 208 #else |
208 LOG(WARNING) << "PAC support disabled because there is no fallback " | 209 NOTREACHED(); |
209 "non-V8 implementation"; | 210 return NULL; |
210 return new ProxyResolverNull(); | 211 #endif |
| 212 } |
| 213 |
| 214 static bool IsSupported() { |
| 215 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 216 return true; |
| 217 #else |
| 218 return false; |
211 #endif | 219 #endif |
212 } | 220 } |
213 }; | 221 }; |
214 | 222 |
215 // NetLog parameter to describe a proxy configuration change. | 223 // NetLog parameter to describe a proxy configuration change. |
216 class ProxyConfigChangedNetLogParam : public NetLog::EventParameters { | 224 class ProxyConfigChangedNetLogParam : public NetLog::EventParameters { |
217 public: | 225 public: |
218 ProxyConfigChangedNetLogParam(const ProxyConfig& old_config, | 226 ProxyConfigChangedNetLogParam(const ProxyConfig& old_config, |
219 const ProxyConfig& new_config) | 227 const ProxyConfig& new_config) |
220 : old_config_(old_config), | 228 : old_config_(old_config), |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 current_state_(STATE_NONE) , | 382 current_state_(STATE_NONE) , |
375 net_log_(net_log), | 383 net_log_(net_log), |
376 stall_proxy_auto_config_delay_( | 384 stall_proxy_auto_config_delay_( |
377 base::TimeDelta::FromMilliseconds( | 385 base::TimeDelta::FromMilliseconds( |
378 kNumMillisToStallAfterNetworkChanges)) { | 386 kNumMillisToStallAfterNetworkChanges)) { |
379 NetworkChangeNotifier::AddObserver(this); | 387 NetworkChangeNotifier::AddObserver(this); |
380 ResetConfigService(config_service); | 388 ResetConfigService(config_service); |
381 } | 389 } |
382 | 390 |
383 // static | 391 // static |
384 ProxyService* ProxyService::Create( | 392 ProxyService* ProxyService::CreateUsingV8ProxyResolver( |
385 ProxyConfigService* proxy_config_service, | 393 ProxyConfigService* proxy_config_service, |
386 bool use_v8_resolver, | |
387 size_t num_pac_threads, | 394 size_t num_pac_threads, |
388 URLRequestContext* url_request_context, | 395 URLRequestContext* url_request_context, |
389 NetLog* net_log, | 396 NetLog* net_log, |
390 MessageLoop* io_loop) { | 397 MessageLoop* io_loop) { |
| 398 DCHECK(proxy_config_service); |
| 399 DCHECK(url_request_context); |
| 400 DCHECK(io_loop); |
| 401 |
391 if (num_pac_threads == 0) | 402 if (num_pac_threads == 0) |
392 num_pac_threads = kDefaultNumPacThreads; | 403 num_pac_threads = kDefaultNumPacThreads; |
393 | 404 |
394 ProxyResolverFactory* sync_resolver_factory; | 405 ProxyResolverFactory* sync_resolver_factory = |
395 if (use_v8_resolver) { | 406 new ProxyResolverFactoryForV8( |
396 sync_resolver_factory = | 407 url_request_context->host_resolver(), |
397 new ProxyResolverFactoryForV8( | 408 io_loop, |
398 url_request_context->host_resolver(), | 409 net_log); |
399 io_loop, | |
400 net_log); | |
401 } else { | |
402 sync_resolver_factory = new ProxyResolverFactoryForNonV8(); | |
403 } | |
404 | 410 |
405 ProxyResolver* proxy_resolver = | 411 ProxyResolver* proxy_resolver = |
406 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads); | 412 new MultiThreadedProxyResolver(sync_resolver_factory, num_pac_threads); |
407 | 413 |
408 ProxyService* proxy_service = | 414 ProxyService* proxy_service = |
409 new ProxyService(proxy_config_service, proxy_resolver, net_log); | 415 new ProxyService(proxy_config_service, proxy_resolver, net_log); |
410 | 416 |
411 if (proxy_resolver->expects_pac_bytes()) { | 417 // Configure PAC script downloads to be issued using |url_request_context|. |
412 // Configure PAC script downloads to be issued using |url_request_context|. | 418 proxy_service->SetProxyScriptFetcher( |
413 DCHECK(url_request_context); | 419 ProxyScriptFetcher::Create(url_request_context)); |
414 proxy_service->SetProxyScriptFetcher( | 420 |
415 ProxyScriptFetcher::Create(url_request_context)); | 421 return proxy_service; |
| 422 } |
| 423 |
| 424 // static |
| 425 ProxyService* ProxyService::CreateUsingSystemProxyResolver( |
| 426 ProxyConfigService* proxy_config_service, |
| 427 size_t num_pac_threads, |
| 428 NetLog* net_log) { |
| 429 DCHECK(proxy_config_service); |
| 430 |
| 431 if (!ProxyResolverFactoryForSystem::IsSupported()) { |
| 432 LOG(WARNING) << "PAC support disabled because there is no " |
| 433 "system implementation"; |
| 434 return CreateWithoutProxyResolver(proxy_config_service, net_log); |
416 } | 435 } |
417 | 436 |
418 return proxy_service; | 437 if (num_pac_threads == 0) |
| 438 num_pac_threads = kDefaultNumPacThreads; |
| 439 |
| 440 ProxyResolver* proxy_resolver = new MultiThreadedProxyResolver( |
| 441 new ProxyResolverFactoryForSystem(), num_pac_threads); |
| 442 |
| 443 return new ProxyService(proxy_config_service, proxy_resolver, net_log); |
| 444 } |
| 445 |
| 446 // static |
| 447 ProxyService* ProxyService::CreateWithoutProxyResolver( |
| 448 ProxyConfigService* proxy_config_service, |
| 449 NetLog* net_log) { |
| 450 return new ProxyService(proxy_config_service, |
| 451 new ProxyResolverNull(), |
| 452 net_log); |
419 } | 453 } |
420 | 454 |
421 // static | 455 // static |
422 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { | 456 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { |
423 // TODO(eroman): This isn't quite right, won't work if |pc| specifies | 457 // TODO(eroman): This isn't quite right, won't work if |pc| specifies |
424 // a PAC script. | 458 // a PAC script. |
425 return Create(new ProxyConfigServiceFixed(pc), false, 0, NULL, NULL, NULL); | 459 return CreateUsingSystemProxyResolver(new ProxyConfigServiceFixed(pc), |
| 460 0, NULL); |
426 } | 461 } |
427 | 462 |
428 // static | 463 // static |
429 ProxyService* ProxyService::CreateDirect() { | 464 ProxyService* ProxyService::CreateDirect() { |
430 // Use direct connections. | 465 // Use direct connections. |
431 return new ProxyService(new ProxyConfigServiceDirect, new ProxyResolverNull, | 466 return new ProxyService(new ProxyConfigServiceDirect, new ProxyResolverNull, |
432 NULL); | 467 NULL); |
433 } | 468 } |
434 | 469 |
435 // static | 470 // static |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
896 OnCompletion(result_); | 931 OnCompletion(result_); |
897 } | 932 } |
898 } | 933 } |
899 | 934 |
900 void SyncProxyServiceHelper::OnCompletion(int rv) { | 935 void SyncProxyServiceHelper::OnCompletion(int rv) { |
901 result_ = rv; | 936 result_ = rv; |
902 event_.Signal(); | 937 event_.Signal(); |
903 } | 938 } |
904 | 939 |
905 } // namespace net | 940 } // namespace net |
OLD | NEW |