| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 public: | 122 public: |
| 123 DefaultPollPolicy() {} | 123 DefaultPollPolicy() {} |
| 124 | 124 |
| 125 virtual Mode GetNextDelay(int initial_error, | 125 virtual Mode GetNextDelay(int initial_error, |
| 126 TimeDelta current_delay, | 126 TimeDelta current_delay, |
| 127 TimeDelta* next_delay) const OVERRIDE { | 127 TimeDelta* next_delay) const OVERRIDE { |
| 128 if (initial_error != OK) { | 128 if (initial_error != OK) { |
| 129 // Re-try policy for failures. | 129 // Re-try policy for failures. |
| 130 const int kDelay1Seconds = 8; | 130 const int kDelay1Seconds = 8; |
| 131 const int kDelay2Seconds = 32; | 131 const int kDelay2Seconds = 32; |
| 132 const int kDelay3Seconds = 2 * 60; // 2 minutes | 132 const int kDelay3Seconds = 2 * 60; // 2 minutes |
| 133 const int kDelay4Seconds = 4 * 60 * 60; // 4 Hours | 133 const int kDelay4Seconds = 4 * 60 * 60; // 4 Hours |
| 134 | 134 |
| 135 // Initial poll. | 135 // Initial poll. |
| 136 if (current_delay < TimeDelta()) { | 136 if (current_delay < TimeDelta()) { |
| 137 *next_delay = TimeDelta::FromSeconds(kDelay1Seconds); | 137 *next_delay = TimeDelta::FromSeconds(kDelay1Seconds); |
| 138 return MODE_USE_TIMER; | 138 return MODE_USE_TIMER; |
| 139 } | 139 } |
| 140 switch (current_delay.InSeconds()) { | 140 switch (current_delay.InSeconds()) { |
| 141 case kDelay1Seconds: | 141 case kDelay1Seconds: |
| 142 *next_delay = TimeDelta::FromSeconds(kDelay2Seconds); | 142 *next_delay = TimeDelta::FromSeconds(kDelay2Seconds); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 158 private: | 158 private: |
| 159 DISALLOW_COPY_AND_ASSIGN(DefaultPollPolicy); | 159 DISALLOW_COPY_AND_ASSIGN(DefaultPollPolicy); |
| 160 }; | 160 }; |
| 161 | 161 |
| 162 // Config getter that always returns direct settings. | 162 // Config getter that always returns direct settings. |
| 163 class ProxyConfigServiceDirect : public ProxyConfigService { | 163 class ProxyConfigServiceDirect : public ProxyConfigService { |
| 164 public: | 164 public: |
| 165 // ProxyConfigService implementation: | 165 // ProxyConfigService implementation: |
| 166 virtual void AddObserver(Observer* observer) OVERRIDE {} | 166 virtual void AddObserver(Observer* observer) OVERRIDE {} |
| 167 virtual void RemoveObserver(Observer* observer) OVERRIDE {} | 167 virtual void RemoveObserver(Observer* observer) OVERRIDE {} |
| 168 virtual ConfigAvailability GetLatestProxyConfig(ProxyConfig* config) | 168 virtual ConfigAvailability GetLatestProxyConfig( |
| 169 OVERRIDE { | 169 ProxyConfig* config) OVERRIDE { |
| 170 *config = ProxyConfig::CreateDirect(); | 170 *config = ProxyConfig::CreateDirect(); |
| 171 config->set_source(PROXY_CONFIG_SOURCE_UNKNOWN); | 171 config->set_source(PROXY_CONFIG_SOURCE_UNKNOWN); |
| 172 return CONFIG_VALID; | 172 return CONFIG_VALID; |
| 173 } | 173 } |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 // Proxy resolver that fails every time. | 176 // Proxy resolver that fails every time. |
| 177 class ProxyResolverNull : public ProxyResolver { | 177 class ProxyResolverNull : public ProxyResolver { |
| 178 public: | 178 public: |
| 179 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} | 179 ProxyResolverNull() : ProxyResolver(false /*expects_pac_bytes*/) {} |
| 180 | 180 |
| 181 // ProxyResolver implementation. | 181 // ProxyResolver implementation. |
| 182 virtual int GetProxyForURL(const GURL& url, | 182 virtual int GetProxyForURL(const GURL& url, |
| 183 ProxyInfo* results, | 183 ProxyInfo* results, |
| 184 const CompletionCallback& callback, | 184 const CompletionCallback& callback, |
| 185 RequestHandle* request, | 185 RequestHandle* request, |
| 186 const BoundNetLog& net_log) OVERRIDE { | 186 const BoundNetLog& net_log) OVERRIDE { |
| 187 return ERR_NOT_IMPLEMENTED; | 187 return ERR_NOT_IMPLEMENTED; |
| 188 } | 188 } |
| 189 | 189 |
| 190 virtual void CancelRequest(RequestHandle request) OVERRIDE { | 190 virtual void CancelRequest(RequestHandle request) OVERRIDE { NOTREACHED(); } |
| 191 NOTREACHED(); | |
| 192 } | |
| 193 | 191 |
| 194 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { | 192 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { |
| 195 NOTREACHED(); | 193 NOTREACHED(); |
| 196 return LOAD_STATE_IDLE; | 194 return LOAD_STATE_IDLE; |
| 197 } | 195 } |
| 198 | 196 |
| 199 virtual void CancelSetPacScript() OVERRIDE { | 197 virtual void CancelSetPacScript() OVERRIDE { NOTREACHED(); } |
| 200 NOTREACHED(); | |
| 201 } | |
| 202 | 198 |
| 203 virtual int SetPacScript( | 199 virtual int SetPacScript( |
| 204 const scoped_refptr<ProxyResolverScriptData>& /*script_data*/, | 200 const scoped_refptr<ProxyResolverScriptData>& /*script_data*/, |
| 205 const CompletionCallback& /*callback*/) OVERRIDE { | 201 const CompletionCallback& /*callback*/) OVERRIDE { |
| 206 return ERR_NOT_IMPLEMENTED; | 202 return ERR_NOT_IMPLEMENTED; |
| 207 } | 203 } |
| 208 }; | 204 }; |
| 209 | 205 |
| 210 // ProxyResolver that simulates a PAC script which returns | 206 // ProxyResolver that simulates a PAC script which returns |
| 211 // |pac_string| for every single URL. | 207 // |pac_string| for every single URL. |
| 212 class ProxyResolverFromPacString : public ProxyResolver { | 208 class ProxyResolverFromPacString : public ProxyResolver { |
| 213 public: | 209 public: |
| 214 explicit ProxyResolverFromPacString(const std::string& pac_string) | 210 explicit ProxyResolverFromPacString(const std::string& pac_string) |
| 215 : ProxyResolver(false /*expects_pac_bytes*/), | 211 : ProxyResolver(false /*expects_pac_bytes*/), pac_string_(pac_string) {} |
| 216 pac_string_(pac_string) {} | |
| 217 | 212 |
| 218 virtual int GetProxyForURL(const GURL& url, | 213 virtual int GetProxyForURL(const GURL& url, |
| 219 ProxyInfo* results, | 214 ProxyInfo* results, |
| 220 const CompletionCallback& callback, | 215 const CompletionCallback& callback, |
| 221 RequestHandle* request, | 216 RequestHandle* request, |
| 222 const BoundNetLog& net_log) OVERRIDE { | 217 const BoundNetLog& net_log) OVERRIDE { |
| 223 results->UsePacString(pac_string_); | 218 results->UsePacString(pac_string_); |
| 224 return OK; | 219 return OK; |
| 225 } | 220 } |
| 226 | 221 |
| 227 virtual void CancelRequest(RequestHandle request) OVERRIDE { | 222 virtual void CancelRequest(RequestHandle request) OVERRIDE { NOTREACHED(); } |
| 228 NOTREACHED(); | |
| 229 } | |
| 230 | 223 |
| 231 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { | 224 virtual LoadState GetLoadState(RequestHandle request) const OVERRIDE { |
| 232 NOTREACHED(); | 225 NOTREACHED(); |
| 233 return LOAD_STATE_IDLE; | 226 return LOAD_STATE_IDLE; |
| 234 } | 227 } |
| 235 | 228 |
| 236 virtual void CancelSetPacScript() OVERRIDE { | 229 virtual void CancelSetPacScript() OVERRIDE { NOTREACHED(); } |
| 237 NOTREACHED(); | |
| 238 } | |
| 239 | 230 |
| 240 virtual int SetPacScript( | 231 virtual int SetPacScript( |
| 241 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 232 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 242 const CompletionCallback& callback) OVERRIDE { | 233 const CompletionCallback& callback) OVERRIDE { |
| 243 return OK; | 234 return OK; |
| 244 } | 235 } |
| 245 | 236 |
| 246 private: | 237 private: |
| 247 const std::string pac_string_; | 238 const std::string pac_string_; |
| 248 }; | 239 }; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 dict->Set("new_config", new_config->ToValue()); | 278 dict->Set("new_config", new_config->ToValue()); |
| 288 return dict; | 279 return dict; |
| 289 } | 280 } |
| 290 | 281 |
| 291 base::Value* NetLogBadProxyListCallback(const ProxyRetryInfoMap* retry_info, | 282 base::Value* NetLogBadProxyListCallback(const ProxyRetryInfoMap* retry_info, |
| 292 NetLog::LogLevel /* log_level */) { | 283 NetLog::LogLevel /* log_level */) { |
| 293 base::DictionaryValue* dict = new base::DictionaryValue(); | 284 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 294 base::ListValue* list = new base::ListValue(); | 285 base::ListValue* list = new base::ListValue(); |
| 295 | 286 |
| 296 for (ProxyRetryInfoMap::const_iterator iter = retry_info->begin(); | 287 for (ProxyRetryInfoMap::const_iterator iter = retry_info->begin(); |
| 297 iter != retry_info->end(); ++iter) { | 288 iter != retry_info->end(); |
| 289 ++iter) { |
| 298 list->Append(new base::StringValue(iter->first)); | 290 list->Append(new base::StringValue(iter->first)); |
| 299 } | 291 } |
| 300 dict->Set("bad_proxy_list", list); | 292 dict->Set("bad_proxy_list", list); |
| 301 return dict; | 293 return dict; |
| 302 } | 294 } |
| 303 | 295 |
| 304 // Returns NetLog parameters on a successfuly proxy resolution. | 296 // Returns NetLog parameters on a successfuly proxy resolution. |
| 305 base::Value* NetLogFinishedResolvingProxyCallback( | 297 base::Value* NetLogFinishedResolvingProxyCallback( |
| 306 ProxyInfo* result, | 298 ProxyInfo* result, |
| 307 NetLog::LogLevel /* log_level */) { | 299 NetLog::LogLevel /* log_level */) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 337 // InitProxyResolver is a single-use class which encapsulates cancellation as | 329 // InitProxyResolver is a single-use class which encapsulates cancellation as |
| 338 // part of its destructor. Start() or StartSkipDecider() should be called just | 330 // part of its destructor. Start() or StartSkipDecider() should be called just |
| 339 // once. The instance can be destroyed at any time, and the request will be | 331 // once. The instance can be destroyed at any time, and the request will be |
| 340 // cancelled. | 332 // cancelled. |
| 341 | 333 |
| 342 class ProxyService::InitProxyResolver { | 334 class ProxyService::InitProxyResolver { |
| 343 public: | 335 public: |
| 344 InitProxyResolver() | 336 InitProxyResolver() |
| 345 : proxy_resolver_(NULL), | 337 : proxy_resolver_(NULL), |
| 346 next_state_(STATE_NONE), | 338 next_state_(STATE_NONE), |
| 347 quick_check_enabled_(true) { | 339 quick_check_enabled_(true) {} |
| 348 } | |
| 349 | 340 |
| 350 ~InitProxyResolver() { | 341 ~InitProxyResolver() { |
| 351 // Note that the destruction of ProxyScriptDecider will automatically cancel | 342 // Note that the destruction of ProxyScriptDecider will automatically cancel |
| 352 // any outstanding work. | 343 // any outstanding work. |
| 353 if (next_state_ == STATE_SET_PAC_SCRIPT_COMPLETE) { | 344 if (next_state_ == STATE_SET_PAC_SCRIPT_COMPLETE) { |
| 354 proxy_resolver_->CancelSetPacScript(); | 345 proxy_resolver_->CancelSetPacScript(); |
| 355 } | 346 } |
| 356 } | 347 } |
| 357 | 348 |
| 358 // Begins initializing the proxy resolver; calls |callback| when done. | 349 // Begins initializing the proxy resolver; calls |callback| when done. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 break; | 452 break; |
| 462 } | 453 } |
| 463 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); | 454 } while (rv != ERR_IO_PENDING && next_state_ != STATE_NONE); |
| 464 return rv; | 455 return rv; |
| 465 } | 456 } |
| 466 | 457 |
| 467 int DoDecideProxyScript() { | 458 int DoDecideProxyScript() { |
| 468 next_state_ = STATE_DECIDE_PROXY_SCRIPT_COMPLETE; | 459 next_state_ = STATE_DECIDE_PROXY_SCRIPT_COMPLETE; |
| 469 | 460 |
| 470 return decider_->Start( | 461 return decider_->Start( |
| 471 config_, wait_delay_, proxy_resolver_->expects_pac_bytes(), | 462 config_, |
| 463 wait_delay_, |
| 464 proxy_resolver_->expects_pac_bytes(), |
| 472 base::Bind(&InitProxyResolver::OnIOCompletion, base::Unretained(this))); | 465 base::Bind(&InitProxyResolver::OnIOCompletion, base::Unretained(this))); |
| 473 } | 466 } |
| 474 | 467 |
| 475 int DoDecideProxyScriptComplete(int result) { | 468 int DoDecideProxyScriptComplete(int result) { |
| 476 if (result != OK) | 469 if (result != OK) |
| 477 return result; | 470 return result; |
| 478 | 471 |
| 479 effective_config_ = decider_->effective_config(); | 472 effective_config_ = decider_->effective_config(); |
| 480 script_data_ = decider_->script_data(); | 473 script_data_ = decider_->script_data(); |
| 481 | 474 |
| 482 next_state_ = STATE_SET_PAC_SCRIPT; | 475 next_state_ = STATE_SET_PAC_SCRIPT; |
| 483 return OK; | 476 return OK; |
| 484 } | 477 } |
| 485 | 478 |
| 486 int DoSetPacScript() { | 479 int DoSetPacScript() { |
| 487 DCHECK(script_data_.get()); | 480 DCHECK(script_data_.get()); |
| 488 // TODO(eroman): Should log this latency to the NetLog. | 481 // TODO(eroman): Should log this latency to the NetLog. |
| 489 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; | 482 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; |
| 490 return proxy_resolver_->SetPacScript( | 483 return proxy_resolver_->SetPacScript( |
| 491 script_data_, | 484 script_data_, |
| 492 base::Bind(&InitProxyResolver::OnIOCompletion, base::Unretained(this))); | 485 base::Bind(&InitProxyResolver::OnIOCompletion, base::Unretained(this))); |
| 493 } | 486 } |
| 494 | 487 |
| 495 int DoSetPacScriptComplete(int result) { | 488 int DoSetPacScriptComplete(int result) { return result; } |
| 496 return result; | |
| 497 } | |
| 498 | 489 |
| 499 void OnIOCompletion(int result) { | 490 void OnIOCompletion(int result) { |
| 500 DCHECK_NE(STATE_NONE, next_state_); | 491 DCHECK_NE(STATE_NONE, next_state_); |
| 501 int rv = DoLoop(result); | 492 int rv = DoLoop(result); |
| 502 if (rv != ERR_IO_PENDING) | 493 if (rv != ERR_IO_PENDING) |
| 503 DoCallback(rv); | 494 DoCallback(rv); |
| 504 } | 495 } |
| 505 | 496 |
| 506 void DoCallback(int result) { | 497 void DoCallback(int result) { |
| 507 DCHECK_NE(ERR_IO_PENDING, result); | 498 DCHECK_NE(ERR_IO_PENDING, result); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 522 }; | 513 }; |
| 523 | 514 |
| 524 // ProxyService::ProxyScriptDeciderPoller ------------------------------------- | 515 // ProxyService::ProxyScriptDeciderPoller ------------------------------------- |
| 525 | 516 |
| 526 // This helper class encapsulates the logic to schedule and run periodic | 517 // This helper class encapsulates the logic to schedule and run periodic |
| 527 // background checks to see if the PAC script (or effective proxy configuration) | 518 // background checks to see if the PAC script (or effective proxy configuration) |
| 528 // has changed. If a change is detected, then the caller will be notified via | 519 // has changed. If a change is detected, then the caller will be notified via |
| 529 // the ChangeCallback. | 520 // the ChangeCallback. |
| 530 class ProxyService::ProxyScriptDeciderPoller { | 521 class ProxyService::ProxyScriptDeciderPoller { |
| 531 public: | 522 public: |
| 532 typedef base::Callback<void(int, ProxyResolverScriptData*, | 523 typedef base::Callback< |
| 533 const ProxyConfig&)> ChangeCallback; | 524 void(int, ProxyResolverScriptData*, const ProxyConfig&)> ChangeCallback; |
| 534 | 525 |
| 535 // Builds a poller helper, and starts polling for updates. Whenever a change | 526 // Builds a poller helper, and starts polling for updates. Whenever a change |
| 536 // is observed, |callback| will be invoked with the details. | 527 // is observed, |callback| will be invoked with the details. |
| 537 // | 528 // |
| 538 // |config| specifies the (unresolved) proxy configuration to poll. | 529 // |config| specifies the (unresolved) proxy configuration to poll. |
| 539 // |proxy_resolver_expects_pac_bytes| the type of proxy resolver we expect | 530 // |proxy_resolver_expects_pac_bytes| the type of proxy resolver we expect |
| 540 // to use the resulting script data with | 531 // to use the resulting script data with |
| 541 // (so it can choose the right format). | 532 // (so it can choose the right format). |
| 542 // |proxy_script_fetcher| this pointer must remain alive throughout our | 533 // |proxy_script_fetcher| this pointer must remain alive throughout our |
| 543 // lifetime. It is the dependency that will be used | 534 // lifetime. It is the dependency that will be used |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 | 619 |
| 629 void DoPoll() { | 620 void DoPoll() { |
| 630 last_poll_time_ = TimeTicks::Now(); | 621 last_poll_time_ = TimeTicks::Now(); |
| 631 | 622 |
| 632 // Start the proxy script decider to see if anything has changed. | 623 // Start the proxy script decider to see if anything has changed. |
| 633 // TODO(eroman): Pass a proper NetLog rather than NULL. | 624 // TODO(eroman): Pass a proper NetLog rather than NULL. |
| 634 decider_.reset(new ProxyScriptDecider( | 625 decider_.reset(new ProxyScriptDecider( |
| 635 proxy_script_fetcher_, dhcp_proxy_script_fetcher_, NULL)); | 626 proxy_script_fetcher_, dhcp_proxy_script_fetcher_, NULL)); |
| 636 decider_->set_quick_check_enabled(quick_check_enabled_); | 627 decider_->set_quick_check_enabled(quick_check_enabled_); |
| 637 int result = decider_->Start( | 628 int result = decider_->Start( |
| 638 config_, TimeDelta(), proxy_resolver_expects_pac_bytes_, | 629 config_, |
| 630 TimeDelta(), |
| 631 proxy_resolver_expects_pac_bytes_, |
| 639 base::Bind(&ProxyScriptDeciderPoller::OnProxyScriptDeciderCompleted, | 632 base::Bind(&ProxyScriptDeciderPoller::OnProxyScriptDeciderCompleted, |
| 640 base::Unretained(this))); | 633 base::Unretained(this))); |
| 641 | 634 |
| 642 if (result != ERR_IO_PENDING) | 635 if (result != ERR_IO_PENDING) |
| 643 OnProxyScriptDeciderCompleted(result); | 636 OnProxyScriptDeciderCompleted(result); |
| 644 } | 637 } |
| 645 | 638 |
| 646 void OnProxyScriptDeciderCompleted(int result) { | 639 void OnProxyScriptDeciderCompleted(int result) { |
| 647 if (HasScriptDataChanged(result, decider_->script_data())) { | 640 if (HasScriptDataChanged(result, decider_->script_data())) { |
| 648 // Something has changed, we must notify the ProxyService so it can | 641 // Something has changed, we must notify the ProxyService so it can |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 | 720 |
| 728 // static | 721 // static |
| 729 const ProxyService::PacPollPolicy* | 722 const ProxyService::PacPollPolicy* |
| 730 ProxyService::ProxyScriptDeciderPoller::poll_policy_ = NULL; | 723 ProxyService::ProxyScriptDeciderPoller::poll_policy_ = NULL; |
| 731 | 724 |
| 732 // ProxyService::PacRequest --------------------------------------------------- | 725 // ProxyService::PacRequest --------------------------------------------------- |
| 733 | 726 |
| 734 class ProxyService::PacRequest | 727 class ProxyService::PacRequest |
| 735 : public base::RefCounted<ProxyService::PacRequest> { | 728 : public base::RefCounted<ProxyService::PacRequest> { |
| 736 public: | 729 public: |
| 737 PacRequest(ProxyService* service, | 730 PacRequest(ProxyService* service, |
| 738 const GURL& url, | 731 const GURL& url, |
| 739 ProxyInfo* results, | 732 ProxyInfo* results, |
| 740 const net::CompletionCallback& user_callback, | 733 const net::CompletionCallback& user_callback, |
| 741 const BoundNetLog& net_log) | 734 const BoundNetLog& net_log) |
| 742 : service_(service), | 735 : service_(service), |
| 743 user_callback_(user_callback), | 736 user_callback_(user_callback), |
| 744 results_(results), | 737 results_(results), |
| 745 url_(url), | 738 url_(url), |
| 746 resolve_job_(NULL), | 739 resolve_job_(NULL), |
| 747 config_id_(ProxyConfig::kInvalidConfigID), | 740 config_id_(ProxyConfig::kInvalidConfigID), |
| 748 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN), | 741 config_source_(PROXY_CONFIG_SOURCE_UNKNOWN), |
| 749 net_log_(net_log) { | 742 net_log_(net_log) { |
| 750 DCHECK(!user_callback.is_null()); | 743 DCHECK(!user_callback.is_null()); |
| 751 } | 744 } |
| 752 | 745 |
| 753 // Starts the resolve proxy request. | 746 // Starts the resolve proxy request. |
| 754 int Start() { | 747 int Start() { |
| 755 DCHECK(!was_cancelled()); | 748 DCHECK(!was_cancelled()); |
| 756 DCHECK(!is_started()); | 749 DCHECK(!is_started()); |
| 757 | 750 |
| 758 DCHECK(service_->config_.is_valid()); | 751 DCHECK(service_->config_.is_valid()); |
| 759 | 752 |
| 760 config_id_ = service_->config_.id(); | 753 config_id_ = service_->config_.id(); |
| 761 config_source_ = service_->config_.source(); | 754 config_source_ = service_->config_.source(); |
| 762 proxy_resolve_start_time_ = TimeTicks::Now(); | 755 proxy_resolve_start_time_ = TimeTicks::Now(); |
| 763 | 756 |
| 764 return resolver()->GetProxyForURL( | 757 return resolver()->GetProxyForURL( |
| 765 url_, results_, | 758 url_, |
| 759 results_, |
| 766 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)), | 760 base::Bind(&PacRequest::QueryComplete, base::Unretained(this)), |
| 767 &resolve_job_, net_log_); | 761 &resolve_job_, |
| 762 net_log_); |
| 768 } | 763 } |
| 769 | 764 |
| 770 bool is_started() const { | 765 bool is_started() const { |
| 771 // Note that !! casts to bool. (VS gives a warning otherwise). | 766 // Note that !! casts to bool. (VS gives a warning otherwise). |
| 772 return !!resolve_job_; | 767 return !!resolve_job_; |
| 773 } | 768 } |
| 774 | 769 |
| 775 void StartAndCompleteCheckingForSynchronous() { | 770 void StartAndCompleteCheckingForSynchronous() { |
| 776 int rv = service_->TryToCompleteSynchronously(url_, results_); | 771 int rv = service_->TryToCompleteSynchronously(url_, results_); |
| 777 if (rv == ERR_IO_PENDING) | 772 if (rv == ERR_IO_PENDING) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 796 | 791 |
| 797 // Mark as cancelled, to prevent accessing this again later. | 792 // Mark as cancelled, to prevent accessing this again later. |
| 798 service_ = NULL; | 793 service_ = NULL; |
| 799 user_callback_.Reset(); | 794 user_callback_.Reset(); |
| 800 results_ = NULL; | 795 results_ = NULL; |
| 801 | 796 |
| 802 net_log_.EndEvent(NetLog::TYPE_PROXY_SERVICE); | 797 net_log_.EndEvent(NetLog::TYPE_PROXY_SERVICE); |
| 803 } | 798 } |
| 804 | 799 |
| 805 // Returns true if Cancel() has been called. | 800 // Returns true if Cancel() has been called. |
| 806 bool was_cancelled() const { | 801 bool was_cancelled() const { return user_callback_.is_null(); } |
| 807 return user_callback_.is_null(); | |
| 808 } | |
| 809 | 802 |
| 810 // Helper to call after ProxyResolver completion (both synchronous and | 803 // Helper to call after ProxyResolver completion (both synchronous and |
| 811 // asynchronous). Fixes up the result that is to be returned to user. | 804 // asynchronous). Fixes up the result that is to be returned to user. |
| 812 int QueryDidComplete(int result_code) { | 805 int QueryDidComplete(int result_code) { |
| 813 DCHECK(!was_cancelled()); | 806 DCHECK(!was_cancelled()); |
| 814 | 807 |
| 815 // Note that DidFinishResolvingProxy might modify |results_|. | 808 // Note that DidFinishResolvingProxy might modify |results_|. |
| 816 int rv = service_->DidFinishResolvingProxy(results_, result_code, net_log_); | 809 int rv = service_->DidFinishResolvingProxy(results_, result_code, net_log_); |
| 817 | 810 |
| 818 // Make a note in the results which configuration was in use at the | 811 // Make a note in the results which configuration was in use at the |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 875 TimeTicks proxy_resolve_start_time_; | 868 TimeTicks proxy_resolve_start_time_; |
| 876 }; | 869 }; |
| 877 | 870 |
| 878 // ProxyService --------------------------------------------------------------- | 871 // ProxyService --------------------------------------------------------------- |
| 879 | 872 |
| 880 ProxyService::ProxyService(ProxyConfigService* config_service, | 873 ProxyService::ProxyService(ProxyConfigService* config_service, |
| 881 ProxyResolver* resolver, | 874 ProxyResolver* resolver, |
| 882 NetLog* net_log) | 875 NetLog* net_log) |
| 883 : resolver_(resolver), | 876 : resolver_(resolver), |
| 884 next_config_id_(1), | 877 next_config_id_(1), |
| 885 current_state_(STATE_NONE) , | 878 current_state_(STATE_NONE), |
| 886 net_log_(net_log), | 879 net_log_(net_log), |
| 887 stall_proxy_auto_config_delay_(TimeDelta::FromMilliseconds( | 880 stall_proxy_auto_config_delay_( |
| 888 kDelayAfterNetworkChangesMs)), | 881 TimeDelta::FromMilliseconds(kDelayAfterNetworkChangesMs)), |
| 889 quick_check_enabled_(true) { | 882 quick_check_enabled_(true) { |
| 890 NetworkChangeNotifier::AddIPAddressObserver(this); | 883 NetworkChangeNotifier::AddIPAddressObserver(this); |
| 891 NetworkChangeNotifier::AddDNSObserver(this); | 884 NetworkChangeNotifier::AddDNSObserver(this); |
| 892 ResetConfigService(config_service); | 885 ResetConfigService(config_service); |
| 893 } | 886 } |
| 894 | 887 |
| 895 // static | 888 // static |
| 896 ProxyService* ProxyService::CreateUsingSystemProxyResolver( | 889 ProxyService* ProxyService::CreateUsingSystemProxyResolver( |
| 897 ProxyConfigService* proxy_config_service, | 890 ProxyConfigService* proxy_config_service, |
| 898 size_t num_pac_threads, | 891 size_t num_pac_threads, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 911 ProxyResolver* proxy_resolver = new MultiThreadedProxyResolver( | 904 ProxyResolver* proxy_resolver = new MultiThreadedProxyResolver( |
| 912 new ProxyResolverFactoryForSystem(), num_pac_threads); | 905 new ProxyResolverFactoryForSystem(), num_pac_threads); |
| 913 | 906 |
| 914 return new ProxyService(proxy_config_service, proxy_resolver, net_log); | 907 return new ProxyService(proxy_config_service, proxy_resolver, net_log); |
| 915 } | 908 } |
| 916 | 909 |
| 917 // static | 910 // static |
| 918 ProxyService* ProxyService::CreateWithoutProxyResolver( | 911 ProxyService* ProxyService::CreateWithoutProxyResolver( |
| 919 ProxyConfigService* proxy_config_service, | 912 ProxyConfigService* proxy_config_service, |
| 920 NetLog* net_log) { | 913 NetLog* net_log) { |
| 921 return new ProxyService(proxy_config_service, | 914 return new ProxyService( |
| 922 new ProxyResolverNull(), | 915 proxy_config_service, new ProxyResolverNull(), net_log); |
| 923 net_log); | |
| 924 } | 916 } |
| 925 | 917 |
| 926 // static | 918 // static |
| 927 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { | 919 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { |
| 928 // TODO(eroman): This isn't quite right, won't work if |pc| specifies | 920 // TODO(eroman): This isn't quite right, won't work if |pc| specifies |
| 929 // a PAC script. | 921 // a PAC script. |
| 930 return CreateUsingSystemProxyResolver(new ProxyConfigServiceFixed(pc), | 922 return CreateUsingSystemProxyResolver( |
| 931 0, NULL); | 923 new ProxyConfigServiceFixed(pc), 0, NULL); |
| 932 } | 924 } |
| 933 | 925 |
| 934 // static | 926 // static |
| 935 ProxyService* ProxyService::CreateFixed(const std::string& proxy) { | 927 ProxyService* ProxyService::CreateFixed(const std::string& proxy) { |
| 936 net::ProxyConfig proxy_config; | 928 net::ProxyConfig proxy_config; |
| 937 proxy_config.proxy_rules().ParseFromString(proxy); | 929 proxy_config.proxy_rules().ParseFromString(proxy); |
| 938 return ProxyService::CreateFixed(proxy_config); | 930 return ProxyService::CreateFixed(proxy_config); |
| 939 } | 931 } |
| 940 | 932 |
| 941 // static | 933 // static |
| 942 ProxyService* ProxyService::CreateDirect() { | 934 ProxyService* ProxyService::CreateDirect() { |
| 943 return CreateDirectWithNetLog(NULL); | 935 return CreateDirectWithNetLog(NULL); |
| 944 } | 936 } |
| 945 | 937 |
| 946 ProxyService* ProxyService::CreateDirectWithNetLog(NetLog* net_log) { | 938 ProxyService* ProxyService::CreateDirectWithNetLog(NetLog* net_log) { |
| 947 // Use direct connections. | 939 // Use direct connections. |
| 948 return new ProxyService(new ProxyConfigServiceDirect, new ProxyResolverNull, | 940 return new ProxyService( |
| 949 net_log); | 941 new ProxyConfigServiceDirect, new ProxyResolverNull, net_log); |
| 950 } | 942 } |
| 951 | 943 |
| 952 // static | 944 // static |
| 953 ProxyService* ProxyService::CreateFixedFromPacResult( | 945 ProxyService* ProxyService::CreateFixedFromPacResult( |
| 954 const std::string& pac_string) { | 946 const std::string& pac_string) { |
| 955 | |
| 956 // We need the settings to contain an "automatic" setting, otherwise the | 947 // We need the settings to contain an "automatic" setting, otherwise the |
| 957 // ProxyResolver dependency we give it will never be used. | 948 // ProxyResolver dependency we give it will never be used. |
| 958 scoped_ptr<ProxyConfigService> proxy_config_service( | 949 scoped_ptr<ProxyConfigService> proxy_config_service( |
| 959 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); | 950 new ProxyConfigServiceFixed(ProxyConfig::CreateAutoDetect())); |
| 960 | 951 |
| 961 scoped_ptr<ProxyResolver> proxy_resolver( | 952 scoped_ptr<ProxyResolver> proxy_resolver( |
| 962 new ProxyResolverFromPacString(pac_string)); | 953 new ProxyResolverFromPacString(pac_string)); |
| 963 | 954 |
| 964 return new ProxyService(proxy_config_service.release(), | 955 return new ProxyService( |
| 965 proxy_resolver.release(), | 956 proxy_config_service.release(), proxy_resolver.release(), NULL); |
| 966 NULL); | |
| 967 } | 957 } |
| 968 | 958 |
| 969 int ProxyService::ResolveProxy(const GURL& raw_url, | 959 int ProxyService::ResolveProxy(const GURL& raw_url, |
| 970 ProxyInfo* result, | 960 ProxyInfo* result, |
| 971 const net::CompletionCallback& callback, | 961 const net::CompletionCallback& callback, |
| 972 PacRequest** pac_request, | 962 PacRequest** pac_request, |
| 973 const BoundNetLog& net_log) { | 963 const BoundNetLog& net_log) { |
| 974 DCHECK(CalledOnValidThread()); | 964 DCHECK(CalledOnValidThread()); |
| 975 DCHECK(!callback.is_null()); | 965 DCHECK(!callback.is_null()); |
| 976 | 966 |
| 977 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE); | 967 net_log.BeginEvent(NetLog::TYPE_PROXY_SERVICE); |
| 978 | 968 |
| 979 // Notify our polling-based dependencies that a resolve is taking place. | 969 // Notify our polling-based dependencies that a resolve is taking place. |
| 980 // This way they can schedule their polls in response to network activity. | 970 // This way they can schedule their polls in response to network activity. |
| 981 config_service_->OnLazyPoll(); | 971 config_service_->OnLazyPoll(); |
| 982 if (script_poller_.get()) | 972 if (script_poller_.get()) |
| 983 script_poller_->OnLazyPoll(); | 973 script_poller_->OnLazyPoll(); |
| 984 | 974 |
| 985 if (current_state_ == STATE_NONE) | 975 if (current_state_ == STATE_NONE) |
| 986 ApplyProxyConfigIfAvailable(); | 976 ApplyProxyConfigIfAvailable(); |
| 987 | 977 |
| 988 // Strip away any reference fragments and the username/password, as they | 978 // Strip away any reference fragments and the username/password, as they |
| 989 // are not relevant to proxy resolution. | 979 // are not relevant to proxy resolution. |
| 990 GURL url = SimplifyUrlForRequest(raw_url); | 980 GURL url = SimplifyUrlForRequest(raw_url); |
| 991 | 981 |
| 992 // Check if the request can be completed right away. (This is the case when | 982 // Check if the request can be completed right away. (This is the case when |
| 993 // using a direct connection for example). | 983 // using a direct connection for example). |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1199 | 1189 |
| 1200 // We don't have new proxy settings to try, try to fallback to the next proxy | 1190 // We don't have new proxy settings to try, try to fallback to the next proxy |
| 1201 // in the list. | 1191 // in the list. |
| 1202 bool did_fallback = result->Fallback(net_log); | 1192 bool did_fallback = result->Fallback(net_log); |
| 1203 | 1193 |
| 1204 // Return synchronous failure if there is nothing left to fall-back to. | 1194 // Return synchronous failure if there is nothing left to fall-back to. |
| 1205 // TODO(eroman): This is a yucky API, clean it up. | 1195 // TODO(eroman): This is a yucky API, clean it up. |
| 1206 return did_fallback ? OK : ERR_FAILED; | 1196 return did_fallback ? OK : ERR_FAILED; |
| 1207 } | 1197 } |
| 1208 | 1198 |
| 1209 bool ProxyService::MarkProxiesAsBadUntil( | 1199 bool ProxyService::MarkProxiesAsBadUntil(const ProxyInfo& result, |
| 1210 const ProxyInfo& result, | 1200 base::TimeDelta retry_delay, |
| 1211 base::TimeDelta retry_delay, | 1201 const ProxyServer& another_bad_proxy, |
| 1212 const ProxyServer& another_bad_proxy, | 1202 const BoundNetLog& net_log) { |
| 1213 const BoundNetLog& net_log) { | 1203 result.proxy_list_.UpdateRetryInfoOnFallback( |
| 1214 result.proxy_list_.UpdateRetryInfoOnFallback(&proxy_retry_info_, retry_delay, | 1204 &proxy_retry_info_, retry_delay, false, another_bad_proxy, net_log); |
| 1215 false, | |
| 1216 another_bad_proxy, | |
| 1217 net_log); | |
| 1218 if (another_bad_proxy.is_valid()) | 1205 if (another_bad_proxy.is_valid()) |
| 1219 return result.proxy_list_.size() > 2; | 1206 return result.proxy_list_.size() > 2; |
| 1220 else | 1207 else |
| 1221 return result.proxy_list_.size() > 1; | 1208 return result.proxy_list_.size() > 1; |
| 1222 } | 1209 } |
| 1223 | 1210 |
| 1224 void ProxyService::ReportSuccess(const ProxyInfo& result) { | 1211 void ProxyService::ReportSuccess(const ProxyInfo& result) { |
| 1225 DCHECK(CalledOnValidThread()); | 1212 DCHECK(CalledOnValidThread()); |
| 1226 | 1213 |
| 1227 const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info(); | 1214 const ProxyRetryInfoMap& new_retry_info = result.proxy_retry_info(); |
| 1228 if (new_retry_info.empty()) | 1215 if (new_retry_info.empty()) |
| 1229 return; | 1216 return; |
| 1230 | 1217 |
| 1231 for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin(); | 1218 for (ProxyRetryInfoMap::const_iterator iter = new_retry_info.begin(); |
| 1232 iter != new_retry_info.end(); ++iter) { | 1219 iter != new_retry_info.end(); |
| 1220 ++iter) { |
| 1233 ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first); | 1221 ProxyRetryInfoMap::iterator existing = proxy_retry_info_.find(iter->first); |
| 1234 if (existing == proxy_retry_info_.end()) | 1222 if (existing == proxy_retry_info_.end()) |
| 1235 proxy_retry_info_[iter->first] = iter->second; | 1223 proxy_retry_info_[iter->first] = iter->second; |
| 1236 else if (existing->second.bad_until < iter->second.bad_until) | 1224 else if (existing->second.bad_until < iter->second.bad_until) |
| 1237 existing->second.bad_until = iter->second.bad_until; | 1225 existing->second.bad_until = iter->second.bad_until; |
| 1238 } | 1226 } |
| 1239 if (net_log_) { | 1227 if (net_log_) { |
| 1240 net_log_->AddGlobalEntry( | 1228 net_log_->AddGlobalEntry( |
| 1241 NetLog::TYPE_BAD_PROXY_LIST_REPORTED, | 1229 NetLog::TYPE_BAD_PROXY_LIST_REPORTED, |
| 1242 base::Bind(&NetLogBadProxyListCallback, &new_retry_info)); | 1230 base::Bind(&NetLogBadProxyListCallback, &new_retry_info)); |
| 1243 } | 1231 } |
| 1244 } | 1232 } |
| 1245 | 1233 |
| 1246 void ProxyService::CancelPacRequest(PacRequest* req) { | 1234 void ProxyService::CancelPacRequest(PacRequest* req) { |
| 1247 DCHECK(CalledOnValidThread()); | 1235 DCHECK(CalledOnValidThread()); |
| 1248 DCHECK(req); | 1236 DCHECK(req); |
| 1249 req->Cancel(); | 1237 req->Cancel(); |
| 1250 RemovePendingRequest(req); | 1238 RemovePendingRequest(req); |
| 1251 } | 1239 } |
| 1252 | 1240 |
| 1253 LoadState ProxyService::GetLoadState(const PacRequest* req) const { | 1241 LoadState ProxyService::GetLoadState(const PacRequest* req) const { |
| 1254 CHECK(req); | 1242 CHECK(req); |
| 1255 if (current_state_ == STATE_WAITING_FOR_INIT_PROXY_RESOLVER) | 1243 if (current_state_ == STATE_WAITING_FOR_INIT_PROXY_RESOLVER) |
| 1256 return init_proxy_resolver_->GetLoadState(); | 1244 return init_proxy_resolver_->GetLoadState(); |
| 1257 return req->GetLoadState(); | 1245 return req->GetLoadState(); |
| 1258 } | 1246 } |
| 1259 | 1247 |
| 1260 bool ProxyService::ContainsPendingRequest(PacRequest* req) { | 1248 bool ProxyService::ContainsPendingRequest(PacRequest* req) { |
| 1261 PendingRequests::iterator it = std::find( | 1249 PendingRequests::iterator it = |
| 1262 pending_requests_.begin(), pending_requests_.end(), req); | 1250 std::find(pending_requests_.begin(), pending_requests_.end(), req); |
| 1263 return pending_requests_.end() != it; | 1251 return pending_requests_.end() != it; |
| 1264 } | 1252 } |
| 1265 | 1253 |
| 1266 void ProxyService::RemovePendingRequest(PacRequest* req) { | 1254 void ProxyService::RemovePendingRequest(PacRequest* req) { |
| 1267 DCHECK(ContainsPendingRequest(req)); | 1255 DCHECK(ContainsPendingRequest(req)); |
| 1268 PendingRequests::iterator it = std::find( | 1256 PendingRequests::iterator it = |
| 1269 pending_requests_.begin(), pending_requests_.end(), req); | 1257 std::find(pending_requests_.begin(), pending_requests_.end(), req); |
| 1270 pending_requests_.erase(it); | 1258 pending_requests_.erase(it); |
| 1271 } | 1259 } |
| 1272 | 1260 |
| 1273 int ProxyService::DidFinishResolvingProxy(ProxyInfo* result, | 1261 int ProxyService::DidFinishResolvingProxy(ProxyInfo* result, |
| 1274 int result_code, | 1262 int result_code, |
| 1275 const BoundNetLog& net_log) { | 1263 const BoundNetLog& net_log) { |
| 1276 // Log the result of the proxy resolution. | 1264 // Log the result of the proxy resolution. |
| 1277 if (result_code == OK) { | 1265 if (result_code == OK) { |
| 1278 // When logging all events is enabled, dump the proxy list. | 1266 // When logging all events is enabled, dump the proxy list. |
| 1279 if (net_log.IsLogging()) { | 1267 if (net_log.IsLogging()) { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 #elif defined(OS_IOS) | 1358 #elif defined(OS_IOS) |
| 1371 return new ProxyConfigServiceIOS(); | 1359 return new ProxyConfigServiceIOS(); |
| 1372 #elif defined(OS_MACOSX) | 1360 #elif defined(OS_MACOSX) |
| 1373 return new ProxyConfigServiceMac(io_thread_task_runner); | 1361 return new ProxyConfigServiceMac(io_thread_task_runner); |
| 1374 #elif defined(OS_CHROMEOS) | 1362 #elif defined(OS_CHROMEOS) |
| 1375 LOG(ERROR) << "ProxyConfigService for ChromeOS should be created in " | 1363 LOG(ERROR) << "ProxyConfigService for ChromeOS should be created in " |
| 1376 << "profile_io_data.cc::CreateProxyConfigService and this should " | 1364 << "profile_io_data.cc::CreateProxyConfigService and this should " |
| 1377 << "be used only for examples."; | 1365 << "be used only for examples."; |
| 1378 return new UnsetProxyConfigService; | 1366 return new UnsetProxyConfigService; |
| 1379 #elif defined(OS_LINUX) | 1367 #elif defined(OS_LINUX) |
| 1380 ProxyConfigServiceLinux* linux_config_service = | 1368 ProxyConfigServiceLinux* linux_config_service = new ProxyConfigServiceLinux(); |
| 1381 new ProxyConfigServiceLinux(); | |
| 1382 | 1369 |
| 1383 // Assume we got called on the thread that runs the default glib | 1370 // Assume we got called on the thread that runs the default glib |
| 1384 // main loop, so the current thread is where we should be running | 1371 // main loop, so the current thread is where we should be running |
| 1385 // gconf calls from. | 1372 // gconf calls from. |
| 1386 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner = | 1373 scoped_refptr<base::SingleThreadTaskRunner> glib_thread_task_runner = |
| 1387 base::ThreadTaskRunnerHandle::Get(); | 1374 base::ThreadTaskRunnerHandle::Get(); |
| 1388 | 1375 |
| 1389 // The file loop should be a MessageLoopForIO on Linux. | 1376 // The file loop should be a MessageLoopForIO on Linux. |
| 1390 DCHECK_EQ(base::MessageLoop::TYPE_IO, file_loop->type()); | 1377 DCHECK_EQ(base::MessageLoop::TYPE_IO, file_loop->type()); |
| 1391 | 1378 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1411 } | 1398 } |
| 1412 | 1399 |
| 1413 // static | 1400 // static |
| 1414 const ProxyService::PacPollPolicy* ProxyService::set_pac_script_poll_policy( | 1401 const ProxyService::PacPollPolicy* ProxyService::set_pac_script_poll_policy( |
| 1415 const PacPollPolicy* policy) { | 1402 const PacPollPolicy* policy) { |
| 1416 return ProxyScriptDeciderPoller::set_policy(policy); | 1403 return ProxyScriptDeciderPoller::set_policy(policy); |
| 1417 } | 1404 } |
| 1418 | 1405 |
| 1419 // static | 1406 // static |
| 1420 scoped_ptr<ProxyService::PacPollPolicy> | 1407 scoped_ptr<ProxyService::PacPollPolicy> |
| 1421 ProxyService::CreateDefaultPacPollPolicy() { | 1408 ProxyService::CreateDefaultPacPollPolicy() { |
| 1422 return scoped_ptr<PacPollPolicy>(new DefaultPollPolicy()); | 1409 return scoped_ptr<PacPollPolicy>(new DefaultPollPolicy()); |
| 1423 } | 1410 } |
| 1424 | 1411 |
| 1425 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 1412 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
| 1426 void ProxyService::RecordDataReductionProxyBypassInfo( | 1413 void ProxyService::RecordDataReductionProxyBypassInfo( |
| 1427 bool is_primary, | 1414 bool is_primary, |
| 1428 const ProxyServer& proxy_server, | 1415 const ProxyServer& proxy_server, |
| 1429 DataReductionProxyBypassEventType bypass_type) const { | 1416 DataReductionProxyBypassEventType bypass_type) const { |
| 1430 // Only record UMA if the proxy isn't already on the retry list. | 1417 // Only record UMA if the proxy isn't already on the retry list. |
| 1431 if (proxy_retry_info_.find(proxy_server.ToURI()) != proxy_retry_info_.end()) | 1418 if (proxy_retry_info_.find(proxy_server.ToURI()) != proxy_retry_info_.end()) |
| 1432 return; | 1419 return; |
| 1433 | 1420 |
| 1434 if (is_primary) { | 1421 if (is_primary) { |
| 1435 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.BypassInfoPrimary", | 1422 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.BypassInfoPrimary", |
| 1436 bypass_type, BYPASS_EVENT_TYPE_MAX); | 1423 bypass_type, |
| 1424 BYPASS_EVENT_TYPE_MAX); |
| 1437 } else { | 1425 } else { |
| 1438 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.BypassInfoFallback", | 1426 UMA_HISTOGRAM_ENUMERATION("DataReductionProxy.BypassInfoFallback", |
| 1439 bypass_type, BYPASS_EVENT_TYPE_MAX); | 1427 bypass_type, |
| 1428 BYPASS_EVENT_TYPE_MAX); |
| 1440 } | 1429 } |
| 1441 } | 1430 } |
| 1442 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) | 1431 #endif // defined(SPDY_PROXY_AUTH_ORIGIN) |
| 1443 | 1432 |
| 1444 void ProxyService::OnProxyConfigChanged( | 1433 void ProxyService::OnProxyConfigChanged( |
| 1445 const ProxyConfig& config, | 1434 const ProxyConfig& config, |
| 1446 ProxyConfigService::ConfigAvailability availability) { | 1435 ProxyConfigService::ConfigAvailability availability) { |
| 1447 // Retrieve the current proxy configuration from the ProxyConfigService. | 1436 // Retrieve the current proxy configuration from the ProxyConfigService. |
| 1448 // If a configuration is not available yet, we will get called back later | 1437 // If a configuration is not available yet, we will get called back later |
| 1449 // by our ProxyConfigService::Observer once it changes. | 1438 // by our ProxyConfigService::Observer once it changes. |
| 1450 ProxyConfig effective_config; | 1439 ProxyConfig effective_config; |
| 1451 switch (availability) { | 1440 switch (availability) { |
| 1452 case ProxyConfigService::CONFIG_PENDING: | 1441 case ProxyConfigService::CONFIG_PENDING: |
| 1453 // ProxyConfigService implementors should never pass CONFIG_PENDING. | 1442 // ProxyConfigService implementors should never pass CONFIG_PENDING. |
| 1454 NOTREACHED() << "Proxy config change with CONFIG_PENDING availability!"; | 1443 NOTREACHED() << "Proxy config change with CONFIG_PENDING availability!"; |
| 1455 return; | 1444 return; |
| 1456 case ProxyConfigService::CONFIG_VALID: | 1445 case ProxyConfigService::CONFIG_VALID: |
| 1457 effective_config = config; | 1446 effective_config = config; |
| 1458 break; | 1447 break; |
| 1459 case ProxyConfigService::CONFIG_UNSET: | 1448 case ProxyConfigService::CONFIG_UNSET: |
| 1460 effective_config = ProxyConfig::CreateDirect(); | 1449 effective_config = ProxyConfig::CreateDirect(); |
| 1461 break; | 1450 break; |
| 1462 } | 1451 } |
| 1463 | 1452 |
| 1464 // Emit the proxy settings change to the NetLog stream. | 1453 // Emit the proxy settings change to the NetLog stream. |
| 1465 if (net_log_) { | 1454 if (net_log_) { |
| 1466 net_log_->AddGlobalEntry( | 1455 net_log_->AddGlobalEntry(net::NetLog::TYPE_PROXY_CONFIG_CHANGED, |
| 1467 net::NetLog::TYPE_PROXY_CONFIG_CHANGED, | 1456 base::Bind(&NetLogProxyConfigChangedCallback, |
| 1468 base::Bind(&NetLogProxyConfigChangedCallback, | 1457 &fetched_config_, |
| 1469 &fetched_config_, &effective_config)); | 1458 &effective_config)); |
| 1470 } | 1459 } |
| 1471 | 1460 |
| 1472 // Set the new configuration as the most recently fetched one. | 1461 // Set the new configuration as the most recently fetched one. |
| 1473 fetched_config_ = effective_config; | 1462 fetched_config_ = effective_config; |
| 1474 fetched_config_.set_id(1); // Needed for a later DCHECK of is_valid(). | 1463 fetched_config_.set_id(1); // Needed for a later DCHECK of is_valid(). |
| 1475 | 1464 |
| 1476 InitializeUsingLastFetchedConfig(); | 1465 InitializeUsingLastFetchedConfig(); |
| 1477 } | 1466 } |
| 1478 | 1467 |
| 1479 void ProxyService::InitializeUsingLastFetchedConfig() { | 1468 void ProxyService::InitializeUsingLastFetchedConfig() { |
| 1480 ResetProxyConfig(false); | 1469 ResetProxyConfig(false); |
| 1481 | 1470 |
| 1482 DCHECK(fetched_config_.is_valid()); | 1471 DCHECK(fetched_config_.is_valid()); |
| 1483 | 1472 |
| 1484 // Increment the ID to reflect that the config has changed. | 1473 // Increment the ID to reflect that the config has changed. |
| 1485 fetched_config_.set_id(next_config_id_++); | 1474 fetched_config_.set_id(next_config_id_++); |
| 1486 | 1475 |
| 1487 if (!fetched_config_.HasAutomaticSettings()) { | 1476 if (!fetched_config_.HasAutomaticSettings()) { |
| 1488 config_ = fetched_config_; | 1477 config_ = fetched_config_; |
| 1489 SetReady(); | 1478 SetReady(); |
| 1490 return; | 1479 return; |
| 1491 } | 1480 } |
| 1492 | 1481 |
| 1493 // Start downloading + testing the PAC scripts for this new configuration. | 1482 // Start downloading + testing the PAC scripts for this new configuration. |
| 1494 current_state_ = STATE_WAITING_FOR_INIT_PROXY_RESOLVER; | 1483 current_state_ = STATE_WAITING_FOR_INIT_PROXY_RESOLVER; |
| 1495 | 1484 |
| 1496 // If we changed networks recently, we should delay running proxy auto-config. | 1485 // If we changed networks recently, we should delay running proxy auto-config. |
| 1497 TimeDelta wait_delay = | 1486 TimeDelta wait_delay = stall_proxy_autoconfig_until_ - TimeTicks::Now(); |
| 1498 stall_proxy_autoconfig_until_ - TimeTicks::Now(); | |
| 1499 | 1487 |
| 1500 init_proxy_resolver_.reset(new InitProxyResolver()); | 1488 init_proxy_resolver_.reset(new InitProxyResolver()); |
| 1501 init_proxy_resolver_->set_quick_check_enabled(quick_check_enabled_); | 1489 init_proxy_resolver_->set_quick_check_enabled(quick_check_enabled_); |
| 1502 int rv = init_proxy_resolver_->Start( | 1490 int rv = init_proxy_resolver_->Start( |
| 1503 resolver_.get(), | 1491 resolver_.get(), |
| 1504 proxy_script_fetcher_.get(), | 1492 proxy_script_fetcher_.get(), |
| 1505 dhcp_proxy_script_fetcher_.get(), | 1493 dhcp_proxy_script_fetcher_.get(), |
| 1506 net_log_, | 1494 net_log_, |
| 1507 fetched_config_, | 1495 fetched_config_, |
| 1508 wait_delay, | 1496 wait_delay, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1562 DCHECK(io_message_loop_ != base::MessageLoop::current()); | 1550 DCHECK(io_message_loop_ != base::MessageLoop::current()); |
| 1563 } | 1551 } |
| 1564 | 1552 |
| 1565 int SyncProxyServiceHelper::ResolveProxy(const GURL& url, | 1553 int SyncProxyServiceHelper::ResolveProxy(const GURL& url, |
| 1566 ProxyInfo* proxy_info, | 1554 ProxyInfo* proxy_info, |
| 1567 const BoundNetLog& net_log) { | 1555 const BoundNetLog& net_log) { |
| 1568 DCHECK(io_message_loop_ != base::MessageLoop::current()); | 1556 DCHECK(io_message_loop_ != base::MessageLoop::current()); |
| 1569 | 1557 |
| 1570 io_message_loop_->PostTask( | 1558 io_message_loop_->PostTask( |
| 1571 FROM_HERE, | 1559 FROM_HERE, |
| 1572 base::Bind(&SyncProxyServiceHelper::StartAsyncResolve, this, url, | 1560 base::Bind( |
| 1573 net_log)); | 1561 &SyncProxyServiceHelper::StartAsyncResolve, this, url, net_log)); |
| 1574 | 1562 |
| 1575 event_.Wait(); | 1563 event_.Wait(); |
| 1576 | 1564 |
| 1577 if (result_ == net::OK) { | 1565 if (result_ == net::OK) { |
| 1578 *proxy_info = proxy_info_; | 1566 *proxy_info = proxy_info_; |
| 1579 } | 1567 } |
| 1580 return result_; | 1568 return result_; |
| 1581 } | 1569 } |
| 1582 | 1570 |
| 1583 int SyncProxyServiceHelper::ReconsiderProxyAfterError( | 1571 int SyncProxyServiceHelper::ReconsiderProxyAfterError( |
| 1584 const GURL& url, ProxyInfo* proxy_info, const BoundNetLog& net_log) { | 1572 const GURL& url, |
| 1573 ProxyInfo* proxy_info, |
| 1574 const BoundNetLog& net_log) { |
| 1585 DCHECK(io_message_loop_ != base::MessageLoop::current()); | 1575 DCHECK(io_message_loop_ != base::MessageLoop::current()); |
| 1586 | 1576 |
| 1587 io_message_loop_->PostTask( | 1577 io_message_loop_->PostTask( |
| 1588 FROM_HERE, | 1578 FROM_HERE, |
| 1589 base::Bind(&SyncProxyServiceHelper::StartAsyncReconsider, this, url, | 1579 base::Bind( |
| 1590 net_log)); | 1580 &SyncProxyServiceHelper::StartAsyncReconsider, this, url, net_log)); |
| 1591 | 1581 |
| 1592 event_.Wait(); | 1582 event_.Wait(); |
| 1593 | 1583 |
| 1594 if (result_ == net::OK) { | 1584 if (result_ == net::OK) { |
| 1595 *proxy_info = proxy_info_; | 1585 *proxy_info = proxy_info_; |
| 1596 } | 1586 } |
| 1597 return result_; | 1587 return result_; |
| 1598 } | 1588 } |
| 1599 | 1589 |
| 1600 SyncProxyServiceHelper::~SyncProxyServiceHelper() {} | 1590 SyncProxyServiceHelper::~SyncProxyServiceHelper() { |
| 1591 } |
| 1601 | 1592 |
| 1602 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url, | 1593 void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url, |
| 1603 const BoundNetLog& net_log) { | 1594 const BoundNetLog& net_log) { |
| 1604 result_ = proxy_service_->ResolveProxy( | 1595 result_ = |
| 1605 url, &proxy_info_, callback_, NULL, net_log); | 1596 proxy_service_->ResolveProxy(url, &proxy_info_, callback_, NULL, net_log); |
| 1606 if (result_ != net::ERR_IO_PENDING) { | 1597 if (result_ != net::ERR_IO_PENDING) { |
| 1607 OnCompletion(result_); | 1598 OnCompletion(result_); |
| 1608 } | 1599 } |
| 1609 } | 1600 } |
| 1610 | 1601 |
| 1611 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url, | 1602 void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url, |
| 1612 const BoundNetLog& net_log) { | 1603 const BoundNetLog& net_log) { |
| 1613 result_ = proxy_service_->ReconsiderProxyAfterError( | 1604 result_ = proxy_service_->ReconsiderProxyAfterError( |
| 1614 url, &proxy_info_, callback_, NULL, net_log); | 1605 url, &proxy_info_, callback_, NULL, net_log); |
| 1615 if (result_ != net::ERR_IO_PENDING) { | 1606 if (result_ != net::ERR_IO_PENDING) { |
| 1616 OnCompletion(result_); | 1607 OnCompletion(result_); |
| 1617 } | 1608 } |
| 1618 } | 1609 } |
| 1619 | 1610 |
| 1620 void SyncProxyServiceHelper::OnCompletion(int rv) { | 1611 void SyncProxyServiceHelper::OnCompletion(int rv) { |
| 1621 result_ = rv; | 1612 result_ = rv; |
| 1622 event_.Signal(); | 1613 event_.Signal(); |
| 1623 } | 1614 } |
| 1624 | 1615 |
| 1625 } // namespace net | 1616 } // namespace net |
| OLD | NEW |