| Index: chrome/common/net/url_fetcher.cc
|
| ===================================================================
|
| --- chrome/common/net/url_fetcher.cc (revision 64189)
|
| +++ chrome/common/net/url_fetcher.cc (working copy)
|
| @@ -14,13 +14,14 @@
|
| #include "base/stl_util-inl.h"
|
| #include "base/string_util.h"
|
| #include "base/thread.h"
|
| -#include "chrome/common/net/url_fetcher_protect.h"
|
| #include "chrome/common/net/url_request_context_getter.h"
|
| #include "googleurl/src/gurl.h"
|
| #include "net/base/load_flags.h"
|
| #include "net/base/io_buffer.h"
|
| +#include "net/base/net_errors.h"
|
| #include "net/http/http_request_headers.h"
|
| #include "net/http/http_response_headers.h"
|
| +#include "net/request_throttler/request_throttler_manager.h"
|
| #include "net/url_request/url_request.h"
|
| #include "net/url_request/url_request_context.h"
|
|
|
| @@ -116,17 +117,16 @@
|
| std::string upload_content_; // HTTP POST payload
|
| std::string upload_content_type_; // MIME type of POST payload
|
|
|
| - // The overload protection entry for this URL. This is used to
|
| - // incrementally back off how rapidly we'll send requests to a particular
|
| - // URL, to avoid placing too much demand on the remote resource. We update
|
| - // this with the status of all requests as they return, and in turn use it
|
| - // to determine how long to wait before making another request.
|
| - URLFetcherProtectEntry* protect_entry_;
|
| // |num_retries_| indicates how many times we've failed to successfully
|
| // fetch this URL. Once this value exceeds the maximum number of retries
|
| - // specified by the protection manager, we'll give up.
|
| + // specified by the owner URLFetcher instance, we'll give up.
|
| int num_retries_;
|
|
|
| + // Caches the pointer to the singleton object of RequestThrottlerManager.
|
| + // This is used to determine how long to wait before making a request or doing
|
| + // a retry.
|
| + RequestThrottlerManager* request_throttler_manager_;
|
| +
|
| // True if the URLFetcher has been cancelled.
|
| bool was_cancelled_;
|
|
|
| @@ -170,7 +170,8 @@
|
| Delegate* d)
|
| : ALLOW_THIS_IN_INITIALIZER_LIST(
|
| core_(new Core(this, url, request_type, d))),
|
| - automatically_retry_on_5xx_(true) {
|
| + automatically_retry_on_5xx_(true),
|
| + max_retries_(0) {
|
| }
|
|
|
| URLFetcher::~URLFetcher() {
|
| @@ -197,9 +198,8 @@
|
| load_flags_(net::LOAD_NORMAL),
|
| response_code_(-1),
|
| buffer_(new net::IOBuffer(kBufferSize)),
|
| - protect_entry_(URLFetcherProtectManager::GetInstance()->Register(
|
| - original_url_.host())),
|
| num_retries_(0),
|
| + request_throttler_manager_(Singleton<RequestThrottlerManager>::get()),
|
| was_cancelled_(false) {
|
| }
|
|
|
| @@ -214,10 +214,13 @@
|
| CHECK(request_context_getter_) << "We need an URLRequestContext!";
|
| io_message_loop_proxy_ = request_context_getter_->GetIOMessageLoopProxy();
|
| CHECK(io_message_loop_proxy_.get()) << "We need an IO message loop proxy";
|
| +
|
| + scoped_refptr<RequestThrottlerEntryInterface> entry =
|
| + request_throttler_manager_->RegisterRequestUrl(original_url_);
|
| io_message_loop_proxy_->PostDelayedTask(
|
| FROM_HERE,
|
| NewRunnableMethod(this, &Core::StartURLRequest),
|
| - protect_entry_->UpdateBackoff(URLFetcherProtectEntry::SEND));
|
| + entry->GetRecommendedDelayForNextRequest());
|
| }
|
|
|
| void URLFetcher::Core::Stop() {
|
| @@ -344,11 +347,13 @@
|
| DCHECK(MessageLoop::current() == delegate_loop_);
|
|
|
| // Checks the response from server.
|
| - if (response_code_ >= 500) {
|
| + if (response_code_ >= 500 ||
|
| + status.os_error() == net::ERR_TEMPORARILY_THROTTLED_BY_DDOS) {
|
| // When encountering a server error, we will send the request again
|
| // after backoff time.
|
| - int64 back_off_time =
|
| - protect_entry_->UpdateBackoff(URLFetcherProtectEntry::FAILURE);
|
| + scoped_refptr<RequestThrottlerEntryInterface> entry =
|
| + request_throttler_manager_->RegisterRequestUrl(url_);
|
| + int64 back_off_time = entry->GetRecommendedDelayForNextRequest();
|
| if (delegate_) {
|
| fetcher_->backoff_delay_ =
|
| base::TimeDelta::FromMilliseconds(back_off_time);
|
| @@ -357,7 +362,7 @@
|
| // Restarts the request if we still need to notify the delegate.
|
| if (delegate_) {
|
| if (fetcher_->automatically_retry_on_5xx_ &&
|
| - num_retries_ <= protect_entry_->max_retries()) {
|
| + num_retries_ <= fetcher_->max_retries()) {
|
| io_message_loop_proxy_->PostDelayedTask(
|
| FROM_HERE,
|
| NewRunnableMethod(this, &Core::StartURLRequest), back_off_time);
|
| @@ -367,7 +372,6 @@
|
| }
|
| }
|
| } else {
|
| - protect_entry_->UpdateBackoff(URLFetcherProtectEntry::SUCCESS);
|
| if (delegate_) {
|
| fetcher_->backoff_delay_ = base::TimeDelta();
|
| delegate_->OnURLFetchComplete(fetcher_, url_, status, response_code_,
|
| @@ -382,7 +386,7 @@
|
| }
|
|
|
| void URLFetcher::set_upload_data(const std::string& upload_content_type,
|
| - const std::string& upload_content) {
|
| + const std::string& upload_content) {
|
| core_->upload_content_type_ = upload_content_type;
|
| core_->upload_content_ = upload_content;
|
| }
|
|
|