summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 23:11:34 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 23:11:34 +0000
commit5aa2013cf0fd9c0bb03eb2a1de01774bf2848c38 (patch)
tree2415e8c89e7da63f7834d9ddfaa7adfbcabe54ee /net/http
parentedd91a9b18019e2ea6159cf43b6e0fb0fdc13fbc (diff)
downloadchromium_src-5aa2013cf0fd9c0bb03eb2a1de01774bf2848c38.zip
chromium_src-5aa2013cf0fd9c0bb03eb2a1de01774bf2848c38.tar.gz
chromium_src-5aa2013cf0fd9c0bb03eb2a1de01774bf2848c38.tar.bz2
Flesh out the onBeforeSendHeaders event a bit more. We now send the
requestHeaders and allow the extension to modify them. I also changed the network delegate callbacks, so that they accept arguments beyond just a status code, and they do not outlive the object they are bound to. BUG=60101 TEST=automated Review URL: http://codereview.chromium.org/6899001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_cache_transaction.cc17
-rw-r--r--net/http/http_cache_transaction.h2
-rw-r--r--net/http/http_network_transaction.cc16
-rw-r--r--net/http/http_network_transaction.h2
-rw-r--r--net/http/http_request_headers.h4
5 files changed, 23 insertions, 18 deletions
diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc
index a12a64f..552913f 100644
--- a/net/http/http_cache_transaction.cc
+++ b/net/http/http_cache_transaction.cc
@@ -138,6 +138,12 @@ HttpCache::Transaction::~Transaction() {
// after this point.
callback_ = NULL;
+ if (request_ && cache_ && cache_->GetSession() &&
+ cache_->GetSession()->network_delegate()) {
+ cache_->GetSession()->network_delegate()->NotifyHttpTransactionDestroyed(
+ request_->request_id);
+ }
+
if (cache_) {
if (entry_) {
bool cancel_request = reading_;
@@ -901,22 +907,21 @@ int HttpCache::Transaction::DoAddToEntryComplete(int result) {
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;
+ // Give the delegate a copy of the request headers. We ignore any
+ // modification to these headers, since it doesn't make sense to issue a
+ // request from the cache with modified headers.
+ request_headers_copy_.CopyFrom(request_->extra_headers);
return cache_->GetSession()->network_delegate()->NotifyBeforeSendHeaders(
- request_->request_id, cache_callback_, &headers);
+ request_->request_id, &io_callback_, &request_headers_copy_);
}
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
diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h
index 945a70e..02caba8 100644
--- a/net/http/http_cache_transaction.h
+++ b/net/http/http_cache_transaction.h
@@ -16,6 +16,7 @@
#include "net/base/net_log.h"
#include "net/http/http_cache.h"
#include "net/http/http_response_info.h"
+#include "net/http/http_request_headers.h"
#include "net/http/http_transaction.h"
namespace net {
@@ -330,6 +331,7 @@ class HttpCache::Transaction : public HttpTransaction {
const HttpRequestInfo* request_;
BoundNetLog net_log_;
scoped_ptr<HttpRequestInfo> custom_request_;
+ HttpRequestHeaders request_headers_copy_;
// If extra_headers specified a "if-modified-since" or "if-none-match",
// |external_validation_| contains the value of those headers.
ValidationHeaders external_validation_;
diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc
index 3df89df..46858e6 100644
--- a/net/http/http_network_transaction.cc
+++ b/net/http/http_network_transaction.cc
@@ -99,9 +99,6 @@ HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session)
: pending_auth_target_(HttpAuth::AUTH_NONE),
ALLOW_THIS_IN_INITIALIZER_LIST(
io_callback_(this, &HttpNetworkTransaction::OnIOComplete)),
- ALLOW_THIS_IN_INITIALIZER_LIST(delegate_callback_(
- new CancelableCompletionCallback<HttpNetworkTransaction>(
- this, &HttpNetworkTransaction::OnIOComplete))),
user_callback_(NULL),
session_(session),
request_(NULL),
@@ -117,6 +114,11 @@ HttpNetworkTransaction::HttpNetworkTransaction(HttpNetworkSession* session)
}
HttpNetworkTransaction::~HttpNetworkTransaction() {
+ if (request_ && session_->network_delegate()) {
+ session_->network_delegate()->NotifyHttpTransactionDestroyed(
+ request_->request_id);
+ }
+
if (stream_.get()) {
HttpResponseHeaders* headers = GetResponseHeaders();
// TODO(mbelshe): The stream_ should be able to compute whether or not the
@@ -149,8 +151,6 @@ HttpNetworkTransaction::~HttpNetworkTransaction() {
}
}
}
-
- delegate_callback_->Cancel();
}
int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info,
@@ -748,8 +748,6 @@ void HttpNetworkTransaction::BuildRequestHeaders(bool using_proxy) {
int HttpNetworkTransaction::DoBuildRequest() {
next_state_ = STATE_BUILD_REQUEST_COMPLETE;
- delegate_callback_->AddRef(); // balanced in DoSendRequestComplete
-
request_body_.reset(NULL);
if (request_->upload_data) {
int error_code;
@@ -771,15 +769,13 @@ int HttpNetworkTransaction::DoBuildRequest() {
if (session_->network_delegate()) {
return session_->network_delegate()->NotifyBeforeSendHeaders(
- request_->request_id, delegate_callback_, &request_headers_);
+ request_->request_id, &io_callback_, &request_headers_);
}
return OK;
}
int HttpNetworkTransaction::DoBuildRequestComplete(int result) {
- delegate_callback_->Release(); // balanced in DoBuildRequest
-
if (result == OK)
next_state_ = STATE_SEND_REQUEST;
return result;
diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h
index 00e9a65..1b73b1f 100644
--- a/net/http/http_network_transaction.h
+++ b/net/http/http_network_transaction.h
@@ -223,8 +223,6 @@ class HttpNetworkTransaction : public HttpTransaction,
HttpAuth::Target pending_auth_target_;
CompletionCallbackImpl<HttpNetworkTransaction> io_callback_;
- scoped_refptr<CancelableCompletionCallback<HttpNetworkTransaction> >
- delegate_callback_;
CompletionCallback* user_callback_;
scoped_ptr<UploadDataStream> request_body_;
diff --git a/net/http/http_request_headers.h b/net/http/http_request_headers.h
index ef4b60d..ae9b118 100644
--- a/net/http/http_request_headers.h
+++ b/net/http/http_request_headers.h
@@ -132,6 +132,10 @@ class HttpRequestHeaders {
*this = other;
}
+ void Swap(HttpRequestHeaders* other) {
+ headers_.swap(other->headers_);
+ }
+
// Serializes HttpRequestHeaders to a string representation. Joins all the
// header keys and values with ": ", and inserts "\r\n" between each header
// line, and adds the trailing "\r\n".