diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/base/network_delegate.cc | 35 | ||||
-rw-r--r-- | net/base/network_delegate.h | 59 | ||||
-rw-r--r-- | net/http/http_cache.cc | 4 | ||||
-rw-r--r-- | net/http/http_cache.h | 4 | ||||
-rw-r--r-- | net/http/http_network_delegate.h | 34 | ||||
-rw-r--r-- | net/http/http_network_layer.h | 2 | ||||
-rw-r--r-- | net/http/http_network_session.h | 8 | ||||
-rw-r--r-- | net/http/http_network_transaction.cc | 4 | ||||
-rw-r--r-- | net/net.gyp | 3 | ||||
-rw-r--r-- | net/url_request/url_request.cc | 6 | ||||
-rw-r--r-- | net/url_request/url_request_context.h | 8 | ||||
-rw-r--r-- | net/url_request/url_request_context_storage.cc | 4 | ||||
-rw-r--r-- | net/url_request/url_request_context_storage.h | 6 | ||||
-rw-r--r-- | net/url_request/url_request_job.cc | 9 | ||||
-rw-r--r-- | net/url_request/url_request_test_util.cc | 13 | ||||
-rw-r--r-- | net/url_request/url_request_test_util.h | 18 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 4 |
17 files changed, 142 insertions, 79 deletions
diff --git a/net/base/network_delegate.cc b/net/base/network_delegate.cc new file mode 100644 index 0000000..b00e671 --- /dev/null +++ b/net/base/network_delegate.cc @@ -0,0 +1,35 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/base/network_delegate.h" + +#include "base/logging.h" + +namespace net { + +void NetworkDelegate::NotifyBeforeURLRequest(URLRequest* request) { + DCHECK(CalledOnValidThread()); + DCHECK(request); + OnBeforeURLRequest(request); +} + +void NetworkDelegate::NotifySendHttpRequest(HttpRequestHeaders* headers) { + DCHECK(CalledOnValidThread()); + DCHECK(headers); + OnSendHttpRequest(headers); +} + +void NetworkDelegate::NotifyResponseStarted(URLRequest* request) { + DCHECK(CalledOnValidThread()); + DCHECK(request); + OnResponseStarted(request); +} + +void NetworkDelegate::NotifyReadCompleted(URLRequest* request, int bytes_read) { + DCHECK(CalledOnValidThread()); + DCHECK(request); + OnReadCompleted(request, bytes_read); +} + +} // namespace net diff --git a/net/base/network_delegate.h b/net/base/network_delegate.h new file mode 100644 index 0000000..c4f2b65 --- /dev/null +++ b/net/base/network_delegate.h @@ -0,0 +1,59 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_BASE_NETWORK_DELEGATE_H_ +#define NET_BASE_NETWORK_DELEGATE_H_ +#pragma once + +#include "base/threading/non_thread_safe.h" + +namespace net { + +// NOTE: Layering violations! +// We decided to accept these violations (depending +// on other net/ submodules from net/base/), because otherwise NetworkDelegate +// would have to be broken up into too many smaller interfaces targeted to each +// submodule. Also, since the lower levels in net/ may callback into higher +// levels, we may encounter dangerous casting issues. +// +// NOTE: It is not okay to add any compile-time dependencies on symbols outside +// of net/base here, because we have a net_base library. Forward declarations +// are ok. +class HttpRequestHeaders; +class URLRequest; + +class NetworkDelegate : public base::NonThreadSafe { + public: + virtual ~NetworkDelegate() {} + + // 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. + void NotifyBeforeURLRequest(URLRequest* request); + void NotifySendHttpRequest(HttpRequestHeaders* headers); + void NotifyResponseStarted(URLRequest* request); + void NotifyReadCompleted(URLRequest* request, int bytes_read); + + private: + // This is the interface for subclasses of NetworkDelegate to implement. This + // 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 void OnBeforeURLRequest(URLRequest* request) = 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; + + // This corresponds to URLRequestDelegate::OnResponseStarted. + virtual void OnResponseStarted(URLRequest* request) = 0; + + // This corresponds to URLRequestDelegate::OnReadCompleted. + virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; +}; + +} // namespace net + +#endif // NET_BASE_NETWORK_DELEGATE_H_ diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index a821a30..830fbaa 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -48,7 +48,7 @@ HttpNetworkSession* CreateNetworkSession( SSLHostInfoFactory* ssl_host_info_factory, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, - HttpNetworkDelegate* network_delegate, + NetworkDelegate* network_delegate, NetLog* net_log) { HttpNetworkSession::Params params; params.host_resolver = host_resolver; @@ -316,7 +316,7 @@ HttpCache::HttpCache(HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, - HttpNetworkDelegate* network_delegate, + NetworkDelegate* network_delegate, NetLog* net_log, BackendFactory* backend_factory) : net_log_(net_log), diff --git a/net/http/http_cache.h b/net/http/http_cache.h index ba7a18e..b33689d 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -46,12 +46,12 @@ class DnsCertProvenanceChecker; class DnsRRResolver; class HostResolver; class HttpAuthHandlerFactory; -class HttpNetworkDelegate; class HttpNetworkSession; struct HttpRequestInfo; class HttpResponseInfo; class IOBuffer; class NetLog; +class NetworkDelegate; class ProxyService; class SSLConfigService; class ViewCacheHelper; @@ -124,7 +124,7 @@ class HttpCache : public HttpTransactionFactory, ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, - HttpNetworkDelegate* network_delegate, + NetworkDelegate* network_delegate, NetLog* net_log, BackendFactory* backend_factory); diff --git a/net/http/http_network_delegate.h b/net/http/http_network_delegate.h deleted file mode 100644 index a4b217a..0000000 --- a/net/http/http_network_delegate.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_HTTP_HTTP_NETWORK_DELEGATE_H_ -#define NET_HTTP_HTTP_NETWORK_DELEGATE_H_ -#pragma once - -namespace net { - -class HttpRequestHeaders; -class URLRequest; - -class HttpNetworkDelegate { - public: - virtual ~HttpNetworkDelegate() {} - - // Called before a request is sent. - virtual void OnBeforeURLRequest(URLRequest* request) = 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; - - // This corresponds to URLRequestDelegate::OnResponseStarted. - virtual void OnResponseStarted(URLRequest* request) = 0; - - // This corresponds to URLRequestDelegate::OnReadCompleted. - virtual void OnReadCompleted(URLRequest* request, int bytes_read) = 0; -}; - -} // namespace net - -#endif // NET_HTTP_HTTP_NETWORK_DELEGATE_H_ diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h index da92761..db3d809 100644 --- a/net/http/http_network_layer.h +++ b/net/http/http_network_layer.h @@ -21,9 +21,9 @@ class DnsCertProvenanceChecker; class DnsRRResolver; class HostResolver; class HttpAuthHandlerFactory; -class HttpNetworkDelegate; class HttpNetworkSession; class NetLog; +class NetworkDelegate; class ProxyService; class SpdySessionPool; class SSLConfigService; diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index 5c8f705..9a4b85c 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -29,11 +29,11 @@ class DnsCertProvenanceChecker; class DnsRRResolver; class HostResolver; class HttpAuthHandlerFactory; -class HttpNetworkDelegate; class HttpNetworkSessionPeer; class HttpProxyClientSocketPool; class HttpResponseBodyDrainer; class NetLog; +class NetworkDelegate; class ProxyService; class SSLConfigService; class SSLHostInfoFactory; @@ -65,7 +65,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession>, SSLHostInfoFactory* ssl_host_info_factory; SSLConfigService* ssl_config_service; HttpAuthHandlerFactory* http_auth_handler_factory; - HttpNetworkDelegate* network_delegate; + NetworkDelegate* network_delegate; NetLog* net_log; }; @@ -117,7 +117,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession>, HttpAuthHandlerFactory* http_auth_handler_factory() { return http_auth_handler_factory_; } - HttpNetworkDelegate* network_delegate() { + NetworkDelegate* network_delegate() { return network_delegate_; } @@ -156,7 +156,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession>, ~HttpNetworkSession(); NetLog* const net_log_; - HttpNetworkDelegate* const network_delegate_; + NetworkDelegate* const network_delegate_; CertVerifier* const cert_verifier_; HttpAuthHandlerFactory* const http_auth_handler_factory_; diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index 98b9cd7..d3ed391 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -24,6 +24,7 @@ #include "net/base/load_flags.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" +#include "net/base/network_delegate.h" #include "net/base/ssl_cert_request_info.h" #include "net/base/ssl_connection_status_flags.h" #include "net/base/upload_data_stream.h" @@ -33,7 +34,6 @@ #include "net/http/http_basic_stream.h" #include "net/http/http_chunked_decoder.h" #include "net/http/http_net_log_params.h" -#include "net/http/http_network_delegate.h" #include "net/http/http_network_session.h" #include "net/http/http_proxy_client_socket.h" #include "net/http/http_proxy_client_socket_pool.h" @@ -685,7 +685,7 @@ int HttpNetworkTransaction::DoSendRequest() { &request_headers_); if (session_->network_delegate()) - session_->network_delegate()->OnSendHttpRequest(&request_headers_); + session_->network_delegate()->NotifySendHttpRequest(&request_headers_); } headers_valid_ = false; diff --git a/net/net.gyp b/net/net.gyp index c923165..58cf8fe 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -142,6 +142,8 @@ 'base/network_change_notifier_win.h', 'base/network_config_watcher_mac.cc', 'base/network_config_watcher_mac.h', + 'base/network_delegate.cc', + 'base/network_delegate.h', 'base/nss_memio.c', 'base/nss_memio.h', 'base/openssl_memory_private_key_store.cc', @@ -484,7 +486,6 @@ 'http/http_chunked_decoder.h', 'http/http_net_log_params.cc', 'http/http_net_log_params.h', - 'http/http_network_delegate.h', 'http/http_network_layer.cc', 'http/http_network_layer.h', 'http/http_network_session.cc', diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index ca8aacb..e25bac6 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -13,9 +13,9 @@ #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/upload_data.h" -#include "net/http/http_network_delegate.h" #include "net/http/http_response_headers.h" #include "net/http/http_util.h" #include "net/url_request/url_request_context.h" @@ -370,7 +370,7 @@ void URLRequest::StartJob(URLRequestJob* job) { // TODO(mpcomplete): pass in request ID? // TODO(mpcomplete): allow delegate to potentially delay/cancel request. if (context_ && context_->network_delegate()) - context_->network_delegate()->OnBeforeURLRequest(this); + context_->network_delegate()->NotifyBeforeURLRequest(this); net_log_.BeginEvent( net::NetLog::TYPE_URL_REQUEST_START_JOB, @@ -494,7 +494,7 @@ void URLRequest::ResponseStarted() { RestartWithJob(job); } else { if (context_ && context_->network_delegate()) - context_->network_delegate()->OnResponseStarted(this); + context_->network_delegate()->NotifyResponseStarted(this); if (delegate_) delegate_->OnResponseStarted(this); } diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index fa61297..7976126 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -29,8 +29,8 @@ class DnsRRResolver; class FtpTransactionFactory; class HostResolver; class HttpAuthHandlerFactory; -class HttpNetworkDelegate; class HttpTransactionFactory; +class NetworkDelegate; class SSLConfigService; class URLRequest; @@ -120,10 +120,10 @@ class URLRequestContext ftp_transaction_factory_ = factory; } - void set_network_delegate(HttpNetworkDelegate* network_delegate) { + void set_network_delegate(NetworkDelegate* network_delegate) { network_delegate_ = network_delegate; } - HttpNetworkDelegate* network_delegate() const { return network_delegate_; } + NetworkDelegate* network_delegate() const { return network_delegate_; } // Gets the cookie store for this context (may be null, in which case // cookies are not stored). @@ -196,7 +196,7 @@ class URLRequestContext HttpAuthHandlerFactory* http_auth_handler_factory_; scoped_refptr<ProxyService> proxy_service_; scoped_refptr<SSLConfigService> ssl_config_service_; - HttpNetworkDelegate* network_delegate_; + NetworkDelegate* network_delegate_; scoped_refptr<CookieStore> cookie_store_; CookiePolicy* cookie_policy_; scoped_refptr<TransportSecurityState> transport_security_state_; diff --git a/net/url_request/url_request_context_storage.cc b/net/url_request/url_request_context_storage.cc index 24b49ce..dd48887 100644 --- a/net/url_request/url_request_context_storage.cc +++ b/net/url_request/url_request_context_storage.cc @@ -11,9 +11,9 @@ #include "net/base/dnsrr_resolver.h" #include "net/base/host_resolver.h" #include "net/base/net_log.h" +#include "net/base/network_delegate.h" #include "net/ftp/ftp_transaction_factory.h" #include "net/http/http_auth_handler_factory.h" -#include "net/http/http_network_delegate.h" #include "net/http/http_transaction_factory.h" #include "net/proxy/proxy_service.h" #include "net/url_request/url_request_context.h" @@ -72,7 +72,7 @@ void URLRequestContextStorage::set_ssl_config_service( } void URLRequestContextStorage::set_network_delegate( - HttpNetworkDelegate* network_delegate) { + NetworkDelegate* network_delegate) { context_->set_network_delegate(network_delegate); network_delegate_.reset(network_delegate); } diff --git a/net/url_request/url_request_context_storage.h b/net/url_request/url_request_context_storage.h index 2bcd8f0a..faa6c69 100644 --- a/net/url_request/url_request_context_storage.h +++ b/net/url_request/url_request_context_storage.h @@ -20,9 +20,9 @@ class DnsRRResolver; class FtpTransactionFactory; class HostResolver; class HttpAuthHandlerFactory; -class HttpNetworkDelegate; class HttpTransactionFactory; class NetLog; +class NetworkDelegate; class ProxyService; class SSLConfigService; class TransportSecurityState; @@ -50,7 +50,7 @@ class URLRequestContextStorage { HttpAuthHandlerFactory* http_auth_handler_factory); void set_proxy_service(ProxyService* proxy_service); void set_ssl_config_service(SSLConfigService* ssl_config_service); - void set_network_delegate(HttpNetworkDelegate* network_delegate); + void set_network_delegate(NetworkDelegate* network_delegate); void set_cookie_store(CookieStore* cookie_store); void set_cookie_policy(CookiePolicy* cookie_policy); void set_transport_security_state( @@ -76,7 +76,7 @@ class URLRequestContextStorage { // TODO(willchan): Remove refcounting on these members. scoped_refptr<ProxyService> proxy_service_; scoped_refptr<SSLConfigService> ssl_config_service_; - scoped_ptr<HttpNetworkDelegate> network_delegate_; + scoped_ptr<NetworkDelegate> network_delegate_; scoped_refptr<CookieStore> cookie_store_; scoped_ptr<CookiePolicy> cookie_policy_; scoped_refptr<TransportSecurityState> transport_security_state_; diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index 2aede15..c13b8f5 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -14,7 +14,7 @@ #include "net/base/load_flags.h" #include "net/base/mime_util.h" #include "net/base/net_errors.h" -#include "net/http/http_network_delegate.h" +#include "net/base/network_delegate.h" #include "net/http/http_response_headers.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" @@ -538,7 +538,7 @@ void URLRequestJob::NotifyReadComplete(int bytes_read) { if (ReadFilteredData(&filter_bytes_read)) { postfilter_bytes_read_ += filter_bytes_read; if (request_->context() && request_->context()->network_delegate()) { - request_->context()->network_delegate()->OnReadCompleted( + request_->context()->network_delegate()->NotifyReadCompleted( request_, filter_bytes_read); } request_->delegate()->OnReadCompleted(request_, filter_bytes_read); @@ -546,7 +546,7 @@ void URLRequestJob::NotifyReadComplete(int bytes_read) { } else { postfilter_bytes_read_ += bytes_read; if (request_->context() && request_->context()->network_delegate()) { - request_->context()->network_delegate()->OnReadCompleted( + request_->context()->network_delegate()->NotifyReadCompleted( request_, bytes_read); } request_->delegate()->OnReadCompleted(request_, bytes_read); @@ -621,7 +621,8 @@ void URLRequestJob::CompleteNotifyDone() { if (has_handled_response_) { // We signal the error by calling OnReadComplete with a bytes_read of -1. if (request_->context() && request_->context()->network_delegate()) - request_->context()->network_delegate()->OnReadCompleted(request_, -1); + request_->context()->network_delegate()->NotifyReadCompleted( + request_, -1); request_->delegate()->OnReadCompleted(request_, -1); } else { has_handled_response_ = true; diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc index 4a518c0..5e76729 100644 --- a/net/url_request/url_request_test_util.cc +++ b/net/url_request/url_request_test_util.cc @@ -289,27 +289,28 @@ void TestDelegate::OnResponseCompleted(net::URLRequest* request) { MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); } -TestHttpNetworkDelegate::TestHttpNetworkDelegate() +TestNetworkDelegate::TestNetworkDelegate() : last_os_error_(0), error_count_(0) { } -TestHttpNetworkDelegate::~TestHttpNetworkDelegate() {} +TestNetworkDelegate::~TestNetworkDelegate() {} -void TestHttpNetworkDelegate::OnBeforeURLRequest(net::URLRequest* request) { +void TestNetworkDelegate::OnBeforeURLRequest(net::URLRequest* request) { } -void TestHttpNetworkDelegate::OnSendHttpRequest( +void TestNetworkDelegate::OnSendHttpRequest( net::HttpRequestHeaders* headers) { } -void TestHttpNetworkDelegate::OnResponseStarted(net::URLRequest* request) { +void TestNetworkDelegate::OnResponseStarted(net::URLRequest* request) { if (request->status().status() == net::URLRequestStatus::FAILED) { error_count_++; last_os_error_ = request->status().os_error(); } } -void TestHttpNetworkDelegate::OnReadCompleted(net::URLRequest* request, + +void TestNetworkDelegate::OnReadCompleted(net::URLRequest* request, int bytes_read) { if (request->status().status() == net::URLRequestStatus::FAILED) { error_count_++; diff --git a/net/url_request/url_request_test_util.h b/net/url_request/url_request_test_util.h index c02344c..47ecff4 100644 --- a/net/url_request/url_request_test_util.h +++ b/net/url_request/url_request_test_util.h @@ -23,12 +23,12 @@ #include "net/base/host_resolver.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" +#include "net/base/network_delegate.h" #include "net/base/ssl_config_service_defaults.h" #include "net/disk_cache/disk_cache.h" #include "net/ftp/ftp_network_layer.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_cache.h" -#include "net/http/http_network_delegate.h" #include "net/http/http_network_layer.h" #include "net/test/test_server.h" #include "net/url_request/url_request.h" @@ -191,21 +191,21 @@ class TestDelegate : public net::URLRequest::Delegate { //----------------------------------------------------------------------------- -class TestHttpNetworkDelegate : public net::HttpNetworkDelegate { +class TestNetworkDelegate : public net::NetworkDelegate { public: - TestHttpNetworkDelegate(); - virtual ~TestHttpNetworkDelegate(); + TestNetworkDelegate(); + virtual ~TestNetworkDelegate(); - // net::HttpNetworkDelegate: + int last_os_error() const { return last_os_error_; } + int error_count() const { return error_count_; } + + private: + // net::NetworkDelegate: virtual void OnBeforeURLRequest(net::URLRequest* request); virtual void OnSendHttpRequest(net::HttpRequestHeaders* headers); virtual void OnResponseStarted(net::URLRequest* request); virtual void OnReadCompleted(net::URLRequest* request, int bytes_read); - int last_os_error() const { return last_os_error_; } - int error_count() const { return error_count_; } - - private: int last_os_error_; int error_count_; }; diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index c3b8e37..5e03f9b 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -241,7 +241,7 @@ TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { net::URLRequest r(GURL("https://www.redirect.com/"), &d); scoped_refptr<TestURLRequestContext> context( new TestURLRequestContext(test_server_.host_port_pair().ToString())); - TestHttpNetworkDelegate network_delegate; + TestNetworkDelegate network_delegate; context->set_network_delegate(&network_delegate); r.set_context(context); @@ -2408,9 +2408,9 @@ TEST_F(URLRequestTest, NetworkDelegateProxyError) { scoped_ptr<net::MockHostResolverBase> host_resolver( new net::MockHostResolver); host_resolver->rules()->AddSimulatedFailure("*"); + TestNetworkDelegate network_delegate; scoped_refptr<TestURLRequestContext> context( new TestURLRequestContext("myproxy:70", host_resolver.release())); - TestHttpNetworkDelegate network_delegate; context->set_network_delegate(&network_delegate); req.set_context(context); |