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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 void CancelResolveJob() { | 124 void CancelResolveJob() { |
125 DCHECK(is_started()); | 125 DCHECK(is_started()); |
126 // The request may already be running in the resolver. | 126 // The request may already be running in the resolver. |
127 resolver()->CancelRequest(resolve_job_); | 127 resolver()->CancelRequest(resolve_job_); |
128 resolve_job_ = NULL; | 128 resolve_job_ = NULL; |
129 DCHECK(!is_started()); | 129 DCHECK(!is_started()); |
130 } | 130 } |
131 | 131 |
132 void Cancel() { | 132 void Cancel() { |
133 net_log_.AddEvent(NetLog::TYPE_CANCELLED); | 133 net_log_.AddEvent(NetLog::TYPE_CANCELLED, NULL); |
134 | 134 |
135 if (is_started()) | 135 if (is_started()) |
136 CancelResolveJob(); | 136 CancelResolveJob(); |
137 | 137 |
138 // Mark as cancelled, to prevent accessing this again later. | 138 // Mark as cancelled, to prevent accessing this again later. |
139 service_ = NULL; | 139 service_ = NULL; |
140 user_callback_ = NULL; | 140 user_callback_ = NULL; |
141 results_ = NULL; | 141 results_ = NULL; |
142 | 142 |
143 net_log_.EndEvent(NetLog::TYPE_PROXY_SERVICE); | 143 net_log_.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL); |
144 } | 144 } |
145 | 145 |
146 // Returns true if Cancel() has been called. | 146 // Returns true if Cancel() has been called. |
147 bool was_cancelled() const { return user_callback_ == NULL; } | 147 bool was_cancelled() const { return user_callback_ == NULL; } |
148 | 148 |
149 // Helper to call after ProxyResolver completion (both synchronous and | 149 // Helper to call after ProxyResolver completion (both synchronous and |
150 // asynchronous). Fixes up the result that is to be returned to user. | 150 // asynchronous). Fixes up the result that is to be returned to user. |
151 int QueryDidComplete(int result_code) { | 151 int QueryDidComplete(int result_code) { |
152 DCHECK(!was_cancelled()); | 152 DCHECK(!was_cancelled()); |
153 | 153 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 BoundNetLog()); | 278 BoundNetLog()); |
279 } | 279 } |
280 | 280 |
281 int ProxyService::ResolveProxy(const GURL& raw_url, | 281 int ProxyService::ResolveProxy(const GURL& raw_url, |
282 ProxyInfo* result, | 282 ProxyInfo* result, |
283 CompletionCallback* callback, | 283 CompletionCallback* callback, |
284 PacRequest** pac_request, | 284 PacRequest** pac_request, |
285 const BoundNetLog& net_log) { | 285 const BoundNetLog& net_log) { |
286 DCHECK(callback); | 286 DCHECK(callback); |
287 | 287 |
288 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE); | 288 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE, NULL); |
289 | 289 |
290 // Strip away any reference fragments and the username/password, as they | 290 // Strip away any reference fragments and the username/password, as they |
291 // are not relevant to proxy resolution. | 291 // are not relevant to proxy resolution. |
292 GURL url = SimplifyUrlForRequest(raw_url); | 292 GURL url = SimplifyUrlForRequest(raw_url); |
293 | 293 |
294 // Check if the request can be completed right away. This is the case when | 294 // Check if the request can be completed right away. This is the case when |
295 // using a direct connection, or when the config is bad. | 295 // using a direct connection, or when the config is bad. |
296 UpdateConfigIfOld(net_log); | 296 UpdateConfigIfOld(net_log); |
297 int rv = TryToCompleteSynchronously(url, result); | 297 int rv = TryToCompleteSynchronously(url, result); |
298 if (rv != ERR_IO_PENDING) | 298 if (rv != ERR_IO_PENDING) |
299 return DidFinishResolvingProxy(result, rv, net_log); | 299 return DidFinishResolvingProxy(result, rv, net_log); |
300 | 300 |
301 scoped_refptr<PacRequest> req = | 301 scoped_refptr<PacRequest> req = |
302 new PacRequest(this, url, result, callback, net_log); | 302 new PacRequest(this, url, result, callback, net_log); |
303 | 303 |
304 bool resolver_is_ready = !IsInitializingProxyResolver(); | 304 bool resolver_is_ready = !IsInitializingProxyResolver(); |
305 | 305 |
306 if (resolver_is_ready) { | 306 if (resolver_is_ready) { |
307 // Start the resolve request. | 307 // Start the resolve request. |
308 rv = req->Start(); | 308 rv = req->Start(); |
309 if (rv != ERR_IO_PENDING) | 309 if (rv != ERR_IO_PENDING) |
310 return req->QueryDidComplete(rv); | 310 return req->QueryDidComplete(rv); |
311 } else { | 311 } else { |
312 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); | 312 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC, |
| 313 NULL); |
313 } | 314 } |
314 | 315 |
315 DCHECK_EQ(ERR_IO_PENDING, rv); | 316 DCHECK_EQ(ERR_IO_PENDING, rv); |
316 DCHECK(!ContainsPendingRequest(req)); | 317 DCHECK(!ContainsPendingRequest(req)); |
317 pending_requests_.push_back(req); | 318 pending_requests_.push_back(req); |
318 | 319 |
319 // Completion will be notifed through |callback|, unless the caller cancels | 320 // Completion will be notifed through |callback|, unless the caller cancels |
320 // the request using |pac_request|. | 321 // the request using |pac_request|. |
321 if (pac_request) | 322 if (pac_request) |
322 *pac_request = req.get(); | 323 *pac_request = req.get(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 | 359 |
359 void ProxyService::SuspendAllPendingRequests() { | 360 void ProxyService::SuspendAllPendingRequests() { |
360 for (PendingRequests::iterator it = pending_requests_.begin(); | 361 for (PendingRequests::iterator it = pending_requests_.begin(); |
361 it != pending_requests_.end(); | 362 it != pending_requests_.end(); |
362 ++it) { | 363 ++it) { |
363 PacRequest* req = it->get(); | 364 PacRequest* req = it->get(); |
364 if (req->is_started()) { | 365 if (req->is_started()) { |
365 req->CancelResolveJob(); | 366 req->CancelResolveJob(); |
366 | 367 |
367 req->net_log()->BeginEvent( | 368 req->net_log()->BeginEvent( |
368 NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); | 369 NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC, NULL); |
369 } | 370 } |
370 } | 371 } |
371 } | 372 } |
372 | 373 |
373 void ProxyService::ResumeAllPendingRequests() { | 374 void ProxyService::ResumeAllPendingRequests() { |
374 DCHECK(!IsInitializingProxyResolver()); | 375 DCHECK(!IsInitializingProxyResolver()); |
375 | 376 |
376 // Make a copy in case |this| is deleted during the synchronous completion | 377 // Make a copy in case |this| is deleted during the synchronous completion |
377 // of one of the requests. If |this| is deleted then all of the PacRequest | 378 // of one of the requests. If |this| is deleted then all of the PacRequest |
378 // instances will be Cancel()-ed. | 379 // instances will be Cancel()-ed. |
379 PendingRequests pending_copy = pending_requests_; | 380 PendingRequests pending_copy = pending_requests_; |
380 | 381 |
381 for (PendingRequests::iterator it = pending_copy.begin(); | 382 for (PendingRequests::iterator it = pending_copy.begin(); |
382 it != pending_copy.end(); | 383 it != pending_copy.end(); |
383 ++it) { | 384 ++it) { |
384 PacRequest* req = it->get(); | 385 PacRequest* req = it->get(); |
385 if (!req->is_started() && !req->was_cancelled()) { | 386 if (!req->is_started() && !req->was_cancelled()) { |
386 req->net_log()->EndEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); | 387 req->net_log()->EndEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC, |
| 388 NULL); |
387 | 389 |
388 // Note that we re-check for synchronous completion, in case we are | 390 // Note that we re-check for synchronous completion, in case we are |
389 // no longer using a ProxyResolver (can happen if we fell-back to manual). | 391 // no longer using a ProxyResolver (can happen if we fell-back to manual). |
390 req->StartAndCompleteCheckingForSynchronous(); | 392 req->StartAndCompleteCheckingForSynchronous(); |
391 } | 393 } |
392 } | 394 } |
393 } | 395 } |
394 | 396 |
395 void ProxyService::OnInitProxyResolverComplete(int result) { | 397 void ProxyService::OnInitProxyResolverComplete(int result) { |
396 DCHECK(init_proxy_resolver_.get()); | 398 DCHECK(init_proxy_resolver_.get()); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 pending_requests_.erase(it); | 464 pending_requests_.erase(it); |
463 } | 465 } |
464 | 466 |
465 int ProxyService::DidFinishResolvingProxy(ProxyInfo* result, | 467 int ProxyService::DidFinishResolvingProxy(ProxyInfo* result, |
466 int result_code, | 468 int result_code, |
467 const BoundNetLog& net_log) { | 469 const BoundNetLog& net_log) { |
468 // Log the result of the proxy resolution. | 470 // Log the result of the proxy resolution. |
469 if (result_code == OK) { | 471 if (result_code == OK) { |
470 // When full logging is enabled, dump the proxy list. | 472 // When full logging is enabled, dump the proxy list. |
471 if (net_log.HasListener()) { | 473 if (net_log.HasListener()) { |
472 net_log.AddEventWithString( | 474 net_log.AddEvent( |
473 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 475 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
474 "pac_string", result->ToPacString()); | 476 new NetLogStringParameter("pac_string", result->ToPacString())); |
475 } | 477 } |
476 result->DeprioritizeBadProxies(proxy_retry_info_); | 478 result->DeprioritizeBadProxies(proxy_retry_info_); |
477 } else { | 479 } else { |
478 net_log.AddEventWithInteger( | 480 net_log.AddEvent( |
479 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, | 481 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, |
480 "net_error", result_code); | 482 new NetLogIntegerParameter("net_error", result_code)); |
481 | 483 |
482 // Fall-back to direct when the proxy resolver fails. This corresponds | 484 // Fall-back to direct when the proxy resolver fails. This corresponds |
483 // with a javascript runtime error in the PAC script. | 485 // with a javascript runtime error in the PAC script. |
484 // | 486 // |
485 // This implicit fall-back to direct matches Firefox 3.5 and | 487 // This implicit fall-back to direct matches Firefox 3.5 and |
486 // Internet Explorer 8. For more information, see: | 488 // Internet Explorer 8. For more information, see: |
487 // | 489 // |
488 // http://www.chromium.org/developers/design-documents/proxy-settings-fallba
ck | 490 // http://www.chromium.org/developers/design-documents/proxy-settings-fallba
ck |
489 result->UseDirect(); | 491 result->UseDirect(); |
490 result_code = OK; | 492 result_code = OK; |
491 } | 493 } |
492 | 494 |
493 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE); | 495 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL); |
494 return result_code; | 496 return result_code; |
495 } | 497 } |
496 | 498 |
497 void ProxyService::SetProxyScriptFetcher( | 499 void ProxyService::SetProxyScriptFetcher( |
498 ProxyScriptFetcher* proxy_script_fetcher) { | 500 ProxyScriptFetcher* proxy_script_fetcher) { |
499 if (init_proxy_resolver_.get()) { | 501 if (init_proxy_resolver_.get()) { |
500 // We need to be careful to first cancel |init_proxy_resolver_|, since it | 502 // We need to be careful to first cancel |init_proxy_resolver_|, since it |
501 // holds a pointer to the old proxy script fetcher we are about to delete. | 503 // holds a pointer to the old proxy script fetcher we are about to delete. |
502 | 504 |
503 DCHECK(IsInitializingProxyResolver()); | 505 DCHECK(IsInitializingProxyResolver()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 } | 584 } |
583 | 585 |
584 void ProxyService::UpdateConfig(const BoundNetLog& net_log) { | 586 void ProxyService::UpdateConfig(const BoundNetLog& net_log) { |
585 bool is_first_update = !config_has_been_initialized(); | 587 bool is_first_update = !config_has_been_initialized(); |
586 | 588 |
587 ProxyConfig latest; | 589 ProxyConfig latest; |
588 | 590 |
589 // Fetch the proxy settings. | 591 // Fetch the proxy settings. |
590 TimeTicks start_time = TimeTicks::Now(); | 592 TimeTicks start_time = TimeTicks::Now(); |
591 net_log.BeginEvent( | 593 net_log.BeginEvent( |
592 NetLog::TYPE_PROXY_SERVICE_POLL_CONFIG_SERVICE_FOR_CHANGES); | 594 NetLog::TYPE_PROXY_SERVICE_POLL_CONFIG_SERVICE_FOR_CHANGES, NULL); |
593 int rv = config_service_->GetProxyConfig(&latest); | 595 int rv = config_service_->GetProxyConfig(&latest); |
594 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE_POLL_CONFIG_SERVICE_FOR_CHANGES); | 596 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE_POLL_CONFIG_SERVICE_FOR_CHANGES, |
| 597 NULL); |
595 TimeTicks end_time = TimeTicks::Now(); | 598 TimeTicks end_time = TimeTicks::Now(); |
596 | 599 |
597 // Record how long the call to config_service_->GetConfig() above took. | 600 // Record how long the call to config_service_->GetConfig() above took. |
598 // On some setups of Windows, we have reports that querying the system | 601 // On some setups of Windows, we have reports that querying the system |
599 // proxy settings can take multiple seconds (http://crbug.com/12189). | 602 // proxy settings can take multiple seconds (http://crbug.com/12189). |
600 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyPollConfigurationTime", | 603 UMA_HISTOGRAM_CUSTOM_TIMES("Net.ProxyPollConfigurationTime", |
601 end_time - start_time, | 604 end_time - start_time, |
602 TimeDelta::FromMilliseconds(1), | 605 TimeDelta::FromMilliseconds(1), |
603 TimeDelta::FromSeconds(30), | 606 TimeDelta::FromSeconds(30), |
604 50); | 607 50); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 OnCompletion(result_); | 743 OnCompletion(result_); |
741 } | 744 } |
742 } | 745 } |
743 | 746 |
744 void SyncProxyServiceHelper::OnCompletion(int rv) { | 747 void SyncProxyServiceHelper::OnCompletion(int rv) { |
745 result_ = rv; | 748 result_ = rv; |
746 event_.Signal(); | 749 event_.Signal(); |
747 } | 750 } |
748 | 751 |
749 } // namespace net | 752 } // namespace net |
OLD | NEW |