Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(295)

Side by Side Diff: net/url_request/url_request_job.cc

Issue 2262653003: Make URLRequest::Read to return net errors or bytes read instead of a bool (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 == OK) {
190 // If URLRequestJob read zero bytes, the job is at EOF. 189 // If URLRequestJob read zero bytes, the job is at EOF.
191 if (*bytes_read == 0) 190 if (bytes_read == 0)
192 NotifyDone(URLRequestStatus()); 191 NotifyDone(URLRequestStatus());
193 } else if (error == ERR_IO_PENDING) { 192 } else if (error == ERR_IO_PENDING) {
194 *bytes_read = ERR_IO_PENDING; 193 bytes_read = ERR_IO_PENDING;
195 } else { 194 } else {
196 NotifyDone(URLRequestStatus::FromError(error)); 195 NotifyDone(URLRequestStatus::FromError(error));
197 *bytes_read = error; 196 bytes_read = error;
198 } 197 }
199 return error == OK; 198 return bytes_read;
mmenke 2016/08/30 22:09:12 Suggest re-ordering these and using early returns.
maksims (do not use this acc) 2016/08/31 11:16:59 Done.
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698