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

Side by Side Diff: chrome/browser/predictors/resource_prefetcher.cc

Issue 2264903003: Adjust callers and networking delegates in chrome/ to modified APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@URLRequestRead
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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/predictors/resource_prefetcher.h" 5 #include "chrome/browser/predictors/resource_prefetcher.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 #include <utility> 8 #include <utility>
9 9
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 159
160 TryToLaunchPrefetchRequests(); 160 TryToLaunchPrefetchRequests();
161 } 161 }
162 162
163 void ResourcePrefetcher::ReadFullResponse(net::URLRequest* request) { 163 void ResourcePrefetcher::ReadFullResponse(net::URLRequest* request) {
164 bool status = true; 164 bool status = true;
165 while (status) { 165 while (status) {
166 int bytes_read = 0; 166 int bytes_read = 0;
167 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer( 167 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(
168 kResourceBufferSizeBytes)); 168 kResourceBufferSizeBytes));
169 status = request->Read(buffer.get(), kResourceBufferSizeBytes, &bytes_read); 169 bytes_read = request->Read(buffer.get(), kResourceBufferSizeBytes);
170 170
171 if (status) { 171 if (bytes_read >= 0) {
172 status = ShouldContinueReadingRequest(request, bytes_read); 172 status = ShouldContinueReadingRequest(request, bytes_read);
173 } else if (!request->status().is_success()) { 173 } else if (bytes_read < 0) {
pasko 2016/09/21 18:14:02 why checking the condition again? this equivalent
pasko 2016/09/29 13:51:40 please respond to this comment
maksims (do not use this acc) 2016/09/30 06:06:07 Sorry. Right, done!
174 FinishRequest(request, Request::PREFETCH_STATUS_FAILED); 174 if (bytes_read != net::ERR_IO_PENDING) {
175 return; 175 FinishRequest(request, Request::PREFETCH_STATUS_FAILED);
176 return;
177 }
176 } 178 }
177 } 179 }
178 } 180 }
179 181
180 bool ResourcePrefetcher::ShouldContinueReadingRequest(net::URLRequest* request, 182 bool ResourcePrefetcher::ShouldContinueReadingRequest(net::URLRequest* request,
181 int bytes_read) { 183 int bytes_read) {
182 if (bytes_read == 0) { // When bytes_read == 0, no more data. 184 if (bytes_read == 0) { // When bytes_read == 0, no more data.
183 if (request->was_cached()) 185 if (request->was_cached())
184 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); 186 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE);
185 else 187 else
(...skipping 21 matching lines...) Expand all
207 net::SSLCertRequestInfo* cert_request_info) { 209 net::SSLCertRequestInfo* cert_request_info) {
208 FinishRequest(request, Request::PREFETCH_STATUS_CERT_REQUIRED); 210 FinishRequest(request, Request::PREFETCH_STATUS_CERT_REQUIRED);
209 } 211 }
210 212
211 void ResourcePrefetcher::OnSSLCertificateError(net::URLRequest* request, 213 void ResourcePrefetcher::OnSSLCertificateError(net::URLRequest* request,
212 const net::SSLInfo& ssl_info, 214 const net::SSLInfo& ssl_info,
213 bool fatal) { 215 bool fatal) {
214 FinishRequest(request, Request::PREFETCH_STATUS_CERT_ERROR); 216 FinishRequest(request, Request::PREFETCH_STATUS_CERT_ERROR);
215 } 217 }
216 218
217 void ResourcePrefetcher::OnResponseStarted(net::URLRequest* request) { 219 void ResourcePrefetcher::OnResponseStarted(net::URLRequest* request,
218 if (!request->status().is_success()) { 220 int net_error) {
221 DCHECK_NE(net::ERR_IO_PENDING, net_error);
pasko 2016/09/21 18:14:02 In what circumstances is net::ERR_IO_PENDING provi
maksims (do not use this acc) 2016/09/22 04:17:48 Because it was done like this in some clients. Wha
222
223 if (net_error != net::OK) {
219 FinishRequest(request, Request::PREFETCH_STATUS_FAILED); 224 FinishRequest(request, Request::PREFETCH_STATUS_FAILED);
220 return; 225 return;
221 } 226 }
222 227
223 // TODO(shishir): Do not read cached entries, or ones that are not cacheable. 228 // TODO(shishir): Do not read cached entries, or ones that are not cacheable.
224 ReadFullResponse(request); 229 ReadFullResponse(request);
225 } 230 }
226 231
227 void ResourcePrefetcher::OnReadCompleted(net::URLRequest* request, 232 void ResourcePrefetcher::OnReadCompleted(net::URLRequest* request,
228 int bytes_read) { 233 int bytes_read) {
229 if (!request->status().is_success()) { 234 DCHECK_NE(net::ERR_IO_PENDING, bytes_read);
235
236 if (bytes_read < 0) {
230 FinishRequest(request, Request::PREFETCH_STATUS_FAILED); 237 FinishRequest(request, Request::PREFETCH_STATUS_FAILED);
231 return; 238 return;
232 } 239 }
233 240
234 if (ShouldContinueReadingRequest(request, bytes_read)) 241 if (ShouldContinueReadingRequest(request, bytes_read))
235 ReadFullResponse(request); 242 ReadFullResponse(request);
236 } 243 }
237 244
238 } // namespace predictors 245 } // namespace predictors
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698