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 "net/url_request/view_cache_helper.h" | 5 #include "net/url_request/view_cache_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/stringprintf.h" | 9 #include "base/stringprintf.h" |
10 #include "net/base/escape.h" | 10 #include "net/base/escape.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 281 } |
282 | 282 |
283 int ViewCacheHelper::DoReadResponse() { | 283 int ViewCacheHelper::DoReadResponse() { |
284 next_state_ = STATE_READ_RESPONSE_COMPLETE; | 284 next_state_ = STATE_READ_RESPONSE_COMPLETE; |
285 buf_len_ = entry_->GetDataSize(0); | 285 buf_len_ = entry_->GetDataSize(0); |
286 if (!buf_len_) | 286 if (!buf_len_) |
287 return buf_len_; | 287 return buf_len_; |
288 | 288 |
289 buf_ = new IOBuffer(buf_len_); | 289 buf_ = new IOBuffer(buf_len_); |
290 return entry_->ReadData( | 290 return entry_->ReadData( |
291 0, 0, buf_, buf_len_, | 291 0, |
| 292 0, |
| 293 buf_.get(), |
| 294 buf_len_, |
292 base::Bind(&ViewCacheHelper::OnIOComplete, weak_factory_.GetWeakPtr())); | 295 base::Bind(&ViewCacheHelper::OnIOComplete, weak_factory_.GetWeakPtr())); |
293 } | 296 } |
294 | 297 |
295 int ViewCacheHelper::DoReadResponseComplete(int result) { | 298 int ViewCacheHelper::DoReadResponseComplete(int result) { |
296 if (result && result == buf_len_) { | 299 if (result && result == buf_len_) { |
297 HttpResponseInfo response; | 300 HttpResponseInfo response; |
298 bool truncated; | 301 bool truncated; |
299 if (HttpCache::ParseResponseInfo(buf_->data(), buf_len_, &response, | 302 if (HttpCache::ParseResponseInfo( |
300 &truncated) && | 303 buf_->data(), buf_len_, &response, &truncated) && |
301 response.headers) { | 304 response.headers.get()) { |
302 if (truncated) | 305 if (truncated) |
303 data_->append("<pre>RESPONSE_INFO_TRUNCATED</pre>"); | 306 data_->append("<pre>RESPONSE_INFO_TRUNCATED</pre>"); |
304 | 307 |
305 data_->append("<hr><pre>"); | 308 data_->append("<hr><pre>"); |
306 data_->append(EscapeForHTML(response.headers->GetStatusLine())); | 309 data_->append(EscapeForHTML(response.headers->GetStatusLine())); |
307 data_->push_back('\n'); | 310 data_->push_back('\n'); |
308 | 311 |
309 void* iter = NULL; | 312 void* iter = NULL; |
310 std::string name, value; | 313 std::string name, value; |
311 while (response.headers->EnumerateHeaderLines(&iter, &name, &value)) { | 314 while (response.headers->EnumerateHeaderLines(&iter, &name, &value)) { |
(...skipping 14 matching lines...) Expand all Loading... |
326 int ViewCacheHelper::DoReadData() { | 329 int ViewCacheHelper::DoReadData() { |
327 data_->append("<hr><pre>"); | 330 data_->append("<hr><pre>"); |
328 | 331 |
329 next_state_ = STATE_READ_DATA_COMPLETE; | 332 next_state_ = STATE_READ_DATA_COMPLETE; |
330 buf_len_ = entry_->GetDataSize(index_); | 333 buf_len_ = entry_->GetDataSize(index_); |
331 if (!buf_len_) | 334 if (!buf_len_) |
332 return buf_len_; | 335 return buf_len_; |
333 | 336 |
334 buf_ = new IOBuffer(buf_len_); | 337 buf_ = new IOBuffer(buf_len_); |
335 return entry_->ReadData( | 338 return entry_->ReadData( |
336 index_, 0, buf_, buf_len_, | 339 index_, |
| 340 0, |
| 341 buf_.get(), |
| 342 buf_len_, |
337 base::Bind(&ViewCacheHelper::OnIOComplete, weak_factory_.GetWeakPtr())); | 343 base::Bind(&ViewCacheHelper::OnIOComplete, weak_factory_.GetWeakPtr())); |
338 } | 344 } |
339 | 345 |
340 int ViewCacheHelper::DoReadDataComplete(int result) { | 346 int ViewCacheHelper::DoReadDataComplete(int result) { |
341 if (result && result == buf_len_) { | 347 if (result && result == buf_len_) { |
342 HexDump(buf_->data(), buf_len_, data_); | 348 HexDump(buf_->data(), buf_len_, data_); |
343 } | 349 } |
344 data_->append("</pre>"); | 350 data_->append("</pre>"); |
345 index_++; | 351 index_++; |
346 if (index_ < HttpCache::kNumCacheEntryDataIndices) { | 352 if (index_ < HttpCache::kNumCacheEntryDataIndices) { |
347 next_state_ = STATE_READ_DATA; | 353 next_state_ = STATE_READ_DATA; |
348 } else { | 354 } else { |
349 data_->append(VIEW_CACHE_TAIL); | 355 data_->append(VIEW_CACHE_TAIL); |
350 entry_->Close(); | 356 entry_->Close(); |
351 entry_ = NULL; | 357 entry_ = NULL; |
352 } | 358 } |
353 return OK; | 359 return OK; |
354 } | 360 } |
355 | 361 |
356 void ViewCacheHelper::OnIOComplete(int result) { | 362 void ViewCacheHelper::OnIOComplete(int result) { |
357 DoLoop(result); | 363 DoLoop(result); |
358 } | 364 } |
359 | 365 |
360 } // namespace net. | 366 } // namespace net. |
OLD | NEW |