Chromium Code Reviews| 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> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <string> | 13 #include <string> |
| 14 | 14 |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/metrics/field_trial.h" | 16 #include "base/metrics/field_trial.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/ref_counted.h" | 18 #include "base/ref_counted.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/time.h" | 20 #include "base/time.h" |
| 21 #include "net/base/cert_status_flags.h" | 21 #include "net/base/cert_status_flags.h" |
| 22 #include "net/base/io_buffer.h" | 22 #include "net/base/io_buffer.h" |
| 23 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 24 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 25 #include "net/base/net_log.h" | 25 #include "net/base/net_log.h" |
| 26 #include "net/base/network_delegate.h" | |
| 26 #include "net/base/ssl_cert_request_info.h" | 27 #include "net/base/ssl_cert_request_info.h" |
| 27 #include "net/base/ssl_config_service.h" | 28 #include "net/base/ssl_config_service.h" |
| 28 #include "net/disk_cache/disk_cache.h" | 29 #include "net/disk_cache/disk_cache.h" |
| 29 #include "net/http/disk_cache_based_ssl_host_info.h" | 30 #include "net/http/disk_cache_based_ssl_host_info.h" |
| 31 #include "net/http/http_network_session.h" | |
| 30 #include "net/http/http_request_info.h" | 32 #include "net/http/http_request_info.h" |
| 31 #include "net/http/http_response_headers.h" | 33 #include "net/http/http_response_headers.h" |
| 32 #include "net/http/http_transaction.h" | 34 #include "net/http/http_transaction.h" |
| 33 #include "net/http/http_util.h" | 35 #include "net/http/http_util.h" |
| 34 #include "net/http/partial_data.h" | 36 #include "net/http/partial_data.h" |
| 35 | 37 |
| 36 using base::Time; | 38 using base::Time; |
| 37 | 39 |
| 38 namespace net { | 40 namespace net { |
| 39 | 41 |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 DCHECK_EQ(OK, rv); | 524 DCHECK_EQ(OK, rv); |
| 523 rv = DoPartialHeadersReceived(); | 525 rv = DoPartialHeadersReceived(); |
| 524 break; | 526 break; |
| 525 case STATE_CACHE_READ_RESPONSE: | 527 case STATE_CACHE_READ_RESPONSE: |
| 526 DCHECK_EQ(OK, rv); | 528 DCHECK_EQ(OK, rv); |
| 527 rv = DoCacheReadResponse(); | 529 rv = DoCacheReadResponse(); |
| 528 break; | 530 break; |
| 529 case STATE_CACHE_READ_RESPONSE_COMPLETE: | 531 case STATE_CACHE_READ_RESPONSE_COMPLETE: |
| 530 rv = DoCacheReadResponseComplete(rv); | 532 rv = DoCacheReadResponseComplete(rv); |
| 531 break; | 533 break; |
| 534 case STATE_CACHE_BEFORE_WRITE_RESPONSE: | |
| 535 rv = DoCacheBeforeWriteResponse(rv); | |
| 536 break; | |
| 532 case STATE_CACHE_WRITE_RESPONSE: | 537 case STATE_CACHE_WRITE_RESPONSE: |
| 533 DCHECK_EQ(OK, rv); | 538 DCHECK_EQ(OK, rv); |
| 534 rv = DoCacheWriteResponse(); | 539 rv = DoCacheWriteResponse(); |
| 535 break; | 540 break; |
| 536 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: | 541 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: |
| 537 DCHECK_EQ(OK, rv); | 542 DCHECK_EQ(OK, rv); |
| 538 rv = DoCacheWriteTruncatedResponse(); | 543 rv = DoCacheWriteTruncatedResponse(); |
| 539 break; | 544 break; |
| 540 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: | 545 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: |
| 541 rv = DoCacheWriteResponseComplete(rv); | 546 rv = DoCacheWriteResponseComplete(rv); |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1089 } else if (mode_ != NONE) { | 1094 } else if (mode_ != NONE) { |
| 1090 // We are about to return the headers for a byte-range request to the user, | 1095 // We are about to return the headers for a byte-range request to the user, |
| 1091 // so let's fix them. | 1096 // so let's fix them. |
| 1092 partial_->FixResponseHeaders(response_.headers, true); | 1097 partial_->FixResponseHeaders(response_.headers, true); |
| 1093 } | 1098 } |
| 1094 return OK; | 1099 return OK; |
| 1095 } | 1100 } |
| 1096 | 1101 |
| 1097 int HttpCache::Transaction::DoCacheReadResponse() { | 1102 int HttpCache::Transaction::DoCacheReadResponse() { |
| 1098 DCHECK(entry_); | 1103 DCHECK(entry_); |
| 1104 | |
|
rvargas (doing something else)
2011/03/17 19:40:20
nit: remove
Matt Perry
2011/03/22 21:11:43
Done.
| |
| 1099 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; | 1105 next_state_ = STATE_CACHE_READ_RESPONSE_COMPLETE; |
| 1100 | 1106 |
| 1101 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); | 1107 io_buf_len_ = entry_->disk_entry->GetDataSize(kResponseInfoIndex); |
| 1102 read_buf_ = new IOBuffer(io_buf_len_); | 1108 read_buf_ = new IOBuffer(io_buf_len_); |
| 1103 | 1109 |
| 1104 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); | 1110 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); |
| 1105 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete. | 1111 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete. |
| 1106 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, | 1112 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, |
| 1107 io_buf_len_, cache_callback_); | 1113 io_buf_len_, cache_callback_); |
| 1108 } | 1114 } |
| 1109 | 1115 |
| 1110 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { | 1116 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
| 1111 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse. | 1117 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse. |
| 1112 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); | 1118 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); |
| 1113 if (result != io_buf_len_ || | 1119 if (result != io_buf_len_ || |
| 1114 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, | 1120 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, |
| 1115 &response_, &truncated_)) { | 1121 &response_, &truncated_)) { |
| 1116 DLOG(ERROR) << "ReadData failed: " << result; | 1122 DLOG(ERROR) << "ReadData failed: " << result; |
| 1117 return ERR_CACHE_READ_FAILURE; | 1123 return ERR_CACHE_READ_FAILURE; |
| 1118 } | 1124 } |
| 1119 | 1125 |
| 1126 next_state_ = STATE_CACHE_BEFORE_WRITE_RESPONSE; | |
|
rvargas (doing something else)
2011/03/17 19:40:20
This should be related to the actual action perfor
Matt Perry
2011/03/22 21:11:43
Done.
| |
| 1127 | |
| 1128 cache_callback_->AddRef(); // Balanced in DoCacheBeforeWriteResponse. | |
|
rvargas (doing something else)
2011/03/17 19:40:20
I don't think you want to use this callback. This
Matt Perry
2011/03/22 21:11:43
I need a cancelable callback since the network del
| |
| 1129 if (cache_->GetSession()->network_delegate()) { | |
| 1130 // TODO(mpcomplete): Does it make sense to pass request headers here? Where | |
| 1131 // do we get them? | |
|
rvargas (doing something else)
2011/03/17 19:40:20
request_->extra_headers
Matt Perry
2011/03/22 21:11:43
Done.
| |
| 1132 HttpRequestHeaders empty_headers; | |
| 1133 if (cache_->GetSession()->network_delegate()->NotifyBeforeHttpRequest( | |
| 1134 request_->request_id, &empty_headers, cache_callback_)) | |
| 1135 return ERR_IO_PENDING; | |
| 1136 } | |
| 1137 | |
| 1138 return OK; | |
| 1139 } | |
| 1140 | |
| 1141 int HttpCache::Transaction::DoCacheBeforeWriteResponse(int result) { | |
| 1142 cache_callback_->Release(); // balanced in DoCacheReadResponseComplete | |
| 1143 | |
| 1120 // We now have access to the cache entry. | 1144 // We now have access to the cache entry. |
| 1121 // | 1145 // |
| 1122 // o if we are a reader for the transaction, then we can start reading the | 1146 // o if we are a reader for the transaction, then we can start reading the |
| 1123 // cache entry. | 1147 // cache entry. |
| 1124 // | 1148 // |
| 1125 // o if we can read or write, then we should check if the cache entry needs | 1149 // o if we can read or write, then we should check if the cache entry needs |
| 1126 // to be validated and then issue a network request if needed or just read | 1150 // to be validated and then issue a network request if needed or just read |
| 1127 // from the cache if the cache entry is already valid. | 1151 // from the cache if the cache entry is already valid. |
| 1128 // | 1152 // |
| 1129 // o if we are set to UPDATE, then we are handling an externally | 1153 // o if we are set to UPDATE, then we are handling an externally |
| 1130 // conditionalized request (if-modified-since / if-none-match). We check | 1154 // conditionalized request (if-modified-since / if-none-match). We check |
| 1131 // if the request headers define a validation request. | 1155 // if the request headers define a validation request. |
| 1132 // | 1156 // |
| 1133 switch (mode_) { | 1157 if (result == net::OK) { |
| 1134 case READ: | 1158 switch (mode_) { |
| 1135 result = BeginCacheRead(); | 1159 case READ: |
| 1136 break; | 1160 result = BeginCacheRead(); |
| 1137 case READ_WRITE: | 1161 break; |
| 1138 result = BeginPartialCacheValidation(); | 1162 case READ_WRITE: |
| 1139 break; | 1163 result = BeginPartialCacheValidation(); |
| 1140 case UPDATE: | 1164 break; |
| 1141 result = BeginExternallyConditionalizedRequest(); | 1165 case UPDATE: |
| 1142 break; | 1166 result = BeginExternallyConditionalizedRequest(); |
| 1143 case WRITE: | 1167 break; |
| 1144 default: | 1168 case WRITE: |
| 1145 NOTREACHED(); | 1169 default: |
| 1146 result = ERR_FAILED; | 1170 NOTREACHED(); |
| 1171 result = ERR_FAILED; | |
| 1172 } | |
| 1147 } | 1173 } |
| 1148 return result; | 1174 return result; |
| 1149 } | 1175 } |
| 1150 | 1176 |
| 1151 int HttpCache::Transaction::DoCacheWriteResponse() { | 1177 int HttpCache::Transaction::DoCacheWriteResponse() { |
| 1152 if (net_log_.IsLoggingAllEvents() && entry_) | 1178 if (net_log_.IsLoggingAllEvents() && entry_) |
| 1153 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); | 1179 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); |
| 1154 return WriteResponseInfoToEntry(false); | 1180 return WriteResponseInfoToEntry(false); |
| 1155 } | 1181 } |
| 1156 | 1182 |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1934 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; | 1960 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; |
| 1935 } | 1961 } |
| 1936 return result; | 1962 return result; |
| 1937 } | 1963 } |
| 1938 | 1964 |
| 1939 void HttpCache::Transaction::OnIOComplete(int result) { | 1965 void HttpCache::Transaction::OnIOComplete(int result) { |
| 1940 DoLoop(result); | 1966 DoLoop(result); |
| 1941 } | 1967 } |
| 1942 | 1968 |
| 1943 } // namespace net | 1969 } // namespace net |
| OLD | NEW |