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

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: fixing typos Created 4 years, 2 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"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "net/base/load_flags.h" 12 #include "net/base/load_flags.h"
13 #include "net/base/request_priority.h" 13 #include "net/base/request_priority.h"
14 #include "net/url_request/url_request_context.h" 14 #include "net/url_request/url_request_context.h"
15 #include "url/origin.h" 15 #include "url/origin.h"
16 16
17 namespace { 17 namespace {
18 18
19 // The size of the buffer used to read the resource. 19 // The size of the buffer used to read the resource.
20 static const size_t kResourceBufferSizeBytes = 50000; 20 static const size_t kResourceBufferSizeBytes = 50000;
21 21
22 } // namespace 22 } // namespace
23 23
24 namespace predictors { 24 namespace predictors {
25
25 ResourcePrefetcher::ResourcePrefetcher( 26 ResourcePrefetcher::ResourcePrefetcher(
26 Delegate* delegate, 27 Delegate* delegate,
27 const ResourcePrefetchPredictorConfig& config, 28 const ResourcePrefetchPredictorConfig& config,
28 const GURL& main_frame_url, 29 const GURL& main_frame_url,
29 const std::vector<GURL>& urls) 30 const std::vector<GURL>& urls)
30 : state_(INITIALIZED), 31 : state_(INITIALIZED),
31 delegate_(delegate), 32 delegate_(delegate),
32 config_(config), 33 config_(config),
33 main_frame_url_(main_frame_url) { 34 main_frame_url_(main_frame_url) {
34 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 35 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 136
136 TryToLaunchPrefetchRequests(); 137 TryToLaunchPrefetchRequests();
137 } 138 }
138 139
139 void ResourcePrefetcher::ReadFullResponse(net::URLRequest* request) { 140 void ResourcePrefetcher::ReadFullResponse(net::URLRequest* request) {
140 bool status = true; 141 bool status = true;
141 while (status) { 142 while (status) {
142 int bytes_read = 0; 143 int bytes_read = 0;
143 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer( 144 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(
144 kResourceBufferSizeBytes)); 145 kResourceBufferSizeBytes));
145 status = request->Read(buffer.get(), kResourceBufferSizeBytes, &bytes_read); 146 bytes_read = request->Read(buffer.get(), kResourceBufferSizeBytes);
146 147 if (bytes_read >= 0) {
147 if (status) {
148 status = ShouldContinueReadingRequest(request, bytes_read); 148 status = ShouldContinueReadingRequest(request, bytes_read);
149 } else if (!request->status().is_success()) { 149 } else if (bytes_read != net::ERR_IO_PENDING) {
pasko 2016/10/04 11:18:42 So if we get net::ERR_IO_PENDING, this will turn i
maksims (do not use this acc) 2016/10/04 11:51:35 Basically, previous implementation has this error
pasko 2016/10/04 12:14:16 I noticed you fixed it. Thank you! Feel free to r
150 FinishRequest(request); 150 FinishRequest(request);
151 return; 151 return;
152 } 152 }
153 } 153 }
154 } 154 }
155 155
156 bool ResourcePrefetcher::ShouldContinueReadingRequest(net::URLRequest* request, 156 bool ResourcePrefetcher::ShouldContinueReadingRequest(net::URLRequest* request,
157 int bytes_read) { 157 int bytes_read) {
158 if (bytes_read == 0) { // When bytes_read == 0, no more data. 158 if (bytes_read == 0) { // When bytes_read == 0, no more data.
159 if (request->was_cached()) 159 if (request->was_cached())
(...skipping 23 matching lines...) Expand all
183 net::SSLCertRequestInfo* cert_request_info) { 183 net::SSLCertRequestInfo* cert_request_info) {
184 FinishRequest(request); 184 FinishRequest(request);
185 } 185 }
186 186
187 void ResourcePrefetcher::OnSSLCertificateError(net::URLRequest* request, 187 void ResourcePrefetcher::OnSSLCertificateError(net::URLRequest* request,
188 const net::SSLInfo& ssl_info, 188 const net::SSLInfo& ssl_info,
189 bool fatal) { 189 bool fatal) {
190 FinishRequest(request); 190 FinishRequest(request);
191 } 191 }
192 192
193 void ResourcePrefetcher::OnResponseStarted(net::URLRequest* request) { 193 void ResourcePrefetcher::OnResponseStarted(net::URLRequest* request,
194 int net_error) {
195 DCHECK_NE(net::ERR_IO_PENDING, net_error);
196
197 if (net_error != net::OK) {
198 FinishRequest(request);
199 return;
200 }
201
194 // TODO(shishir): Do not read cached entries, or ones that are not cacheable. 202 // TODO(shishir): Do not read cached entries, or ones that are not cacheable.
195 if (request->status().is_success()) 203 ReadFullResponse(request);
196 ReadFullResponse(request);
197 else
198 FinishRequest(request);
199 } 204 }
200 205
201 void ResourcePrefetcher::OnReadCompleted(net::URLRequest* request, 206 void ResourcePrefetcher::OnReadCompleted(net::URLRequest* request,
202 int bytes_read) { 207 int bytes_read) {
203 if (!request->status().is_success()) { 208 DCHECK_NE(net::ERR_IO_PENDING, bytes_read);
209
210 if (bytes_read < 0) {
204 FinishRequest(request); 211 FinishRequest(request);
205 return; 212 return;
206 } 213 }
207 214
208 if (ShouldContinueReadingRequest(request, bytes_read)) 215 if (ShouldContinueReadingRequest(request, bytes_read))
209 ReadFullResponse(request); 216 ReadFullResponse(request);
210 } 217 }
211 218
212 } // namespace predictors 219 } // namespace predictors
OLDNEW
« no previous file with comments | « chrome/browser/predictors/resource_prefetcher.h ('k') | chrome/browser/predictors/resource_prefetcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698