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

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: delegate callbcak 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_CACHE_NOTIFY_BEFORE_SEND_HEADERS:
535 rv = DoCacheNotifyBeforeSendHeaders(rv);
536 break;
537 case STATE_CACHE_NOTIFY_BEFORE_SEND_HEADERS_COMPLETE:
538 rv = DoCacheNotifyBeforeSendHeadersComplete(rv);
539 break;
532 case STATE_CACHE_WRITE_RESPONSE: 540 case STATE_CACHE_WRITE_RESPONSE:
533 DCHECK_EQ(OK, rv); 541 DCHECK_EQ(OK, rv);
534 rv = DoCacheWriteResponse(); 542 rv = DoCacheWriteResponse();
535 break; 543 break;
536 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE: 544 case STATE_CACHE_WRITE_TRUNCATED_RESPONSE:
537 DCHECK_EQ(OK, rv); 545 DCHECK_EQ(OK, rv);
538 rv = DoCacheWriteTruncatedResponse(); 546 rv = DoCacheWriteTruncatedResponse();
539 break; 547 break;
540 case STATE_CACHE_WRITE_RESPONSE_COMPLETE: 548 case STATE_CACHE_WRITE_RESPONSE_COMPLETE:
541 rv = DoCacheWriteResponseComplete(rv); 549 rv = DoCacheWriteResponseComplete(rv);
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 read_buf_ = new IOBuffer(io_buf_len_); 1110 read_buf_ = new IOBuffer(io_buf_len_);
1103 1111
1104 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL); 1112 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_READ_INFO, NULL);
1105 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete. 1113 cache_callback_->AddRef(); // Balanced in DoCacheReadResponseComplete.
1106 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_, 1114 return entry_->disk_entry->ReadData(kResponseInfoIndex, 0, read_buf_,
1107 io_buf_len_, cache_callback_); 1115 io_buf_len_, cache_callback_);
1108 } 1116 }
1109 1117
1110 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { 1118 int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
1111 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse. 1119 cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse.
1120 next_state_ = STATE_CACHE_NOTIFY_BEFORE_SEND_HEADERS;
1121
1112 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); 1122 net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result);
1113 if (result != io_buf_len_ || 1123 if (result != io_buf_len_ ||
1114 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, 1124 !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_,
1115 &response_, &truncated_)) { 1125 &response_, &truncated_)) {
1116 DLOG(ERROR) << "ReadData failed: " << result; 1126 DLOG(ERROR) << "ReadData failed: " << result;
1117 return ERR_CACHE_READ_FAILURE; 1127 return ERR_CACHE_READ_FAILURE;
1118 } 1128 }
1119 1129
1130 return OK;
1131 }
1132
1133 int HttpCache::Transaction::DoCacheNotifyBeforeSendHeaders(int result) {
rvargas (doing something else) 2011/03/23 00:54:35 nit: no need for the argument.
Matt Perry 2011/03/24 00:11:25 Done.
1134 // Balanced in DoCacheNotifyBeforeSendHeadersComplete.
1135 cache_callback_->AddRef();
1136 next_state_ = STATE_CACHE_NOTIFY_BEFORE_SEND_HEADERS_COMPLETE;
1137
1138 if (cache_->GetSession()->network_delegate()) {
1139 // TODO(mpcomplete): need to e able to modify these headers.
rvargas (doing something else) 2011/03/23 00:54:35 nit: to be able.
Matt Perry 2011/03/24 00:11:25 Done.
1140 HttpRequestHeaders headers = request_->extra_headers;
1141 if (cache_->GetSession()->network_delegate()->NotifyBeforeSendHeaders(
rvargas (doing something else) 2011/03/23 00:54:35 I forgot to mention that it is possible to go thro
Matt Perry 2011/03/24 00:11:25 We will actually only respond to the first notific
1142 request_->request_id, &headers, cache_callback_))
1143 return ERR_IO_PENDING;
1144 }
1145
1146 return OK;
1147 }
1148
1149 int HttpCache::Transaction::DoCacheNotifyBeforeSendHeadersComplete(int result) {
rvargas (doing something else) 2011/03/23 00:54:35 Result should be related to the return value of No
Matt Perry 2011/03/24 00:11:25 The result from the callback is either net::OK, or
rvargas (doing something else) 2011/03/24 18:16:02 Just to double check, an error code here means tha
Matt Perry 2011/03/24 20:39:37 Right.
1150 cache_callback_->Release(); // Balanced in DoCacheNotifyBeforeSendHeaders.
1151
1120 // We now have access to the cache entry. 1152 // We now have access to the cache entry.
1121 // 1153 //
1122 // o if we are a reader for the transaction, then we can start reading the 1154 // o if we are a reader for the transaction, then we can start reading the
1123 // cache entry. 1155 // cache entry.
1124 // 1156 //
1125 // o if we can read or write, then we should check if the cache entry needs 1157 // 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 1158 // 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. 1159 // from the cache if the cache entry is already valid.
1128 // 1160 //
1129 // o if we are set to UPDATE, then we are handling an externally 1161 // o if we are set to UPDATE, then we are handling an externally
1130 // conditionalized request (if-modified-since / if-none-match). We check 1162 // conditionalized request (if-modified-since / if-none-match). We check
1131 // if the request headers define a validation request. 1163 // if the request headers define a validation request.
1132 // 1164 //
1133 switch (mode_) { 1165 if (result == net::OK) {
1134 case READ: 1166 switch (mode_) {
1135 result = BeginCacheRead(); 1167 case READ:
1136 break; 1168 result = BeginCacheRead();
1137 case READ_WRITE: 1169 break;
1138 result = BeginPartialCacheValidation(); 1170 case READ_WRITE:
1139 break; 1171 result = BeginPartialCacheValidation();
1140 case UPDATE: 1172 break;
1141 result = BeginExternallyConditionalizedRequest(); 1173 case UPDATE:
1142 break; 1174 result = BeginExternallyConditionalizedRequest();
1143 case WRITE: 1175 break;
1144 default: 1176 case WRITE:
1145 NOTREACHED(); 1177 default:
1146 result = ERR_FAILED; 1178 NOTREACHED();
1179 result = ERR_FAILED;
1180 }
1147 } 1181 }
1148 return result; 1182 return result;
1149 } 1183 }
1150 1184
1151 int HttpCache::Transaction::DoCacheWriteResponse() { 1185 int HttpCache::Transaction::DoCacheWriteResponse() {
1152 if (net_log_.IsLoggingAllEvents() && entry_) 1186 if (net_log_.IsLoggingAllEvents() && entry_)
1153 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL); 1187 net_log_.BeginEvent(NetLog::TYPE_HTTP_CACHE_WRITE_INFO, NULL);
1154 return WriteResponseInfoToEntry(false); 1188 return WriteResponseInfoToEntry(false);
1155 } 1189 }
1156 1190
(...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION; 1968 next_state_ = STATE_START_PARTIAL_CACHE_VALIDATION;
1935 } 1969 }
1936 return result; 1970 return result;
1937 } 1971 }
1938 1972
1939 void HttpCache::Transaction::OnIOComplete(int result) { 1973 void HttpCache::Transaction::OnIOComplete(int result) {
1940 DoLoop(result); 1974 DoLoop(result);
1941 } 1975 }
1942 1976
1943 } // namespace net 1977 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698