OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 391 } |
392 | 392 |
393 LoadState HttpCache::Transaction::GetWriterLoadState() const { | 393 LoadState HttpCache::Transaction::GetWriterLoadState() const { |
394 if (network_trans_.get()) | 394 if (network_trans_.get()) |
395 return network_trans_->GetLoadState(); | 395 return network_trans_->GetLoadState(); |
396 if (entry_ || !request_) | 396 if (entry_ || !request_) |
397 return LOAD_STATE_IDLE; | 397 return LOAD_STATE_IDLE; |
398 return LOAD_STATE_WAITING_FOR_CACHE; | 398 return LOAD_STATE_WAITING_FOR_CACHE; |
399 } | 399 } |
400 | 400 |
401 const BoundNetLog& HttpCache::Transaction::net_log() const { | |
402 return net_log_; | |
403 } | |
404 | |
405 //----------------------------------------------------------------------------- | 401 //----------------------------------------------------------------------------- |
406 | 402 |
407 void HttpCache::Transaction::DoCallback(int rv) { | 403 void HttpCache::Transaction::DoCallback(int rv) { |
408 DCHECK(rv != ERR_IO_PENDING); | 404 DCHECK(rv != ERR_IO_PENDING); |
409 DCHECK(callback_); | 405 DCHECK(callback_); |
410 | 406 |
411 // Since Run may result in Read being called, clear callback_ up front. | 407 // Since Run may result in Read being called, clear callback_ up front. |
412 CompletionCallback* c = callback_; | 408 CompletionCallback* c = callback_; |
413 callback_ = NULL; | 409 callback_ = NULL; |
414 c->Run(rv); | 410 c->Run(rv); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 | 572 |
577 if (rv != ERR_IO_PENDING) | 573 if (rv != ERR_IO_PENDING) |
578 HandleResult(rv); | 574 HandleResult(rv); |
579 | 575 |
580 return rv; | 576 return rv; |
581 } | 577 } |
582 | 578 |
583 int HttpCache::Transaction::DoGetBackend() { | 579 int HttpCache::Transaction::DoGetBackend() { |
584 cache_pending_ = true; | 580 cache_pending_ = true; |
585 next_state_ = STATE_GET_BACKEND_COMPLETE; | 581 next_state_ = STATE_GET_BACKEND_COMPLETE; |
586 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, NULL); | 582 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); |
587 return cache_->GetBackendForTransaction(this); | 583 return cache_->GetBackendForTransaction(this); |
588 } | 584 } |
589 | 585 |
590 int HttpCache::Transaction::DoGetBackendComplete(int result) { | 586 int HttpCache::Transaction::DoGetBackendComplete(int result) { |
591 DCHECK(result == OK || result == ERR_FAILED); | 587 DCHECK(result == OK || result == ERR_FAILED); |
592 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, | 588 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); |
593 result); | |
594 cache_pending_ = false; | 589 cache_pending_ = false; |
595 | 590 |
596 if (!ShouldPassThrough()) { | 591 if (!ShouldPassThrough()) { |
597 cache_key_ = cache_->GenerateCacheKey(request_); | 592 cache_key_ = cache_->GenerateCacheKey(request_); |
598 | 593 |
599 // Requested cache access mode. | 594 // Requested cache access mode. |
600 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { | 595 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { |
601 mode_ = READ; | 596 mode_ = READ; |
602 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) { | 597 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) { |
603 mode_ = WRITE; | 598 mode_ = WRITE; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
755 next_state_ = STATE_OPEN_ENTRY_COMPLETE; | 750 next_state_ = STATE_OPEN_ENTRY_COMPLETE; |
756 cache_pending_ = true; | 751 cache_pending_ = true; |
757 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL); | 752 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL); |
758 return cache_->OpenEntry(cache_key_, &new_entry_, this); | 753 return cache_->OpenEntry(cache_key_, &new_entry_, this); |
759 } | 754 } |
760 | 755 |
761 int HttpCache::Transaction::DoOpenEntryComplete(int result) { | 756 int HttpCache::Transaction::DoOpenEntryComplete(int result) { |
762 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 757 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
763 // OK, otherwise the cache will end up with an active entry without any | 758 // OK, otherwise the cache will end up with an active entry without any |
764 // transaction attached. | 759 // transaction attached. |
765 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); | 760 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, NULL); |
766 cache_pending_ = false; | 761 cache_pending_ = false; |
767 if (result == OK) { | 762 if (result == OK) { |
768 next_state_ = STATE_ADD_TO_ENTRY; | 763 next_state_ = STATE_ADD_TO_ENTRY; |
769 return OK; | 764 return OK; |
770 } | 765 } |
771 | 766 |
772 if (result == ERR_CACHE_RACE) { | 767 if (result == ERR_CACHE_RACE) { |
773 next_state_ = STATE_INIT_ENTRY; | 768 next_state_ = STATE_INIT_ENTRY; |
774 return OK; | 769 return OK; |
775 } | 770 } |
(...skipping 22 matching lines...) Expand all Loading... |
798 next_state_ = STATE_CREATE_ENTRY_COMPLETE; | 793 next_state_ = STATE_CREATE_ENTRY_COMPLETE; |
799 cache_pending_ = true; | 794 cache_pending_ = true; |
800 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL); | 795 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL); |
801 return cache_->CreateEntry(cache_key_, &new_entry_, this); | 796 return cache_->CreateEntry(cache_key_, &new_entry_, this); |
802 } | 797 } |
803 | 798 |
804 int HttpCache::Transaction::DoCreateEntryComplete(int result) { | 799 int HttpCache::Transaction::DoCreateEntryComplete(int result) { |
805 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is | 800 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is |
806 // OK, otherwise the cache will end up with an active entry without any | 801 // OK, otherwise the cache will end up with an active entry without any |
807 // transaction attached. | 802 // transaction attached. |
808 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, | 803 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, NULL); |
809 result); | |
810 cache_pending_ = false; | 804 cache_pending_ = false; |
811 next_state_ = STATE_ADD_TO_ENTRY; | 805 next_state_ = STATE_ADD_TO_ENTRY; |
812 | 806 |
813 if (result == ERR_CACHE_RACE) { | 807 if (result == ERR_CACHE_RACE) { |
814 next_state_ = STATE_INIT_ENTRY; | 808 next_state_ = STATE_INIT_ENTRY; |
815 return OK; | 809 return OK; |
816 } | 810 } |
817 | 811 |
818 if (result != OK) { | 812 if (result != OK) { |
819 // We have a race here: Maybe we failed to open the entry and decided to | 813 // We have a race here: Maybe we failed to open the entry and decided to |
(...skipping 10 matching lines...) Expand all Loading... |
830 } | 824 } |
831 | 825 |
832 int HttpCache::Transaction::DoDoomEntry() { | 826 int HttpCache::Transaction::DoDoomEntry() { |
833 next_state_ = STATE_DOOM_ENTRY_COMPLETE; | 827 next_state_ = STATE_DOOM_ENTRY_COMPLETE; |
834 cache_pending_ = true; | 828 cache_pending_ = true; |
835 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL); | 829 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL); |
836 return cache_->DoomEntry(cache_key_, this); | 830 return cache_->DoomEntry(cache_key_, this); |
837 } | 831 } |
838 | 832 |
839 int HttpCache::Transaction::DoDoomEntryComplete(int result) { | 833 int HttpCache::Transaction::DoDoomEntryComplete(int result) { |
840 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result); | 834 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, NULL); |
841 next_state_ = STATE_CREATE_ENTRY; | 835 next_state_ = STATE_CREATE_ENTRY; |
842 cache_pending_ = false; | 836 cache_pending_ = false; |
843 if (result == ERR_CACHE_RACE) | 837 if (result == ERR_CACHE_RACE) |
844 next_state_ = STATE_INIT_ENTRY; | 838 next_state_ = STATE_INIT_ENTRY; |
845 | 839 |
846 return OK; | 840 return OK; |
847 } | 841 } |
848 | 842 |
849 int HttpCache::Transaction::DoAddToEntry() { | 843 int HttpCache::Transaction::DoAddToEntry() { |
850 DCHECK(new_entry_); | 844 DCHECK(new_entry_); |
851 cache_pending_ = true; | 845 cache_pending_ = true; |
852 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; | 846 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; |
853 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, NULL); | 847 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); |
854 DCHECK(entry_lock_waiting_since_.is_null()); | 848 DCHECK(entry_lock_waiting_since_.is_null()); |
855 entry_lock_waiting_since_ = base::TimeTicks::Now(); | 849 entry_lock_waiting_since_ = base::TimeTicks::Now(); |
856 return cache_->AddTransactionToEntry(new_entry_, this); | 850 return cache_->AddTransactionToEntry(new_entry_, this); |
857 } | 851 } |
858 | 852 |
859 int HttpCache::Transaction::DoAddToEntryComplete(int result) { | 853 int HttpCache::Transaction::DoAddToEntryComplete(int result) { |
860 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, | 854 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WAITING, NULL); |
861 result); | |
862 | 855 |
863 const base::TimeDelta entry_lock_wait = | 856 const base::TimeDelta entry_lock_wait = |
864 base::TimeTicks::Now() - entry_lock_waiting_since_; | 857 base::TimeTicks::Now() - entry_lock_waiting_since_; |
865 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); | 858 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); |
866 static const bool prefetching_fieldtrial = | 859 static const bool prefetching_fieldtrial = |
867 base::FieldTrialList::Find("Prefetch") && | 860 base::FieldTrialList::Find("Prefetch") && |
868 !base::FieldTrialList::Find("Prefetch")->group_name().empty(); | 861 !base::FieldTrialList::Find("Prefetch")->group_name().empty(); |
869 if (prefetching_fieldtrial) { | 862 if (prefetching_fieldtrial) { |
870 UMA_HISTOGRAM_TIMES( | 863 UMA_HISTOGRAM_TIMES( |
871 base::FieldTrial::MakeName("HttpCache.EntryLockWait", "Prefetch"), | 864 base::FieldTrial::MakeName("HttpCache.EntryLockWait", "Prefetch"), |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : | 995 next_state_ = truncated_ ? STATE_CACHE_WRITE_TRUNCATED_RESPONSE : |
1003 STATE_CACHE_WRITE_RESPONSE; | 996 STATE_CACHE_WRITE_RESPONSE; |
1004 return OK; | 997 return OK; |
1005 } | 998 } |
1006 | 999 |
1007 int HttpCache::Transaction::DoTruncateCachedData() { | 1000 int HttpCache::Transaction::DoTruncateCachedData() { |
1008 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; | 1001 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; |
1009 cache_callback_->AddRef(); // Balanced in DoTruncateCachedDataComplete. | 1002 cache_callback_->AddRef(); // Balanced in DoTruncateCachedDataComplete. |
1010 if (!entry_) | 1003 if (!entry_) |
1011 return OK; | 1004 return OK; |
1012 if (net_log_.IsLoggingAllEvents()) | |
1013 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, NULL); | |
1014 | 1005 |
1015 // Truncate the stream. | 1006 // Truncate the stream. |
1016 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, cache_callback_); | 1007 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, cache_callback_); |
1017 } | 1008 } |
1018 | 1009 |
1019 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { | 1010 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { |
1020 if (net_log_.IsLoggingAllEvents() && entry_) { | |
1021 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | |
1022 result); | |
1023 } | |
1024 | |
1025 // Balance the AddRef from DoTruncateCachedData. | 1011 // Balance the AddRef from DoTruncateCachedData. |
1026 cache_callback_->Release(); | 1012 cache_callback_->Release(); |
1027 next_state_ = STATE_TRUNCATE_CACHED_METADATA; | 1013 next_state_ = STATE_TRUNCATE_CACHED_METADATA; |
1028 return OK; | 1014 return OK; |
1029 } | 1015 } |
1030 | 1016 |
1031 int HttpCache::Transaction::DoTruncateCachedMetadata() { | 1017 int HttpCache::Transaction::DoTruncateCachedMetadata() { |
1032 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; | 1018 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; |
1033 cache_callback_->AddRef(); // Balanced in DoTruncateCachedMetadataComplete. | 1019 cache_callback_->AddRef(); // Balanced in DoTruncateCachedMetadataComplete. |
1034 if (!entry_) | 1020 if (!entry_) |
1035 return OK; | 1021 return OK; |
1036 | 1022 |
1037 if (net_log_.IsLoggingAllEvents()) | |
1038 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); | |
1039 return WriteToEntry(kMetadataIndex, 0, NULL, 0, cache_callback_); | 1023 return WriteToEntry(kMetadataIndex, 0, NULL, 0, cache_callback_); |
1040 } | 1024 } |
1041 | 1025 |
1042 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { | 1026 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { |
1043 if (net_log_.IsLoggingAllEvents() && entry_) { | |
1044 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | |
1045 result); | |
1046 } | |
1047 | |
1048 // Balance the AddRef from DoTruncateCachedMetadata. | 1027 // Balance the AddRef from DoTruncateCachedMetadata. |
1049 cache_callback_->Release(); | 1028 cache_callback_->Release(); |
1050 | 1029 |
1051 // If this response is a redirect, then we can stop writing now. (We don't | 1030 // If this response is a redirect, then we can stop writing now. (We don't |
1052 // need to cache the response body of a redirect.) | 1031 // need to cache the response body of a redirect.) |
1053 if (response_.headers->IsRedirect(NULL)) | 1032 if (response_.headers->IsRedirect(NULL)) |
1054 DoneWritingToEntry(true); | 1033 DoneWritingToEntry(true); |
1055 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; | 1034 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; |
1056 return OK; | 1035 return OK; |
1057 } | 1036 } |
(...skipping 29 matching lines...) Expand all Loading... |
1087 read_buf_ = new IOBuffer(io_buf_len_); | 1066 read_buf_ = new IOBuffer(io_buf_len_); |
1088 | 1067 |
1089 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); | 1068 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); |
1090 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete. | 1069 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete. |
1091 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, | 1070 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, |
1092 io_buf_len_, cache_callback_); | 1071 io_buf_len_, cache_callback_); |
1093 } | 1072 } |
1094 | 1073 |
1095 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { | 1074 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
1096 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse. | 1075 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse. |
1097 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 1076 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); |
1098 if (result != io_buf_len_ || | 1077 if (result != io_buf_len_ || |
1099 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, | 1078 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, |
1100 &response_, &truncated_)) { | 1079 &response_, &truncated_)) { |
1101 DLOG(ERROR) << "ReadData failed: " << result; | 1080 DLOG(ERROR) << "ReadData failed: " << result; |
1102 return ERR_CACHE_READ_FAILURE; | 1081 return ERR_CACHE_READ_FAILURE; |
1103 } | 1082 } |
1104 | 1083 |
1105 // We now have access to the cache entry. | 1084 // We now have access to the cache entry. |
1106 // | 1085 // |
1107 // o if we are a reader for the transaction, then we can start reading the | 1086 // o if we are a reader for the transaction, then we can start reading the |
(...skipping 19 matching lines...) Expand all Loading... |
1127 break; | 1106 break; |
1128 case WRITE: | 1107 case WRITE: |
1129 default: | 1108 default: |
1130 NOTREACHED(); | 1109 NOTREACHED(); |
1131 result = ERR_FAILED; | 1110 result = ERR_FAILED; |
1132 } | 1111 } |
1133 return result; | 1112 return result; |
1134 } | 1113 } |
1135 | 1114 |
1136 int HttpCache::Transaction::DoCacheWriteResponse() { | 1115 int HttpCache::Transaction::DoCacheWriteResponse() { |
1137 if (net_log_.IsLoggingAllEvents() && entry_) | |
1138 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); | |
1139 return WriteResponseInfoToEntry(false); | 1116 return WriteResponseInfoToEntry(false); |
1140 } | 1117 } |
1141 | 1118 |
1142 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { | 1119 int HttpCache::Transaction::DoCacheWriteTruncatedResponse() { |
1143 if (net_log_.IsLoggingAllEvents() && entry_) | |
1144 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); | |
1145 return WriteResponseInfoToEntry(true); | 1120 return WriteResponseInfoToEntry(true); |
1146 } | 1121 } |
1147 | 1122 |
1148 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { | 1123 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { |
1149 next_state_ = target_state_; | 1124 next_state_ = target_state_; |
1150 target_state_ = STATE_NONE; | 1125 target_state_ = STATE_NONE; |
1151 if (!entry_) | 1126 if (!entry_) |
1152 return OK; | 1127 return OK; |
1153 if (net_log_.IsLoggingAllEvents()) { | |
1154 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, | |
1155 result); | |
1156 } | |
1157 | 1128 |
1158 // Balance the AddRef from WriteResponseInfoToEntry. | 1129 // Balance the AddRef from WriteResponseInfoToEntry. |
1159 write_headers_callback_->Release(); | 1130 write_headers_callback_->Release(); |
1160 if (result != io_buf_len_) { | 1131 if (result != io_buf_len_) { |
1161 DLOG(ERROR) << "failed to write response info to cache"; | 1132 DLOG(ERROR) << "failed to write response info to cache"; |
1162 DoneWritingToEntry(false); | 1133 DoneWritingToEntry(false); |
1163 } | 1134 } |
1164 return OK; | 1135 return OK; |
1165 } | 1136 } |
1166 | 1137 |
1167 int HttpCache::Transaction::DoCacheReadMetadata() { | 1138 int HttpCache::Transaction::DoCacheReadMetadata() { |
1168 DCHECK(entry_); | 1139 DCHECK(entry_); |
1169 DCHECK(!response_.metadata); | 1140 DCHECK(!response_.metadata); |
1170 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; | 1141 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; |
1171 | 1142 |
1172 response_.metadata = | 1143 response_.metadata = |
1173 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); | 1144 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); |
1174 | 1145 |
1175 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); | 1146 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); |
1176 cache_callback_->AddRef(); // Balanced in DoCacheReadMetadataComplete. | 1147 cache_callback_->AddRef(); // Balanced in DoCacheReadMetadataComplete. |
1177 return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata, | 1148 return entry_->disk_entry->ReadData(kMetadataIndex, 0, response_.metadata, |
1178 response_.metadata->size(), | 1149 response_.metadata->size(), |
1179 cache_callback_); | 1150 cache_callback_); |
1180 } | 1151 } |
1181 | 1152 |
1182 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { | 1153 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { |
1183 cache_callback_->Release(); // Balance the AddRef from DoCacheReadMetadata. | 1154 cache_callback_->Release(); // Balance the AddRef from DoCacheReadMetadata. |
1184 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 1155 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); |
1185 if (result != response_.metadata->size()) { | 1156 if (result != response_.metadata->size()) { |
1186 DLOG(ERROR) << "ReadData failed: " << result; | 1157 DLOG(ERROR) << "ReadData failed: " << result; |
1187 return ERR_CACHE_READ_FAILURE; | 1158 return ERR_CACHE_READ_FAILURE; |
1188 } | 1159 } |
1189 | 1160 |
1190 return OK; | 1161 return OK; |
1191 } | 1162 } |
1192 | 1163 |
1193 int HttpCache::Transaction::DoCacheQueryData() { | 1164 int HttpCache::Transaction::DoCacheQueryData() { |
1194 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; | 1165 next_state_ = STATE_CACHE_QUERY_DATA_COMPLETE; |
(...skipping 10 matching lines...) Expand all Loading... |
1205 if (!cache_) | 1176 if (!cache_) |
1206 return ERR_UNEXPECTED; | 1177 return ERR_UNEXPECTED; |
1207 | 1178 |
1208 return ValidateEntryHeadersAndContinue(true); | 1179 return ValidateEntryHeadersAndContinue(true); |
1209 } | 1180 } |
1210 | 1181 |
1211 int HttpCache::Transaction::DoCacheReadData() { | 1182 int HttpCache::Transaction::DoCacheReadData() { |
1212 DCHECK(entry_); | 1183 DCHECK(entry_); |
1213 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; | 1184 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; |
1214 cache_callback_->AddRef(); // Balanced in DoCacheReadDataComplete. | 1185 cache_callback_->AddRef(); // Balanced in DoCacheReadDataComplete. |
1215 | |
1216 if (net_log_.IsLoggingAllEvents()) | |
1217 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA, NULL); | |
1218 if (partial_.get()) { | 1186 if (partial_.get()) { |
1219 return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, | 1187 return partial_->CacheRead(entry_->disk_entry, read_buf_, io_buf_len_, |
1220 cache_callback_); | 1188 cache_callback_); |
1221 } | 1189 } |
1222 | 1190 |
1223 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, | 1191 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, |
1224 read_buf_, io_buf_len_, cache_callback_); | 1192 read_buf_, io_buf_len_, cache_callback_); |
1225 } | 1193 } |
1226 | 1194 |
1227 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { | 1195 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { |
1228 cache_callback_->Release(); // Balance the AddRef from DoCacheReadData. | 1196 cache_callback_->Release(); // Balance the AddRef from DoCacheReadData. |
1229 if (net_log_.IsLoggingAllEvents()) { | |
1230 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, | |
1231 result); | |
1232 } | |
1233 | 1197 |
1234 if (!cache_) | 1198 if (!cache_) |
1235 return ERR_UNEXPECTED; | 1199 return ERR_UNEXPECTED; |
1236 | 1200 |
1237 if (partial_.get()) | 1201 if (partial_.get()) |
1238 return DoPartialCacheReadCompleted(result); | 1202 return DoPartialCacheReadCompleted(result); |
1239 | 1203 |
1240 if (result > 0) { | 1204 if (result > 0) { |
1241 read_offset_ += result; | 1205 read_offset_ += result; |
1242 } else if (result == 0) { // End of file. | 1206 } else if (result == 0) { // End of file. |
1243 cache_->DoneReadingFromEntry(entry_, this); | 1207 cache_->DoneReadingFromEntry(entry_, this); |
1244 entry_ = NULL; | 1208 entry_ = NULL; |
1245 } | 1209 } |
1246 return result; | 1210 return result; |
1247 } | 1211 } |
1248 | 1212 |
1249 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { | 1213 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { |
1250 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; | 1214 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; |
1251 write_len_ = num_bytes; | 1215 write_len_ = num_bytes; |
1252 if (net_log_.IsLoggingAllEvents() && entry_) | |
1253 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, NULL); | |
1254 cache_callback_->AddRef(); // Balanced in DoCacheWriteDataComplete. | 1216 cache_callback_->AddRef(); // Balanced in DoCacheWriteDataComplete. |
1255 | 1217 |
1256 return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_); | 1218 return AppendResponseDataToEntry(read_buf_, num_bytes, cache_callback_); |
1257 } | 1219 } |
1258 | 1220 |
1259 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { | 1221 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { |
1260 if (net_log_.IsLoggingAllEvents() && entry_) { | |
1261 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, | |
1262 result); | |
1263 } | |
1264 // Balance the AddRef from DoCacheWriteData. | 1222 // Balance the AddRef from DoCacheWriteData. |
1265 cache_callback_->Release(); | 1223 cache_callback_->Release(); |
1266 if (!cache_) | 1224 if (!cache_) |
1267 return ERR_UNEXPECTED; | 1225 return ERR_UNEXPECTED; |
1268 | 1226 |
1269 if (result != write_len_) { | 1227 if (result != write_len_) { |
1270 DLOG(ERROR) << "failed to write response data to cache"; | 1228 DLOG(ERROR) << "failed to write response data to cache"; |
1271 DoneWritingToEntry(false); | 1229 DoneWritingToEntry(false); |
1272 | 1230 |
1273 // We want to ignore errors writing to disk and just keep reading from | 1231 // We want to ignore errors writing to disk and just keep reading from |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1908 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; | 1866 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; |
1909 } | 1867 } |
1910 return result; | 1868 return result; |
1911 } | 1869 } |
1912 | 1870 |
1913 void HttpCache::Transaction::OnIOComplete(int result) { | 1871 void HttpCache::Transaction::OnIOComplete(int result) { |
1914 DoLoop(result); | 1872 DoLoop(result); |
1915 } | 1873 } |
1916 | 1874 |
1917 } // namespace net | 1875 } // namespace net |
OLD | NEW |