diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-15 16:39:44 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-15 16:39:44 +0000 |
commit | ac039524eca084f5169500f5d977276d122d2a02 (patch) | |
tree | 0f96468a44177234f2c7d4fd63bd84b38b982c9e /net/http | |
parent | 7c186b16ffa7f386a60223157daa08a897052681 (diff) | |
download | chromium_src-ac039524eca084f5169500f5d977276d122d2a02.zip chromium_src-ac039524eca084f5169500f5d977276d122d2a02.tar.gz chromium_src-ac039524eca084f5169500f5d977276d122d2a02.tar.bz2 |
Add a net::HttpNetworkDelegate and a ChromeNetworkDelegate.
net::HttpNetworkDelegate is an interface for providing hooks into http network activity. ChromeNetworkDelgate implements this interface in chrome/ code. In the future, it might also implement other interfaces. My only current intended consumer for this would be extensions. There's no actual behavior change, this is all just plumbing for now.
BUG=29314
Review URL: http://codereview.chromium.org/2749015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49804 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache.cc | 2 | ||||
-rw-r--r-- | net/http/http_cache.h | 2 | ||||
-rw-r--r-- | net/http/http_network_delegate.h | 24 | ||||
-rw-r--r-- | net/http/http_network_layer.cc | 7 | ||||
-rw-r--r-- | net/http/http_network_layer.h | 4 | ||||
-rw-r--r-- | net/http/http_network_layer_unittest.cc | 6 | ||||
-rw-r--r-- | net/http/http_network_session.cc | 2 | ||||
-rw-r--r-- | net/http/http_network_session.h | 8 | ||||
-rw-r--r-- | net/http/http_network_transaction.cc | 5 | ||||
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 4 |
10 files changed, 59 insertions, 5 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 162cc26..ef9198c 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -226,6 +226,7 @@ HttpCache::HttpCache(NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, + HttpNetworkDelegate* network_delegate, NetLog* net_log, BackendFactory* backend_factory) : backend_factory_(backend_factory), @@ -235,6 +236,7 @@ HttpCache::HttpCache(NetworkChangeNotifier* network_change_notifier, network_layer_(HttpNetworkLayer::CreateFactory( network_change_notifier, host_resolver, proxy_service, ssl_config_service, http_auth_handler_factory, + network_delegate, net_log)), ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), enable_range_support_(true) { diff --git a/net/http/http_cache.h b/net/http/http_cache.h index 04dc144..9ed20b4 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -40,6 +40,7 @@ namespace net { class HostResolver; class HttpAuthHandlerFactory; +class HttpNetworkDelegate; class HttpNetworkSession; struct HttpRequestInfo; class HttpResponseInfo; @@ -116,6 +117,7 @@ class HttpCache : public HttpTransactionFactory, HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, + HttpNetworkDelegate* network_delegate, NetLog* net_log, BackendFactory* backend_factory); diff --git a/net/http/http_network_delegate.h b/net/http/http_network_delegate.h new file mode 100644 index 0000000..51c6766 --- /dev/null +++ b/net/http/http_network_delegate.h @@ -0,0 +1,24 @@ +// 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_ + +namespace net { + +class HttpRequestHeaders; + +class HttpNetworkDelegate { + public: + // 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; + + protected: + virtual ~HttpNetworkDelegate() {} +}; + +} // namespace net + +#endif // NET_HTTP_HTTP_NETWORK_DELEGATE_H_ diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc index 0b8ed96..2329627 100644 --- a/net/http/http_network_layer.cc +++ b/net/http/http_network_layer.cc @@ -26,6 +26,7 @@ HttpTransactionFactory* HttpNetworkLayer::CreateFactory( ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, + HttpNetworkDelegate* network_delegate, NetLog* net_log) { DCHECK(proxy_service); @@ -33,6 +34,7 @@ HttpTransactionFactory* HttpNetworkLayer::CreateFactory( network_change_notifier, host_resolver, proxy_service, ssl_config_service, http_auth_handler_factory, + network_delegate, net_log); } @@ -54,6 +56,7 @@ HttpNetworkLayer::HttpNetworkLayer( ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, + HttpNetworkDelegate* network_delegate, NetLog* net_log) : socket_factory_(socket_factory), network_change_notifier_(network_change_notifier), @@ -63,6 +66,7 @@ HttpNetworkLayer::HttpNetworkLayer( session_(NULL), spdy_session_pool_(NULL), http_auth_handler_factory_(http_auth_handler_factory), + network_delegate_(network_delegate), net_log_(net_log), suspended_(false) { DCHECK(proxy_service_); @@ -76,6 +80,7 @@ HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) session_(session), spdy_session_pool_(session->spdy_session_pool()), http_auth_handler_factory_(NULL), + network_delegate_(NULL), net_log_(NULL), suspended_(false) { DCHECK(session_.get()); @@ -114,6 +119,7 @@ HttpNetworkSession* HttpNetworkLayer::GetSession() { network_change_notifier_, host_resolver_, proxy_service_, socket_factory_, ssl_config_service_, spdy_pool, http_auth_handler_factory_, + network_delegate_, net_log_); // These were just temps for lazy-initializing HttpNetworkSession. network_change_notifier_ = NULL; @@ -122,6 +128,7 @@ HttpNetworkSession* HttpNetworkLayer::GetSession() { socket_factory_ = NULL; http_auth_handler_factory_ = NULL; net_log_ = NULL; + network_delegate_ = NULL; } return session_; } diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h index a045798..54989410 100644 --- a/net/http/http_network_layer.h +++ b/net/http/http_network_layer.h @@ -16,6 +16,7 @@ namespace net { class ClientSocketFactory; class HostResolver; class HttpAuthHandlerFactory; +class HttpNetworkDelegate; class HttpNetworkSession; class NetLog; class NetworkChangeNotifier; @@ -33,6 +34,7 @@ class HttpNetworkLayer : public HttpTransactionFactory { HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, + HttpNetworkDelegate* network_delegate, NetLog* net_log); // Construct a HttpNetworkLayer with an existing HttpNetworkSession which // contains a valid ProxyService. @@ -47,6 +49,7 @@ class HttpNetworkLayer : public HttpTransactionFactory { ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, + HttpNetworkDelegate* network_delegate, NetLog* net_log); // Create a transaction factory that instantiate a network layer over an // existing network session. Network session contains some valuable @@ -88,6 +91,7 @@ class HttpNetworkLayer : public HttpTransactionFactory { scoped_refptr<SpdySessionPool> spdy_session_pool_; HttpAuthHandlerFactory* http_auth_handler_factory_; + HttpNetworkDelegate* network_delegate_; NetLog* net_log_; bool suspended_; diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc index 780ab68..9f20943 100644 --- a/net/http/http_network_layer_unittest.cc +++ b/net/http/http_network_layer_unittest.cc @@ -18,7 +18,7 @@ class HttpNetworkLayerTest : public PlatformTest { TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { net::HttpNetworkLayer factory( NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), - new net::SSLConfigServiceDefaults, NULL, NULL); + new net::SSLConfigServiceDefaults, NULL, NULL, NULL); scoped_ptr<net::HttpTransaction> trans; int rv = factory.CreateTransaction(&trans); @@ -29,7 +29,7 @@ TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { TEST_F(HttpNetworkLayerTest, Suspend) { net::HttpNetworkLayer factory( NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), - new net::SSLConfigServiceDefaults, NULL, NULL); + new net::SSLConfigServiceDefaults, NULL, NULL, NULL); scoped_ptr<net::HttpTransaction> trans; int rv = factory.CreateTransaction(&trans); @@ -71,7 +71,7 @@ TEST_F(HttpNetworkLayerTest, GET) { new net::MockHostResolver, net::ProxyService::CreateNull(), new net::SSLConfigServiceDefaults, - NULL, NULL); + NULL, NULL, NULL); TestCompletionCallback callback; diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc index c9a716e..1083626 100644 --- a/net/http/http_network_session.cc +++ b/net/http/http_network_session.cc @@ -43,6 +43,7 @@ HttpNetworkSession::HttpNetworkSession( SSLConfigService* ssl_config_service, SpdySessionPool* spdy_session_pool, HttpAuthHandlerFactory* http_auth_handler_factory, + HttpNetworkDelegate* network_delegate, NetLog* net_log) : network_change_notifier_(network_change_notifier), // TODO(vandebo) when we've completely converted to pools, the base TCP @@ -62,6 +63,7 @@ HttpNetworkSession::HttpNetworkSession( ssl_config_service_(ssl_config_service), spdy_session_pool_(spdy_session_pool), http_auth_handler_factory_(http_auth_handler_factory), + network_delegate_(network_delegate), net_log_(net_log) { DCHECK(proxy_service); DCHECK(ssl_config_service); diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index a6e10b1..1288197 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -14,6 +14,8 @@ #include "net/base/ssl_config_service.h" #include "net/http/http_alternate_protocols.h" #include "net/http/http_auth_cache.h" +#include "net/http/http_network_delegate.h" +#include "net/http/http_network_transaction.h" #include "net/proxy/proxy_service.h" #include "net/socket/client_socket_pool_histograms.h" #include "net/socket/socks_client_socket_pool.h" @@ -24,6 +26,7 @@ namespace net { class ClientSocketFactory; class HttpAuthHandlerFactory; +class HttpNetworkDelegate; class HttpNetworkSessionPeer; class NetworkChangeNotifier; class SpdySessionPool; @@ -39,6 +42,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { SSLConfigService* ssl_config_service, SpdySessionPool* spdy_session_pool, HttpAuthHandlerFactory* http_auth_handler_factory, + HttpNetworkDelegate* network_delegate, NetLog* net_log); HttpAuthCache* auth_cache() { return &auth_cache_; } @@ -83,6 +87,9 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { HttpAuthHandlerFactory* http_auth_handler_factory() { return http_auth_handler_factory_; } + HttpNetworkDelegate* network_delegate() { + return network_delegate_; + } static void set_max_sockets_per_group(int socket_count); @@ -120,6 +127,7 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { scoped_refptr<SSLConfigService> ssl_config_service_; scoped_refptr<SpdySessionPool> spdy_session_pool_; HttpAuthHandlerFactory* http_auth_handler_factory_; + HttpNetworkDelegate* const network_delegate_; NetLog* net_log_; SpdySettingsStorage spdy_settings_; }; diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index 13fbf9d..27db570 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -1220,12 +1220,17 @@ int HttpNetworkTransaction::DoSendRequest() { BuildRequestHeaders(request_, authorization_headers, request_body, !using_ssl_ && proxy_info_.is_http(), &request_line, &request_headers); + + if (session_->network_delegate()) + session_->network_delegate()->OnSendHttpRequest(&request_headers); + if (net_log_.HasListener()) { net_log_.AddEvent( NetLog::TYPE_HTTP_TRANSACTION_SEND_REQUEST_HEADERS, new NetLogHttpRequestParameter( request_line, request_headers)); } + request_headers_ = request_line + request_headers.ToString(); } diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index aaa2a19..2f0971c 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -75,8 +75,7 @@ class HttpNetworkSessionPeer { // Helper to manage the lifetimes of the dependencies for a // HttpNetworkTransaction. -class SessionDependencies { - public: +struct SessionDependencies { // Default set of dependencies -- "null" proxy service. SessionDependencies() : host_resolver(new MockHostResolver), @@ -115,6 +114,7 @@ HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { session_deps->ssl_config_service, session_deps->spdy_session_pool, session_deps->http_auth_handler_factory.get(), + NULL, NULL); } |