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/url_request/url_request_job.h" | 5 #include "net/url_request/url_request_job.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 : request_(request), | 66 : request_(request), |
67 done_(false), | 67 done_(false), |
68 prefilter_bytes_read_(0), | 68 prefilter_bytes_read_(0), |
69 postfilter_bytes_read_(0), | 69 postfilter_bytes_read_(0), |
70 filter_needs_more_output_space_(false), | 70 filter_needs_more_output_space_(false), |
71 filtered_read_buffer_len_(0), | 71 filtered_read_buffer_len_(0), |
72 has_handled_response_(false), | 72 has_handled_response_(false), |
73 expected_content_size_(-1), | 73 expected_content_size_(-1), |
74 network_delegate_(network_delegate), | 74 network_delegate_(network_delegate), |
75 last_notified_total_received_bytes_(0), | 75 last_notified_total_received_bytes_(0), |
| 76 last_notified_total_sent_bytes_(0), |
76 weak_factory_(this) { | 77 weak_factory_(this) { |
77 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); | 78 base::PowerMonitor* power_monitor = base::PowerMonitor::Get(); |
78 if (power_monitor) | 79 if (power_monitor) |
79 power_monitor->AddObserver(this); | 80 power_monitor->AddObserver(this); |
80 } | 81 } |
81 | 82 |
82 void URLRequestJob::SetUpload(UploadDataStream* upload) { | 83 void URLRequestJob::SetUpload(UploadDataStream* upload) { |
83 } | 84 } |
84 | 85 |
85 void URLRequestJob::SetExtraRequestHeaders(const HttpRequestHeaders& headers) { | 86 void URLRequestJob::SetExtraRequestHeaders(const HttpRequestHeaders& headers) { |
(...skipping 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
941 request_->referrer(), | 942 request_->referrer(), |
942 redirect_info.new_url).spec(); | 943 redirect_info.new_url).spec(); |
943 | 944 |
944 return redirect_info; | 945 return redirect_info; |
945 } | 946 } |
946 | 947 |
947 void URLRequestJob::MaybeNotifyNetworkBytes() { | 948 void URLRequestJob::MaybeNotifyNetworkBytes() { |
948 if (!request_ || !network_delegate_) | 949 if (!request_ || !network_delegate_) |
949 return; | 950 return; |
950 | 951 |
| 952 // Report any new received bytes. |
951 int64_t total_received_bytes = GetTotalReceivedBytes(); | 953 int64_t total_received_bytes = GetTotalReceivedBytes(); |
952 DCHECK_GE(total_received_bytes, last_notified_total_received_bytes_); | 954 DCHECK_GE(total_received_bytes, last_notified_total_received_bytes_); |
953 if (total_received_bytes > last_notified_total_received_bytes_) { | 955 if (total_received_bytes > last_notified_total_received_bytes_) { |
954 network_delegate_->NotifyNetworkBytesReceived( | 956 network_delegate_->NotifyNetworkBytesReceived( |
955 *request_, total_received_bytes - last_notified_total_received_bytes_); | 957 *request_, total_received_bytes - last_notified_total_received_bytes_); |
956 } | 958 } |
957 last_notified_total_received_bytes_ = total_received_bytes; | 959 last_notified_total_received_bytes_ = total_received_bytes; |
| 960 |
| 961 // Report any new sent bytes. |
| 962 int64_t total_sent_bytes = GetTotalSentBytes(); |
| 963 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); |
| 964 if (total_sent_bytes > last_notified_total_sent_bytes_) { |
| 965 network_delegate_->NotifyNetworkBytesSent( |
| 966 *request_, total_sent_bytes - last_notified_total_sent_bytes_); |
| 967 } |
| 968 last_notified_total_sent_bytes_ = total_sent_bytes; |
958 } | 969 } |
959 | 970 |
960 } // namespace net | 971 } // namespace net |
OLD | NEW |