| 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 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 return write_complete; | 596 return write_complete; |
| 596 } | 597 } |
| 597 | 598 |
| 598 void URLFetcherCore::OnReadCompleted(net::URLRequest* request, | 599 void URLFetcherCore::OnReadCompleted(net::URLRequest* request, |
| 599 int bytes_read) { | 600 int bytes_read) { |
| 600 DCHECK(request == request_); | 601 DCHECK(request == request_); |
| 601 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 602 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 602 | 603 |
| 603 url_ = request->url(); | 604 url_ = request->url(); |
| 604 url_throttler_entry_ = | 605 url_throttler_entry_ = |
| 605 net::URLRequestThrottlerManager::GetInstance()->RegisterRequestUrl(url_); | 606 request->context()->throttler_manager()->RegisterRequestUrl(url_); |
| 606 | 607 |
| 607 bool waiting_on_write = false; | 608 bool waiting_on_write = false; |
| 608 do { | 609 do { |
| 609 if (!request_->status().is_success() || bytes_read <= 0) | 610 if (!request_->status().is_success() || bytes_read <= 0) |
| 610 break; | 611 break; |
| 611 | 612 |
| 612 current_response_bytes_ += bytes_read; | 613 current_response_bytes_ += bytes_read; |
| 613 InformDelegateDownloadProgress(); | 614 InformDelegateDownloadProgress(); |
| 614 | 615 |
| 615 if (!WriteBuffer(bytes_read)) { | 616 if (!WriteBuffer(bytes_read)) { |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 781 | 782 |
| 782 request_->Start(); | 783 request_->Start(); |
| 783 } | 784 } |
| 784 | 785 |
| 785 void URLFetcherCore::StartURLRequestWhenAppropriate() { | 786 void URLFetcherCore::StartURLRequestWhenAppropriate() { |
| 786 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 787 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); |
| 787 | 788 |
| 788 if (was_cancelled_) | 789 if (was_cancelled_) |
| 789 return; | 790 return; |
| 790 | 791 |
| 792 DCHECK(request_context_getter_); |
| 793 |
| 791 if (original_url_throttler_entry_ == NULL) { | 794 if (original_url_throttler_entry_ == NULL) { |
| 792 original_url_throttler_entry_ = | 795 original_url_throttler_entry_ = |
| 793 net::URLRequestThrottlerManager::GetInstance()->RegisterRequestUrl( | 796 request_context_getter_->GetURLRequestContext()-> |
| 794 original_url_); | 797 throttler_manager()->RegisterRequestUrl(original_url_); |
| 795 } | 798 } |
| 796 | 799 |
| 797 int64 delay = original_url_throttler_entry_->ReserveSendingTimeForNextRequest( | 800 int64 delay = original_url_throttler_entry_->ReserveSendingTimeForNextRequest( |
| 798 GetBackoffReleaseTime()); | 801 GetBackoffReleaseTime()); |
| 799 if (delay == 0) { | 802 if (delay == 0) { |
| 800 StartURLRequest(); | 803 StartURLRequest(); |
| 801 } else { | 804 } else { |
| 802 MessageLoop::current()->PostDelayedTask( | 805 MessageLoop::current()->PostDelayedTask( |
| 803 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this), | 806 FROM_HERE, base::Bind(&URLFetcherCore::StartURLRequest, this), |
| 804 base::TimeDelta::FromMilliseconds(delay)); | 807 base::TimeDelta::FromMilliseconds(delay)); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 original_url_throttler_entry_ != url_throttler_entry_) { | 918 original_url_throttler_entry_ != url_throttler_entry_) { |
| 916 destination_url_backoff = | 919 destination_url_backoff = |
| 917 url_throttler_entry_->GetExponentialBackoffReleaseTime(); | 920 url_throttler_entry_->GetExponentialBackoffReleaseTime(); |
| 918 } | 921 } |
| 919 | 922 |
| 920 return original_url_backoff > destination_url_backoff ? | 923 return original_url_backoff > destination_url_backoff ? |
| 921 original_url_backoff : destination_url_backoff; | 924 original_url_backoff : destination_url_backoff; |
| 922 } | 925 } |
| 923 | 926 |
| 924 } // namespace content | 927 } // namespace content |
| OLD | NEW |