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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // Kill(). | 153 // Kill(). |
154 // TODO(mmenke): The URLRequest is currently deleted before this method | 154 // TODO(mmenke): The URLRequest is currently deleted before this method |
155 // invokes its async callback whenever this is called by the URLRequest. | 155 // invokes its async callback whenever this is called by the URLRequest. |
156 // Try to simplify how cancellation works. | 156 // Try to simplify how cancellation works. |
157 NotifyCanceled(); | 157 NotifyCanceled(); |
158 } | 158 } |
159 | 159 |
160 // This function calls ReadRawData to get stream data. If a filter exists, it | 160 // This function calls ReadRawData to get stream data. If a filter exists, it |
161 // passes the data to the attached filter. It then returns the output from | 161 // passes the data to the attached filter. It then returns the output from |
162 // filter back to the caller. | 162 // filter back to the caller. |
163 bool URLRequestJob::Read(IOBuffer* buf, int buf_size, int *bytes_read) { | 163 int URLRequestJob::Read(IOBuffer* buf, int buf_size) { |
164 DCHECK_LT(buf_size, 1000000); // Sanity check. | 164 DCHECK_LT(buf_size, 1000000); // Sanity check. |
165 DCHECK(buf); | 165 DCHECK(buf); |
166 DCHECK(bytes_read); | |
167 DCHECK(!filtered_read_buffer_); | 166 DCHECK(!filtered_read_buffer_); |
168 DCHECK_EQ(0, filtered_read_buffer_len_); | 167 DCHECK_EQ(0, filtered_read_buffer_len_); |
169 | 168 |
170 Error error = OK; | 169 Error error = OK; |
171 *bytes_read = 0; | 170 int bytes_read = 0; |
172 | 171 |
173 // Skip Filter if not present. | 172 // Skip Filter if not present. |
174 if (!filter_) { | 173 if (!filter_) { |
175 error = ReadRawDataHelper(buf, buf_size, bytes_read); | 174 error = ReadRawDataHelper(buf, buf_size, &bytes_read); |
176 } else { | 175 } else { |
177 // Save the caller's buffers while we do IO | 176 // Save the caller's buffers while we do IO |
178 // in the filter's buffers. | 177 // in the filter's buffers. |
179 filtered_read_buffer_ = buf; | 178 filtered_read_buffer_ = buf; |
180 filtered_read_buffer_len_ = buf_size; | 179 filtered_read_buffer_len_ = buf_size; |
181 | 180 |
182 error = ReadFilteredData(bytes_read); | 181 error = ReadFilteredData(&bytes_read); |
183 | 182 |
184 // Synchronous EOF from the filter. | 183 // Synchronous EOF from the filter. |
185 if (error == OK && *bytes_read == 0) | 184 if (error == OK && bytes_read == 0) |
186 DoneReading(); | 185 DoneReading(); |
187 } | 186 } |
188 | 187 |
189 if (error == OK) { | 188 if (error == ERR_IO_PENDING) |
190 // If URLRequestJob read zero bytes, the job is at EOF. | 189 return ERR_IO_PENDING; |
191 if (*bytes_read == 0) | 190 |
192 NotifyDone(URLRequestStatus()); | 191 if (error < 0) { |
193 } else if (error == ERR_IO_PENDING) { | |
194 *bytes_read = ERR_IO_PENDING; | |
195 } else { | |
196 NotifyDone(URLRequestStatus::FromError(error)); | 192 NotifyDone(URLRequestStatus::FromError(error)); |
197 *bytes_read = error; | 193 return error; |
198 } | 194 } |
199 return error == OK; | 195 |
| 196 if (bytes_read == 0) |
| 197 NotifyDone(URLRequestStatus()); |
| 198 return bytes_read; |
200 } | 199 } |
201 | 200 |
202 void URLRequestJob::StopCaching() { | 201 void URLRequestJob::StopCaching() { |
203 // Nothing to do here. | 202 // Nothing to do here. |
204 } | 203 } |
205 | 204 |
206 bool URLRequestJob::GetFullRequestHeaders(HttpRequestHeaders* headers) const { | 205 bool URLRequestJob::GetFullRequestHeaders(HttpRequestHeaders* headers) const { |
207 // Most job types don't send request headers. | 206 // Most job types don't send request headers. |
208 return false; | 207 return false; |
209 } | 208 } |
(...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1003 int64_t total_sent_bytes = GetTotalSentBytes(); | 1002 int64_t total_sent_bytes = GetTotalSentBytes(); |
1004 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); | 1003 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); |
1005 if (total_sent_bytes > last_notified_total_sent_bytes_) { | 1004 if (total_sent_bytes > last_notified_total_sent_bytes_) { |
1006 network_delegate_->NotifyNetworkBytesSent( | 1005 network_delegate_->NotifyNetworkBytesSent( |
1007 request_, total_sent_bytes - last_notified_total_sent_bytes_); | 1006 request_, total_sent_bytes - last_notified_total_sent_bytes_); |
1008 } | 1007 } |
1009 last_notified_total_sent_bytes_ = total_sent_bytes; | 1008 last_notified_total_sent_bytes_ = total_sent_bytes; |
1010 } | 1009 } |
1011 | 1010 |
1012 } // namespace net | 1011 } // namespace net |
OLD | NEW |