OLD | NEW |
---|---|
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 | 160 |
161 TryToLaunchPrefetchRequests(); | 161 TryToLaunchPrefetchRequests(); |
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); |
rvargas (doing something else)
2013/01/03 23:16:09
I'm surprised that we keep reading and discarding
Shishir
2013/01/04 00:29:04
We dont need to use the data, only warm up the cac
rvargas (doing something else)
2013/01/04 01:04:59
yes, I'm surprised that we keep reading even if th
Shishir
2013/01/04 01:29:15
Right! Will add a todo. Will fix this in an upcomi
| |
171 | 171 |
172 if (status) { | 172 if (status) { |
173 if (request->status().error()) { | 173 if (request->status().error()) { |
174 FinishRequest(request, Request::PREFETCH_STATUS_FAILED); | 174 FinishRequest(request, Request::PREFETCH_STATUS_FAILED); |
175 return; | 175 return; |
176 } else if (bytes_read == 0) { | 176 } else if (bytes_read == 0) { |
177 if (request->was_cached()) | 177 if (request->was_cached()) |
178 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); | 178 FinishRequest(request, Request::PREFETCH_STATUS_FROM_CACHE); |
179 else | 179 else |
180 FinishRequest(request, Request::PREFETCH_STATUS_FROM_NETWORK); | 180 FinishRequest(request, Request::PREFETCH_STATUS_FROM_NETWORK); |
(...skipping 30 matching lines...) Expand all Loading... | |
211 if (request->status().error()) { | 211 if (request->status().error()) { |
212 FinishRequest(request, Request::PREFETCH_STATUS_FAILED); | 212 FinishRequest(request, Request::PREFETCH_STATUS_FAILED); |
213 return; | 213 return; |
214 } | 214 } |
215 | 215 |
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()) { |
rvargas (doing something else)
2013/01/03 23:16:09
This is a lot of code duplication with ReadFullRes
Shishir
2013/01/04 00:29:04
Not sure if I fully understand your comment. The c
rvargas (doing something else)
2013/01/04 01:04:59
I meant:
while (status) {
status = req->Read();
| |
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) { | |
rvargas (doing something else)
2013/01/03 23:16:09
Note that this condition is not the same one used
Shishir
2013/01/04 00:29:04
Fixed this to be == 0 as above.
| |
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 |
OLD | NEW |