| 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 "content/common/net/url_fetcher_core.h" | 5 #include "content/common/net/url_fetcher_core.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/file_util_proxy.h" | 8 #include "base/file_util_proxy.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
| 13 #include "base/tracked_objects.h" | 13 #include "base/tracked_objects.h" |
| 14 #include "content/public/common/url_fetcher_delegate.h" | 14 #include "content/public/common/url_fetcher_delegate.h" |
| 15 #include "net/base/io_buffer.h" | 15 #include "net/base/io_buffer.h" |
| 16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 19 #include "net/url_request/url_request_context.h" |
| 19 #include "net/url_request/url_request_context_getter.h" | 20 #include "net/url_request/url_request_context_getter.h" |
| 20 #include "net/url_request/url_request_throttler_manager.h" | 21 #include "net/url_request/url_request_throttler_manager.h" |
| 21 | 22 |
| 22 namespace content { | 23 namespace content { |
| 23 | 24 |
| 24 static const int kBufferSize = 4096; | 25 static const int kBufferSize = 4096; |
| 25 static const int kUploadProgressTimerInterval = 100; | 26 static const int kUploadProgressTimerInterval = 100; |
| 26 | 27 |
| 27 URLFetcherCore::Registry::Registry() {} | 28 URLFetcherCore::Registry::Registry() {} |
| 28 URLFetcherCore::Registry::~Registry() {} | 29 URLFetcherCore::Registry::~Registry() {} |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 600 return write_complete; | 601 return write_complete; |
| 601 } | 602 } |
| 602 | 603 |
| 603 void URLFetcherCore::OnReadCompleted(net::URLRequest* request, | 604 void URLFetcherCore::OnReadCompleted(net::URLRequest* request, |
| 604 int bytes_read) { | 605 int bytes_read) { |
| 605 DCHECK(request == request_); | 606 DCHECK(request == request_); |
| 606 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 607 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 607 | 608 |
| 608 url_ = request->url(); | 609 url_ = request->url(); |
| 609 url_throttler_entry_ = | 610 url_throttler_entry_ = |
| 610 net::URLRequestThrottlerManager::GetInstance()->RegisterRequestUrl(url_); | 611 request->context()->throttler_manager()->RegisterRequestUrl(url_); |
| 611 | 612 |
| 612 bool waiting_on_write = false; | 613 bool waiting_on_write = false; |
| 613 do { | 614 do { |
| 614 if (!request_->status().is_success() || bytes_read <= 0) | 615 if (!request_->status().is_success() || bytes_read <= 0) |
| 615 break; | 616 break; |
| 616 | 617 |
| 617 current_response_bytes_ += bytes_read; | 618 current_response_bytes_ += bytes_read; |
| 618 InformDelegateDownloadProgress(); | 619 InformDelegateDownloadProgress(); |
| 619 InformDelegateDownloadDataIfNecessary(bytes_read); | 620 InformDelegateDownloadDataIfNecessary(bytes_read); |
| 620 | 621 |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 | 788 |
| 788 request_->Start(); | 789 request_->Start(); |
| 789 } | 790 } |
| 790 | 791 |
| 791 void URLFetcherCore::StartURLRequestWhenAppropriate() { | 792 void URLFetcherCore::StartURLRequestWhenAppropriate() { |
| 792 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 793 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 793 | 794 |
| 794 if (was_cancelled_) | 795 if (was_cancelled_) |
| 795 return; | 796 return; |
| 796 | 797 |
| 798 DCHECK(request_context_getter_); |
| 799 |
| 797 if (original_url_throttler_entry_ == NULL) { | 800 if (original_url_throttler_entry_ == NULL) { |
| 798 original_url_throttler_entry_ = | 801 original_url_throttler_entry_ = |
| 799 net::URLRequestThrottlerManager::GetInstance()->RegisterRequestUrl( | 802 request_context_getter_->GetURLRequestContext()-> |
| 800 original_url_); | 803 throttler_manager()->RegisterRequestUrl(original_url_); |
| 801 } | 804 } |
| 802 | 805 |
| 803 int64 delay = original_url_throttler_entry_->ReserveSendingTimeForNextRequest( | 806 int64 delay = original_url_throttler_entry_->ReserveSendingTimeForNextRequest( |
| 804 GetBackoffReleaseTime()); | 807 GetBackoffReleaseTime()); |
| 805 if (delay == 0) { | 808 if (delay == 0) { |
| 806 StartURLRequest(); | 809 StartURLRequest(); |
| 807 } else { | 810 } else { |
| 808 MessageLoop::current()->PostDelayedTask( | 811 MessageLoop::current()->PostDelayedTask( |
| 809 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this), | 812 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this), |
| 810 base::TimeDelta::FromMilliseconds(delay)); | 813 base::TimeDelta::FromMilliseconds(delay)); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 original_url_throttler_entry_ != url_throttler_entry_) { | 944 original_url_throttler_entry_ != url_throttler_entry_) { |
| 942 destination_url_backoff = | 945 destination_url_backoff = |
| 943 url_throttler_entry_->GetExponentialBackoffReleaseTime(); | 946 url_throttler_entry_->GetExponentialBackoffReleaseTime(); |
| 944 } | 947 } |
| 945 | 948 |
| 946 return original_url_backoff > destination_url_backoff ? | 949 return original_url_backoff > destination_url_backoff ? |
| 947 original_url_backoff : destination_url_backoff; | 950 original_url_backoff : destination_url_backoff; |
| 948 } | 951 } |
| 949 | 952 |
| 950 } // namespace content | 953 } // namespace content |
| OLD | NEW |