summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/base/network_delegate.cc8
-rw-r--r--net/base/network_delegate.h19
-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
-rw-r--r--net/url_request/url_request_test_util.cc3
-rw-r--r--net/url_request/url_request_test_util.h1
9 files changed, 46 insertions, 26 deletions
diff --git a/net/base/network_delegate.cc b/net/base/network_delegate.cc
index 3062c7b..d018455 100644
--- a/net/base/network_delegate.cc
+++ b/net/base/network_delegate.cc
@@ -53,8 +53,14 @@ void NetworkDelegate::NotifyCompleted(URLRequest* request) {
}
void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) {
+ DCHECK(CalledOnValidThread());
DCHECK(request);
- return OnURLRequestDestroyed(request);
+ OnURLRequestDestroyed(request);
+}
+
+void NetworkDelegate::NotifyHttpTransactionDestroyed(uint64 request_id) {
+ DCHECK(CalledOnValidThread());
+ OnHttpTransactionDestroyed(request_id);
}
URLRequestJob* NetworkDelegate::MaybeCreateURLRequestJob(URLRequest* request) {
diff --git a/net/base/network_delegate.h b/net/base/network_delegate.h
index 86949a8..3cc7b45 100644
--- a/net/base/network_delegate.h
+++ b/net/base/network_delegate.h
@@ -48,6 +48,7 @@ class NetworkDelegate : public base::NonThreadSafe {
void NotifyResponseStarted(URLRequest* request);
void NotifyCompleted(URLRequest* request);
void NotifyURLRequestDestroyed(URLRequest* request);
+ void NotifyHttpTransactionDestroyed(uint64 request_id);
// Returns a URLRequestJob that will be used to handle the request if
// non-null.
@@ -63,18 +64,18 @@ class NetworkDelegate : public base::NonThreadSafe {
// member function, which will perform basic sanity checking.
// Called before a request is sent. Allows the delegate to rewrite the URL
- // being fetched by modifying |new_url|. The callback can be called at any
- // time, but will have no effect if the request has already been cancelled or
- // deleted. Returns a net status code, generally either OK to continue with
- // the request or ERR_IO_PENDING if the result is not ready yet.
+ // being fetched by modifying |new_url|. |callback| and |new_url| are valid
+ // only until OnURLRequestDestroyed is called for this request. Returns a net
+ // status code, generally either OK to continue with the request or
+ // ERR_IO_PENDING if the result is not ready yet.
virtual int OnBeforeURLRequest(URLRequest* request,
CompletionCallback* callback,
GURL* new_url) = 0;
// Called right before the HTTP headers are sent. Allows the delegate to
- // read/write |headers| before they get sent out. The callback can be called
- // at any time, but will have no effect if the transaction handling this
- // request has been cancelled. Returns a net status code.
+ // read/write |headers| before they get sent out. |callback| and |headers| are
+ // valid only until OnHttpTransactionDestroyed is called for this request.
+ // Returns a net status code.
virtual int OnBeforeSendHeaders(uint64 request_id,
CompletionCallback* callback,
HttpRequestHeaders* headers) = 0;
@@ -99,6 +100,10 @@ class NetworkDelegate : public base::NonThreadSafe {
// a virtual method call.
virtual void OnURLRequestDestroyed(URLRequest* request) = 0;
+ // Called when the HttpTransaction for the request with the given ID is
+ // destroyed.
+ virtual void OnHttpTransactionDestroyed(uint64 request_id) = 0;
+
// Called before a request is sent and before a URLRequestJob is created to
// handle the request.
virtual URLRequestJob* OnMaybeCreateURLRequestJob(URLRequest* request) = 0;
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".
diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc
index 96d1391..f89458a 100644
--- a/net/url_request/url_request_test_util.cc
+++ b/net/url_request/url_request_test_util.cc
@@ -298,6 +298,9 @@ void TestNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) {
destroyed_requests_++;
}
+void TestNetworkDelegate::OnHttpTransactionDestroyed(uint64 request_id) {
+}
+
net::URLRequestJob* TestNetworkDelegate::OnMaybeCreateURLRequestJob(
net::URLRequest* request) {
return NULL;
diff --git a/net/url_request/url_request_test_util.h b/net/url_request/url_request_test_util.h
index 0778e13..0fbf052 100644
--- a/net/url_request/url_request_test_util.h
+++ b/net/url_request/url_request_test_util.h
@@ -212,6 +212,7 @@ class TestNetworkDelegate : public net::NetworkDelegate {
virtual void OnResponseStarted(net::URLRequest* request);
virtual void OnCompleted(net::URLRequest* request);
virtual void OnURLRequestDestroyed(net::URLRequest* request);
+ virtual void OnHttpTransactionDestroyed(uint64 request_id);
virtual net::URLRequestJob* OnMaybeCreateURLRequestJob(
net::URLRequest* request);