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

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: more fixes 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Kill(). 156 // Kill().
157 // TODO(mmenke): The URLRequest is currently deleted before this method 157 // TODO(mmenke): The URLRequest is currently deleted before this method
158 // invokes its async callback whenever this is called by the URLRequest. 158 // invokes its async callback whenever this is called by the URLRequest.
159 // Try to simplify how cancellation works. 159 // Try to simplify how cancellation works.
160 NotifyCanceled(); 160 NotifyCanceled();
161 } 161 }
162 162
163 // This function calls ReadRawData to get stream data. If a filter exists, it 163 // This function calls ReadRawData to get stream data. If a filter exists, it
164 // passes the data to the attached filter. It then returns the output from 164 // passes the data to the attached filter. It then returns the output from
165 // filter back to the caller. 165 // filter back to the caller.
166 int URLRequestJob::Read(IOBuffer* buf, int buf_size) {
167 DCHECK_LT(buf_size, 1000000); // Sanity check.
168 DCHECK(buf);
169 DCHECK(!filtered_read_buffer_);
170 DCHECK_EQ(0, filtered_read_buffer_len_);
171
172 Error error = OK;
173 int bytes_read = 0;
174
175 // Skip Filter if not present.
176 if (!filter_) {
177 error = ReadRawDataHelper(buf, buf_size, &bytes_read);
178 } else {
179 // Save the caller's buffers while we do IO
180 // in the filter's buffers.
181 filtered_read_buffer_ = buf;
182 filtered_read_buffer_len_ = buf_size;
183
184 error = ReadFilteredData(&bytes_read);
185
186 // Synchronous EOF from the filter.
187 if (error == OK && bytes_read == 0)
188 DoneReading();
189 }
190
191 if (error == OK) {
192 // If URLRequestJob read zero bytes, the job is at EOF.
193 if (bytes_read == 0)
194 NotifyDone(URLRequestStatus());
195 } else if (error == ERR_IO_PENDING) {
196 bytes_read = ERR_IO_PENDING;
197 } else {
198 NotifyDone(URLRequestStatus::FromError(error));
199 bytes_read = error;
200 }
201 return bytes_read;
202 }
203
204 // Deprecated.
166 bool URLRequestJob::Read(IOBuffer* buf, int buf_size, int *bytes_read) { 205 bool URLRequestJob::Read(IOBuffer* buf, int buf_size, int *bytes_read) {
167 DCHECK_LT(buf_size, 1000000); // Sanity check. 206 DCHECK_LT(buf_size, 1000000); // Sanity check.
168 DCHECK(buf); 207 DCHECK(buf);
169 DCHECK(bytes_read); 208 DCHECK(bytes_read);
170 DCHECK(!filtered_read_buffer_); 209 DCHECK(!filtered_read_buffer_);
171 DCHECK_EQ(0, filtered_read_buffer_len_); 210 DCHECK_EQ(0, filtered_read_buffer_len_);
172 211
173 Error error = OK; 212 Error error = OK;
174 *bytes_read = 0; 213 *bytes_read = 0;
175 214
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
1011 int64_t total_sent_bytes = GetTotalSentBytes(); 1050 int64_t total_sent_bytes = GetTotalSentBytes();
1012 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_); 1051 DCHECK_GE(total_sent_bytes, last_notified_total_sent_bytes_);
1013 if (total_sent_bytes > last_notified_total_sent_bytes_) { 1052 if (total_sent_bytes > last_notified_total_sent_bytes_) {
1014 network_delegate_->NotifyNetworkBytesSent( 1053 network_delegate_->NotifyNetworkBytesSent(
1015 request_, total_sent_bytes - last_notified_total_sent_bytes_); 1054 request_, total_sent_bytes - last_notified_total_sent_bytes_);
1016 } 1055 }
1017 last_notified_total_sent_bytes_ = total_sent_bytes; 1056 last_notified_total_sent_bytes_ = total_sent_bytes;
1018 } 1057 }
1019 1058
1020 } // namespace net 1059 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698