Chromium Code Reviews| 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/http/http_cache_transaction.h" | 5 #include "net/http/http_cache_transaction.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 | 8 |
| 9 #if defined(OS_POSIX) | 9 #if defined(OS_POSIX) |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
| 26 #include "net/base/net_errors.h" | 26 #include "net/base/net_errors.h" |
| 27 #include "net/base/net_log.h" | 27 #include "net/base/net_log.h" |
| 28 #include "net/base/ssl_cert_request_info.h" | 28 #include "net/base/ssl_cert_request_info.h" |
| 29 #include "net/base/ssl_config_service.h" | 29 #include "net/base/ssl_config_service.h" |
| 30 #include "net/disk_cache/disk_cache.h" | 30 #include "net/disk_cache/disk_cache.h" |
| 31 #include "net/http/http_network_session.h" | 31 #include "net/http/http_network_session.h" |
| 32 #include "net/http/http_request_info.h" | 32 #include "net/http/http_request_info.h" |
| 33 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 34 #include "net/http/http_transaction.h" | 34 #include "net/http/http_transaction.h" |
| 35 #include "net/http/http_transaction_delegate.h" | |
| 35 #include "net/http/http_util.h" | 36 #include "net/http/http_util.h" |
| 36 #include "net/http/partial_data.h" | 37 #include "net/http/partial_data.h" |
| 37 | 38 |
| 38 using base::Time; | 39 using base::Time; |
| 39 | 40 |
| 40 namespace net { | 41 namespace net { |
| 41 | 42 |
| 42 struct HeaderNameAndValue { | 43 struct HeaderNameAndValue { |
| 43 const char* name; | 44 const char* name; |
| 44 const char* value; | 45 const char* value; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 92 while (v.GetNext()) { | 93 while (v.GetNext()) { |
| 93 if (LowerCaseEqualsASCII(v.value_begin(), v.value_end(), search->value)) | 94 if (LowerCaseEqualsASCII(v.value_begin(), v.value_end(), search->value)) |
| 94 return true; | 95 return true; |
| 95 } | 96 } |
| 96 } | 97 } |
| 97 return false; | 98 return false; |
| 98 } | 99 } |
| 99 | 100 |
| 100 //----------------------------------------------------------------------------- | 101 //----------------------------------------------------------------------------- |
| 101 | 102 |
| 102 HttpCache::Transaction::Transaction(HttpCache* cache) | 103 HttpCache::Transaction::Transaction(HttpCache* cache, |
| 104 HttpTransactionDelegate* delegate) | |
| 103 : next_state_(STATE_NONE), | 105 : next_state_(STATE_NONE), |
| 104 request_(NULL), | 106 request_(NULL), |
| 105 cache_(cache->AsWeakPtr()), | 107 cache_(cache->AsWeakPtr()), |
| 106 entry_(NULL), | 108 entry_(NULL), |
| 107 new_entry_(NULL), | 109 new_entry_(NULL), |
| 108 network_trans_(NULL), | 110 network_trans_(NULL), |
| 109 new_response_(NULL), | 111 new_response_(NULL), |
| 110 mode_(NONE), | 112 mode_(NONE), |
| 111 target_state_(STATE_NONE), | 113 target_state_(STATE_NONE), |
| 112 reading_(false), | 114 reading_(false), |
| 113 invalid_range_(false), | 115 invalid_range_(false), |
| 114 truncated_(false), | 116 truncated_(false), |
| 115 is_sparse_(false), | 117 is_sparse_(false), |
| 116 range_requested_(false), | 118 range_requested_(false), |
| 117 handling_206_(false), | 119 handling_206_(false), |
| 118 cache_pending_(false), | 120 cache_pending_(false), |
| 119 done_reading_(false), | 121 done_reading_(false), |
| 120 read_offset_(0), | 122 read_offset_(0), |
| 121 effective_load_flags_(0), | 123 effective_load_flags_(0), |
| 122 write_len_(0), | 124 write_len_(0), |
| 123 final_upload_progress_(0), | 125 final_upload_progress_(0), |
| 124 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), | 126 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), |
| 125 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( | 127 ALLOW_THIS_IN_INITIALIZER_LIST(io_callback_( |
| 126 base::Bind(&Transaction::OnIOComplete, | 128 base::Bind(&Transaction::OnIOComplete, |
| 127 weak_factory_.GetWeakPtr()))) { | 129 weak_factory_.GetWeakPtr()))), |
| 130 delegate_(delegate) { | |
| 128 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == | 131 COMPILE_ASSERT(HttpCache::Transaction::kNumValidationHeaders == |
| 129 arraysize(kValidationHeaders), | 132 arraysize(kValidationHeaders), |
| 130 Invalid_number_of_validation_headers); | 133 Invalid_number_of_validation_headers); |
| 131 } | 134 } |
| 132 | 135 |
| 133 HttpCache::Transaction::~Transaction() { | 136 HttpCache::Transaction::~Transaction() { |
| 134 // We may have to issue another IO, but we should never invoke the callback_ | 137 // We may have to issue another IO, but we should never invoke the callback_ |
| 135 // after this point. | 138 // after this point. |
| 136 callback_.Reset(); | 139 callback_.Reset(); |
| 137 | 140 |
| (...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 645 if (rv != ERR_IO_PENDING) | 648 if (rv != ERR_IO_PENDING) |
| 646 HandleResult(rv); | 649 HandleResult(rv); |
| 647 | 650 |
| 648 return rv; | 651 return rv; |
| 649 } | 652 } |
| 650 | 653 |
| 651 int HttpCache::Transaction::DoGetBackend() { | 654 int HttpCache::Transaction::DoGetBackend() { |
| 652 cache_pending_ = true; | 655 cache_pending_ = true; |
| 653 next_state_ = STATE_GET_BACKEND_COMPLETE; | 656 next_state_ = STATE_GET_BACKEND_COMPLETE; |
| 654 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND); | 657 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND); |
| 658 ReportCacheActionStart(); | |
| 655 return cache_->GetBackendForTransaction(this); | 659 return cache_->GetBackendForTransaction(this); |
| 656 } | 660 } |
| 657 | 661 |
| 658 int HttpCache::Transaction::DoGetBackendComplete(int result) { | 662 int HttpCache::Transaction::DoGetBackendComplete(int result) { |
| 659 DCHECK(result == OK || result == ERR_FAILED); | 663 DCHECK(result == OK || result == ERR_FAILED); |
| 664 ReportCacheActionFinish(); | |
| 660 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, | 665 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, |
| 661 result); | 666 result); |
| 662 cache_pending_ = false; | 667 cache_pending_ = false; |
| 663 | 668 |
| 664 if (!ShouldPassThrough()) { | 669 if (!ShouldPassThrough()) { |
| 665 cache_key_ = cache_->GenerateCacheKey(request_); | 670 cache_key_ = cache_->GenerateCacheKey(request_); |
| 666 | 671 |
| 667 // Requested cache access mode. | 672 // Requested cache access mode. |
| 668 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { | 673 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { |
| 669 mode_ = READ; | 674 mode_ = READ; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 range_requested_ = (partial_.get() != NULL); | 715 range_requested_ = (partial_.get() != NULL); |
| 711 | 716 |
| 712 return OK; | 717 return OK; |
| 713 } | 718 } |
| 714 | 719 |
| 715 int HttpCache::Transaction::DoSendRequest() { | 720 int HttpCache::Transaction::DoSendRequest() { |
| 716 DCHECK(mode_ & WRITE || mode_ == NONE); | 721 DCHECK(mode_ & WRITE || mode_ == NONE); |
| 717 DCHECK(!network_trans_.get()); | 722 DCHECK(!network_trans_.get()); |
| 718 | 723 |
| 719 // Create a network transaction. | 724 // Create a network transaction. |
| 720 int rv = cache_->network_layer_->CreateTransaction(&network_trans_); | 725 int rv = cache_->network_layer_->CreateTransaction(&network_trans_, NULL); |
|
rvargas (doing something else)
2012/07/23 22:22:36
It would be interesting to track the network activ
tburkard
2012/07/24 01:03:12
(nothing to do here).
On 2012/07/23 22:22:36, rva
| |
| 721 if (rv != OK) | 726 if (rv != OK) |
| 722 return rv; | 727 return rv; |
| 723 | 728 |
| 724 next_state_ = STATE_SEND_REQUEST_COMPLETE; | 729 next_state_ = STATE_SEND_REQUEST_COMPLETE; |
| 725 rv = network_trans_->Start(request_, io_callback_, net_log_); | 730 rv = network_trans_->Start(request_, io_callback_, net_log_); |
| 726 return rv; | 731 return rv; |
| 727 } | 732 } |
| 728 | 733 |
| 729 int HttpCache::Transaction::DoSendRequestComplete(int result) { | 734 int HttpCache::Transaction::DoSendRequestComplete(int result) { |
| 730 if (!cache_) | 735 if (!cache_) |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 | 843 |
| 839 next_state_ = STATE_OPEN_ENTRY; | 844 next_state_ = STATE_OPEN_ENTRY; |
| 840 return OK; | 845 return OK; |
| 841 } | 846 } |
| 842 | 847 |
| 843 int HttpCache::Transaction::DoOpenEntry() { | 848 int HttpCache::Transaction::DoOpenEntry() { |
| 844 DCHECK(!new_entry_); | 849 DCHECK(!new_entry_); |
| 845 next_state_ = STATE_OPEN_ENTRY_COMPLETE; | 850 next_state_ = STATE_OPEN_ENTRY_COMPLETE; |
| 846 cache_pending_ = true; | 851 cache_pending_ = true; |
| 847 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY); | 852 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY); |
| 853 ReportCacheActionStart(); | |
| 848 return cache_->OpenEntry(cache_key_, &new_entry_, this); | 854 return cache_->OpenEntry(cache_key_, &new_entry_, this); |
| 849 } | 855 } |
| 850 | 856 |
| 851 int HttpCache::Transaction::DoOpenEntryComplete(int result) { | 857 int HttpCache::Transaction::DoOpenEntryComplete(int result) { |
| 852 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 858 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
| 853 // OK, otherwise the cache will end up with an active entry without any | 859 // OK, otherwise the cache will end up with an active entry without any |
| 854 // transaction attached. | 860 // transaction attached. |
| 861 ReportCacheActionFinish(); | |
| 855 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); | 862 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); |
| 856 cache_pending_ = false; | 863 cache_pending_ = false; |
| 857 if (result == OK) { | 864 if (result == OK) { |
| 858 next_state_ = STATE_ADD_TO_ENTRY; | 865 next_state_ = STATE_ADD_TO_ENTRY; |
| 859 return OK; | 866 return OK; |
| 860 } | 867 } |
| 861 | 868 |
| 862 if (result == ERR_CACHE_RACE) { | 869 if (result == ERR_CACHE_RACE) { |
| 863 next_state_ = STATE_INIT_ENTRY; | 870 next_state_ = STATE_INIT_ENTRY; |
| 864 return OK; | 871 return OK; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 888 // The entry does not exist, and we are not permitted to create a new entry, | 895 // The entry does not exist, and we are not permitted to create a new entry, |
| 889 // so we must fail. | 896 // so we must fail. |
| 890 return ERR_CACHE_MISS; | 897 return ERR_CACHE_MISS; |
| 891 } | 898 } |
| 892 | 899 |
| 893 int HttpCache::Transaction::DoCreateEntry() { | 900 int HttpCache::Transaction::DoCreateEntry() { |
| 894 DCHECK(!new_entry_); | 901 DCHECK(!new_entry_); |
| 895 next_state_ = STATE_CREATE_ENTRY_COMPLETE; | 902 next_state_ = STATE_CREATE_ENTRY_COMPLETE; |
| 896 cache_pending_ = true; | 903 cache_pending_ = true; |
| 897 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY); | 904 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY); |
| 905 ReportCacheActionStart(); | |
| 898 return cache_->CreateEntry(cache_key_, &new_entry_, this); | 906 return cache_->CreateEntry(cache_key_, &new_entry_, this); |
| 899 } | 907 } |
| 900 | 908 |
| 901 int HttpCache::Transaction::DoCreateEntryComplete(int result) { | 909 int HttpCache::Transaction::DoCreateEntryComplete(int result) { |
| 902 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 910 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
| 903 // OK, otherwise the cache will end up with an active entry without any | 911 // OK, otherwise the cache will end up with an active entry without any |
| 904 // transaction attached. | 912 // transaction attached. |
| 913 ReportCacheActionFinish(); | |
| 905 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, | 914 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, |
| 906 result); | 915 result); |
| 907 cache_pending_ = false; | 916 cache_pending_ = false; |
| 908 next_state_ = STATE_ADD_TO_ENTRY; | 917 next_state_ = STATE_ADD_TO_ENTRY; |
| 909 | 918 |
| 910 if (result == ERR_CACHE_RACE) { | 919 if (result == ERR_CACHE_RACE) { |
| 911 next_state_ = STATE_INIT_ENTRY; | 920 next_state_ = STATE_INIT_ENTRY; |
| 912 return OK; | 921 return OK; |
| 913 } | 922 } |
| 914 | 923 |
| 915 if (result != OK) { | 924 if (result != OK) { |
| 916 // We have a race here: Maybe we failed to open the entry and decided to | 925 // We have a race here: Maybe we failed to open the entry and decided to |
| 917 // create one, but by the time we called create, another transaction already | 926 // create one, but by the time we called create, another transaction already |
| 918 // created the entry. If we want to eliminate this issue, we need an atomic | 927 // created the entry. If we want to eliminate this issue, we need an atomic |
| 919 // OpenOrCreate() method exposed by the disk cache. | 928 // OpenOrCreate() method exposed by the disk cache. |
| 920 DLOG(WARNING) << "Unable to create cache entry"; | 929 DLOG(WARNING) << "Unable to create cache entry"; |
| 921 mode_ = NONE; | 930 mode_ = NONE; |
| 922 if (partial_.get()) | 931 if (partial_.get()) |
| 923 partial_->RestoreHeaders(&custom_request_->extra_headers); | 932 partial_->RestoreHeaders(&custom_request_->extra_headers); |
| 924 next_state_ = STATE_SEND_REQUEST; | 933 next_state_ = STATE_SEND_REQUEST; |
| 925 } | 934 } |
| 926 return OK; | 935 return OK; |
| 927 } | 936 } |
| 928 | 937 |
| 929 int HttpCache::Transaction::DoDoomEntry() { | 938 int HttpCache::Transaction::DoDoomEntry() { |
| 930 next_state_ = STATE_DOOM_ENTRY_COMPLETE; | 939 next_state_ = STATE_DOOM_ENTRY_COMPLETE; |
| 931 cache_pending_ = true; | 940 cache_pending_ = true; |
| 932 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY); | 941 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY); |
| 942 ReportCacheActionStart(); | |
| 933 return cache_->DoomEntry(cache_key_, this); | 943 return cache_->DoomEntry(cache_key_, this); |
| 934 } | 944 } |
| 935 | 945 |
| 936 int HttpCache::Transaction::DoDoomEntryComplete(int result) { | 946 int HttpCache::Transaction::DoDoomEntryComplete(int result) { |
| 947 ReportCacheActionFinish(); | |
| 937 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result); | 948 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result); |
| 938 next_state_ = STATE_CREATE_ENTRY; | 949 next_state_ = STATE_CREATE_ENTRY; |
| 939 cache_pending_ = false; | 950 cache_pending_ = false; |
| 940 if (result == ERR_CACHE_RACE) | 951 if (result == ERR_CACHE_RACE) |
| 941 next_state_ = STATE_INIT_ENTRY; | 952 next_state_ = STATE_INIT_ENTRY; |
| 942 | 953 |
| 943 return OK; | 954 return OK; |
| 944 } | 955 } |
| 945 | 956 |
| 946 int HttpCache::Transaction::DoAddToEntry() { | 957 int HttpCache::Transaction::DoAddToEntry() { |
| 947 DCHECK(new_entry_); | 958 DCHECK(new_entry_); |
| 948 cache_pending_ = true; | 959 cache_pending_ = true; |
| 949 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; | 960 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |
| 950 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); | 961 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); |
| 962 ReportCacheActionStart(); | |
|
rvargas (doing something else)
2012/07/23 22:22:36
We should treat this one some other way. This is n
tburkard
2012/07/24 01:03:12
Why is the distinction important? What is the dif
rvargas (doing something else)
2012/07/24 03:10:38
No matter what we change at the disk cache layer,
tburkard
2012/07/24 22:23:26
Done.
| |
| 951 DCHECK(entry_lock_waiting_since_.is_null()); | 963 DCHECK(entry_lock_waiting_since_.is_null()); |
| 952 entry_lock_waiting_since_ = base::TimeTicks::Now(); | 964 entry_lock_waiting_since_ = base::TimeTicks::Now(); |
| 953 return cache_->AddTransactionToEntry(new_entry_, this); | 965 return cache_->AddTransactionToEntry(new_entry_, this); |
| 954 } | 966 } |
| 955 | 967 |
| 956 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 968 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
| 969 ReportCacheActionFinish(); | |
| 957 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, | 970 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, |
| 958 result); | 971 result); |
| 959 | 972 |
| 960 const base::TimeDelta entry_lock_wait = | 973 const base::TimeDelta entry_lock_wait = |
| 961 base::TimeTicks::Now() - entry_lock_waiting_since_; | 974 base::TimeTicks::Now() - entry_lock_waiting_since_; |
| 962 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); | 975 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); |
| 963 static const bool prefetching_fieldtrial = | 976 static const bool prefetching_fieldtrial = |
| 964 base::FieldTrialList::TrialExists("Prefetch"); | 977 base::FieldTrialList::TrialExists("Prefetch"); |
| 965 if (prefetching_fieldtrial) { | 978 if (prefetching_fieldtrial) { |
| 966 UMA_HISTOGRAM_TIMES( | 979 UMA_HISTOGRAM_TIMES( |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1128 STATE_CACHE_WRITE_RESPONSE; | 1141 STATE_CACHE_WRITE_RESPONSE; |
| 1129 return OK; | 1142 return OK; |
| 1130 } | 1143 } |
| 1131 | 1144 |
| 1132 int HttpCache::Transaction::DoTruncateCachedData() { | 1145 int HttpCache::Transaction::DoTruncateCachedData() { |
| 1133 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; | 1146 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; |
| 1134 if (!entry_) | 1147 if (!entry_) |
| 1135 return OK; | 1148 return OK; |
| 1136 if (net_log_.IsLoggingAllEvents()) | 1149 if (net_log_.IsLoggingAllEvents()) |
| 1137 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); | 1150 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); |
| 1138 | 1151 ReportCacheActionStart(); |
| 1139 // Truncate the stream. | 1152 // Truncate the stream. |
| 1140 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); | 1153 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); |
| 1141 } | 1154 } |
| 1142 | 1155 |
| 1143 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { | 1156 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { |
| 1144 if (net_log_.IsLoggingAllEvents() && entry_) { | 1157 if (entry_) { |
| 1145 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | 1158 ReportCacheActionFinish(); |
| 1146 result); | 1159 if (net_log_.IsLoggingAllEvents()) { |
| 1160 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | |
| 1161 result); | |
| 1162 } | |
| 1147 } | 1163 } |
| 1148 | 1164 |
| 1149 next_state_ = STATE_TRUNCATE_CACHED_METADATA; | 1165 next_state_ = STATE_TRUNCATE_CACHED_METADATA; |
| 1150 return OK; | 1166 return OK; |
| 1151 } | 1167 } |
| 1152 | 1168 |
| 1153 int HttpCache::Transaction::DoTruncateCachedMetadata() { | 1169 int HttpCache::Transaction::DoTruncateCachedMetadata() { |
| 1154 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; | 1170 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; |
| 1155 if (!entry_) | 1171 if (!entry_) |
| 1156 return OK; | 1172 return OK; |
| 1157 | 1173 |
| 1158 if (net_log_.IsLoggingAllEvents()) | 1174 if (net_log_.IsLoggingAllEvents()) |
| 1159 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1175 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); |
| 1176 ReportCacheActionStart(); | |
| 1160 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); | 1177 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); |
| 1161 } | 1178 } |
| 1162 | 1179 |
| 1163 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { | 1180 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { |
| 1164 if (net_log_.IsLoggingAllEvents() && entry_) { | 1181 if (entry_) { |
| 1165 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | 1182 ReportCacheActionFinish(); |
| 1166 result); | 1183 if (net_log_.IsLoggingAllEvents()) { |
| 1184 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | |
| 1185 result); | |
| 1186 } | |
| 1167 } | 1187 } |
| 1168 | 1188 |
| 1169 // If this response is a redirect, then we can stop writing now. (We don't | 1189 // If this response is a redirect, then we can stop writing now. (We don't |
| 1170 // need to cache the response body of a redirect.) | 1190 // need to cache the response body of a redirect.) |
| 1171 if (response_.headers->IsRedirect(NULL)) | 1191 if (response_.headers->IsRedirect(NULL)) |
| 1172 DoneWritingToEntry(true); | 1192 DoneWritingToEntry(true); |
| 1173 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1193 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
| 1174 return OK; | 1194 return OK; |
| 1175 } | 1195 } |
| 1176 | 1196 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 1198 } | 1218 } |
| 1199 | 1219 |
| 1200 int HttpCache::Transaction::DoCacheReadResponse() { | 1220 int HttpCache::Transaction::DoCacheReadResponse() { |
| 1201 DCHECK(entry_); | 1221 DCHECK(entry_); |
| 1202 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; | 1222 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; |
| 1203 | 1223 |
| 1204 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); | 1224 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); |
| 1205 read_buf_ = new IOBuffer(io_buf_len_); | 1225 read_buf_ = new IOBuffer(io_buf_len_); |
| 1206 | 1226 |
| 1207 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); | 1227 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); |
| 1228 ReportCacheActionStart(); | |
|
rvargas (doing something else)
2012/07/23 22:22:36
This is where we start getting confusing results.
tburkard
2012/07/24 01:03:12
That doesn't matter for the purpose of what I'm tr
rvargas (doing something else)
2012/07/24 03:10:38
I think it matters.
If we only care about a singl
tburkard
2012/07/24 22:23:26
Per discussion on the phone, we are in agreement o
| |
| 1208 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, | 1229 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, |
| 1209 io_buf_len_, io_callback_); | 1230 io_buf_len_, io_callback_); |
| 1210 } | 1231 } |
| 1211 | 1232 |
| 1212 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { | 1233 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
| 1234 ReportCacheActionFinish(); | |
| 1213 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 1235 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); |
| 1214 if (result != io_buf_len_ || | 1236 if (result != io_buf_len_ || |
| 1215 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, | 1237 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, |
| 1216 &response_, &truncated_)) { | 1238 &response_, &truncated_)) { |
| 1217 return OnCacheReadError(result, true); | 1239 return OnCacheReadError(result, true); |
| 1218 } | 1240 } |
| 1219 | 1241 |
| 1220 // Some resources may have slipped in as truncated when they're not. | 1242 // Some resources may have slipped in as truncated when they're not. |
| 1221 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); | 1243 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); |
| 1222 if (response_.headers->GetContentLength() == current_size) | 1244 if (response_.headers->GetContentLength() == current_size) |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1247 break; | 1269 break; |
| 1248 case WRITE: | 1270 case WRITE: |
| 1249 default: | 1271 default: |
| 1250 NOTREACHED(); | 1272 NOTREACHED(); |
| 1251 result = ERR_FAILED; | 1273 result = ERR_FAILED; |
| 1252 } | 1274 } |
| 1253 return result; | 1275 return result; |
| 1254 } | 1276 } |
| 1255 | 1277 |
| 1256 int HttpCache::Transaction::DoCacheWriteResponse() { | 1278 int HttpCache::Transaction::DoCacheWriteResponse() { |
| 1257 if (net_log_.IsLoggingAllEvents() && entry_) | 1279 if (entry_) { |
| 1258 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1280 if (net_log_.IsLoggingAllEvents()) |
| 1281 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | |
| 1282 ReportCacheActionStart(); | |
| 1283 } | |
| 1259 return WriteResponseInfoToEntry(false); | 1284 return WriteResponseInfoToEntry(false); |
| 1260 } | 1285 } |
| 1261 | 1286 |
| 1262 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { | 1287 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |
| 1263 if (net_log_.IsLoggingAllEvents() && entry_) | 1288 if (entry_) { |
| 1264 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | 1289 if (net_log_.IsLoggingAllEvents() && entry_) |
| 1290 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); | |
| 1291 ReportCacheActionStart(); | |
| 1292 } | |
| 1265 return WriteResponseInfoToEntry(true); | 1293 return WriteResponseInfoToEntry(true); |
| 1266 } | 1294 } |
| 1267 | 1295 |
| 1268 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { | 1296 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { |
| 1269 next_state_ = target_state_; | 1297 next_state_ = target_state_; |
| 1270 target_state_ = STATE_NONE; | 1298 target_state_ = STATE_NONE; |
| 1271 if (!entry_) | 1299 if (!entry_) |
| 1272 return OK; | 1300 return OK; |
| 1301 ReportCacheActionFinish(); | |
| 1273 if (net_log_.IsLoggingAllEvents()) { | 1302 if (net_log_.IsLoggingAllEvents()) { |
| 1274 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | 1303 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, |
| 1275 result); | 1304 result); |
| 1276 } | 1305 } |
| 1277 | 1306 |
| 1278 // Balance the AddRef from WriteResponseInfoToEntry. | 1307 // Balance the AddRef from WriteResponseInfoToEntry. |
| 1279 if (result != io_buf_len_) { | 1308 if (result != io_buf_len_) { |
| 1280 DLOG(ERROR) << "failed to write response info to cache"; | 1309 DLOG(ERROR) << "failed to write response info to cache"; |
| 1281 DoneWritingToEntry(false); | 1310 DoneWritingToEntry(false); |
| 1282 } | 1311 } |
| 1283 return OK; | 1312 return OK; |
| 1284 } | 1313 } |
| 1285 | 1314 |
| 1286 int HttpCache::Transaction::DoCacheReadMetadata() { | 1315 int HttpCache::Transaction::DoCacheReadMetadata() { |
| 1287 DCHECK(entry_); | 1316 DCHECK(entry_); |
| 1288 DCHECK(!response_.metadata); | 1317 DCHECK(!response_.metadata); |
| 1289 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; | 1318 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; |
| 1290 | 1319 |
| 1291 response_.metadata = | 1320 response_.metadata = |
| 1292 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); | 1321 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); |
| 1293 | 1322 |
| 1294 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); | 1323 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); |
| 1324 ReportCacheActionStart(); | |
| 1295 return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata, | 1325 return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata, |
| 1296 response_.metadata->size(), | 1326 response_.metadata->size(), |
| 1297 io_callback_); | 1327 io_callback_); |
| 1298 } | 1328 } |
| 1299 | 1329 |
| 1300 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { | 1330 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { |
| 1331 ReportCacheActionFinish(); | |
| 1301 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 1332 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); |
| 1302 if (result != response_.metadata->size()) | 1333 if (result != response_.metadata->size()) |
| 1303 return OnCacheReadError(result, false); | 1334 return OnCacheReadError(result, false); |
| 1304 | 1335 |
| 1305 return OK; | 1336 return OK; |
| 1306 } | 1337 } |
| 1307 | 1338 |
| 1308 int HttpCache::Transaction::DoCacheQueryData() { | 1339 int HttpCache::Transaction::DoCacheQueryData() { |
| 1309 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; | 1340 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; |
| 1310 | 1341 |
| 1311 // Balanced in DoCacheQueryDataComplete. | 1342 // Balanced in DoCacheQueryDataComplete. |
| 1312 return entry_->disk_entry->ReadyForSparseIO(io_callback_); | 1343 return entry_->disk_entry->ReadyForSparseIO(io_callback_); |
| 1313 } | 1344 } |
| 1314 | 1345 |
| 1315 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) { | 1346 int HttpCache::Transaction::DoCacheQueryDataComplete(int result) { |
| 1316 DCHECK_EQ(OK, result); | 1347 DCHECK_EQ(OK, result); |
| 1317 if (!cache_) | 1348 if (!cache_) |
| 1318 return ERR_UNEXPECTED; | 1349 return ERR_UNEXPECTED; |
| 1319 | 1350 |
| 1320 return ValidateEntryHeadersAndContinue(); | 1351 return ValidateEntryHeadersAndContinue(); |
| 1321 } | 1352 } |
| 1322 | 1353 |
| 1323 int HttpCache::Transaction::DoCacheReadData() { | 1354 int HttpCache::Transaction::DoCacheReadData() { |
| 1324 DCHECK(entry_); | 1355 DCHECK(entry_); |
| 1325 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; | 1356 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; |
| 1326 | 1357 |
| 1327 if (net_log_.IsLoggingAllEvents()) | 1358 if (net_log_.IsLoggingAllEvents()) |
| 1328 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); | 1359 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); |
| 1360 ReportCacheActionStart(); | |
| 1329 if (partial_.get()) { | 1361 if (partial_.get()) { |
| 1330 return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, | 1362 return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, |
| 1331 io_callback_); | 1363 io_callback_); |
| 1332 } | 1364 } |
| 1333 | 1365 |
| 1334 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 1366 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |
| 1335 read_buf_, io_buf_len_, io_callback_); | 1367 read_buf_, io_buf_len_, io_callback_); |
| 1336 } | 1368 } |
| 1337 | 1369 |
| 1338 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { | 1370 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |
| 1371 ReportCacheActionFinish(); | |
| 1339 if (net_log_.IsLoggingAllEvents()) { | 1372 if (net_log_.IsLoggingAllEvents()) { |
| 1340 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, | 1373 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, |
| 1341 result); | 1374 result); |
| 1342 } | 1375 } |
| 1343 | 1376 |
| 1344 if (!cache_) | 1377 if (!cache_) |
| 1345 return ERR_UNEXPECTED; | 1378 return ERR_UNEXPECTED; |
| 1346 | 1379 |
| 1347 if (partial_.get()) | 1380 if (partial_.get()) |
| 1348 return DoPartialCacheReadCompleted(result); | 1381 return DoPartialCacheReadCompleted(result); |
| 1349 | 1382 |
| 1350 if (result > 0) { | 1383 if (result > 0) { |
| 1351 read_offset_ += result; | 1384 read_offset_ += result; |
| 1352 } else if (result == 0) { // End of file. | 1385 } else if (result == 0) { // End of file. |
| 1353 cache_->DoneReadingFromEntry(entry_, this); | 1386 cache_->DoneReadingFromEntry(entry_, this); |
| 1354 entry_ = NULL; | 1387 entry_ = NULL; |
| 1355 } else { | 1388 } else { |
| 1356 return OnCacheReadError(result, false); | 1389 return OnCacheReadError(result, false); |
| 1357 } | 1390 } |
| 1358 return result; | 1391 return result; |
| 1359 } | 1392 } |
| 1360 | 1393 |
| 1361 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { | 1394 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |
| 1362 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; | 1395 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |
| 1363 write_len_ = num_bytes; | 1396 write_len_ = num_bytes; |
| 1364 if (net_log_.IsLoggingAllEvents() && entry_) | 1397 if (entry_) { |
| 1365 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); | 1398 if (net_log_.IsLoggingAllEvents()) |
| 1399 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); | |
| 1400 ReportCacheActionStart(); | |
| 1401 } | |
| 1366 | 1402 |
| 1367 return AppendResponseDataToEntry(read_buf_, num_bytes, io_callback_); | 1403 return AppendResponseDataToEntry(read_buf_, num_bytes, io_callback_); |
| 1368 } | 1404 } |
| 1369 | 1405 |
| 1370 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { | 1406 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |
| 1371 if (net_log_.IsLoggingAllEvents() && entry_) { | 1407 if (entry_) { |
| 1372 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | 1408 ReportCacheActionFinish(); |
| 1373 result); | 1409 if (net_log_.IsLoggingAllEvents()) { |
| 1410 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | |
| 1411 result); | |
| 1412 } | |
| 1374 } | 1413 } |
| 1375 // Balance the AddRef from DoCacheWriteData. | 1414 // Balance the AddRef from DoCacheWriteData. |
| 1376 if (!cache_) | 1415 if (!cache_) |
| 1377 return ERR_UNEXPECTED; | 1416 return ERR_UNEXPECTED; |
| 1378 | 1417 |
| 1379 if (result != write_len_) { | 1418 if (result != write_len_) { |
| 1380 DLOG(ERROR) << "failed to write response data to cache"; | 1419 DLOG(ERROR) << "failed to write response data to cache"; |
| 1381 DoneWritingToEntry(false); | 1420 DoneWritingToEntry(false); |
| 1382 | 1421 |
| 1383 // We want to ignore errors writing to disk and just keep reading from | 1422 // We want to ignore errors writing to disk and just keep reading from |
| (...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2103 !response_.headers->HasStrongValidators()) | 2142 !response_.headers->HasStrongValidators()) |
| 2104 return false; | 2143 return false; |
| 2105 | 2144 |
| 2106 return true; | 2145 return true; |
| 2107 } | 2146 } |
| 2108 | 2147 |
| 2109 void HttpCache::Transaction::OnIOComplete(int result) { | 2148 void HttpCache::Transaction::OnIOComplete(int result) { |
| 2110 DoLoop(result); | 2149 DoLoop(result); |
| 2111 } | 2150 } |
| 2112 | 2151 |
| 2152 void HttpCache::Transaction::ReportCacheActionStart() { | |
| 2153 if (delegate_) | |
| 2154 delegate_->OnCacheActionStart(); | |
| 2155 } | |
| 2156 | |
| 2157 void HttpCache::Transaction::ReportCacheActionFinish() { | |
| 2158 if (delegate_) | |
| 2159 delegate_->OnCacheActionFinish(); | |
| 2160 } | |
| 2161 | |
| 2113 } // namespace net | 2162 } // namespace net |
| OLD | NEW |