Skip to content

Commit

Permalink
Add a net::HttpNetworkDelegate and a ChromeNetworkDelegate.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
willchan@chromium.org committed Jun 15, 2010
1 parent 7c186b1 commit ac03952
Show file tree
Hide file tree
Showing 28 changed files with 156 additions and 23 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/io_thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/scoped_ptr.h"
#include "base/task.h"
#include "chrome/browser/browser_process_sub_thread.h"
#include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/common/net/dns.h"
#include "net/base/host_resolver.h"

Expand All @@ -36,6 +37,7 @@ class IOThread : public BrowserProcessSubThread {
scoped_refptr<net::HostResolver> host_resolver;
scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory;
scoped_ptr<net::URLSecurityManager> url_security_manager;
ChromeNetworkDelegate network_delegate;
};

IOThread();
Expand Down
18 changes: 18 additions & 0 deletions chrome/browser/net/chrome_network_delegate.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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.

#include "chrome/browser/net/chrome_network_delegate.h"

#include "base/logging.h"
#include "net/http/http_request_headers.h"

ChromeNetworkDelegate::ChromeNetworkDelegate() {}
ChromeNetworkDelegate::~ChromeNetworkDelegate() {}

void ChromeNetworkDelegate::OnSendHttpRequest(
net::HttpRequestHeaders* headers) {
DCHECK(headers);

// TODO(willchan): Add Chrome-side hooks to listen / mutate requests here.
}
30 changes: 30 additions & 0 deletions chrome/browser/net/chrome_network_delegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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 CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_
#define CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_

#include "base/basictypes.h"
#include "net/http/http_network_delegate.h"

// ChromeNetworkDelegate is the central point from within the chrome code to
// add hooks into the network stack. In the future, we can use this for
// extensions to register hooks for the network stack.
class ChromeNetworkDelegate : public net::HttpNetworkDelegate {
public:
ChromeNetworkDelegate();
~ChromeNetworkDelegate();

// net::HttpNetworkDelegate methods:

virtual void OnSendHttpRequest(net::HttpRequestHeaders* headers);

// TODO(willchan): Add functions for consumers to register ways to
// access/modify the request.

private:
DISALLOW_COPY_AND_ASSIGN(ChromeNetworkDelegate);
};

#endif // CHROME_BROWSER_NET_CHROME_NETWORK_DELEGATE_H_
37 changes: 24 additions & 13 deletions chrome/browser/net/chrome_url_request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,16 +232,18 @@ ChromeURLRequestContext* FactoryForOriginal::Create() {
ChromeURLRequestContext* context = new ChromeURLRequestContext;
ApplyProfileParametersToContext(context);

IOThread::Globals* io_thread_globals = io_thread()->globals();

// Global host resolver for the context.
context->set_host_resolver(io_thread()->globals()->host_resolver);
context->set_host_resolver(io_thread_globals->host_resolver);
context->set_http_auth_handler_factory(
io_thread()->globals()->http_auth_handler_factory.get());
io_thread_globals->http_auth_handler_factory.get());

const CommandLine& command_line = *CommandLine::ForCurrentProcess();

context->set_proxy_service(
CreateProxyService(io_thread()->globals()->network_change_notifier.get(),
io_thread()->globals()->net_log.get(),
CreateProxyService(io_thread_globals->network_change_notifier.get(),
io_thread_globals->net_log.get(),
context,
proxy_config_service_.release(),
command_line,
Expand All @@ -251,12 +253,13 @@ ChromeURLRequestContext* FactoryForOriginal::Create() {
net::DISK_CACHE, disk_cache_path_, cache_size_,
ChromeThread::GetMessageLoopProxyForThread(ChromeThread::CACHE));
net::HttpCache* cache =
new net::HttpCache(io_thread()->globals()->network_change_notifier.get(),
new net::HttpCache(io_thread_globals->network_change_notifier.get(),
context->host_resolver(),
context->proxy_service(),
context->ssl_config_service(),
context->http_auth_handler_factory(),
io_thread()->globals()->net_log.get(),
&io_thread_globals->network_delegate,
io_thread_globals->net_log.get(),
backend);

if (command_line.HasSwitch(switches::kDisableByteRangeSupport))
Expand Down Expand Up @@ -300,7 +303,7 @@ ChromeURLRequestContext* FactoryForOriginal::Create() {
net::SetURLRequestContextForOCSP(context);
#endif

context->set_net_log(io_thread()->globals()->net_log.get());
context->set_net_log(io_thread_globals->net_log.get());
return context;
}

Expand All @@ -322,6 +325,8 @@ ChromeURLRequestContext* FactoryForExtensions::Create() {
ChromeURLRequestContext* context = new ChromeURLRequestContext;
ApplyProfileParametersToContext(context);

IOThread::Globals* io_thread_globals = io_thread()->globals();

// All we care about for extensions is the cookie store.
DCHECK(!cookie_store_path_.empty());

Expand All @@ -336,7 +341,7 @@ ChromeURLRequestContext* FactoryForExtensions::Create() {
context->set_cookie_store(cookie_monster);
// TODO(cbentzel): How should extensions handle HTTP Authentication?
context->set_http_auth_handler_factory(
io_thread()->globals()->http_auth_handler_factory.get());
io_thread_globals->http_auth_handler_factory.get());

return context;
}
Expand Down Expand Up @@ -364,6 +369,8 @@ ChromeURLRequestContext* FactoryForOffTheRecord::Create() {
ChromeURLRequestContext* original_context =
original_context_getter_->GetIOContext();

IOThread::Globals* io_thread_globals = io_thread()->globals();

// Share the same proxy service, host resolver, and http_auth_handler_factory
// as the original profile.
context->set_host_resolver(original_context->host_resolver());
Expand All @@ -375,12 +382,13 @@ ChromeURLRequestContext* FactoryForOffTheRecord::Create() {
net::HttpCache::DefaultBackend::InMemory(0);

net::HttpCache* cache =
new net::HttpCache(io_thread()->globals()->network_change_notifier.get(),
new net::HttpCache(io_thread_globals->network_change_notifier.get(),
context->host_resolver(),
context->proxy_service(),
context->ssl_config_service(),
context->http_auth_handler_factory(),
io_thread()->globals()->net_log.get(),
&io_thread_globals->network_delegate,
io_thread_globals->net_log.get(),
backend);
context->set_cookie_store(new net::CookieMonster(NULL,
cookie_monster_delegate_));
Expand All @@ -399,7 +407,7 @@ ChromeURLRequestContext* FactoryForOffTheRecord::Create() {
context->set_appcache_service(
new ChromeAppCacheService(profile_dir_path_, context));

context->set_net_log(io_thread()->globals()->net_log.get());
context->set_net_log(io_thread_globals->net_log.get());
return context;
}

Expand Down Expand Up @@ -436,6 +444,8 @@ ChromeURLRequestContext* FactoryForMedia::Create() {
ChromeURLRequestContext* main_context =
main_context_getter_->GetIOContext();

IOThread::Globals* io_thread_globals = io_thread()->globals();

// Share the same proxy service of the common profile.
context->set_proxy_service(main_context->proxy_service());
context->set_http_auth_handler_factory(
Expand Down Expand Up @@ -471,12 +481,13 @@ ChromeURLRequestContext* FactoryForMedia::Create() {
// If original HttpCache doesn't exist, simply construct one with a whole
// new set of network stack.
cache = new net::HttpCache(
io_thread()->globals()->network_change_notifier.get(),
io_thread_globals->network_change_notifier.get(),
main_context->host_resolver(),
main_context->proxy_service(),
main_context->ssl_config_service(),
main_context->http_auth_handler_factory(),
io_thread()->globals()->net_log.get(),
&io_thread_globals->network_delegate,
io_thread_globals->net_log.get(),
backend);
}

Expand Down
5 changes: 5 additions & 0 deletions chrome/browser/net/chrome_url_request_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CommandLine;
class Profile;

namespace net {
class NetworkDelegate;
class ProxyConfig;
}

Expand Down Expand Up @@ -218,6 +219,10 @@ class ChromeURLRequestContext : public URLRequestContext {
void set_net_log(net::NetLog* net_log) {
net_log_ = net_log;
}
void set_network_delegate(
net::HttpNetworkDelegate* network_delegate) {
network_delegate_ = network_delegate;
}

// Callback for when the accept language changes.
void OnAcceptLanguageChange(const std::string& accept_language);
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/net/connection_tester.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class ExperimentURLRequestContext : public URLRequestContext {
proxy_service_,
ssl_config_service_,
http_auth_handler_factory_,
NULL,
NULL),
net::HttpCache::DefaultBackend::InMemory(0));
// In-memory cookie store.
Expand Down Expand Up @@ -401,4 +402,3 @@ void ConnectionTester::OnExperimentCompleted(int result) {
StartNextExperiment();
}
}

2 changes: 2 additions & 0 deletions chrome/chrome_browser.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,8 @@
'browser/net/chrome_cookie_policy.h',
'browser/net/chrome_net_log.cc',
'browser/net/chrome_net_log.h',
'browser/net/chrome_network_delegate.cc',
'browser/net/chrome_network_delegate.h',
'browser/net/chrome_url_request_context.cc',
'browser/net/chrome_url_request_context.h',
'browser/net/connection_tester.cc',
Expand Down
4 changes: 2 additions & 2 deletions chrome/service/net/service_url_request_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ ServiceURLRequestContext::ServiceURLRequestContext() {
proxy_service_,
ssl_config_service_,
http_auth_handler_factory_,
NULL /*net_log*/),
NULL /* network_delegate */,
NULL /* net_log */),
net::HttpCache::DefaultBackend::InMemory(0));
// In-memory cookie store.
cookie_store_ = new net::CookieMonster(NULL, NULL);
Expand All @@ -53,4 +54,3 @@ ServiceURLRequestContext::~ServiceURLRequestContext() {
delete http_transaction_factory_;
delete http_auth_handler_factory_;
}

1 change: 1 addition & 0 deletions chrome_frame/test/test_server_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class URLRequestTestContext : public URLRequestContext {
proxy_service_,
ssl_config_service_,
http_auth_handler_factory_,
NULL,
NULL),
net::HttpCache::DefaultBackend::InMemory(0));
// In-memory cookie store.
Expand Down
2 changes: 2 additions & 0 deletions net/http/http_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions net/http/http_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace net {

class HostResolver;
class HttpAuthHandlerFactory;
class HttpNetworkDelegate;
class HttpNetworkSession;
struct HttpRequestInfo;
class HttpResponseInfo;
Expand Down Expand Up @@ -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);

Expand Down
24 changes: 24 additions & 0 deletions net/http/http_network_delegate.h
Original file line number Diff line number Diff line change
@@ -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_
7 changes: 7 additions & 0 deletions net/http/http_network_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ HttpTransactionFactory* HttpNetworkLayer::CreateFactory(
ProxyService* proxy_service,
SSLConfigService* ssl_config_service,
HttpAuthHandlerFactory* http_auth_handler_factory,
HttpNetworkDelegate* network_delegate,
NetLog* net_log) {
DCHECK(proxy_service);

return new HttpNetworkLayer(ClientSocketFactory::GetDefaultFactory(),
network_change_notifier,
host_resolver, proxy_service, ssl_config_service,
http_auth_handler_factory,
network_delegate,
net_log);
}

Expand All @@ -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),
Expand All @@ -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_);
Expand All @@ -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());
Expand Down Expand Up @@ -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;
Expand All @@ -122,6 +128,7 @@ HttpNetworkSession* HttpNetworkLayer::GetSession() {
socket_factory_ = NULL;
http_auth_handler_factory_ = NULL;
net_log_ = NULL;
network_delegate_ = NULL;
}
return session_;
}
Expand Down
4 changes: 4 additions & 0 deletions net/http/http_network_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace net {
class ClientSocketFactory;
class HostResolver;
class HttpAuthHandlerFactory;
class HttpNetworkDelegate;
class HttpNetworkSession;
class NetLog;
class NetworkChangeNotifier;
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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_;
Expand Down
Loading

0 comments on commit ac03952

Please sign in to comment.