summaryrefslogtreecommitdiffstats
path: root/net/http/http_cache_transaction.cc
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 22:31:51 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 22:31:51 +0000
commit4875ba17099e50f482ec826fc38e7922096b7be2 (patch)
tree7bb5ec4498187f7c9673ada84c54aca1c0cdd6e5 /net/http/http_cache_transaction.cc
parentb04f6c6aea3ffd3a03368b67abacc1f36d2f8ce8 (diff)
downloadchromium_src-4875ba17099e50f482ec826fc38e7922096b7be2.zip
chromium_src-4875ba17099e50f482ec826fc38e7922096b7be2.tar.gz
chromium_src-4875ba17099e50f482ec826fc38e7922096b7be2.tar.bz2
Add request_id to HttpRequestInfo and pass it to the NetworkDelegate for events.
This lets us look up the request associated with an http transaction and send event details for the webRequest.onBeforeRequest extension event. I also hooked up the onBeforeRequest event for HTTP network and cache transactions so that they are separate from other requests. This lets us have the request header information. BUG=60101 TEST=no Review URL: http://codereview.chromium.org/6698009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79905 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http/http_cache_transaction.cc')
-rw-r--r--net/http/http_cache_transaction.cc92
1 files changed, 63 insertions, 29 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index bf29f85..201f647 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"
@@ -486,6 +488,13 @@ int HttpCache::Transaction::DoLoop(int result) {
case STATE_ADD_TO_ENTRY_COMPLETE:
rv = DoAddToEntryComplete(rv);
break;
+ case STATE_NOTIFY_BEFORE_SEND_HEADERS:
+ DCHECK_EQ(OK, rv);
+ rv = DoNotifyBeforeSendHeaders();
+ break;
+ case STATE_NOTIFY_BEFORE_SEND_HEADERS_COMPLETE:
+ rv = DoNotifyBeforeSendHeadersComplete(rv);
+ break;
case STATE_START_PARTIAL_CACHE_VALIDATION:
DCHECK_EQ(OK, rv);
rv = DoStartPartialCacheValidation();
@@ -909,6 +918,57 @@ int HttpCache::Transaction::DoAddToEntryComplete(int result) {
return OK;
}
+int HttpCache::Transaction::DoNotifyBeforeSendHeaders() {
+ // Balanced in DoNotifyBeforeSendHeadersComplete.
+ cache_callback_->AddRef();
+ next_state_ = STATE_NOTIFY_BEFORE_SEND_HEADERS_COMPLETE;
+
+ if (cache_->GetSession() && cache_->GetSession()->network_delegate()) {
+ // TODO(mpcomplete): need to be able to modify these headers.
+ HttpRequestHeaders headers = request_->extra_headers;
+ return cache_->GetSession()->network_delegate()->NotifyBeforeSendHeaders(
+ request_->request_id, &headers, cache_callback_);
+ }
+
+ 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
+ // cache entry.
+ //
+ // o if we can read or write, then we should check if the cache entry needs
+ // to be validated and then issue a network request if needed or just read
+ // from the cache if the cache entry is already valid.
+ //
+ // o if we are set to UPDATE, then we are handling an externally
+ // conditionalized request (if-modified-since / if-none-match). We check
+ // if the request headers define a validation request.
+ //
+ 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;
+}
+
// We may end up here multiple times for a given request.
int HttpCache::Transaction::DoStartPartialCacheValidation() {
if (mode_ == NONE)
@@ -1109,6 +1169,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,35 +1179,7 @@ int HttpCache::Transaction::DoCacheReadResponseComplete(int result) {
return ERR_CACHE_READ_FAILURE;
}
- // We now have access to the cache entry.
- //
- // o if we are a reader for the transaction, then we can start reading the
- // cache entry.
- //
- // o if we can read or write, then we should check if the cache entry needs
- // to be validated and then issue a network request if needed or just read
- // from the cache if the cache entry is already valid.
- //
- // o if we are set to UPDATE, then we are handling an externally
- // 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;
- }
- return result;
+ return OK;
}
int HttpCache::Transaction::DoCacheWriteResponse() {