Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(655)

Side by Side Diff: net/http/http_cache_transaction.cc

Issue 2315613002: Extracted NetLog class's inner enum types into their own enum classes and (Closed)
Patch Set: Ran "git cl format" on code. Much formatting ensued. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/http_auth_handler_unittest.cc ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" // For OS_POSIX 7 #include "build/build_config.h" // For OS_POSIX
8 8
9 #if defined(OS_POSIX) 9 #if defined(OS_POSIX)
10 #include <unistd.h> 10 #include <unistd.h>
(...skipping 21 matching lines...) Expand all
32 #include "net/base/auth.h" 32 #include "net/base/auth.h"
33 #include "net/base/load_flags.h" 33 #include "net/base/load_flags.h"
34 #include "net/base/load_timing_info.h" 34 #include "net/base/load_timing_info.h"
35 #include "net/base/upload_data_stream.h" 35 #include "net/base/upload_data_stream.h"
36 #include "net/cert/cert_status_flags.h" 36 #include "net/cert/cert_status_flags.h"
37 #include "net/cert/x509_certificate.h" 37 #include "net/cert/x509_certificate.h"
38 #include "net/disk_cache/disk_cache.h" 38 #include "net/disk_cache/disk_cache.h"
39 #include "net/http/http_network_session.h" 39 #include "net/http/http_network_session.h"
40 #include "net/http/http_request_info.h" 40 #include "net/http/http_request_info.h"
41 #include "net/http/http_util.h" 41 #include "net/http/http_util.h"
42 #include "net/log/net_log_event_type.h"
42 #include "net/ssl/ssl_cert_request_info.h" 43 #include "net/ssl/ssl_cert_request_info.h"
43 #include "net/ssl/ssl_config_service.h" 44 #include "net/ssl/ssl_config_service.h"
44 45
45 using base::Time; 46 using base::Time;
46 using base::TimeDelta; 47 using base::TimeDelta;
47 using base::TimeTicks; 48 using base::TimeTicks;
48 49
49 namespace net { 50 namespace net {
50 51
51 using CacheEntryStatus = HttpResponseInfo::CacheEntryStatus; 52 using CacheEntryStatus = HttpResponseInfo::CacheEntryStatus;
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 read_buf_ = NULL; // Release the buffer before invoking the callback. 871 read_buf_ = NULL; // Release the buffer before invoking the callback.
871 base::ResetAndReturn(&callback_).Run(rv); 872 base::ResetAndReturn(&callback_).Run(rv);
872 } 873 }
873 874
874 return rv; 875 return rv;
875 } 876 }
876 877
877 int HttpCache::Transaction::DoGetBackend() { 878 int HttpCache::Transaction::DoGetBackend() {
878 cache_pending_ = true; 879 cache_pending_ = true;
879 next_state_ = STATE_GET_BACKEND_COMPLETE; 880 next_state_ = STATE_GET_BACKEND_COMPLETE;
880 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_GET_BACKEND); 881 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_GET_BACKEND);
881 return cache_->GetBackendForTransaction(this); 882 return cache_->GetBackendForTransaction(this);
882 } 883 }
883 884
884 int HttpCache::Transaction::DoGetBackendComplete(int result) { 885 int HttpCache::Transaction::DoGetBackendComplete(int result) {
885 DCHECK(result == OK || result == ERR_FAILED); 886 DCHECK(result == OK || result == ERR_FAILED);
886 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_GET_BACKEND, 887 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_GET_BACKEND,
887 result); 888 result);
888 cache_pending_ = false; 889 cache_pending_ = false;
889 890
890 if (!ShouldPassThrough()) { 891 if (!ShouldPassThrough()) {
891 cache_key_ = cache_->GenerateCacheKey(request_); 892 cache_key_ = cache_->GenerateCacheKey(request_);
892 893
893 // Requested cache access mode. 894 // Requested cache access mode.
894 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) { 895 if (effective_load_flags_ & LOAD_ONLY_FROM_CACHE) {
895 mode_ = READ; 896 mode_ = READ;
896 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) { 897 } else if (effective_load_flags_ & LOAD_BYPASS_CACHE) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 } 959 }
959 960
960 next_state_ = STATE_OPEN_ENTRY; 961 next_state_ = STATE_OPEN_ENTRY;
961 return OK; 962 return OK;
962 } 963 }
963 964
964 int HttpCache::Transaction::DoOpenEntry() { 965 int HttpCache::Transaction::DoOpenEntry() {
965 DCHECK(!new_entry_); 966 DCHECK(!new_entry_);
966 next_state_ = STATE_OPEN_ENTRY_COMPLETE; 967 next_state_ = STATE_OPEN_ENTRY_COMPLETE;
967 cache_pending_ = true; 968 cache_pending_ = true;
968 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY); 969 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_OPEN_ENTRY);
969 first_cache_access_since_ = TimeTicks::Now(); 970 first_cache_access_since_ = TimeTicks::Now();
970 return cache_->OpenEntry(cache_key_, &new_entry_, this); 971 return cache_->OpenEntry(cache_key_, &new_entry_, this);
971 } 972 }
972 973
973 int HttpCache::Transaction::DoOpenEntryComplete(int result) { 974 int HttpCache::Transaction::DoOpenEntryComplete(int result) {
974 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is 975 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is
975 // OK, otherwise the cache will end up with an active entry without any 976 // OK, otherwise the cache will end up with an active entry without any
976 // transaction attached. 977 // transaction attached.
977 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_OPEN_ENTRY, result); 978 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_OPEN_ENTRY,
979 result);
978 cache_pending_ = false; 980 cache_pending_ = false;
979 if (result == OK) { 981 if (result == OK) {
980 next_state_ = STATE_ADD_TO_ENTRY; 982 next_state_ = STATE_ADD_TO_ENTRY;
981 return OK; 983 return OK;
982 } 984 }
983 985
984 if (result == ERR_CACHE_RACE) { 986 if (result == ERR_CACHE_RACE) {
985 next_state_ = STATE_INIT_ENTRY; 987 next_state_ = STATE_INIT_ENTRY;
986 return OK; 988 return OK;
987 } 989 }
(...skipping 21 matching lines...) Expand all
1009 // The entry does not exist, and we are not permitted to create a new entry, 1011 // The entry does not exist, and we are not permitted to create a new entry,
1010 // so we must fail. 1012 // so we must fail.
1011 return ERR_CACHE_MISS; 1013 return ERR_CACHE_MISS;
1012 } 1014 }
1013 1015
1014 int HttpCache::Transaction::DoDoomEntry() { 1016 int HttpCache::Transaction::DoDoomEntry() {
1015 next_state_ = STATE_DOOM_ENTRY_COMPLETE; 1017 next_state_ = STATE_DOOM_ENTRY_COMPLETE;
1016 cache_pending_ = true; 1018 cache_pending_ = true;
1017 if (first_cache_access_since_.is_null()) 1019 if (first_cache_access_since_.is_null())
1018 first_cache_access_since_ = TimeTicks::Now(); 1020 first_cache_access_since_ = TimeTicks::Now();
1019 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY); 1021 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_DOOM_ENTRY);
1020 return cache_->DoomEntry(cache_key_, this); 1022 return cache_->DoomEntry(cache_key_, this);
1021 } 1023 }
1022 1024
1023 int HttpCache::Transaction::DoDoomEntryComplete(int result) { 1025 int HttpCache::Transaction::DoDoomEntryComplete(int result) {
1024 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_DOOM_ENTRY, result); 1026 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_DOOM_ENTRY,
1027 result);
1025 next_state_ = STATE_CREATE_ENTRY; 1028 next_state_ = STATE_CREATE_ENTRY;
1026 cache_pending_ = false; 1029 cache_pending_ = false;
1027 if (result == ERR_CACHE_RACE) 1030 if (result == ERR_CACHE_RACE)
1028 next_state_ = STATE_INIT_ENTRY; 1031 next_state_ = STATE_INIT_ENTRY;
1029 return OK; 1032 return OK;
1030 } 1033 }
1031 1034
1032 int HttpCache::Transaction::DoCreateEntry() { 1035 int HttpCache::Transaction::DoCreateEntry() {
1033 DCHECK(!new_entry_); 1036 DCHECK(!new_entry_);
1034 next_state_ = STATE_CREATE_ENTRY_COMPLETE; 1037 next_state_ = STATE_CREATE_ENTRY_COMPLETE;
1035 cache_pending_ = true; 1038 cache_pending_ = true;
1036 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY); 1039 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_CREATE_ENTRY);
1037 return cache_->CreateEntry(cache_key_, &new_entry_, this); 1040 return cache_->CreateEntry(cache_key_, &new_entry_, this);
1038 } 1041 }
1039 1042
1040 int HttpCache::Transaction::DoCreateEntryComplete(int result) { 1043 int HttpCache::Transaction::DoCreateEntryComplete(int result) {
1041 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is 1044 // It is important that we go to STATE_ADD_TO_ENTRY whenever the result is
1042 // OK, otherwise the cache will end up with an active entry without any 1045 // OK, otherwise the cache will end up with an active entry without any
1043 // transaction attached. 1046 // transaction attached.
1044 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_CREATE_ENTRY, 1047 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_CREATE_ENTRY,
1045 result); 1048 result);
1046 cache_pending_ = false; 1049 cache_pending_ = false;
1047 switch (result) { 1050 switch (result) {
1048 case OK: 1051 case OK:
1049 next_state_ = STATE_ADD_TO_ENTRY; 1052 next_state_ = STATE_ADD_TO_ENTRY;
1050 break; 1053 break;
1051 1054
1052 case ERR_CACHE_RACE: 1055 case ERR_CACHE_RACE:
1053 next_state_ = STATE_INIT_ENTRY; 1056 next_state_ = STATE_INIT_ENTRY;
1054 break; 1057 break;
1055 1058
1056 default: 1059 default:
1057 // We have a race here: Maybe we failed to open the entry and decided to 1060 // We have a race here: Maybe we failed to open the entry and decided to
1058 // create one, but by the time we called create, another transaction 1061 // create one, but by the time we called create, another transaction
1059 // already created the entry. If we want to eliminate this issue, we 1062 // already created the entry. If we want to eliminate this issue, we
1060 // need an atomic OpenOrCreate() method exposed by the disk cache. 1063 // need an atomic OpenOrCreate() method exposed by the disk cache.
1061 DLOG(WARNING) << "Unable to create cache entry"; 1064 DLOG(WARNING) << "Unable to create cache entry";
1062 mode_ = NONE; 1065 mode_ = NONE;
1063 if (partial_) 1066 if (partial_)
1064 partial_->RestoreHeaders(&custom_request_->extra_headers); 1067 partial_->RestoreHeaders(&custom_request_->extra_headers);
1065 next_state_ = STATE_SEND_REQUEST; 1068 next_state_ = STATE_SEND_REQUEST;
1066 } 1069 }
1067 return OK; 1070 return OK;
1068 } 1071 }
1069 1072
1070 int HttpCache::Transaction::DoAddToEntry() { 1073 int HttpCache::Transaction::DoAddToEntry() {
1071 DCHECK(new_entry_); 1074 DCHECK(new_entry_);
1072 cache_pending_ = true; 1075 cache_pending_ = true;
1073 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE; 1076 next_state_ = STATE_ADD_TO_ENTRY_COMPLETE;
1074 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY); 1077 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY);
1075 DCHECK(entry_lock_waiting_since_.is_null()); 1078 DCHECK(entry_lock_waiting_since_.is_null());
1076 entry_lock_waiting_since_ = TimeTicks::Now(); 1079 entry_lock_waiting_since_ = TimeTicks::Now();
1077 int rv = cache_->AddTransactionToEntry(new_entry_, this); 1080 int rv = cache_->AddTransactionToEntry(new_entry_, this);
1078 if (rv == ERR_IO_PENDING) { 1081 if (rv == ERR_IO_PENDING) {
1079 if (bypass_lock_for_test_) { 1082 if (bypass_lock_for_test_) {
1080 OnAddToEntryTimeout(entry_lock_waiting_since_); 1083 OnAddToEntryTimeout(entry_lock_waiting_since_);
1081 } else { 1084 } else {
1082 int timeout_milliseconds = 20 * 1000; 1085 int timeout_milliseconds = 20 * 1000;
1083 if (partial_ && new_entry_->writer && 1086 if (partial_ && new_entry_->writer &&
1084 new_entry_->writer->range_requested_) { 1087 new_entry_->writer->range_requested_) {
(...skipping 17 matching lines...) Expand all
1102 FROM_HERE, 1105 FROM_HERE,
1103 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout, 1106 base::Bind(&HttpCache::Transaction::OnAddToEntryTimeout,
1104 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_), 1107 weak_factory_.GetWeakPtr(), entry_lock_waiting_since_),
1105 TimeDelta::FromMilliseconds(timeout_milliseconds)); 1108 TimeDelta::FromMilliseconds(timeout_milliseconds));
1106 } 1109 }
1107 } 1110 }
1108 return rv; 1111 return rv;
1109 } 1112 }
1110 1113
1111 int HttpCache::Transaction::DoAddToEntryComplete(int result) { 1114 int HttpCache::Transaction::DoAddToEntryComplete(int result) {
1112 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_ADD_TO_ENTRY, 1115 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_ADD_TO_ENTRY,
1113 result); 1116 result);
1114 const TimeDelta entry_lock_wait = 1117 const TimeDelta entry_lock_wait =
1115 TimeTicks::Now() - entry_lock_waiting_since_; 1118 TimeTicks::Now() - entry_lock_waiting_since_;
1116 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait); 1119 UMA_HISTOGRAM_TIMES("HttpCache.EntryLockWait", entry_lock_wait);
1117 1120
1118 entry_lock_waiting_since_ = TimeTicks(); 1121 entry_lock_waiting_since_ = TimeTicks();
1119 DCHECK(new_entry_); 1122 DCHECK(new_entry_);
1120 cache_pending_ = false; 1123 cache_pending_ = false;
1121 1124
1122 if (result == OK) 1125 if (result == OK)
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 return OK; 1163 return OK;
1161 } 1164 }
1162 1165
1163 int HttpCache::Transaction::DoCacheReadResponse() { 1166 int HttpCache::Transaction::DoCacheReadResponse() {
1164 DCHECK(entry_); 1167 DCHECK(entry_);
1165 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; 1168 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE;
1166 1169
1167 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); 1170 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex);
1168 read_buf_ = new IOBuffer(io_buf_len_); 1171 read_buf_ = new IOBuffer(io_buf_len_);
1169 1172
1170 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); 1173 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO);
1171 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(), 1174 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_.get(),
1172 io_buf_len_, io_callback_); 1175 io_buf_len_, io_callback_);
1173 } 1176 }
1174 1177
1175 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { 1178 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
1176 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); 1179 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO,
1180 result);
1177 if (result != io_buf_len_ || 1181 if (result != io_buf_len_ ||
1178 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, &response_, 1182 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, &response_,
1179 &truncated_)) { 1183 &truncated_)) {
1180 return OnCacheReadError(result, true); 1184 return OnCacheReadError(result, true);
1181 } 1185 }
1182 1186
1183 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); 1187 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex);
1184 int64_t full_response_length = response_.headers->GetContentLength(); 1188 int64_t full_response_length = response_.headers->GetContentLength();
1185 1189
1186 // Some resources may have slipped in as truncated when they're not. 1190 // Some resources may have slipped in as truncated when they're not.
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 ResetNetworkTransaction(); 1420 ResetNetworkTransaction();
1417 return ERR_CACHE_AUTH_FAILURE_AFTER_READ; 1421 return ERR_CACHE_AUTH_FAILURE_AFTER_READ;
1418 } 1422 }
1419 1423
1420 new_response_ = new_response; 1424 new_response_ = new_response;
1421 if (!ValidatePartialResponse() && !auth_response_.headers.get()) { 1425 if (!ValidatePartialResponse() && !auth_response_.headers.get()) {
1422 // Something went wrong with this request and we have to restart it. 1426 // Something went wrong with this request and we have to restart it.
1423 // If we have an authentication response, we are exposed to weird things 1427 // If we have an authentication response, we are exposed to weird things
1424 // hapenning if the user cancels the authentication before we receive 1428 // hapenning if the user cancels the authentication before we receive
1425 // the new response. 1429 // the new response.
1426 net_log_.AddEvent(NetLog::TYPE_HTTP_CACHE_RE_SEND_PARTIAL_REQUEST); 1430 net_log_.AddEvent(NetLogEventType::HTTP_CACHE_RE_SEND_PARTIAL_REQUEST);
1427 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); 1431 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER);
1428 SetResponse(HttpResponseInfo()); 1432 SetResponse(HttpResponseInfo());
1429 ResetNetworkTransaction(); 1433 ResetNetworkTransaction();
1430 new_response_ = NULL; 1434 new_response_ = NULL;
1431 next_state_ = STATE_SEND_REQUEST; 1435 next_state_ = STATE_SEND_REQUEST;
1432 return OK; 1436 return OK;
1433 } 1437 }
1434 1438
1435 if (handling_206_ && mode_ == READ_WRITE && !truncated_ && !is_sparse_) { 1439 if (handling_206_ && mode_ == READ_WRITE && !truncated_ && !is_sparse_) {
1436 // We have stored the full entry, but it changed and the server is 1440 // We have stored the full entry, but it changed and the server is
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) { 1614 int HttpCache::Transaction::DoCacheWriteResponseComplete(int result) {
1611 next_state_ = STATE_TRUNCATE_CACHED_DATA; 1615 next_state_ = STATE_TRUNCATE_CACHED_DATA;
1612 return OnWriteResponseInfoToEntryComplete(result); 1616 return OnWriteResponseInfoToEntryComplete(result);
1613 } 1617 }
1614 1618
1615 int HttpCache::Transaction::DoTruncateCachedData() { 1619 int HttpCache::Transaction::DoTruncateCachedData() {
1616 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE; 1620 next_state_ = STATE_TRUNCATE_CACHED_DATA_COMPLETE;
1617 if (!entry_) 1621 if (!entry_)
1618 return OK; 1622 return OK;
1619 if (net_log_.IsCapturing()) 1623 if (net_log_.IsCapturing())
1620 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); 1624 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA);
1621 // Truncate the stream. 1625 // Truncate the stream.
1622 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_); 1626 return WriteToEntry(kResponseContentIndex, 0, NULL, 0, io_callback_);
1623 } 1627 }
1624 1628
1625 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) { 1629 int HttpCache::Transaction::DoTruncateCachedDataComplete(int result) {
1626 if (entry_) { 1630 if (entry_) {
1627 if (net_log_.IsCapturing()) { 1631 if (net_log_.IsCapturing()) {
1628 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, 1632 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA,
1629 result); 1633 result);
1630 } 1634 }
1631 } 1635 }
1632 1636
1633 next_state_ = STATE_TRUNCATE_CACHED_METADATA; 1637 next_state_ = STATE_TRUNCATE_CACHED_METADATA;
1634 return OK; 1638 return OK;
1635 } 1639 }
1636 1640
1637 int HttpCache::Transaction::DoTruncateCachedMetadata() { 1641 int HttpCache::Transaction::DoTruncateCachedMetadata() {
1638 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE; 1642 next_state_ = STATE_TRUNCATE_CACHED_METADATA_COMPLETE;
1639 if (!entry_) 1643 if (!entry_)
1640 return OK; 1644 return OK;
1641 1645
1642 if (net_log_.IsCapturing()) 1646 if (net_log_.IsCapturing())
1643 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); 1647 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_INFO);
1644 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_); 1648 return WriteToEntry(kMetadataIndex, 0, NULL, 0, io_callback_);
1645 } 1649 }
1646 1650
1647 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) { 1651 int HttpCache::Transaction::DoTruncateCachedMetadataComplete(int result) {
1648 if (entry_) { 1652 if (entry_) {
1649 if (net_log_.IsCapturing()) { 1653 if (net_log_.IsCapturing()) {
1650 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, 1654 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_INFO,
1651 result); 1655 result);
1652 } 1656 }
1653 } 1657 }
1654 1658
1655 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED; 1659 next_state_ = STATE_PARTIAL_HEADERS_RECEIVED;
1656 return OK; 1660 return OK;
1657 } 1661 }
1658 1662
1659 int HttpCache::Transaction::DoPartialHeadersReceived() { 1663 int HttpCache::Transaction::DoPartialHeadersReceived() {
1660 new_response_ = NULL; 1664 new_response_ = NULL;
(...skipping 18 matching lines...) Expand all
1679 } 1683 }
1680 1684
1681 int HttpCache::Transaction::DoCacheReadMetadata() { 1685 int HttpCache::Transaction::DoCacheReadMetadata() {
1682 DCHECK(entry_); 1686 DCHECK(entry_);
1683 DCHECK(!response_.metadata.get()); 1687 DCHECK(!response_.metadata.get());
1684 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE; 1688 next_state_ = STATE_CACHE_READ_METADATA_COMPLETE;
1685 1689
1686 response_.metadata = 1690 response_.metadata =
1687 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex)); 1691 new IOBufferWithSize(entry_->disk_entry->GetDataSize(kMetadataIndex));
1688 1692
1689 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO); 1693 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_INFO);
1690 return entry_->disk_entry->ReadData(kMetadataIndex, 0, 1694 return entry_->disk_entry->ReadData(kMetadataIndex, 0,
1691 response_.metadata.get(), 1695 response_.metadata.get(),
1692 response_.metadata->size(), 1696 response_.metadata->size(),
1693 io_callback_); 1697 io_callback_);
1694 } 1698 }
1695 1699
1696 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) { 1700 int HttpCache::Transaction::DoCacheReadMetadataComplete(int result) {
1697 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); 1701 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_INFO,
1702 result);
1698 if (result != response_.metadata->size()) 1703 if (result != response_.metadata->size())
1699 return OnCacheReadError(result, false); 1704 return OnCacheReadError(result, false);
1700 return OK; 1705 return OK;
1701 } 1706 }
1702 1707
1703 int HttpCache::Transaction::DoNetworkRead() { 1708 int HttpCache::Transaction::DoNetworkRead() {
1704 next_state_ = STATE_NETWORK_READ_COMPLETE; 1709 next_state_ = STATE_NETWORK_READ_COMPLETE;
1705 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_); 1710 return network_trans_->Read(read_buf_.get(), io_buf_len_, io_callback_);
1706 } 1711 }
1707 1712
(...skipping 13 matching lines...) Expand all
1721 } 1726 }
1722 1727
1723 int HttpCache::Transaction::DoCacheReadData() { 1728 int HttpCache::Transaction::DoCacheReadData() {
1724 if (request_->method == "HEAD") 1729 if (request_->method == "HEAD")
1725 return 0; 1730 return 0;
1726 1731
1727 DCHECK(entry_); 1732 DCHECK(entry_);
1728 next_state_ = STATE_CACHE_READ_DATA_COMPLETE; 1733 next_state_ = STATE_CACHE_READ_DATA_COMPLETE;
1729 1734
1730 if (net_log_.IsCapturing()) 1735 if (net_log_.IsCapturing())
1731 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_DATA); 1736 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_READ_DATA);
1732 if (partial_) { 1737 if (partial_) {
1733 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_, 1738 return partial_->CacheRead(entry_->disk_entry, read_buf_.get(), io_buf_len_,
1734 io_callback_); 1739 io_callback_);
1735 } 1740 }
1736 1741
1737 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_, 1742 return entry_->disk_entry->ReadData(kResponseContentIndex, read_offset_,
1738 read_buf_.get(), io_buf_len_, 1743 read_buf_.get(), io_buf_len_,
1739 io_callback_); 1744 io_callback_);
1740 } 1745 }
1741 1746
1742 int HttpCache::Transaction::DoCacheReadDataComplete(int result) { 1747 int HttpCache::Transaction::DoCacheReadDataComplete(int result) {
1743 if (net_log_.IsCapturing()) { 1748 if (net_log_.IsCapturing()) {
1744 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_DATA, 1749 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_READ_DATA,
1745 result); 1750 result);
1746 } 1751 }
1747 1752
1748 if (!cache_.get()) 1753 if (!cache_.get())
1749 return ERR_UNEXPECTED; 1754 return ERR_UNEXPECTED;
1750 1755
1751 if (partial_) { 1756 if (partial_) {
1752 // Partial requests are confusing to report in histograms because they may 1757 // Partial requests are confusing to report in histograms because they may
1753 // have multiple underlying requests. 1758 // have multiple underlying requests.
1754 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER); 1759 UpdateCacheEntryStatus(CacheEntryStatus::ENTRY_OTHER);
(...skipping 10 matching lines...) Expand all
1765 return OnCacheReadError(result, false); 1770 return OnCacheReadError(result, false);
1766 } 1771 }
1767 return result; 1772 return result;
1768 } 1773 }
1769 1774
1770 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) { 1775 int HttpCache::Transaction::DoCacheWriteData(int num_bytes) {
1771 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE; 1776 next_state_ = STATE_CACHE_WRITE_DATA_COMPLETE;
1772 write_len_ = num_bytes; 1777 write_len_ = num_bytes;
1773 if (entry_) { 1778 if (entry_) {
1774 if (net_log_.IsCapturing()) 1779 if (net_log_.IsCapturing())
1775 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_DATA); 1780 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_DATA);
1776 } 1781 }
1777 1782
1778 if (!entry_ || !num_bytes) 1783 if (!entry_ || !num_bytes)
1779 return num_bytes; 1784 return num_bytes;
1780 1785
1781 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex); 1786 int current_size = entry_->disk_entry->GetDataSize(kResponseContentIndex);
1782 return WriteToEntry(kResponseContentIndex, current_size, read_buf_.get(), 1787 return WriteToEntry(kResponseContentIndex, current_size, read_buf_.get(),
1783 num_bytes, io_callback_); 1788 num_bytes, io_callback_);
1784 } 1789 }
1785 1790
1786 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) { 1791 int HttpCache::Transaction::DoCacheWriteDataComplete(int result) {
1787 if (entry_) { 1792 if (entry_) {
1788 if (net_log_.IsCapturing()) { 1793 if (net_log_.IsCapturing()) {
1789 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_DATA, 1794 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_DATA,
1790 result); 1795 result);
1791 } 1796 }
1792 } 1797 }
1793 if (!cache_.get()) 1798 if (!cache_.get())
1794 return ERR_UNEXPECTED; 1799 return ERR_UNEXPECTED;
1795 1800
1796 if (result != write_len_) { 1801 if (result != write_len_) {
1797 DLOG(ERROR) << "failed to write response data to cache"; 1802 DLOG(ERROR) << "failed to write response data to cache";
1798 DoneWritingToEntry(false); 1803 DoneWritingToEntry(false);
1799 1804
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1893 } 1898 }
1894 external_validation_.values[i] = validation_value; 1899 external_validation_.values[i] = validation_value;
1895 external_validation_.initialized = true; 1900 external_validation_.initialized = true;
1896 } 1901 }
1897 } 1902 }
1898 1903
1899 if (range_found || special_headers || external_validation_.initialized) { 1904 if (range_found || special_headers || external_validation_.initialized) {
1900 // Log the headers before request_ is modified. 1905 // Log the headers before request_ is modified.
1901 std::string empty; 1906 std::string empty;
1902 net_log_.AddEvent( 1907 net_log_.AddEvent(
1903 NetLog::TYPE_HTTP_CACHE_CALLER_REQUEST_HEADERS, 1908 NetLogEventType::HTTP_CACHE_CALLER_REQUEST_HEADERS,
1904 base::Bind(&HttpRequestHeaders::NetLogCallback, 1909 base::Bind(&HttpRequestHeaders::NetLogCallback,
1905 base::Unretained(&request_->extra_headers), &empty)); 1910 base::Unretained(&request_->extra_headers), &empty));
1906 } 1911 }
1907 1912
1908 // We don't support ranges and validation headers. 1913 // We don't support ranges and validation headers.
1909 if (range_found && external_validation_.initialized) { 1914 if (range_found && external_validation_.initialized) {
1910 LOG(WARNING) << "Byte ranges AND validation headers found."; 1915 LOG(WARNING) << "Byte ranges AND validation headers found.";
1911 effective_load_flags_ |= LOAD_DISABLE_CACHE; 1916 effective_load_flags_ |= LOAD_DISABLE_CACHE;
1912 } 1917 }
1913 1918
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
2516 rv = partial_->CacheWrite(entry_->disk_entry, data, data_len, callback); 2521 rv = partial_->CacheWrite(entry_->disk_entry, data, data_len, callback);
2517 } 2522 }
2518 return rv; 2523 return rv;
2519 } 2524 }
2520 2525
2521 int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) { 2526 int HttpCache::Transaction::WriteResponseInfoToEntry(bool truncated) {
2522 if (!entry_) 2527 if (!entry_)
2523 return OK; 2528 return OK;
2524 2529
2525 if (net_log_.IsCapturing()) 2530 if (net_log_.IsCapturing())
2526 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); 2531 net_log_.BeginEvent(NetLogEventType::HTTP_CACHE_WRITE_INFO);
2527 2532
2528 // Do not cache no-store content. Do not cache content with cert errors 2533 // Do not cache no-store content. Do not cache content with cert errors
2529 // either. This is to prevent not reporting net errors when loading a 2534 // either. This is to prevent not reporting net errors when loading a
2530 // resource from the cache. When we load a page over HTTPS with a cert error 2535 // resource from the cache. When we load a page over HTTPS with a cert error
2531 // we show an SSL blocking page. If the user clicks proceed we reload the 2536 // we show an SSL blocking page. If the user clicks proceed we reload the
2532 // resource ignoring the errors. The loaded resource is then cached. If that 2537 // resource ignoring the errors. The loaded resource is then cached. If that
2533 // resource is subsequently loaded from the cache, no net error is reported 2538 // resource is subsequently loaded from the cache, no net error is reported
2534 // (even though the cert status contains the actual errors) and no SSL 2539 // (even though the cert status contains the actual errors) and no SSL
2535 // blocking page is shown. An alternative would be to reverse-map the cert 2540 // blocking page is shown. An alternative would be to reverse-map the cert
2536 // status to a net error and replay the net error. 2541 // status to a net error and replay the net error.
2537 if ((response_.headers->HasHeaderValue("cache-control", "no-store")) || 2542 if ((response_.headers->HasHeaderValue("cache-control", "no-store")) ||
2538 IsCertStatusError(response_.ssl_info.cert_status)) { 2543 IsCertStatusError(response_.ssl_info.cert_status)) {
2539 DoneWritingToEntry(false); 2544 DoneWritingToEntry(false);
2540 if (net_log_.IsCapturing()) 2545 if (net_log_.IsCapturing())
2541 net_log_.EndEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO); 2546 net_log_.EndEvent(NetLogEventType::HTTP_CACHE_WRITE_INFO);
2542 return OK; 2547 return OK;
2543 } 2548 }
2544 2549
2545 if (truncated) 2550 if (truncated)
2546 DCHECK_EQ(200, response_.headers->response_code()); 2551 DCHECK_EQ(200, response_.headers->response_code());
2547 2552
2548 // When writing headers, we normally only write the non-transient headers. 2553 // When writing headers, we normally only write the non-transient headers.
2549 bool skip_transient_headers = true; 2554 bool skip_transient_headers = true;
2550 scoped_refptr<PickledIOBuffer> data(new PickledIOBuffer()); 2555 scoped_refptr<PickledIOBuffer> data(new PickledIOBuffer());
2551 response_.Persist(data->pickle(), skip_transient_headers, truncated); 2556 response_.Persist(data->pickle(), skip_transient_headers, truncated);
2552 data->Done(); 2557 data->Done();
2553 2558
2554 io_buf_len_ = data->pickle()->size(); 2559 io_buf_len_ = data->pickle()->size();
2555 return entry_->disk_entry->WriteData(kResponseInfoIndex, 0, data.get(), 2560 return entry_->disk_entry->WriteData(kResponseInfoIndex, 0, data.get(),
2556 io_buf_len_, io_callback_, true); 2561 io_buf_len_, io_callback_, true);
2557 } 2562 }
2558 2563
2559 int HttpCache::Transaction::OnWriteResponseInfoToEntryComplete(int result) { 2564 int HttpCache::Transaction::OnWriteResponseInfoToEntryComplete(int result) {
2560 if (!entry_) 2565 if (!entry_)
2561 return OK; 2566 return OK;
2562 if (net_log_.IsCapturing()) { 2567 if (net_log_.IsCapturing()) {
2563 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, 2568 net_log_.EndEventWithNetErrorCode(NetLogEventType::HTTP_CACHE_WRITE_INFO,
2564 result); 2569 result);
2565 } 2570 }
2566 2571
2567 if (result != io_buf_len_) { 2572 if (result != io_buf_len_) {
2568 DLOG(ERROR) << "failed to write response info to cache"; 2573 DLOG(ERROR) << "failed to write response info to cache";
2569 DoneWritingToEntry(false); 2574 DoneWritingToEntry(false);
2570 } 2575 }
2571 return OK; 2576 return OK;
2572 } 2577 }
2573 2578
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 // We need to move on to the next range. 2659 // We need to move on to the next range.
2655 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; 2660 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION;
2656 } else if (result < 0) { 2661 } else if (result < 0) {
2657 return OnCacheReadError(result, false); 2662 return OnCacheReadError(result, false);
2658 } 2663 }
2659 return result; 2664 return result;
2660 } 2665 }
2661 2666
2662 int HttpCache::Transaction::DoRestartPartialRequest() { 2667 int HttpCache::Transaction::DoRestartPartialRequest() {
2663 // The stored data cannot be used. Get rid of it and restart this request. 2668 // The stored data cannot be used. Get rid of it and restart this request.
2664 net_log_.AddEvent(NetLog::TYPE_HTTP_CACHE_RESTART_PARTIAL_REQUEST); 2669 net_log_.AddEvent(NetLogEventType::HTTP_CACHE_RESTART_PARTIAL_REQUEST);
2665 2670
2666 // WRITE + Doom + STATE_INIT_ENTRY == STATE_CREATE_ENTRY (without an attempt 2671 // WRITE + Doom + STATE_INIT_ENTRY == STATE_CREATE_ENTRY (without an attempt
2667 // to Doom the entry again). 2672 // to Doom the entry again).
2668 mode_ = WRITE; 2673 mode_ = WRITE;
2669 ResetPartialState(!range_requested_); 2674 ResetPartialState(!range_requested_);
2670 next_state_ = STATE_CREATE_ENTRY; 2675 next_state_ = STATE_CREATE_ENTRY;
2671 return OK; 2676 return OK;
2672 } 2677 }
2673 2678
2674 void HttpCache::Transaction::ResetPartialState(bool delete_object) { 2679 void HttpCache::Transaction::ResetPartialState(bool delete_object) {
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
3015 default: 3020 default:
3016 NOTREACHED(); 3021 NOTREACHED();
3017 } 3022 }
3018 } 3023 }
3019 3024
3020 void HttpCache::Transaction::OnIOComplete(int result) { 3025 void HttpCache::Transaction::OnIOComplete(int result) {
3021 DoLoop(result); 3026 DoLoop(result);
3022 } 3027 }
3023 3028
3024 } // namespace net 3029 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_auth_handler_unittest.cc ('k') | net/http/http_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698