Chromium Code Reviews| Index: net/http/http_cache_transaction.cc |
| diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc |
| index 6665d5ff404661c09502d469b815db7a506dc255..0f0a618562b76cc2b54e8127d5f7585114522c02 100644 |
| --- a/net/http/http_cache_transaction.cc |
| +++ b/net/http/http_cache_transaction.cc |
| @@ -23,10 +23,12 @@ |
| #include "net/base/load_flags.h" |
| #include "net/base/net_errors.h" |
| #include "net/base/net_log.h" |
| +#include "net/base/network_delegate.h" |
| #include "net/base/ssl_cert_request_info.h" |
| #include "net/base/ssl_config_service.h" |
| #include "net/disk_cache/disk_cache.h" |
| #include "net/http/disk_cache_based_ssl_host_info.h" |
| +#include "net/http/http_network_session.h" |
| #include "net/http/http_request_info.h" |
| #include "net/http/http_response_headers.h" |
| #include "net/http/http_transaction.h" |
| @@ -529,6 +531,13 @@ int HttpCache::Transaction::DoLoop(int result) { |
| case STATE_CACHE_READ_RESPONSE_COMPLETE: |
| rv = DoCacheReadResponseComplete(rv); |
| break; |
| + 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
|
| + DCHECK_EQ(OK, rv); |
| + rv = DoNotifyBeforeSendHeaders(); |
| + break; |
| + case STATE_NOTIFY_BEFORE_SEND_HEADERS_COMPLETE: |
| + rv = DoNotifyBeforeSendHeadersComplete(rv); |
| + break; |
| case STATE_CACHE_WRITE_RESPONSE: |
| DCHECK_EQ(OK, rv); |
| rv = DoCacheWriteResponse(); |
| @@ -1109,6 +1118,8 @@ int HttpCache::Transaction::DoCacheReadResponse() { |
| int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
| cache_callback_->Release(); // Balance the AddRef from DoCacheReadResponse. |
| + next_state_ = STATE_NOTIFY_BEFORE_SEND_HEADERS; |
| + |
| net_log_.EndEventWithNetErrorCode(NetLog::TYPE_HTTP_CACHE_READ_INFO, result); |
| if (result != io_buf_len_ || |
| !HttpCache::ParseResponseInfo(read_buf_->data(), io_buf_len_, |
| @@ -1117,6 +1128,28 @@ int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
| return ERR_CACHE_READ_FAILURE; |
| } |
| + return OK; |
| +} |
| + |
| +int HttpCache::Transaction::DoNotifyBeforeSendHeaders() { |
| + // Balanced in DoNotifyBeforeSendHeadersComplete. |
| + cache_callback_->AddRef(); |
| + next_state_ = STATE_NOTIFY_BEFORE_SEND_HEADERS_COMPLETE; |
| + |
| + if (cache_->GetSession()->network_delegate()) { |
| + // TODO(mpcomplete): need to be able to modify these headers. |
| + HttpRequestHeaders headers = request_->extra_headers; |
| + if (cache_->GetSession()->network_delegate()->NotifyBeforeSendHeaders( |
| + request_->request_id, &headers, cache_callback_)) |
| + return ERR_IO_PENDING; |
| + } |
| + |
| + return OK; |
| +} |
| + |
| +int HttpCache::Transaction::DoNotifyBeforeSendHeadersComplete(int result) { |
| + cache_callback_->Release(); // Balanced in DoNotifyBeforeSendHeaders. |
| + |
| // We now have access to the cache entry. |
| // |
| // o if we are a reader for the transaction, then we can start reading the |
| @@ -1130,20 +1163,22 @@ int HttpCache::Transaction::DoCacheReadResponseComplete(int result) { |
| // conditionalized request (if-modified-since / if-none-match). We check |
| // if the request headers define a validation request. |
| // |
| - switch (mode_) { |
| - case READ: |
| - result = BeginCacheRead(); |
| - break; |
| - case READ_WRITE: |
| - result = BeginPartialCacheValidation(); |
| - break; |
| - case UPDATE: |
| - result = BeginExternallyConditionalizedRequest(); |
| - break; |
| - case WRITE: |
| - default: |
| - NOTREACHED(); |
| - result = ERR_FAILED; |
| + if (result == net::OK) { |
| + switch (mode_) { |
| + case READ: |
| + result = BeginCacheRead(); |
| + break; |
| + case READ_WRITE: |
| + result = BeginPartialCacheValidation(); |
| + break; |
| + case UPDATE: |
| + result = BeginExternallyConditionalizedRequest(); |
| + break; |
| + case WRITE: |
| + default: |
| + NOTREACHED(); |
| + result = ERR_FAILED; |
| + } |
| } |
| return result; |
| } |