diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 21:30:38 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 21:30:38 +0000 |
commit | 66761b95332549f825999e482c17c94675275f49 (patch) | |
tree | fc5307808a2c62f1eff2a9f37db3aff11c5455d9 /net/http | |
parent | e313f3b11360902a3da9b3b1cc0df2a4792d0867 (diff) | |
download | chromium_src-66761b95332549f825999e482c17c94675275f49.zip chromium_src-66761b95332549f825999e482c17c94675275f49.tar.gz chromium_src-66761b95332549f825999e482c17c94675275f49.tar.bz2 |
Massively simplify the NetworkChangeNotifier infrastructure:
* Use a process-wide object (singleton pattern)
* Create/destroy this object on the main thread, make it outlive all consumers
* Make observer-related functions threadsafe
As a result, the notifier can now be used by any thread (eliminating things like NetworkChangeObserverProxy and NetworkChangeNotifierProxy, and expanding its usefulness); its creation and inner workings are much simplified (eliminating implementation-specific classes); and it is simpler to access (eliminating things like NetworkChangeNotifierThread and a LOT of passing pointers around).
BUG=none
TEST=Unittests; network changes still trigger notifications
Review URL: http://codereview.chromium.org/2802015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50895 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r-- | net/http/http_cache.cc | 11 | ||||
-rw-r--r-- | net/http/http_cache.h | 5 | ||||
-rw-r--r-- | net/http/http_network_layer.cc | 15 | ||||
-rw-r--r-- | net/http/http_network_layer.h | 12 | ||||
-rw-r--r-- | net/http/http_network_layer_unittest.cc | 20 | ||||
-rw-r--r-- | net/http/http_network_session.cc | 45 | ||||
-rw-r--r-- | net/http/http_network_session.h | 3 | ||||
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 18 |
8 files changed, 46 insertions, 83 deletions
diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index ef9198c..7e73d94 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -222,8 +222,7 @@ void HttpCache::MetadataWriter::OnIOComplete(int result) { //----------------------------------------------------------------------------- -HttpCache::HttpCache(NetworkChangeNotifier* network_change_notifier, - HostResolver* host_resolver, ProxyService* proxy_service, +HttpCache::HttpCache(HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, HttpNetworkDelegate* network_delegate, @@ -233,11 +232,9 @@ HttpCache::HttpCache(NetworkChangeNotifier* network_change_notifier, temp_backend_(NULL), building_backend_(false), mode_(NORMAL), - network_layer_(HttpNetworkLayer::CreateFactory( - network_change_notifier, host_resolver, proxy_service, - ssl_config_service, http_auth_handler_factory, - network_delegate, - net_log)), + network_layer_(HttpNetworkLayer::CreateFactory(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 9ed20b4..734e58d 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -46,7 +46,6 @@ struct HttpRequestInfo; class HttpResponseInfo; class IOBuffer; class NetLog; -class NetworkChangeNotifier; class ProxyService; class SSLConfigService; class ViewCacheHelper; @@ -113,8 +112,8 @@ class HttpCache : public HttpTransactionFactory, // The disk cache is initialized lazily (by CreateTransaction) in this case. // The HttpCache takes ownership of the |backend_factory|. - HttpCache(NetworkChangeNotifier* network_change_notifier, - HostResolver* host_resolver, ProxyService* proxy_service, + HttpCache(HostResolver* host_resolver, + ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, HttpNetworkDelegate* network_delegate, diff --git a/net/http/http_network_layer.cc b/net/http/http_network_layer.cc index 2329627..27c6272 100644 --- a/net/http/http_network_layer.cc +++ b/net/http/http_network_layer.cc @@ -21,7 +21,6 @@ namespace net { // static HttpTransactionFactory* HttpNetworkLayer::CreateFactory( - NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, @@ -31,7 +30,6 @@ HttpTransactionFactory* HttpNetworkLayer::CreateFactory( DCHECK(proxy_service); return new HttpNetworkLayer(ClientSocketFactory::GetDefaultFactory(), - network_change_notifier, host_resolver, proxy_service, ssl_config_service, http_auth_handler_factory, network_delegate, @@ -51,7 +49,6 @@ bool HttpNetworkLayer::force_spdy_ = false; HttpNetworkLayer::HttpNetworkLayer( ClientSocketFactory* socket_factory, - NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, @@ -59,7 +56,6 @@ HttpNetworkLayer::HttpNetworkLayer( HttpNetworkDelegate* network_delegate, NetLog* net_log) : socket_factory_(socket_factory), - network_change_notifier_(network_change_notifier), host_resolver_(host_resolver), proxy_service_(proxy_service), ssl_config_service_(ssl_config_service), @@ -75,7 +71,6 @@ HttpNetworkLayer::HttpNetworkLayer( HttpNetworkLayer::HttpNetworkLayer(HttpNetworkSession* session) : socket_factory_(ClientSocketFactory::GetDefaultFactory()), - network_change_notifier_(NULL), ssl_config_service_(NULL), session_(session), spdy_session_pool_(session->spdy_session_pool()), @@ -114,15 +109,11 @@ void HttpNetworkLayer::Suspend(bool suspend) { HttpNetworkSession* HttpNetworkLayer::GetSession() { if (!session_) { DCHECK(proxy_service_); - SpdySessionPool* spdy_pool = new SpdySessionPool(network_change_notifier_); - session_ = new HttpNetworkSession( - network_change_notifier_, host_resolver_, proxy_service_, + SpdySessionPool* spdy_pool = new SpdySessionPool(); + session_ = new HttpNetworkSession(host_resolver_, proxy_service_, socket_factory_, ssl_config_service_, spdy_pool, - http_auth_handler_factory_, - network_delegate_, - net_log_); + http_auth_handler_factory_, network_delegate_, net_log_); // These were just temps for lazy-initializing HttpNetworkSession. - network_change_notifier_ = NULL; host_resolver_ = NULL; proxy_service_ = NULL; socket_factory_ = NULL; diff --git a/net/http/http_network_layer.h b/net/http/http_network_layer.h index 54989410..4a61065 100644 --- a/net/http/http_network_layer.h +++ b/net/http/http_network_layer.h @@ -19,7 +19,6 @@ class HttpAuthHandlerFactory; class HttpNetworkDelegate; class HttpNetworkSession; class NetLog; -class NetworkChangeNotifier; class ProxyInfo; class ProxyService; class SpdySessionPool; @@ -27,11 +26,11 @@ class SSLConfigService; class HttpNetworkLayer : public HttpTransactionFactory { public: - // |socket_factory|, |network_change_notifier|, |proxy_service| and - // |host_resolver| must remain valid for the lifetime of HttpNetworkLayer. + // |socket_factory|, |proxy_service| and |host_resolver| must remain valid for + // the lifetime of HttpNetworkLayer. HttpNetworkLayer(ClientSocketFactory* socket_factory, - NetworkChangeNotifier* network_change_notifier, - HostResolver* host_resolver, ProxyService* proxy_service, + HostResolver* host_resolver, + ProxyService* proxy_service, SSLConfigService* ssl_config_service, HttpAuthHandlerFactory* http_auth_handler_factory, HttpNetworkDelegate* network_delegate, @@ -44,7 +43,6 @@ class HttpNetworkLayer : public HttpTransactionFactory { // This function hides the details of how a network layer gets instantiated // and allows other implementations to be substituted. static HttpTransactionFactory* CreateFactory( - NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, SSLConfigService* ssl_config_service, @@ -77,8 +75,6 @@ class HttpNetworkLayer : public HttpTransactionFactory { // The factory we will use to create network sockets. ClientSocketFactory* socket_factory_; - NetworkChangeNotifier* network_change_notifier_; - // The host resolver and proxy service that will be used when lazily // creating |session_|. scoped_refptr<HostResolver> host_resolver_; diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc index 9f20943..274d2dc 100644 --- a/net/http/http_network_layer_unittest.cc +++ b/net/http/http_network_layer_unittest.cc @@ -16,9 +16,9 @@ class HttpNetworkLayerTest : public PlatformTest { }; TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { - net::HttpNetworkLayer factory( - NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), - new net::SSLConfigServiceDefaults, NULL, NULL, NULL); + net::HttpNetworkLayer factory(NULL, new net::MockHostResolver, + net::ProxyService::CreateNull(), new net::SSLConfigServiceDefaults, NULL, + NULL, NULL); scoped_ptr<net::HttpTransaction> trans; int rv = factory.CreateTransaction(&trans); @@ -27,9 +27,9 @@ TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { } TEST_F(HttpNetworkLayerTest, Suspend) { - net::HttpNetworkLayer factory( - NULL, NULL, new net::MockHostResolver, net::ProxyService::CreateNull(), - new net::SSLConfigServiceDefaults, NULL, NULL, NULL); + net::HttpNetworkLayer factory(NULL, new net::MockHostResolver, + net::ProxyService::CreateNull(), new net::SSLConfigServiceDefaults, NULL, + NULL, NULL); scoped_ptr<net::HttpTransaction> trans; int rv = factory.CreateTransaction(&trans); @@ -67,11 +67,9 @@ TEST_F(HttpNetworkLayerTest, GET) { data_writes, arraysize(data_reads)); mock_socket_factory.AddSocketDataProvider(&data); - net::HttpNetworkLayer factory(&mock_socket_factory, NULL, - new net::MockHostResolver, - net::ProxyService::CreateNull(), - new net::SSLConfigServiceDefaults, - NULL, NULL, NULL); + net::HttpNetworkLayer factory(&mock_socket_factory, new net::MockHostResolver, + net::ProxyService::CreateNull(), new net::SSLConfigServiceDefaults, NULL, + NULL, NULL); TestCompletionCallback callback; diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc index 1083626..ea5a5cf 100644 --- a/net/http/http_network_session.cc +++ b/net/http/http_network_session.cc @@ -36,7 +36,6 @@ uint16 g_fixed_https_port = 0; } // namespace HttpNetworkSession::HttpNetworkSession( - NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, ClientSocketFactory* client_socket_factory, @@ -45,18 +44,16 @@ HttpNetworkSession::HttpNetworkSession( 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 // pool name should get changed to TCP instead of Transport. - tcp_pool_histograms_(new ClientSocketPoolHistograms("Transport")), + : tcp_pool_histograms_(new ClientSocketPoolHistograms("Transport")), http_proxy_pool_histograms_(new ClientSocketPoolHistograms("HTTPProxy")), tcp_for_socks_pool_histograms_( new ClientSocketPoolHistograms("TCPforSOCKS")), socks_pool_histograms_(new ClientSocketPoolHistograms("SOCK")), - tcp_socket_pool_(new TCPClientSocketPool( - g_max_sockets, g_max_sockets_per_group, tcp_pool_histograms_, - host_resolver, client_socket_factory, network_change_notifier_, - net_log)), + tcp_socket_pool_(new TCPClientSocketPool(g_max_sockets, + g_max_sockets_per_group, tcp_pool_histograms_, host_resolver, + client_socket_factory, net_log)), socket_factory_(client_socket_factory), host_resolver_(host_resolver), proxy_service_(proxy_service), @@ -80,14 +77,10 @@ HttpNetworkSession::GetSocketPoolForHTTPProxy(const HostPortPair& http_proxy) { return it->second; std::pair<HTTPProxySocketPoolMap::iterator, bool> ret = - http_proxy_socket_pool_.insert( - std::make_pair( - http_proxy, - new TCPClientSocketPool( - g_max_sockets_per_proxy_server, g_max_sockets_per_group, - http_proxy_pool_histograms_, host_resolver_, socket_factory_, - network_change_notifier_, - net_log_))); + http_proxy_socket_pool_.insert(std::make_pair(http_proxy, + new TCPClientSocketPool(g_max_sockets_per_proxy_server, + g_max_sockets_per_group, http_proxy_pool_histograms_, + host_resolver_, socket_factory_, net_log_))); return ret.first->second; } @@ -99,20 +92,14 @@ HttpNetworkSession::GetSocketPoolForSOCKSProxy( if (it != socks_socket_pool_.end()) return it->second; - std::pair<SOCKSSocketPoolMap::iterator, bool> ret = - socks_socket_pool_.insert( - std::make_pair( - socks_proxy, - new SOCKSClientSocketPool( - g_max_sockets_per_proxy_server, g_max_sockets_per_group, - socks_pool_histograms_, host_resolver_, - new TCPClientSocketPool(g_max_sockets_per_proxy_server, - g_max_sockets_per_group, - tcp_for_socks_pool_histograms_, - host_resolver_, socket_factory_, - network_change_notifier_, - net_log_), - network_change_notifier_, net_log_))); + std::pair<SOCKSSocketPoolMap::iterator, bool> ret = socks_socket_pool_.insert( + std::make_pair(socks_proxy, new SOCKSClientSocketPool( + g_max_sockets_per_proxy_server, g_max_sockets_per_group, + socks_pool_histograms_, host_resolver_, + new TCPClientSocketPool(g_max_sockets_per_proxy_server, + g_max_sockets_per_group, tcp_for_socks_pool_histograms_, + host_resolver_, socket_factory_, net_log_), + net_log_))); return ret.first->second; } diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index 1288197..319753c 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -28,14 +28,12 @@ class ClientSocketFactory; class HttpAuthHandlerFactory; class HttpNetworkDelegate; class HttpNetworkSessionPeer; -class NetworkChangeNotifier; class SpdySessionPool; // This class holds session objects used by HttpNetworkTransaction objects. class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { public: HttpNetworkSession( - NetworkChangeNotifier* network_change_notifier, HostResolver* host_resolver, ProxyService* proxy_service, ClientSocketFactory* client_socket_factory, @@ -113,7 +111,6 @@ class HttpNetworkSession : public base::RefCounted<HttpNetworkSession> { HttpAuthCache auth_cache_; SSLClientAuthCache ssl_client_auth_cache_; HttpAlternateProtocols alternate_protocols_; - NetworkChangeNotifier* const network_change_notifier_; scoped_refptr<ClientSocketPoolHistograms> tcp_pool_histograms_; scoped_refptr<ClientSocketPoolHistograms> http_proxy_pool_histograms_; scoped_refptr<ClientSocketPoolHistograms> tcp_for_socks_pool_histograms_; diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 35ba760..dd04773 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -83,7 +83,7 @@ struct SessionDependencies { proxy_service(ProxyService::CreateNull()), ssl_config_service(new SSLConfigServiceDefaults), http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool(NULL)) {} + spdy_session_pool(new SpdySessionPool()) {} // Custom proxy service dependency. explicit SessionDependencies(ProxyService* proxy_service) @@ -91,7 +91,7 @@ struct SessionDependencies { proxy_service(proxy_service), ssl_config_service(new SSLConfigServiceDefaults), http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()), - spdy_session_pool(new SpdySessionPool(NULL)) {} + spdy_session_pool(new SpdySessionPool()) {} scoped_refptr<MockHostResolverBase> host_resolver; scoped_refptr<ProxyService> proxy_service; @@ -108,8 +108,7 @@ ProxyService* CreateFixedProxyService(const std::string& proxy) { } HttpNetworkSession* CreateSession(SessionDependencies* session_deps) { - return new HttpNetworkSession(NULL, - session_deps->host_resolver, + return new HttpNetworkSession(session_deps->host_resolver, session_deps->proxy_service, &session_deps->socket_factory, session_deps->ssl_config_service, @@ -241,7 +240,8 @@ class CaptureGroupNameSocketPool : public EmulatedClientSocketPool { public: explicit CaptureGroupNameSocketPool(HttpNetworkSession* session) : EmulatedClientSocketPool(0, 0, NULL, session->host_resolver(), NULL, - NULL, NULL) {} + NULL) { + } const std::string last_group_name_received() const { return last_group_name_; } @@ -5249,11 +5249,9 @@ TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForTunneledNpnSpdy) { CapturingProxyResolver* capturing_proxy_resolver = new CapturingProxyResolver(); - SessionDependencies session_deps( - new ProxyService(new ProxyConfigServiceFixed(proxy_config), - capturing_proxy_resolver, - NULL, - NULL)); + SessionDependencies session_deps(new ProxyService( + new ProxyConfigServiceFixed(proxy_config), capturing_proxy_resolver, + NULL)); HttpRequestInfo request; request.method = "GET"; |