OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 next_config_id_(1), | 200 next_config_id_(1), |
201 config_is_bad_(false), | 201 config_is_bad_(false), |
202 ALLOW_THIS_IN_INITIALIZER_LIST(proxy_script_fetcher_callback_( | 202 ALLOW_THIS_IN_INITIALIZER_LIST(proxy_script_fetcher_callback_( |
203 this, &ProxyService::OnScriptFetchCompletion)), | 203 this, &ProxyService::OnScriptFetchCompletion)), |
204 fetched_pac_config_id_(ProxyConfig::INVALID_ID), | 204 fetched_pac_config_id_(ProxyConfig::INVALID_ID), |
205 fetched_pac_error_(OK), | 205 fetched_pac_error_(OK), |
206 in_progress_fetch_config_id_(ProxyConfig::INVALID_ID) { | 206 in_progress_fetch_config_id_(ProxyConfig::INVALID_ID) { |
207 } | 207 } |
208 | 208 |
209 // static | 209 // static |
210 ProxyService* ProxyService::Create(const ProxyConfig* pc) { | 210 ProxyService* ProxyService::Create( |
| 211 const ProxyConfig* pc, |
| 212 bool use_v8_resolver, |
| 213 URLRequestContext* url_request_context, |
| 214 MessageLoop* io_loop) { |
211 // Choose the system configuration service appropriate for each platform. | 215 // Choose the system configuration service appropriate for each platform. |
212 ProxyConfigService* proxy_config_service = pc ? | 216 ProxyConfigService* proxy_config_service = pc ? |
213 new ProxyConfigServiceFixed(*pc) : | 217 new ProxyConfigServiceFixed(*pc) : |
214 CreateSystemProxyConfigService(); | 218 CreateSystemProxyConfigService(io_loop); |
215 | 219 |
216 // Try to choose a non-v8 proxy resolver implementation. | 220 ProxyResolver* proxy_resolver = use_v8_resolver ? |
217 return new ProxyService(proxy_config_service, CreateNonV8ProxyResolver()); | 221 new ProxyResolverV8() : CreateNonV8ProxyResolver(); |
| 222 |
| 223 ProxyService* proxy_service = new ProxyService( |
| 224 proxy_config_service, proxy_resolver); |
| 225 |
| 226 if (!proxy_resolver->does_fetch()) { |
| 227 // Configure PAC script downloads to be issued using |url_request_context|. |
| 228 DCHECK(url_request_context); |
| 229 proxy_service->SetProxyScriptFetcher( |
| 230 ProxyScriptFetcher::Create(url_request_context)); |
| 231 } |
| 232 |
| 233 return proxy_service; |
218 } | 234 } |
219 | 235 |
220 // static | 236 // static |
221 ProxyService* ProxyService::CreateUsingV8Resolver( | 237 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { |
222 const ProxyConfig* pc, URLRequestContext* url_request_context) { | 238 return Create(&pc, false, NULL, NULL); |
223 // Choose the system configuration service appropriate for each platform. | |
224 ProxyConfigService* proxy_config_service = pc ? | |
225 new ProxyConfigServiceFixed(*pc) : | |
226 CreateSystemProxyConfigService(); | |
227 | |
228 // Create a ProxyService that uses V8 to evaluate PAC scripts. | |
229 ProxyService* proxy_service = new ProxyService( | |
230 proxy_config_service, new ProxyResolverV8()); | |
231 | |
232 // Configure PAC script downloads to be issued using |url_request_context|. | |
233 proxy_service->SetProxyScriptFetcher( | |
234 ProxyScriptFetcher::Create(url_request_context)); | |
235 | |
236 return proxy_service; | |
237 } | 239 } |
238 | 240 |
239 // static | 241 // static |
240 ProxyService* ProxyService::CreateNull() { | 242 ProxyService* ProxyService::CreateNull() { |
241 // Use a configuration fetcher and proxy resolver which always fail. | 243 // Use a configuration fetcher and proxy resolver which always fail. |
242 return new ProxyService(new ProxyConfigServiceNull, new ProxyResolverNull); | 244 return new ProxyService(new ProxyConfigServiceNull, new ProxyResolverNull); |
243 } | 245 } |
244 | 246 |
245 int ProxyService::ResolveProxy(const GURL& url, ProxyInfo* result, | 247 int ProxyService::ResolveProxy(const GURL& url, ProxyInfo* result, |
246 CompletionCallback* callback, | 248 CompletionCallback* callback, |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 | 524 |
523 // Our config may have already changed. | 525 // Our config may have already changed. |
524 if (result_code == OK || config_id != config_.id()) | 526 if (result_code == OK || config_id != config_.id()) |
525 return; | 527 return; |
526 | 528 |
527 // Remember that this configuration doesn't work. | 529 // Remember that this configuration doesn't work. |
528 config_is_bad_ = true; | 530 config_is_bad_ = true; |
529 } | 531 } |
530 | 532 |
531 // static | 533 // static |
532 ProxyConfigService* ProxyService::CreateSystemProxyConfigService() { | 534 ProxyConfigService* ProxyService::CreateSystemProxyConfigService( |
| 535 MessageLoop* io_loop) { |
533 #if defined(OS_WIN) | 536 #if defined(OS_WIN) |
534 return new ProxyConfigServiceWin(); | 537 return new ProxyConfigServiceWin(); |
535 #elif defined(OS_MACOSX) | 538 #elif defined(OS_MACOSX) |
536 return new ProxyConfigServiceMac(); | 539 return new ProxyConfigServiceMac(); |
537 #elif defined(OS_LINUX) | 540 #elif defined(OS_LINUX) |
538 return new ProxyConfigServiceLinux(); | 541 ProxyConfigServiceLinux* linux_config_service |
| 542 = new ProxyConfigServiceLinux(); |
| 543 |
| 544 // Assume we got called from the UI loop, which runs the default |
| 545 // glib main loop, so the current thread is where we should be |
| 546 // running gconf calls from. |
| 547 MessageLoop* glib_default_loop = MessageLoopForUI::current(); |
| 548 |
| 549 // Synchronously fetch the current proxy config (since we are |
| 550 // running on glib_default_loop). Additionally register for gconf |
| 551 // notifications (delivered in |glib_default_loop|) to keep us |
| 552 // updated on when the proxy config has changed. |
| 553 linux_config_service->SetupAndFetchInitialConfig(glib_default_loop, io_loop); |
| 554 |
| 555 return linux_config_service; |
539 #else | 556 #else |
540 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " | 557 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " |
541 "for this platform."; | 558 "for this platform."; |
542 return new ProxyConfigServiceNull(); | 559 return new ProxyConfigServiceNull(); |
543 #endif | 560 #endif |
544 } | 561 } |
545 | 562 |
546 // static | 563 // static |
547 ProxyResolver* ProxyService::CreateNonV8ProxyResolver() { | 564 ProxyResolver* ProxyService::CreateNonV8ProxyResolver() { |
548 #if defined(OS_WIN) | 565 #if defined(OS_WIN) |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 OnCompletion(result_); | 743 OnCompletion(result_); |
727 } | 744 } |
728 } | 745 } |
729 | 746 |
730 void SyncProxyServiceHelper::OnCompletion(int rv) { | 747 void SyncProxyServiceHelper::OnCompletion(int rv) { |
731 result_ = rv; | 748 result_ = rv; |
732 event_.Signal(); | 749 event_.Signal(); |
733 } | 750 } |
734 | 751 |
735 } // namespace net | 752 } // namespace net |
OLD | NEW |