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

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

Issue 6698009: Add request_id to HttpRequestInfo and pass it to the NetworkDelegate for events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback Created 9 years, 9 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 | Annotate | Revision Log
OLDNEW
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
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_NOTIFY_BEFORE_SEND_HEADERS:
rvargas (doing something else) 2011/03/24 18:16:03 nit: this also follows the same order of the enum.
Matt Perry 2011/03/24 20:39:37 Isn't it confusing that the ordering doesn't match
rvargas (doing something else) 2011/03/24 20:56:34 It would be if the flow were a single line, but at
535 DCHECK_EQ(OK, rv);
536 rv = DoNotifyBeforeSendHeaders();
537 break;
538 case STATE_NOTIFY_BEFORE_SEND_HEADERS_COMPLETE:
539 rv = DoNotifyBeforeSendHeadersComplete(rv);
540 break;
532 case STATE_CACHE_WRITE_RESPONSE: 541 case STATE_CACHE_WRITE_RESPONSE:
533 DCHECK_EQ(OK, rv); 542 DCHECK_EQ(OK, rv);
534 rv = DoCacheWriteResponse(); 543 rv = DoCacheWriteResponse();
535 break; 544 break;
536 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: 545 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE:
537 DCHECK_EQ(OK, rv); 546 DCHECK_EQ(OK, rv);
538 rv = DoCacheWriteTruncatedResponse(); 547 rv = DoCacheWriteTruncatedResponse();
539 break; 548 break;
540 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: 549 case STATE_CACHE_WRITE_RESPONSE_COMPLETE:
541 rv = DoCacheWriteResponseComplete(rv); 550 rv = DoCacheWriteResponseComplete(rv);
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 read_buf_ = new IOBuffer(io_buf_len_); 1111 read_buf_ = new IOBuffer(io_buf_len_);
1103 1112
1104 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); 1113 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL);
1105 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete. 1114 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete.
1106 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, 1115 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_,
1107 io_buf_len_, cache_callback_); 1116 io_buf_len_, cache_callback_);
1108 } 1117 }
1109 1118
1110 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { 1119 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
1111 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse. 1120 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse.
1121 next_state_ = STATE_NOTIFY_BEFORE_SEND_HEADERS;
1122
1112 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); 1123 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result);
1113 if (result != io_buf_len_ || 1124 if (result != io_buf_len_ ||
1114 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, 1125 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_,
1115 &response_, &truncated_)) { 1126 &response_, &truncated_)) {
1116 DLOG(ERROR) << "ReadData failed: " << result; 1127 DLOG(ERROR) << "ReadData failed: " << result;
1117 return ERR_CACHE_READ_FAILURE; 1128 return ERR_CACHE_READ_FAILURE;
1118 } 1129 }
1119 1130
1131 return OK;
1132 }
1133
1134 int HttpCache::Transaction::DoNotifyBeforeSendHeaders() {
1135 // Balanced in DoNotifyBeforeSendHeadersComplete.
1136 cache_callback_->AddRef();
1137 next_state_ = STATE_NOTIFY_BEFORE_SEND_HEADERS_COMPLETE;
1138
1139 if (cache_->GetSession()->network_delegate()) {
1140 // TODO(mpcomplete): need to be able to modify these headers.
1141 HttpRequestHeaders headers = request_->extra_headers;
1142 if (cache_->GetSession()->network_delegate()->NotifyBeforeSendHeaders(
1143 request_->request_id, &headers, cache_callback_))
1144 return ERR_IO_PENDING;
1145 }
1146
1147 return OK;
1148 }
1149
1150 int HttpCache::Transaction::DoNotifyBeforeSendHeadersComplete(int result) {
1151 cache_callback_->Release(); // Balanced in DoNotifyBeforeSendHeaders.
1152
1120 // We now have access to the cache entry. 1153 // We now have access to the cache entry.
1121 // 1154 //
1122 // o if we are a reader for the transaction, then we can start reading the 1155 // o if we are a reader for the transaction, then we can start reading the
1123 // cache entry. 1156 // cache entry.
1124 // 1157 //
1125 // o if we can read or write, then we should check if the cache entry needs 1158 // 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 1159 // 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. 1160 // from the cache if the cache entry is already valid.
1128 // 1161 //
1129 // o if we are set to UPDATE, then we are handling an externally 1162 // o if we are set to UPDATE, then we are handling an externally
1130 // conditionalized request (if-modified-since / if-none-match). We check 1163 // conditionalized request (if-modified-since / if-none-match). We check
1131 // if the request headers define a validation request. 1164 // if the request headers define a validation request.
1132 // 1165 //
1133 switch (mode_) { 1166 if (result == net::OK) {
1134 case READ: 1167 switch (mode_) {
1135 result = BeginCacheRead(); 1168 case READ:
1136 break; 1169 result = BeginCacheRead();
1137 case READ_WRITE: 1170 break;
1138 result = BeginPartialCacheValidation(); 1171 case READ_WRITE:
1139 break; 1172 result = BeginPartialCacheValidation();
1140 case UPDATE: 1173 break;
1141 result = BeginExternallyConditionalizedRequest(); 1174 case UPDATE:
1142 break; 1175 result = BeginExternallyConditionalizedRequest();
1143 case WRITE: 1176 break;
1144 default: 1177 case WRITE:
1145 NOTREACHED(); 1178 default:
1146 result = ERR_FAILED; 1179 NOTREACHED();
1180 result = ERR_FAILED;
1181 }
1147 } 1182 }
1148 return result; 1183 return result;
1149 } 1184 }
1150 1185
1151 int HttpCache::Transaction::DoCacheWriteResponse() { 1186 int HttpCache::Transaction::DoCacheWriteResponse() {
1152 if (net_log_.IsLoggingAllEvents() && entry_) 1187 if (net_log_.IsLoggingAllEvents() && entry_)
1153 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); 1188 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL);
1154 return WriteResponseInfoToEntry(false); 1189 return WriteResponseInfoToEntry(false);
1155 } 1190 }
1156 1191
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; 1969 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION;
1935 } 1970 }
1936 return result; 1971 return result;
1937 } 1972 }
1938 1973
1939 void HttpCache::Transaction::OnIOComplete(int result) { 1974 void HttpCache::Transaction::OnIOComplete(int result) {
1940 DoLoop(result); 1975 DoLoop(result);
1941 } 1976 }
1942 1977
1943 } // namespace net 1978 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698