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

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

Issue 11761022: Fixing possible read on URLRequest when there is no more data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing rvargas's comments. Created 7 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <iterator> 5 #include <iterator>
6 6
7 #include "chrome/browser/predictors/resource_prefetcher.h" 7 #include "chrome/browser/predictors/resource_prefetcher.h"
8 8
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 } 162 }
163 163
164 void ResourcePrefetcher::ReadFullResponse(net::URLRequest* request) { 164 void ResourcePrefetcher::ReadFullResponse(net::URLRequest* request) {
165 bool status = true; 165 bool status = true;
166 while (status) { 166 while (status) {
167 int bytes_read = 0; 167 int bytes_read = 0;
168 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer( 168 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(
169 kResourceBufferSizeBytes)); 169 kResourceBufferSizeBytes));
170 status = request->Read(buffer, kResourceBufferSizeBytes, &bytes_read); 170 status = request->Read(buffer, kResourceBufferSizeBytes, &bytes_read);
171 171
172 if (status) { 172 if (request->status().error()) {
rvargas (doing something else) 2013/01/04 02:02:40 The contract is not to inspect status() regardless
Shishir 2013/01/04 02:21:14 From the comment on the Read function: // If a rea
173 if (request->status().error()) { 173 FinishRequest(request, Request::PREFETCH_STATUS_FAILED);
174 FinishRequest(request, Request::PREFETCH_STATUS_FAILED); 174 return;
175 return; 175 }
176 } else if (bytes_read == 0) { 176
177 if (request->was_cached()) 177 if (status && bytes_read == 0) { // When bytes_read == 0, no more data.
178 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); 178 if (request->was_cached())
179 else 179 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE);
180 FinishRequest(request, Request::PREFETCH_STATUS_FROM_NETWORK); 180 else
181 return; 181 FinishRequest(request, Request::PREFETCH_STATUS_FROM_NETWORK);
182 } 182 return;
183 } 183 }
184 } 184 }
185 } 185 }
186 186
187 void ResourcePrefetcher::OnReceivedRedirect(net::URLRequest* request, 187 void ResourcePrefetcher::OnReceivedRedirect(net::URLRequest* request,
188 const GURL& new_url, 188 const GURL& new_url,
189 bool* defer_redirect) { 189 bool* defer_redirect) {
190 FinishRequest(request, Request::PREFETCH_STATUS_REDIRECTED); 190 FinishRequest(request, Request::PREFETCH_STATUS_REDIRECTED);
191 } 191 }
192 192
(...skipping 23 matching lines...) Expand all
216 ReadFullResponse(request); 216 ReadFullResponse(request);
217 } 217 }
218 218
219 void ResourcePrefetcher::OnReadCompleted(net::URLRequest* request, 219 void ResourcePrefetcher::OnReadCompleted(net::URLRequest* request,
220 int bytes_read) { 220 int bytes_read) {
221 if (request->status().error()) { 221 if (request->status().error()) {
222 FinishRequest(request, Request::PREFETCH_STATUS_FAILED); 222 FinishRequest(request, Request::PREFETCH_STATUS_FAILED);
223 return; 223 return;
224 } 224 }
225 225
226 // If the bytes_read is == 0, there is no more data to read.
227 if (bytes_read == 0) {
228 if (request->was_cached())
229 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE);
230 else
231 FinishRequest(request, Request::PREFETCH_STATUS_FROM_NETWORK);
232 return;
233 }
234
226 ReadFullResponse(request); 235 ReadFullResponse(request);
227 } 236 }
228 237
229 } // namespace predictors 238 } // namespace predictors
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698