| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 doomed(false) { | 153 doomed(false) { |
| 154 } | 154 } |
| 155 | 155 |
| 156 HttpCache::ActiveEntry::~ActiveEntry() { | 156 HttpCache::ActiveEntry::~ActiveEntry() { |
| 157 if (disk_entry) | 157 if (disk_entry) |
| 158 disk_entry->Close(); | 158 disk_entry->Close(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 //----------------------------------------------------------------------------- | 161 //----------------------------------------------------------------------------- |
| 162 | 162 |
| 163 class HttpCache::Transaction : public HttpTransaction { | 163 class HttpCache::Transaction |
| 164 : public HttpTransaction, public RevocableStore::Revocable { |
| 164 public: | 165 public: |
| 165 explicit Transaction(HttpCache* cache) | 166 explicit Transaction(HttpCache* cache) |
| 166 : request_(NULL), | 167 : RevocableStore::Revocable(&cache->transactions_), |
| 168 request_(NULL), |
| 167 cache_(cache), | 169 cache_(cache), |
| 168 entry_(NULL), | 170 entry_(NULL), |
| 169 network_trans_(NULL), | 171 network_trans_(NULL), |
| 170 callback_(NULL), | 172 callback_(NULL), |
| 171 mode_(NONE), | 173 mode_(NONE), |
| 172 read_offset_(0), | 174 read_offset_(0), |
| 173 effective_load_flags_(0), | 175 effective_load_flags_(0), |
| 174 final_upload_progress_(0), | 176 final_upload_progress_(0), |
| 175 ALLOW_THIS_IN_INITIALIZER_LIST( | 177 ALLOW_THIS_IN_INITIALIZER_LIST( |
| 176 network_info_callback_(this, &Transaction::OnNetworkInfoAvailable)), | 178 network_info_callback_(this, &Transaction::OnNetworkInfoAvailable)), |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 scoped_refptr<IOBuffer> read_buf_; | 313 scoped_refptr<IOBuffer> read_buf_; |
| 312 int read_offset_; | 314 int read_offset_; |
| 313 int effective_load_flags_; | 315 int effective_load_flags_; |
| 314 uint64 final_upload_progress_; | 316 uint64 final_upload_progress_; |
| 315 CompletionCallbackImpl<Transaction> network_info_callback_; | 317 CompletionCallbackImpl<Transaction> network_info_callback_; |
| 316 CompletionCallbackImpl<Transaction> network_read_callback_; | 318 CompletionCallbackImpl<Transaction> network_read_callback_; |
| 317 scoped_refptr<CancelableCompletionCallback<Transaction> > cache_read_callback_
; | 319 scoped_refptr<CancelableCompletionCallback<Transaction> > cache_read_callback_
; |
| 318 }; | 320 }; |
| 319 | 321 |
| 320 HttpCache::Transaction::~Transaction() { | 322 HttpCache::Transaction::~Transaction() { |
| 321 if (entry_) { | 323 if (!revoked()) { |
| 322 cache_->DoneWithEntry(entry_, this); | 324 if (entry_) { |
| 323 } else { | 325 cache_->DoneWithEntry(entry_, this); |
| 324 cache_->RemovePendingTransaction(this); | 326 } else { |
| 327 cache_->RemovePendingTransaction(this); |
| 328 } |
| 325 } | 329 } |
| 326 | 330 |
| 327 // If there is an outstanding callback, mark it as cancelled so running it | 331 // If there is an outstanding callback, mark it as cancelled so running it |
| 328 // does nothing. | 332 // does nothing. |
| 329 cache_read_callback_->Cancel(); | 333 cache_read_callback_->Cancel(); |
| 330 | 334 |
| 331 // We could still have a cache read in progress, so we just null the cache_ | 335 // We could still have a cache read in progress, so we just null the cache_ |
| 332 // pointer to signal that we are dead. See OnCacheReadCompleted. | 336 // pointer to signal that we are dead. See OnCacheReadCompleted. |
| 333 cache_ = NULL; | 337 cache_ = NULL; |
| 334 } | 338 } |
| 335 | 339 |
| 336 int HttpCache::Transaction::Start(const HttpRequestInfo* request, | 340 int HttpCache::Transaction::Start(const HttpRequestInfo* request, |
| 337 CompletionCallback* callback) { | 341 CompletionCallback* callback) { |
| 338 DCHECK(request); | 342 DCHECK(request); |
| 339 DCHECK(callback); | 343 DCHECK(callback); |
| 340 | 344 |
| 341 // ensure that we only have one asynchronous call at a time. | 345 // ensure that we only have one asynchronous call at a time. |
| 342 DCHECK(!callback_); | 346 DCHECK(!callback_); |
| 343 | 347 |
| 348 if (revoked()) |
| 349 return ERR_FAILED; |
| 350 |
| 344 SetRequest(request); | 351 SetRequest(request); |
| 345 | 352 |
| 346 int rv; | 353 int rv; |
| 347 | 354 |
| 348 if (ShouldPassThrough()) { | 355 if (ShouldPassThrough()) { |
| 349 // if must use cache, then we must fail. this can happen for back/forward | 356 // if must use cache, then we must fail. this can happen for back/forward |
| 350 // navigations to a page generated via a form post. | 357 // navigations to a page generated via a form post. |
| 351 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) | 358 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) |
| 352 return ERR_CACHE_MISS; | 359 return ERR_CACHE_MISS; |
| 353 | 360 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 | 485 |
| 479 uint64 HttpCache::Transaction::GetUploadProgress() const { | 486 uint64 HttpCache::Transaction::GetUploadProgress() const { |
| 480 if (network_trans_.get()) | 487 if (network_trans_.get()) |
| 481 return network_trans_->GetUploadProgress(); | 488 return network_trans_->GetUploadProgress(); |
| 482 return final_upload_progress_; | 489 return final_upload_progress_; |
| 483 } | 490 } |
| 484 | 491 |
| 485 int HttpCache::Transaction::AddToEntry() { | 492 int HttpCache::Transaction::AddToEntry() { |
| 486 ActiveEntry* entry = NULL; | 493 ActiveEntry* entry = NULL; |
| 487 | 494 |
| 495 if (revoked()) |
| 496 return ERR_FAILED; |
| 497 |
| 488 if (mode_ == WRITE) { | 498 if (mode_ == WRITE) { |
| 489 cache_->DoomEntry(cache_key_); | 499 cache_->DoomEntry(cache_key_); |
| 490 } else { | 500 } else { |
| 491 entry = cache_->FindActiveEntry(cache_key_); | 501 entry = cache_->FindActiveEntry(cache_key_); |
| 492 if (!entry) { | 502 if (!entry) { |
| 493 entry = cache_->OpenEntry(cache_key_); | 503 entry = cache_->OpenEntry(cache_key_); |
| 494 if (!entry) { | 504 if (!entry) { |
| 495 if (mode_ & WRITE) { | 505 if (mode_ & WRITE) { |
| 496 mode_ = WRITE; | 506 mode_ = WRITE; |
| 497 } else { | 507 } else { |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 << " status: " << response_.headers->response_code(); | 845 << " status: " << response_.headers->response_code(); |
| 836 | 846 |
| 837 cache_->DoneWritingToEntry(entry_, success); | 847 cache_->DoneWritingToEntry(entry_, success); |
| 838 entry_ = NULL; | 848 entry_ = NULL; |
| 839 mode_ = NONE; // switch to 'pass through' mode | 849 mode_ = NONE; // switch to 'pass through' mode |
| 840 } | 850 } |
| 841 | 851 |
| 842 void HttpCache::Transaction::OnNetworkInfoAvailable(int result) { | 852 void HttpCache::Transaction::OnNetworkInfoAvailable(int result) { |
| 843 DCHECK(result != ERR_IO_PENDING); | 853 DCHECK(result != ERR_IO_PENDING); |
| 844 | 854 |
| 855 if (revoked()) |
| 856 return; |
| 857 |
| 845 if (result == OK) { | 858 if (result == OK) { |
| 846 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); | 859 const HttpResponseInfo* new_response = network_trans_->GetResponseInfo(); |
| 847 if (new_response->headers->response_code() == 401 || | 860 if (new_response->headers->response_code() == 401 || |
| 848 new_response->headers->response_code() == 407) { | 861 new_response->headers->response_code() == 407) { |
| 849 auth_response_ = *new_response; | 862 auth_response_ = *new_response; |
| 850 } else { | 863 } else { |
| 851 // Are we expecting a response to a conditional query? | 864 // Are we expecting a response to a conditional query? |
| 852 if (mode_ == READ_WRITE) { | 865 if (mode_ == READ_WRITE) { |
| 853 if (new_response->headers->response_code() == 304) { | 866 if (new_response->headers->response_code() == 304) { |
| 854 // Update cached response based on headers in new_response | 867 // Update cached response based on headers in new_response |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1372 | 1385 |
| 1373 entry->pending_queue.erase(entry->pending_queue.begin()); | 1386 entry->pending_queue.erase(entry->pending_queue.begin()); |
| 1374 | 1387 |
| 1375 AddTransactionToEntry(entry, next); | 1388 AddTransactionToEntry(entry, next); |
| 1376 } | 1389 } |
| 1377 | 1390 |
| 1378 //----------------------------------------------------------------------------- | 1391 //----------------------------------------------------------------------------- |
| 1379 | 1392 |
| 1380 } // namespace net | 1393 } // namespace net |
| 1381 | 1394 |
| OLD | NEW |