| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 const std::string& key() const { return cache_key_; } | 246 const std::string& key() const { return cache_key_; } |
| 247 | 247 |
| 248 // Associates this transaction with a cache entry. | 248 // Associates this transaction with a cache entry. |
| 249 int AddToEntry(); | 249 int AddToEntry(); |
| 250 | 250 |
| 251 // Called by the HttpCache when the given disk cache entry becomes accessible | 251 // Called by the HttpCache when the given disk cache entry becomes accessible |
| 252 // to the transaction. Returns network error code. | 252 // to the transaction. Returns network error code. |
| 253 int EntryAvailable(ActiveEntry* entry); | 253 int EntryAvailable(ActiveEntry* entry); |
| 254 | 254 |
| 255 // This transaction is being deleted and we are not done writing to the cache. | 255 // This transaction is being deleted and we are not done writing to the cache. |
| 256 // We need to indicate that the response data was truncated. | 256 // We need to indicate that the response data was truncated. Returns true on |
| 257 void AddTruncatedFlag(); | 257 // success. |
| 258 bool AddTruncatedFlag(); |
| 258 | 259 |
| 259 private: | 260 private: |
| 260 // This is a helper function used to trigger a completion callback. It may | 261 // This is a helper function used to trigger a completion callback. It may |
| 261 // only be called if callback_ is non-null. | 262 // only be called if callback_ is non-null. |
| 262 void DoCallback(int rv); | 263 void DoCallback(int rv); |
| 263 | 264 |
| 264 // This will trigger the completion callback if appropriate. | 265 // This will trigger the completion callback if appropriate. |
| 265 int HandleResult(int rv); | 266 int HandleResult(int rv); |
| 266 | 267 |
| 267 // Sets request_ and fields derived from it. | 268 // Sets request_ and fields derived from it. |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 uint64 final_upload_progress_; | 402 uint64 final_upload_progress_; |
| 402 CompletionCallbackImpl<Transaction> network_info_callback_; | 403 CompletionCallbackImpl<Transaction> network_info_callback_; |
| 403 CompletionCallbackImpl<Transaction> network_read_callback_; | 404 CompletionCallbackImpl<Transaction> network_read_callback_; |
| 404 scoped_refptr<CancelableCompletionCallback<Transaction> > | 405 scoped_refptr<CancelableCompletionCallback<Transaction> > |
| 405 cache_read_callback_; | 406 cache_read_callback_; |
| 406 }; | 407 }; |
| 407 | 408 |
| 408 HttpCache::Transaction::~Transaction() { | 409 HttpCache::Transaction::~Transaction() { |
| 409 if (!revoked()) { | 410 if (!revoked()) { |
| 410 if (entry_) { | 411 if (entry_) { |
| 411 bool cancel_request = reading_ && !partial_.get() && | 412 bool cancel_request = reading_ && enable_range_support_; |
| 412 enable_range_support_ && | 413 if (cancel_request && !partial_.get()) |
| 413 response_.headers->response_code() == 200; | 414 cancel_request &= (response_.headers->response_code() == 200); |
| 414 | 415 |
| 415 cache_->DoneWithEntry(entry_, this, cancel_request); | 416 cache_->DoneWithEntry(entry_, this, cancel_request); |
| 416 } else { | 417 } else { |
| 417 cache_->RemovePendingTransaction(this); | 418 cache_->RemovePendingTransaction(this); |
| 418 } | 419 } |
| 419 } | 420 } |
| 420 | 421 |
| 421 // If there is an outstanding callback, mark it as cancelled so running it | 422 // If there is an outstanding callback, mark it as cancelled so running it |
| 422 // does nothing. | 423 // does nothing. |
| 423 cache_read_callback_->Cancel(); | 424 cache_read_callback_->Cancel(); |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 712 case UPDATE: | 713 case UPDATE: |
| 713 rv = BeginExternallyConditionalizedRequest(); | 714 rv = BeginExternallyConditionalizedRequest(); |
| 714 break; | 715 break; |
| 715 default: | 716 default: |
| 716 NOTREACHED(); | 717 NOTREACHED(); |
| 717 rv = ERR_FAILED; | 718 rv = ERR_FAILED; |
| 718 } | 719 } |
| 719 return rv; | 720 return rv; |
| 720 } | 721 } |
| 721 | 722 |
| 722 void HttpCache::Transaction::AddTruncatedFlag() { | 723 bool HttpCache::Transaction::AddTruncatedFlag() { |
| 723 DCHECK(mode_ & WRITE); | 724 DCHECK(mode_ & WRITE); |
| 725 |
| 726 // Don't set the flag for sparse entries. |
| 727 if (partial_.get()) |
| 728 return true; |
| 729 |
| 730 // Double check that there is something worth keeping. |
| 731 if (!entry_->disk_entry->GetDataSize(kResponseContentIndex)) |
| 732 return false; |
| 733 |
| 724 truncated_ = true; | 734 truncated_ = true; |
| 725 WriteResponseInfoToEntry(true); | 735 WriteResponseInfoToEntry(true); |
| 736 return true; |
| 726 } | 737 } |
| 727 | 738 |
| 728 void HttpCache::Transaction::DoCallback(int rv) { | 739 void HttpCache::Transaction::DoCallback(int rv) { |
| 729 DCHECK(rv != ERR_IO_PENDING); | 740 DCHECK(rv != ERR_IO_PENDING); |
| 730 DCHECK(callback_); | 741 DCHECK(callback_); |
| 731 | 742 |
| 732 // since Run may result in Read being called, clear callback_ up front. | 743 // since Run may result in Read being called, clear callback_ up front. |
| 733 CompletionCallback* c = callback_; | 744 CompletionCallback* c = callback_; |
| 734 callback_ = NULL; | 745 callback_ = NULL; |
| 735 c->Run(rv); | 746 c->Run(rv); |
| (...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1996 | 2007 |
| 1997 if (entry->writer) { | 2008 if (entry->writer) { |
| 1998 DCHECK(trans == entry->writer); | 2009 DCHECK(trans == entry->writer); |
| 1999 | 2010 |
| 2000 // Assume there was a failure. | 2011 // Assume there was a failure. |
| 2001 bool success = false; | 2012 bool success = false; |
| 2002 if (cancel) { | 2013 if (cancel) { |
| 2003 DCHECK(entry->disk_entry); | 2014 DCHECK(entry->disk_entry); |
| 2004 // This is a successful operation in the sense that we want to keep the | 2015 // This is a successful operation in the sense that we want to keep the |
| 2005 // entry. | 2016 // entry. |
| 2006 success = true; | 2017 success = trans->AddTruncatedFlag(); |
| 2007 // Double check that there is something worth keeping. | |
| 2008 if (!entry->disk_entry->GetDataSize(kResponseContentIndex)) | |
| 2009 success = false; | |
| 2010 trans->AddTruncatedFlag(); | |
| 2011 } | 2018 } |
| 2012 DoneWritingToEntry(entry, success); | 2019 DoneWritingToEntry(entry, success); |
| 2013 } else { | 2020 } else { |
| 2014 DoneReadingFromEntry(entry, trans); | 2021 DoneReadingFromEntry(entry, trans); |
| 2015 } | 2022 } |
| 2016 } | 2023 } |
| 2017 | 2024 |
| 2018 void HttpCache::DoneWritingToEntry(ActiveEntry* entry, bool success) { | 2025 void HttpCache::DoneWritingToEntry(ActiveEntry* entry, bool success) { |
| 2019 DCHECK(entry->readers.empty()); | 2026 DCHECK(entry->readers.empty()); |
| 2020 | 2027 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2120 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); | 2127 static_cast<net::HttpNetworkLayer*>(network_layer_.get()); |
| 2121 HttpNetworkSession* session = network->GetSession(); | 2128 HttpNetworkSession* session = network->GetSession(); |
| 2122 if (session) { | 2129 if (session) { |
| 2123 session->tcp_socket_pool()->CloseIdleSockets(); | 2130 session->tcp_socket_pool()->CloseIdleSockets(); |
| 2124 } | 2131 } |
| 2125 } | 2132 } |
| 2126 | 2133 |
| 2127 //----------------------------------------------------------------------------- | 2134 //----------------------------------------------------------------------------- |
| 2128 | 2135 |
| 2129 } // namespace net | 2136 } // namespace net |
| OLD | NEW |