| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 10 #include "net/base/escape.h" | 8 #include "net/base/escape.h" |
| 11 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
| 12 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| 13 #include "net/disk_cache/disk_cache.h" | 11 #include "net/disk_cache/disk_cache.h" |
| 14 #include "net/http/http_cache.h" | 12 #include "net/http/http_cache.h" |
| 15 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
| 16 #include "net/http/http_response_info.h" | 14 #include "net/http/http_response_info.h" |
| 17 #include "net/url_request/url_request_context.h" | 15 #include "net/url_request/url_request_context.h" |
| 18 | 16 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 41 } // namespace. | 39 } // namespace. |
| 42 | 40 |
| 43 ViewCacheHelper::ViewCacheHelper() | 41 ViewCacheHelper::ViewCacheHelper() |
| 44 : disk_cache_(NULL), | 42 : disk_cache_(NULL), |
| 45 entry_(NULL), | 43 entry_(NULL), |
| 46 iter_(NULL), | 44 iter_(NULL), |
| 47 buf_len_(0), | 45 buf_len_(0), |
| 48 index_(0), | 46 index_(0), |
| 49 data_(NULL), | 47 data_(NULL), |
| 50 next_state_(STATE_NONE), | 48 next_state_(STATE_NONE), |
| 51 ALLOW_THIS_IN_INITIALIZER_LIST(cache_callback_( | |
| 52 base::Bind(&ViewCacheHelper::OnIOComplete, base::Unretained(this)))), | |
| 53 ALLOW_THIS_IN_INITIALIZER_LIST( | 49 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 54 old_cache_callback_(this, &ViewCacheHelper::OnIOComplete)), | 50 cache_callback_(this, &ViewCacheHelper::OnIOComplete)), |
| 55 ALLOW_THIS_IN_INITIALIZER_LIST( | 51 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 56 entry_callback_(new CancelableOldCompletionCallback<ViewCacheHelper>( | 52 entry_callback_(new CancelableOldCompletionCallback<ViewCacheHelper>( |
| 57 this, &ViewCacheHelper::OnIOComplete))) { | 53 this, &ViewCacheHelper::OnIOComplete))) { |
| 58 } | 54 } |
| 59 | 55 |
| 60 ViewCacheHelper::~ViewCacheHelper() { | 56 ViewCacheHelper::~ViewCacheHelper() { |
| 61 if (entry_) | 57 if (entry_) |
| 62 entry_->Close(); | 58 entry_->Close(); |
| 63 | 59 |
| 64 // Cancel any pending entry callback. | 60 // Cancel any pending entry callback. |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 int ViewCacheHelper::DoGetBackend() { | 212 int ViewCacheHelper::DoGetBackend() { |
| 217 next_state_ = STATE_GET_BACKEND_COMPLETE; | 213 next_state_ = STATE_GET_BACKEND_COMPLETE; |
| 218 | 214 |
| 219 if (!context_->http_transaction_factory()) | 215 if (!context_->http_transaction_factory()) |
| 220 return ERR_FAILED; | 216 return ERR_FAILED; |
| 221 | 217 |
| 222 HttpCache* http_cache = context_->http_transaction_factory()->GetCache(); | 218 HttpCache* http_cache = context_->http_transaction_factory()->GetCache(); |
| 223 if (!http_cache) | 219 if (!http_cache) |
| 224 return ERR_FAILED; | 220 return ERR_FAILED; |
| 225 | 221 |
| 226 return http_cache->GetBackend(&disk_cache_, cache_callback_); | 222 return http_cache->GetBackend(&disk_cache_, &cache_callback_); |
| 227 } | 223 } |
| 228 | 224 |
| 229 int ViewCacheHelper::DoGetBackendComplete(int result) { | 225 int ViewCacheHelper::DoGetBackendComplete(int result) { |
| 230 if (result == ERR_FAILED) { | 226 if (result == ERR_FAILED) { |
| 231 data_->append("no disk cache"); | 227 data_->append("no disk cache"); |
| 232 return OK; | 228 return OK; |
| 233 } | 229 } |
| 234 | 230 |
| 235 DCHECK_EQ(OK, result); | 231 DCHECK_EQ(OK, result); |
| 236 if (key_.empty()) { | 232 if (key_.empty()) { |
| 237 data_->assign(VIEW_CACHE_HEAD); | 233 data_->assign(VIEW_CACHE_HEAD); |
| 238 DCHECK(!iter_); | 234 DCHECK(!iter_); |
| 239 next_state_ = STATE_OPEN_NEXT_ENTRY; | 235 next_state_ = STATE_OPEN_NEXT_ENTRY; |
| 240 return OK; | 236 return OK; |
| 241 } | 237 } |
| 242 | 238 |
| 243 next_state_ = STATE_OPEN_ENTRY; | 239 next_state_ = STATE_OPEN_ENTRY; |
| 244 return OK; | 240 return OK; |
| 245 } | 241 } |
| 246 | 242 |
| 247 int ViewCacheHelper::DoOpenNextEntry() { | 243 int ViewCacheHelper::DoOpenNextEntry() { |
| 248 next_state_ = STATE_OPEN_NEXT_ENTRY_COMPLETE; | 244 next_state_ = STATE_OPEN_NEXT_ENTRY_COMPLETE; |
| 249 return disk_cache_->OpenNextEntry(&iter_, &entry_, &old_cache_callback_); | 245 return disk_cache_->OpenNextEntry(&iter_, &entry_, &cache_callback_); |
| 250 } | 246 } |
| 251 | 247 |
| 252 int ViewCacheHelper::DoOpenNextEntryComplete(int result) { | 248 int ViewCacheHelper::DoOpenNextEntryComplete(int result) { |
| 253 if (result == ERR_FAILED) { | 249 if (result == ERR_FAILED) { |
| 254 data_->append(VIEW_CACHE_TAIL); | 250 data_->append(VIEW_CACHE_TAIL); |
| 255 return OK; | 251 return OK; |
| 256 } | 252 } |
| 257 | 253 |
| 258 DCHECK_EQ(OK, result); | 254 DCHECK_EQ(OK, result); |
| 259 data_->append(FormatEntryInfo(entry_, url_prefix_)); | 255 data_->append(FormatEntryInfo(entry_, url_prefix_)); |
| 260 entry_->Close(); | 256 entry_->Close(); |
| 261 entry_ = NULL; | 257 entry_ = NULL; |
| 262 | 258 |
| 263 next_state_ = STATE_OPEN_NEXT_ENTRY; | 259 next_state_ = STATE_OPEN_NEXT_ENTRY; |
| 264 return OK; | 260 return OK; |
| 265 } | 261 } |
| 266 | 262 |
| 267 int ViewCacheHelper::DoOpenEntry() { | 263 int ViewCacheHelper::DoOpenEntry() { |
| 268 next_state_ = STATE_OPEN_ENTRY_COMPLETE; | 264 next_state_ = STATE_OPEN_ENTRY_COMPLETE; |
| 269 return disk_cache_->OpenEntry(key_, &entry_, &old_cache_callback_); | 265 return disk_cache_->OpenEntry(key_, &entry_, &cache_callback_); |
| 270 } | 266 } |
| 271 | 267 |
| 272 int ViewCacheHelper::DoOpenEntryComplete(int result) { | 268 int ViewCacheHelper::DoOpenEntryComplete(int result) { |
| 273 if (result == ERR_FAILED) { | 269 if (result == ERR_FAILED) { |
| 274 data_->append("no matching cache entry for: " + EscapeForHTML(key_)); | 270 data_->append("no matching cache entry for: " + EscapeForHTML(key_)); |
| 275 return OK; | 271 return OK; |
| 276 } | 272 } |
| 277 | 273 |
| 278 data_->assign(VIEW_CACHE_HEAD); | 274 data_->assign(VIEW_CACHE_HEAD); |
| 279 data_->append(EscapeForHTML(entry_->GetKey())); | 275 data_->append(EscapeForHTML(entry_->GetKey())); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 entry_ = NULL; | 348 entry_ = NULL; |
| 353 } | 349 } |
| 354 return OK; | 350 return OK; |
| 355 } | 351 } |
| 356 | 352 |
| 357 void ViewCacheHelper::OnIOComplete(int result) { | 353 void ViewCacheHelper::OnIOComplete(int result) { |
| 358 DoLoop(result); | 354 DoLoop(result); |
| 359 } | 355 } |
| 360 | 356 |
| 361 } // namespace net. | 357 } // namespace net. |
| OLD | NEW |