diff options
author | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-30 22:31:51 +0000 |
---|---|---|
committer | mpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-30 22:31:51 +0000 |
commit | 4875ba17099e50f482ec826fc38e7922096b7be2 (patch) | |
tree | 7bb5ec4498187f7c9673ada84c54aca1c0cdd6e5 /net | |
parent | b04f6c6aea3ffd3a03368b67abacc1f36d2f8ce8 (diff) | |
download | chromium_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')
-rw-r--r-- | net/base/network_delegate.cc | 16 | ||||
-rw-r--r-- | net/base/network_delegate.h | 35 | ||||
-rw-r--r-- | net/http/http_cache_transaction.cc | 92 | ||||
-rw-r--r-- | net/http/http_cache_transaction.h | 4 | ||||
-rw-r--r-- | net/http/http_network_transaction.cc | 62 | ||||
-rw-r--r-- | net/http/http_network_transaction.h | 7 | ||||
-rw-r--r-- | net/http/http_request_info.cc | 3 | ||||
-rw-r--r-- | net/http/http_request_info.h | 4 | ||||
-rw-r--r-- | net/url_request/url_request.cc | 8 | ||||
-rw-r--r-- | net/url_request/url_request_http_job.cc | 1 | ||||
-rw-r--r-- | net/url_request/url_request_test_util.cc | 14 | ||||
-rw-r--r-- | net/url_request/url_request_test_util.h | 7 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 4 |
13 files changed, 190 insertions, 67 deletions
diff --git a/net/base/network_delegate.cc b/net/base/network_delegate.cc index 17da7a8..2ed1ea5 100644 --- a/net/base/network_delegate.cc +++ b/net/base/network_delegate.cc @@ -8,18 +8,21 @@ namespace net { -bool NetworkDelegate::NotifyBeforeURLRequest(URLRequest* request, - CompletionCallback* callback) { +int NetworkDelegate::NotifyBeforeURLRequest(URLRequest* request, + CompletionCallback* callback) { DCHECK(CalledOnValidThread()); DCHECK(request); DCHECK(callback); return OnBeforeURLRequest(request, callback); } -void NetworkDelegate::NotifySendHttpRequest(HttpRequestHeaders* headers) { +int NetworkDelegate::NotifyBeforeSendHeaders(uint64 request_id, + HttpRequestHeaders* headers, + CompletionCallback* callback) { DCHECK(CalledOnValidThread()); DCHECK(headers); - OnSendHttpRequest(headers); + DCHECK(callback); + return OnBeforeSendHeaders(request_id, headers, callback); } void NetworkDelegate::NotifyResponseStarted(URLRequest* request) { @@ -34,6 +37,11 @@ void NetworkDelegate::NotifyReadCompleted(URLRequest* request, int bytes_read) { OnReadCompleted(request, bytes_read); } +void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) { + DCHECK(request); + return OnURLRequestDestroyed(request); +} + URLRequestJob* NetworkDelegate::MaybeCreateURLRequestJob(URLRequest* request) { DCHECK(CalledOnValidThread()); DCHECK(request); diff --git a/net/base/network_delegate.h b/net/base/network_delegate.h index 284728b4..effc699 100644 --- a/net/base/network_delegate.h +++ b/net/base/network_delegate.h @@ -31,12 +31,16 @@ class NetworkDelegate : public base::NonThreadSafe { // Notification interface called by the network stack. Note that these // functions mostly forward to the private virtuals. They also add some sanity - // checking on parameters. - bool NotifyBeforeURLRequest(URLRequest* request, + // checking on parameters. See the corresponding virtuals for explanations of + // the methods and their arguments. + int NotifyBeforeURLRequest(URLRequest* request, + CompletionCallback* callback); + int NotifyBeforeSendHeaders(uint64 request_id, + HttpRequestHeaders* headers, CompletionCallback* callback); - void NotifySendHttpRequest(HttpRequestHeaders* headers); void NotifyResponseStarted(URLRequest* request); void NotifyReadCompleted(URLRequest* request, int bytes_read); + void NotifyURLRequestDestroyed(URLRequest* request); // Returns a URLRequestJob that will be used to handle the request if // non-null. @@ -51,13 +55,20 @@ class NetworkDelegate : public base::NonThreadSafe { // member functions will be called by the respective public notification // member function, which will perform basic sanity checking. - // Called before a request is sent. - virtual bool OnBeforeURLRequest(URLRequest* request, - CompletionCallback* callback) = 0; + // Called before a request is sent. 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. + virtual int OnBeforeURLRequest(URLRequest* request, + CompletionCallback* callback) = 0; - // Called right before the HTTP headers are sent. Allows the delegate to - // read/write |headers| before they get sent out. - virtual void OnSendHttpRequest(HttpRequestHeaders* headers) = 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. + virtual int OnBeforeSendHeaders(uint64 request_id, + HttpRequestHeaders* headers, + CompletionCallback* callback) = 0; // This corresponds to URLRequestDelegate::OnResponseStarted. virtual void OnResponseStarted(URLRequest* request) = 0; @@ -65,9 +76,15 @@ class NetworkDelegate : public base::NonThreadSafe { // This corresponds to URLRequestDelegate::OnReadCompleted. virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; + // Called when an URLRequest is being destroyed. Note that the request is + // being deleted, so it's not safe to call any methods that may result in + // a virtual method call. + virtual void OnURLRequestDestroyed(URLRequest* request) = 0; + // Called before a request is sent and before a URLRequestJob is created to // handle the request. virtual URLRequestJob* OnMaybeCreateURLRequestJob(URLRequest* request) = 0; + }; } // namespace net 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() { diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h index 81160d5..17d7ead 100644 --- a/net/http/http_cache_transaction.h +++ b/net/http/http_cache_transaction.h @@ -141,6 +141,8 @@ class HttpCache::Transaction : public HttpTransaction { STATE_DOOM_ENTRY_COMPLETE, STATE_ADD_TO_ENTRY, STATE_ADD_TO_ENTRY_COMPLETE, + STATE_NOTIFY_BEFORE_SEND_HEADERS, + STATE_NOTIFY_BEFORE_SEND_HEADERS_COMPLETE, STATE_START_PARTIAL_CACHE_VALIDATION, STATE_COMPLETE_PARTIAL_CACHE_VALIDATION, STATE_UPDATE_CACHED_RESPONSE, @@ -195,6 +197,8 @@ class HttpCache::Transaction : public HttpTransaction { int DoDoomEntryComplete(int result); int DoAddToEntry(); int DoAddToEntryComplete(int result); + int DoNotifyBeforeSendHeaders(); + int DoNotifyBeforeSendHeadersComplete(int result); int DoStartPartialCacheValidation(); int DoCompletePartialCacheValidation(int result); int DoUpdateCachedResponse(); diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index fb197f8..6d1e3d5 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -99,6 +99,9 @@ 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), @@ -146,6 +149,8 @@ HttpNetworkTransaction::~HttpNetworkTransaction() { } } } + + delegate_callback_->Cancel(); } int HttpNetworkTransaction::Start(const HttpRequestInfo* request_info, @@ -514,9 +519,16 @@ int HttpNetworkTransaction::DoLoop(int result) { case STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE: rv = DoGenerateServerAuthTokenComplete(rv); break; - case STATE_SEND_REQUEST: + case STATE_BUILD_REQUEST: DCHECK_EQ(OK, rv); net_log_.BeginEvent(NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST, NULL); + rv = DoBuildRequest(); + break; + case STATE_BUILD_REQUEST_COMPLETE: + rv = DoBuildRequestComplete(rv); + break; + case STATE_SEND_REQUEST: + DCHECK_EQ(OK, rv); rv = DoSendRequest(); break; case STATE_SEND_REQUEST_COMPLETE: @@ -661,38 +673,58 @@ int HttpNetworkTransaction::DoGenerateServerAuthToken() { int HttpNetworkTransaction::DoGenerateServerAuthTokenComplete(int rv) { DCHECK_NE(ERR_IO_PENDING, rv); if (rv == OK) - next_state_ = STATE_SEND_REQUEST; + next_state_ = STATE_BUILD_REQUEST; return rv; } -int HttpNetworkTransaction::DoSendRequest() { - next_state_ = STATE_SEND_REQUEST_COMPLETE; +int HttpNetworkTransaction::DoBuildRequest() { + next_state_ = STATE_BUILD_REQUEST_COMPLETE; - UploadDataStream* request_body = NULL; + request_body_.reset(NULL); if (request_->upload_data) { int error_code; - request_body = UploadDataStream::Create(request_->upload_data, &error_code); - if (!request_body) + request_body_.reset( + UploadDataStream::Create(request_->upload_data, &error_code)); + if (!request_body_.get()) return error_code; } + headers_valid_ = false; + // This is constructed lazily (instead of within our Start method), so that // we have proxy info available. if (request_headers_.IsEmpty()) { - bool using_proxy = (proxy_info_.is_http()|| proxy_info_.is_https()) && + bool using_proxy = (proxy_info_.is_http() || proxy_info_.is_https()) && !is_https_request(); - HttpUtil::BuildRequestHeaders(request_, request_body, auth_controllers_, + HttpUtil::BuildRequestHeaders(request_, request_body_.get(), + auth_controllers_, ShouldApplyServerAuth(), ShouldApplyProxyAuth(), using_proxy, &request_headers_); + } - if (session_->network_delegate()) - session_->network_delegate()->NotifySendHttpRequest(&request_headers_); + delegate_callback_->AddRef(); // balanced in DoSendRequestComplete + if (session_->network_delegate()) { + return session_->network_delegate()->NotifyBeforeSendHeaders( + request_->request_id, &request_headers_, delegate_callback_); } - headers_valid_ = false; - return stream_->SendRequest(request_headers_, request_body, &response_, - &io_callback_); + return OK; +} + +int HttpNetworkTransaction::DoBuildRequestComplete(int result) { + delegate_callback_->Release(); // balanced in DoBuildRequest +
+ if (result == OK)
+ next_state_ = STATE_SEND_REQUEST;
+ return result; +} + +int HttpNetworkTransaction::DoSendRequest() { + next_state_ = STATE_SEND_REQUEST_COMPLETE; + + return stream_->SendRequest( + request_headers_, request_body_.release(), &response_, &io_callback_); } int HttpNetworkTransaction::DoSendRequestComplete(int result) { @@ -1238,6 +1270,8 @@ std::string HttpNetworkTransaction::DescribeState(State state) { switch (state) { STATE_CASE(STATE_CREATE_STREAM); STATE_CASE(STATE_CREATE_STREAM_COMPLETE); + STATE_CASE(STATE_BUILD_REQUEST); + STATE_CASE(STATE_BUILD_REQUEST_COMPLETE); STATE_CASE(STATE_SEND_REQUEST); STATE_CASE(STATE_SEND_REQUEST_COMPLETE); STATE_CASE(STATE_READ_HEADERS); diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h index 2f55f4f..414b1f9 100644 --- a/net/http/http_network_transaction.h +++ b/net/http/http_network_transaction.h @@ -94,6 +94,8 @@ class HttpNetworkTransaction : public HttpTransaction, STATE_GENERATE_PROXY_AUTH_TOKEN_COMPLETE, STATE_GENERATE_SERVER_AUTH_TOKEN, STATE_GENERATE_SERVER_AUTH_TOKEN_COMPLETE, + STATE_BUILD_REQUEST, + STATE_BUILD_REQUEST_COMPLETE, STATE_SEND_REQUEST, STATE_SEND_REQUEST_COMPLETE, STATE_READ_HEADERS, @@ -125,6 +127,8 @@ class HttpNetworkTransaction : public HttpTransaction, int DoGenerateProxyAuthTokenComplete(int result); int DoGenerateServerAuthToken(); int DoGenerateServerAuthTokenComplete(int result); + int DoBuildRequest(); + int DoBuildRequestComplete(int result); int DoSendRequest(); int DoSendRequestComplete(int result); int DoReadHeaders(); @@ -217,7 +221,10 @@ 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_; scoped_refptr<HttpNetworkSession> session_; diff --git a/net/http/http_request_info.cc b/net/http/http_request_info.cc index 8ab3096..18c1b84 100644 --- a/net/http/http_request_info.cc +++ b/net/http/http_request_info.cc @@ -9,7 +9,8 @@ namespace net { HttpRequestInfo::HttpRequestInfo() : load_flags(0), priority(LOWEST), - motivation(NORMAL_MOTIVATION) { + motivation(NORMAL_MOTIVATION), + request_id(0) { } HttpRequestInfo::~HttpRequestInfo() {} diff --git a/net/http/http_request_info.h b/net/http/http_request_info.h index 70c1300..b906cf5 100644 --- a/net/http/http_request_info.h +++ b/net/http/http_request_info.h @@ -52,6 +52,10 @@ struct HttpRequestInfo { // The motivation behind this request. RequestMotivation motivation; + + // An optional globally unique identifier for this request for use by the + // consumer. 0 is invalid. + uint64 request_id; }; } // namespace net diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 17e23a5..5c437c2 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -44,7 +44,8 @@ void StripPostSpecificHeaders(HttpRequestHeaders* headers) { } // This counter keeps track of the identifiers used for URL requests so far. -uint64 g_next_url_request_identifier = 0; +// 0 is reserved to represent an invalid ID. +uint64 g_next_url_request_identifier = 1; // This lock protects g_next_url_request_identifier. base::Lock g_next_url_request_identifier_lock; @@ -130,6 +131,9 @@ URLRequest::URLRequest(const GURL& url, Delegate* delegate) } URLRequest::~URLRequest() { + if (context_ && context_->network_delegate()) + context_->network_delegate()->NotifyURLRequestDestroyed(this); + if (before_request_callback_) before_request_callback_->Cancel(); @@ -362,7 +366,7 @@ void URLRequest::Start() { before_request_callback_ = new CancelableCompletionCallback<URLRequest>( this, &URLRequest::BeforeRequestComplete); if (context_->network_delegate()->NotifyBeforeURLRequest( - this, before_request_callback_)) { + this, before_request_callback_) == net::ERR_IO_PENDING) { before_request_callback_->AddRef(); // balanced in BeforeRequestComplete net_log_.BeginEvent(NetLog::TYPE_URL_REQUEST_BLOCKED_ON_EXTENSION, NULL); return; // paused diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 1a3e28e..b3eaa0c 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -764,6 +764,7 @@ void URLRequestHttpJob::Start() { request_info_.method = request_->method(); request_info_.load_flags = request_->load_flags(); request_info_.priority = request_->priority(); + request_info_.request_id = request_->identifier(); if (request_->context()) { request_info_.extra_headers.SetHeaderIfMissing( diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc index d13ee06..e3627c4 100644 --- a/net/url_request/url_request_test_util.cc +++ b/net/url_request/url_request_test_util.cc @@ -296,13 +296,16 @@ TestNetworkDelegate::TestNetworkDelegate() TestNetworkDelegate::~TestNetworkDelegate() {} -bool TestNetworkDelegate::OnBeforeURLRequest( +int TestNetworkDelegate::OnBeforeURLRequest( net::URLRequest* request, net::CompletionCallback* callback) { - return false; + return net::OK; } -void TestNetworkDelegate::OnSendHttpRequest( - net::HttpRequestHeaders* headers) { +int TestNetworkDelegate::OnBeforeSendHeaders( + uint64 request_id, + net::HttpRequestHeaders* headers, + net::CompletionCallback* callback) { + return net::OK; } void TestNetworkDelegate::OnResponseStarted(net::URLRequest* request) { @@ -320,6 +323,9 @@ void TestNetworkDelegate::OnReadCompleted(net::URLRequest* request, } } +void TestNetworkDelegate::OnURLRequestDestroyed(net::URLRequest* request) { +} + 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 6dcd39d..789c82a 100644 --- a/net/url_request/url_request_test_util.h +++ b/net/url_request/url_request_test_util.h @@ -201,11 +201,14 @@ class TestNetworkDelegate : public net::NetworkDelegate { private: // net::NetworkDelegate: - virtual bool OnBeforeURLRequest(net::URLRequest* request, + virtual int OnBeforeURLRequest(net::URLRequest* request, + net::CompletionCallback* callback); + virtual int OnBeforeSendHeaders(uint64 request_id, + net::HttpRequestHeaders* headers, net::CompletionCallback* callback); - virtual void OnSendHttpRequest(net::HttpRequestHeaders* headers); virtual void OnResponseStarted(net::URLRequest* request); virtual void OnReadCompleted(net::URLRequest* request, int bytes_read); + virtual void OnURLRequestDestroyed(net::URLRequest* request); virtual net::URLRequestJob* OnMaybeCreateURLRequestJob( net::URLRequest* request); diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index 4f454d0..d12bc8a 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -239,10 +239,10 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { TestDelegate d; { + TestNetworkDelegate network_delegate; // must outlive URLRequest URLRequest r(GURL("https://www.redirect.com/"), &d); scoped_refptr<TestURLRequestContext> context( new TestURLRequestContext(test_server_.host_port_pair().ToString())); - TestNetworkDelegate network_delegate; context->set_network_delegate(&network_delegate); r.set_context(context); @@ -2403,13 +2403,13 @@ TEST_F(URLRequestTest, Identifiers) { // delegate. TEST_F(URLRequestTest, NetworkDelegateProxyError) { TestDelegate d; + TestNetworkDelegate network_delegate; TestURLRequest req(GURL("http://example.com"), &d); req.set_method("GET"); scoped_ptr<MockHostResolverBase> host_resolver( new MockHostResolver); host_resolver->rules()->AddSimulatedFailure("*"); - TestNetworkDelegate network_delegate; scoped_refptr<TestURLRequestContext> context( new TestURLRequestContext("myproxy:70", host_resolver.release())); context->set_network_delegate(&network_delegate); |