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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 NOTREACHED(); | 76 NOTREACHED(); |
77 } | 77 } |
78 | 78 |
79 virtual int SetPacScript( | 79 virtual int SetPacScript( |
80 const scoped_refptr<ProxyResolverScriptData>& /*script_data*/, | 80 const scoped_refptr<ProxyResolverScriptData>& /*script_data*/, |
81 CompletionCallback* /*callback*/) { | 81 CompletionCallback* /*callback*/) { |
82 return ERR_NOT_IMPLEMENTED; | 82 return ERR_NOT_IMPLEMENTED; |
83 } | 83 } |
84 }; | 84 }; |
85 | 85 |
| 86 // ProxyResolver that simulates a PAC script which returns |
| 87 // |pac_string| for every single URL. |
| 88 class ProxyResolverFromPacString : public ProxyResolver { |
| 89 public: |
| 90 ProxyResolverFromPacString(const std::string& pac_string) |
| 91 : ProxyResolver(false /*expects_pac_bytes*/), |
| 92 pac_string_(pac_string) {} |
| 93 |
| 94 virtual int GetProxyForURL(const GURL& url, |
| 95 ProxyInfo* results, |
| 96 CompletionCallback* callback, |
| 97 RequestHandle* request, |
| 98 const BoundNetLog& net_log) { |
| 99 results->UsePacString(pac_string_); |
| 100 return OK; |
| 101 } |
| 102 |
| 103 virtual void CancelRequest(RequestHandle request) { |
| 104 NOTREACHED(); |
| 105 } |
| 106 |
| 107 virtual int SetPacScript( |
| 108 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 109 CompletionCallback* callback) { |
| 110 return OK; |
| 111 } |
| 112 |
| 113 private: |
| 114 const std::string pac_string_; |
| 115 }; |
| 116 |
86 // This factory creates V8ProxyResolvers with appropriate javascript bindings. | 117 // This factory creates V8ProxyResolvers with appropriate javascript bindings. |
87 class ProxyResolverFactoryForV8 : public ProxyResolverFactory { | 118 class ProxyResolverFactoryForV8 : public ProxyResolverFactory { |
88 public: | 119 public: |
89 // |async_host_resolver|, |io_loop| and |net_log| must remain | 120 // |async_host_resolver|, |io_loop| and |net_log| must remain |
90 // valid for the duration of our lifetime. | 121 // valid for the duration of our lifetime. |
91 // Both |async_host_resolver| and |net_log| will only be operated on | 122 // Both |async_host_resolver| and |net_log| will only be operated on |
92 // |io_loop|. | 123 // |io_loop|. |
93 ProxyResolverFactoryForV8(HostResolver* async_host_resolver, | 124 ProxyResolverFactoryForV8(HostResolver* async_host_resolver, |
94 MessageLoop* io_loop, | 125 MessageLoop* io_loop, |
95 NetLog* net_log) | 126 NetLog* net_log) |
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 return Create(new ProxyConfigServiceFixed(pc), false, 0, NULL, NULL, NULL); | 384 return Create(new ProxyConfigServiceFixed(pc), false, 0, NULL, NULL, NULL); |
354 } | 385 } |
355 | 386 |
356 // static | 387 // static |
357 ProxyService* ProxyService::CreateNull() { | 388 ProxyService* ProxyService::CreateNull() { |
358 // Use direct connections. | 389 // Use direct connections. |
359 return new ProxyService(new ProxyConfigServiceDirect, new ProxyResolverNull, | 390 return new ProxyService(new ProxyConfigServiceDirect, new ProxyResolverNull, |
360 NULL); | 391 NULL); |
361 } | 392 } |
362 | 393 |
| 394 // static |
| 395 ProxyService* ProxyService::CreateFixedFromPacResult( |
| 396 const std::string& pac_string) { |
| 397 |
| 398 // We need the settings to contain an "automatic" setting, otherwise the |
| 399 // ProxyResolver dependency we give it will never be used. |
| 400 scoped_ptr<ProxyConfigService> proxy_config_service( |
| 401 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); |
| 402 |
| 403 scoped_ptr<ProxyResolver> proxy_resolver( |
| 404 new ProxyResolverFromPacString(pac_string)); |
| 405 |
| 406 return new ProxyService(proxy_config_service.release(), |
| 407 proxy_resolver.release(), |
| 408 NULL); |
| 409 } |
| 410 |
363 int ProxyService::ResolveProxy(const GURL& raw_url, | 411 int ProxyService::ResolveProxy(const GURL& raw_url, |
364 ProxyInfo* result, | 412 ProxyInfo* result, |
365 CompletionCallback* callback, | 413 CompletionCallback* callback, |
366 PacRequest** pac_request, | 414 PacRequest** pac_request, |
367 const BoundNetLog& net_log) { | 415 const BoundNetLog& net_log) { |
368 DCHECK(callback); | 416 DCHECK(callback); |
369 | 417 |
370 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE, NULL); | 418 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE, NULL); |
371 | 419 |
372 config_service_->OnLazyPoll(); | 420 config_service_->OnLazyPoll(); |
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
774 OnCompletion(result_); | 822 OnCompletion(result_); |
775 } | 823 } |
776 } | 824 } |
777 | 825 |
778 void SyncProxyServiceHelper::OnCompletion(int rv) { | 826 void SyncProxyServiceHelper::OnCompletion(int rv) { |
779 result_ = rv; | 827 result_ = rv; |
780 event_.Signal(); | 828 event_.Signal(); |
781 } | 829 } |
782 | 830 |
783 } // namespace net | 831 } // namespace net |
OLD | NEW |