diff options
106 files changed, 614 insertions, 2821 deletions
diff --git a/base/observer_list_threadsafe.h b/base/observer_list_threadsafe.h index 125c412..62db5dc 100644 --- a/base/observer_list_threadsafe.h +++ b/base/observer_list_threadsafe.h @@ -28,7 +28,7 @@ // * Observers can register for notifications from any thread. // Callbacks to the observer will occur on the same thread where // the observer initially called AddObserver() from. -// * Any thread may trigger a notification via NOTIFY_OBSERVERS. +// * Any thread may trigger a notification via Notify(). // * Observers can remove themselves from the observer list inside // of a callback. // * If one thread is notifying observers concurrently with an observer diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index a1324fa..a954eec 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -74,6 +74,7 @@ #include "grit/generated_resources.h" #include "net/base/cookie_monster.h" #include "net/base/net_module.h" +#include "net/base/network_change_notifier.h" #include "net/http/http_network_layer.h" #include "net/http/http_network_session.h" #include "net/http/http_network_transaction.h" @@ -899,6 +900,8 @@ int BrowserMain(const MainFunctionParams& parameters) { SystemMonitor system_monitor; HighResolutionTimerManager hi_res_timer_manager; + scoped_ptr<net::NetworkChangeNotifier> network_change_notifier( + net::NetworkChangeNotifier::Create()); const char* kThreadName = "CrBrowserMain"; PlatformThread::SetName(kThreadName); diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index bf6f83e..faa40e7 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -19,18 +19,15 @@ #include "net/base/host_resolver.h" #include "net/base/host_resolver_impl.h" #include "net/base/net_util.h" -#include "net/base/network_change_notifier.h" #include "net/http/http_auth_filter.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_auth_handler_negotiate.h" namespace { -net::HostResolver* CreateGlobalHostResolver( - net::NetworkChangeNotifier* network_change_notifier) { +net::HostResolver* CreateGlobalHostResolver() { const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - net::HostResolver* global_host_resolver = - net::CreateSystemHostResolver(network_change_notifier); + net::HostResolver* global_host_resolver = net::CreateSystemHostResolver(); // Determine if we should disable IPv6 support. if (!command_line.HasSwitch(switches::kEnableIPv6)) { @@ -135,10 +132,7 @@ void IOThread::Init() { globals_ = new Globals; globals_->net_log.reset(new ChromeNetLog()); - globals_->network_change_notifier.reset( - net::NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier()); - globals_->host_resolver = - CreateGlobalHostResolver(globals_->network_change_notifier.get()); + globals_->host_resolver = CreateGlobalHostResolver(); globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory()); } diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index 9708509..60e3a40 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -26,7 +26,6 @@ class Predictor; namespace net { class HttpAuthHandlerFactory; -class NetworkChangeNotifier; class URLSecurityManager; } // namespace net @@ -34,7 +33,6 @@ class IOThread : public BrowserProcessSubThread { public: struct Globals { scoped_ptr<ChromeNetLog> net_log; - scoped_ptr<net::NetworkChangeNotifier> network_change_notifier; // TODO(willchan): Stop reference counting HostResolver. It's owned by // IOThread now. scoped_refptr<net::HostResolver> host_resolver; diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index 5beaa65..143d1e9 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -83,7 +83,6 @@ net::ProxyConfigService* CreateProxyConfigService( // Create a proxy service according to the options on command line. net::ProxyService* CreateProxyService( - net::NetworkChangeNotifier* network_change_notifier, net::NetLog* net_log, URLRequestContext* context, net::ProxyConfigService* proxy_config_service, @@ -103,7 +102,6 @@ net::ProxyService* CreateProxyService( proxy_config_service, use_v8, context, - network_change_notifier, net_log, io_loop); } @@ -239,8 +237,7 @@ ChromeURLRequestContext* FactoryForOriginal::Create() { 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->net_log.get(), context, proxy_config_service_.release(), command_line, @@ -250,8 +247,7 @@ 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(), - context->host_resolver(), + new net::HttpCache(context->host_resolver(), context->proxy_service(), context->ssl_config_service(), context->http_auth_handler_factory(), @@ -379,8 +375,7 @@ ChromeURLRequestContext* FactoryForOffTheRecord::Create() { net::HttpCache::DefaultBackend::InMemory(0); net::HttpCache* cache = - new net::HttpCache(io_thread_globals->network_change_notifier.get(), - context->host_resolver(), + new net::HttpCache(context->host_resolver(), context->proxy_service(), context->ssl_config_service(), context->http_auth_handler_factory(), @@ -477,15 +472,13 @@ ChromeURLRequestContext* FactoryForMedia::Create() { } else { // 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(), - main_context->host_resolver(), - main_context->proxy_service(), - main_context->ssl_config_service(), - main_context->http_auth_handler_factory(), - &io_thread_globals->network_delegate, - io_thread_globals->net_log.get(), - backend); + cache = new net::HttpCache(main_context->host_resolver(), + main_context->proxy_service(), + main_context->ssl_config_service(), + main_context->http_auth_handler_factory(), + &io_thread_globals->network_delegate, + io_thread_globals->net_log.get(), + backend); } if (CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/chrome/browser/net/connection_tester.cc b/chrome/browser/net/connection_tester.cc index 3c7c299..26c2d1d 100644 --- a/chrome/browser/net/connection_tester.cc +++ b/chrome/browser/net/connection_tester.cc @@ -53,15 +53,10 @@ class ExperimentURLRequestContext : public URLRequestContext { ftp_transaction_factory_ = new net::FtpNetworkLayer(host_resolver_); ssl_config_service_ = new net::SSLConfigServiceDefaults; http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault(); - http_transaction_factory_ = - new net::HttpCache( - net::HttpNetworkLayer::CreateFactory(NULL, host_resolver_, - proxy_service_, - ssl_config_service_, - http_auth_handler_factory_, - NULL, - NULL), - net::HttpCache::DefaultBackend::InMemory(0)); + http_transaction_factory_ = new net::HttpCache( + net::HttpNetworkLayer::CreateFactory(host_resolver_, proxy_service_, + ssl_config_service_, http_auth_handler_factory_, NULL, NULL), + net::HttpCache::DefaultBackend::InMemory(0)); // In-memory cookie store. cookie_store_ = new net::CookieMonster(NULL, NULL); @@ -84,8 +79,8 @@ class ExperimentURLRequestContext : public URLRequestContext { scoped_refptr<net::HostResolver>* host_resolver) { // Create a vanilla HostResolver that disables caching. const size_t kMaxJobs = 50u; - scoped_refptr<net::HostResolverImpl> impl = new net::HostResolverImpl( - NULL, NULL, NULL, kMaxJobs); + scoped_refptr<net::HostResolverImpl> impl = + new net::HostResolverImpl(NULL, NULL, kMaxJobs); *host_resolver = impl; @@ -155,9 +150,8 @@ class ExperimentURLRequestContext : public URLRequestContext { return net::ERR_NOT_IMPLEMENTED; } - *proxy_service = net::ProxyService::Create( - config_service.release(), - true, this, NULL, NULL, MessageLoop::current()); + *proxy_service = net::ProxyService::Create(config_service.release(), true, + this, NULL, MessageLoop::current()); return net::OK; } diff --git a/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc b/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc index 9017f59..c84ad41 100644 --- a/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc +++ b/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -55,7 +55,7 @@ class MyDelegate : public ResolveProxyMsgHelper::Delegate { TEST(ResolveProxyMsgHelperTest, Sequential) { net::MockAsyncProxyResolver* resolver = new net::MockAsyncProxyResolver; scoped_refptr<net::ProxyService> service( - new net::ProxyService(new MockProxyConfigService, resolver, NULL, NULL)); + new net::ProxyService(new MockProxyConfigService, resolver, NULL)); MyDelegate delegate; ResolveProxyMsgHelper helper(&delegate, service); @@ -118,7 +118,7 @@ TEST(ResolveProxyMsgHelperTest, Sequential) { TEST(ResolveProxyMsgHelperTest, QueueRequests) { net::MockAsyncProxyResolver* resolver = new net::MockAsyncProxyResolver; scoped_refptr<net::ProxyService> service( - new net::ProxyService(new MockProxyConfigService, resolver, NULL, NULL)); + new net::ProxyService(new MockProxyConfigService, resolver, NULL)); MyDelegate delegate; ResolveProxyMsgHelper helper(&delegate, service); @@ -185,7 +185,7 @@ TEST(ResolveProxyMsgHelperTest, QueueRequests) { TEST(ResolveProxyMsgHelperTest, CancelPendingRequests) { net::MockAsyncProxyResolver* resolver = new net::MockAsyncProxyResolver; scoped_refptr<net::ProxyService> service( - new net::ProxyService(new MockProxyConfigService, resolver, NULL, NULL)); + new net::ProxyService(new MockProxyConfigService, resolver, NULL)); MyDelegate delegate; scoped_ptr<ResolveProxyMsgHelper> helper( diff --git a/chrome/browser/profile.cc b/chrome/browser/profile.cc index 5ed4be0..7a34dbc 100644 --- a/chrome/browser/profile.cc +++ b/chrome/browser/profile.cc @@ -56,7 +56,6 @@ #include "chrome/browser/sessions/session_service.h" #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/ssl/ssl_host_state.h" -#include "chrome/browser/sync/net/network_change_notifier_io_thread.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_factory_impl.h" #include "chrome/browser/tabs/pinned_tab_service.h" @@ -1671,12 +1670,8 @@ CloudPrintProxyService* ProfileImpl::GetCloudPrintProxyService() { } void ProfileImpl::InitSyncService() { - network_change_notifier_thread_.reset( - new NetworkChangeNotifierIOThread(g_browser_process->io_thread())); profile_sync_factory_.reset( - new ProfileSyncFactoryImpl(this, - network_change_notifier_thread_.get(), - CommandLine::ForCurrentProcess())); + new ProfileSyncFactoryImpl(this, CommandLine::ForCurrentProcess())); sync_service_.reset( profile_sync_factory_->CreateProfileSyncService()); sync_service_->Initialize(); diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h index 4fc6223..6c3eb45 100644 --- a/chrome/browser/profile.h +++ b/chrome/browser/profile.h @@ -22,10 +22,6 @@ #include "chrome/browser/chromeos/preferences.h" #endif -namespace chrome_common_net { -class NetworkChangeNotifierThread; -} - namespace history { class TopSites; } @@ -605,9 +601,6 @@ class ProfileImpl : public Profile, scoped_refptr<WebResourceService> web_resource_service_; scoped_ptr<NTPResourceCache> ntp_resource_cache_; - // Used by |profile_sync_factory_|. - scoped_ptr<chrome_common_net::NetworkChangeNotifierThread> - network_change_notifier_thread_; scoped_ptr<ProfileSyncFactory> profile_sync_factory_; scoped_ptr<ProfileSyncService> sync_service_; scoped_ptr<CloudPrintProxyService> cloud_print_proxy_service_; diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc index e970c81..1012bf7 100644 --- a/chrome/browser/sync/engine/syncapi.cc +++ b/chrome/browser/sync/engine/syncapi.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// 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. @@ -54,7 +54,6 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/deprecated/event_sys.h" #include "chrome/common/net/gaia/gaia_authenticator.h" -#include "chrome/common/net/network_change_notifier_proxy.h" #include "chrome/common/net/notifier/listener/mediator_thread_impl.h" #include "chrome/common/net/notifier/listener/notification_constants.h" #include "chrome/common/net/notifier/listener/talk_mediator.h" @@ -883,8 +882,6 @@ class SyncManager::SyncInternal const char* gaia_service_id, const char* gaia_source, bool use_ssl, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, HttpPostProviderFactory* post_factory, HttpPostProviderFactory* auth_post_factory, ModelSafeWorkerRegistrar* model_safe_worker_registrar, @@ -1166,10 +1163,6 @@ class SyncManager::SyncInternal // The sync dir_manager to which we belong. SyncManager* const sync_manager_; - // An object that notifies us whenever there is a network-related - // change (e.g., disconnections). - scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; - // The entity that provides us with information about which types to sync. // The instance is shared between the SyncManager and the Syncer. ModelSafeWorkerRegistrar* registrar_; @@ -1201,8 +1194,6 @@ bool SyncManager::Init(const FilePath& database_location, const char* gaia_service_id, const char* gaia_source, bool use_ssl, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, HttpPostProviderFactory* post_factory, HttpPostProviderFactory* auth_post_factory, ModelSafeWorkerRegistrar* registrar, @@ -1221,7 +1212,6 @@ bool SyncManager::Init(const FilePath& database_location, gaia_service_id, gaia_source, use_ssl, - network_change_notifier_thread, post_factory, auth_post_factory, registrar, @@ -1271,8 +1261,6 @@ bool SyncManager::SyncInternal::Init( const char* gaia_service_id, const char* gaia_source, bool use_ssl, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, HttpPostProviderFactory* post_factory, HttpPostProviderFactory* auth_post_factory, ModelSafeWorkerRegistrar* model_safe_worker_registrar, @@ -1310,29 +1298,22 @@ bool SyncManager::SyncInternal::Init( // Watch various objects for aggregated status. allstatus_.WatchConnectionManager(connection_manager()); - network_change_notifier_.reset( - new chrome_common_net::NetworkChangeNotifierProxy( - network_change_notifier_thread)); - network_change_notifier_->AddObserver(this); - // TODO(akalin): CheckServerReachable() can block, which may cause - // jank if we try to shut down sync. Fix this. + net::NetworkChangeNotifier::AddObserver(this); + // TODO(akalin): CheckServerReachable() can block, which may cause jank if we + // try to shut down sync. Fix this. connection_manager()->CheckServerReachable(); - // NOTIFICATION_SERVER uses a substantially different notification - // method, so it has its own MediatorThread implementation. - // Everything else just uses MediatorThreadImpl. + // NOTIFICATION_SERVER uses a substantially different notification method, so + // it has its own MediatorThread implementation. Everything else just uses + // MediatorThreadImpl. notifier::MediatorThread* mediator_thread = (notification_method == browser_sync::NOTIFICATION_SERVER) ? - static_cast<notifier::MediatorThread*>( - new sync_notifier::ServerNotifierThread( - network_change_notifier_thread)) : - static_cast<notifier::MediatorThread*>( - new notifier::MediatorThreadImpl(network_change_notifier_thread)); + new sync_notifier::ServerNotifierThread() : + new notifier::MediatorThreadImpl(); const bool kInitializeSsl = true; const bool kConnectImmediately = false; - talk_mediator_.reset(new TalkMediatorImpl( - mediator_thread, - kInitializeSsl, kConnectImmediately, invalidate_xmpp_auth_token)); + talk_mediator_.reset(new TalkMediatorImpl(mediator_thread, kInitializeSsl, + kConnectImmediately, invalidate_xmpp_auth_token)); if (notification_method != browser_sync::NOTIFICATION_LEGACY && notification_method != browser_sync::NOTIFICATION_SERVER) { if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) { @@ -1595,10 +1576,7 @@ void SyncManager::SyncInternal::Shutdown() { core_message_loop_->SetNestableTasksAllowed(old_state); } - if (network_change_notifier_.get()) { - network_change_notifier_->RemoveObserver(this); - network_change_notifier_.reset(); - } + net::NetworkChangeNotifier::RemoveObserver(this); if (dir_manager()) { dir_manager()->FinalSaveChangesForAll(); diff --git a/chrome/browser/sync/engine/syncapi.h b/chrome/browser/sync/engine/syncapi.h index 88b2f0b..c9380e5 100644 --- a/chrome/browser/sync/engine/syncapi.h +++ b/chrome/browser/sync/engine/syncapi.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -60,10 +60,6 @@ struct SyncSessionSnapshot; } } -namespace chrome_common_net { -class NetworkChangeNotifierThread; -} - // Forward declarations of internal class types so that sync API objects // may have opaque pointers to these types. namespace syncable { @@ -710,9 +706,6 @@ class SyncManager { // the default is false. // |gaia_service_id| is the service id used for GAIA authentication. If it's // null then default will be used. - // |network_change_notifier_thread| (which we don't own) is the - // thread from which we get notifications regarding changes to the - // network state. // |post_factory| will be owned internally and used to create // instances of an HttpPostProvider. // |auth_post_factory| will be owned internally and used to create @@ -745,8 +738,6 @@ class SyncManager { const char* gaia_service_id, const char* gaia_source, bool use_ssl, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, HttpPostProviderFactory* post_factory, HttpPostProviderFactory* auth_post_factory, browser_sync::ModelSafeWorkerRegistrar* registrar, diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc index 0c36f3d..7428245 100644 --- a/chrome/browser/sync/glue/sync_backend_host.cc +++ b/chrome/browser/sync/glue/sync_backend_host.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -67,8 +67,6 @@ SyncBackendHost::~SyncBackendHost() { void SyncBackendHost::Initialize( const GURL& sync_service_url, const syncable::ModelTypeSet& types, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, URLRequestContextGetter* baseline_context_getter, const std::string& lsid, bool delete_sync_data_folder, @@ -107,7 +105,6 @@ void SyncBackendHost::Initialize( NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoInitialize, Core::DoInitializeOptions( sync_service_url, true, - network_change_notifier_thread, new HttpBridgeFactory(baseline_context_getter), new HttpBridgeFactory(baseline_context_getter), lsid, @@ -392,7 +389,6 @@ void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { kGaiaServiceId, kGaiaSourceForChrome, options.service_url.SchemeIsSecure(), - options.network_change_notifier_thread, options.http_bridge_factory, options.auth_http_bridge_factory, host_, // ModelSafeWorkerRegistrar. diff --git a/chrome/browser/sync/glue/sync_backend_host.h b/chrome/browser/sync/glue/sync_backend_host.h index be20013..0193163 100644 --- a/chrome/browser/sync/glue/sync_backend_host.h +++ b/chrome/browser/sync/glue/sync_backend_host.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -29,10 +29,6 @@ class CancelableTask; class Profile; -namespace chrome_common_net { -class NetworkChangeNotifierThread; -} - namespace browser_sync { namespace sessions { @@ -100,8 +96,6 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar { // Optionally delete the Sync Data folder (if it's corrupt). void Initialize(const GURL& service_url, const syncable::ModelTypeSet& types, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, URLRequestContextGetter* baseline_context_getter, const std::string& lsid, bool delete_sync_data_folder, @@ -180,8 +174,6 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar { // Called from unit test to bypass authentication and initialize the syncapi // to a state suitable for testing but not production. void InitializeForTestMode(const std::wstring& test_user, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, sync_api::HttpPostProviderFactory* factory, sync_api::HttpPostProviderFactory* auth_factory, bool delete_sync_data_folder, @@ -201,7 +193,6 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar { NewRunnableMethod(core_.get(), &SyncBackendHost::Core::DoInitializeForTest, test_user, - network_change_notifier_thread, factory, auth_factory, delete_sync_data_folder, @@ -237,8 +228,6 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar { DoInitializeOptions( const GURL& service_url, bool attempt_last_user_authentication, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, sync_api::HttpPostProviderFactory* http_bridge_factory, sync_api::HttpPostProviderFactory* auth_http_bridge_factory, const std::string& lsid, @@ -248,7 +237,6 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar { NotificationMethod notification_method) : service_url(service_url), attempt_last_user_authentication(attempt_last_user_authentication), - network_change_notifier_thread(network_change_notifier_thread), http_bridge_factory(http_bridge_factory), auth_http_bridge_factory(auth_http_bridge_factory), lsid(lsid), @@ -259,8 +247,6 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar { GURL service_url; bool attempt_last_user_authentication; - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread; sync_api::HttpPostProviderFactory* http_bridge_factory; sync_api::HttpPostProviderFactory* auth_http_bridge_factory; std::string lsid; @@ -321,19 +307,13 @@ class SyncBackendHost : public browser_sync::ModelSafeWorkerRegistrar { // last known user (since it will fail in test mode) and does some extra // setup to nudge the syncapi into a useable state. void DoInitializeForTest(const std::wstring& test_user, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, sync_api::HttpPostProviderFactory* factory, sync_api::HttpPostProviderFactory* auth_factory, bool delete_sync_data_folder, NotificationMethod notification_method) { - DoInitialize( - DoInitializeOptions(GURL(), false, - network_change_notifier_thread, - factory, auth_factory, - std::string(), delete_sync_data_folder, - false, false, - notification_method)); + DoInitialize(DoInitializeOptions(GURL(), false, factory, auth_factory, + std::string(), delete_sync_data_folder, + false, false, notification_method)); syncapi_->SetupForTestMode(test_user); } #endif diff --git a/chrome/browser/sync/net/network_change_notifier_io_thread.cc b/chrome/browser/sync/net/network_change_notifier_io_thread.cc deleted file mode 100644 index c2cd2b4..0000000 --- a/chrome/browser/sync/net/network_change_notifier_io_thread.cc +++ /dev/null @@ -1,24 +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. - -#include "chrome/browser/sync/net/network_change_notifier_io_thread.h" - -#include "base/logging.h" -#include "chrome/browser/io_thread.h" - -NetworkChangeNotifierIOThread::NetworkChangeNotifierIOThread( - IOThread* io_thread) : io_thread_(io_thread) { - DCHECK(io_thread_); -} - -NetworkChangeNotifierIOThread::~NetworkChangeNotifierIOThread() {} - -MessageLoop* NetworkChangeNotifierIOThread::GetMessageLoop() const { - return io_thread_->message_loop(); -} - -net::NetworkChangeNotifier* -NetworkChangeNotifierIOThread::GetNetworkChangeNotifier() const { - return io_thread_->globals()->network_change_notifier.get(); -} diff --git a/chrome/browser/sync/net/network_change_notifier_io_thread.h b/chrome/browser/sync/net/network_change_notifier_io_thread.h deleted file mode 100644 index c15156a..0000000 --- a/chrome/browser/sync/net/network_change_notifier_io_thread.h +++ /dev/null @@ -1,38 +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 CHROME_BROWSER_SYNC_NET_NETWORK_CHANGE_NOTIFIER_IO_THREAD_H_ -#define CHROME_BROWSER_SYNC_NET_NETWORK_CHANGE_NOTIFIER_IO_THREAD_H_ - -// This is a simple NetworkChangeNotifierThread wrapper around an -// IOThread and its NetworkChangeNotifier. - -#include "base/basictypes.h" -#include "chrome/common/net/network_change_notifier_thread.h" - -class IOThread; -class MessageLoop; - -class NetworkChangeNotifierIOThread - : public chrome_common_net::NetworkChangeNotifierThread { - public: - // Does not take ownership of |io_thread|. This instance must live - // no longer than |io_thread|. - explicit NetworkChangeNotifierIOThread(IOThread* io_thread); - - virtual ~NetworkChangeNotifierIOThread(); - - // chrome_common_net::NetworkChangeNotifierThread implementation. - - virtual MessageLoop* GetMessageLoop() const; - - virtual net::NetworkChangeNotifier* GetNetworkChangeNotifier() const; - - private: - IOThread* const io_thread_; - - DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierIOThread); -}; - -#endif // CHROME_BROWSER_SYNC_NET_NETWORK_CHANGE_NOTIFIER_IO_THREAD_H_ diff --git a/chrome/browser/sync/net/network_change_notifier_io_thread_unittest.cc b/chrome/browser/sync/net/network_change_notifier_io_thread_unittest.cc deleted file mode 100644 index e2b4e91..0000000 --- a/chrome/browser/sync/net/network_change_notifier_io_thread_unittest.cc +++ /dev/null @@ -1,80 +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. - -#include "chrome/browser/sync/net/network_change_notifier_io_thread.h" - -#include "base/basictypes.h" -#include "base/message_loop.h" -#include "base/scoped_ptr.h" -#include "base/task.h" -#include "chrome/browser/io_thread.h" -#include "chrome/common/net/thread_blocker.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class NetworkChangeNotifierIOThreadTest : public testing::Test { - protected: - NetworkChangeNotifierIOThreadTest() {} - - virtual ~NetworkChangeNotifierIOThreadTest() {} - - virtual void SetUp() { - // We need to set the message loop type explicitly because - // IOThread doesn't do it for us and the Linux - // NetworkChangeNotifier expects it. - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - EXPECT_TRUE(io_thread_.StartWithOptions(options)); - thread_blocker_.reset(new chrome_common_net::ThreadBlocker(&io_thread_)); - thread_blocker_->Block(); - network_change_notifier_io_thread_.reset( - new NetworkChangeNotifierIOThread(&io_thread_)); - } - - virtual void TearDown() { - network_change_notifier_io_thread_.reset(); - // Nothing should be posted on |io_thread_| at this point; - // otherwise, it may try to access - // network_change_notifier_io_thread_, which now NULL - thread_blocker_->Unblock(); - thread_blocker_.reset(); - io_thread_.Stop(); - } - - IOThread io_thread_; - scoped_ptr<chrome_common_net::ThreadBlocker> thread_blocker_; - scoped_ptr<NetworkChangeNotifierIOThread> - network_change_notifier_io_thread_; - - private: - DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierIOThreadTest); -}; - -void CompareNetworkChangeNotifiers( - IOThread* io_thread, - NetworkChangeNotifierIOThread* network_change_notifier_io_thread) { - EXPECT_EQ(network_change_notifier_io_thread->GetMessageLoop(), - MessageLoop::current()); - EXPECT_EQ(io_thread->globals()->network_change_notifier.get(), - network_change_notifier_io_thread->GetNetworkChangeNotifier()); -} - -TEST_F(NetworkChangeNotifierIOThreadTest, Basic) { - EXPECT_EQ(io_thread_.message_loop(), - network_change_notifier_io_thread_->GetMessageLoop()); - ASSERT_TRUE( - io_thread_.PostTask(ChromeThread::IO, - FROM_HERE, - NewRunnableFunction( - &CompareNetworkChangeNotifiers, - &io_thread_, - network_change_notifier_io_thread_.get()))); - // Pump the thread to make sure the task we just posted is run - // before this test ends. - thread_blocker_->Unblock(); - thread_blocker_->Block(); -} - -} // namespace diff --git a/chrome/browser/sync/notifier/server_notifier_thread.cc b/chrome/browser/sync/notifier/server_notifier_thread.cc index fbfc999..093adb4 100644 --- a/chrome/browser/sync/notifier/server_notifier_thread.cc +++ b/chrome/browser/sync/notifier/server_notifier_thread.cc @@ -18,10 +18,7 @@ namespace sync_notifier { -ServerNotifierThread::ServerNotifierThread( - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread) - : notifier::MediatorThreadImpl(network_change_notifier_thread) {} +ServerNotifierThread::ServerNotifierThread() {} ServerNotifierThread::~ServerNotifierThread() {} diff --git a/chrome/browser/sync/notifier/server_notifier_thread.h b/chrome/browser/sync/notifier/server_notifier_thread.h index 9f079e2..021095c 100644 --- a/chrome/browser/sync/notifier/server_notifier_thread.h +++ b/chrome/browser/sync/notifier/server_notifier_thread.h @@ -20,10 +20,6 @@ #include "chrome/common/net/notifier/listener/mediator_thread_impl.h" #include "google/cacheinvalidation/invalidation-client.h" -namespace chrome_common_net { -class NetworkChangeNotifierThread; -} // namespace chrome_common_net - namespace sync_notifier { class ChromeInvalidationClient; @@ -32,9 +28,7 @@ class ServerNotifierThread : public notifier::MediatorThreadImpl, public invalidation::InvalidationListener { public: - explicit ServerNotifierThread( - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread); + ServerNotifierThread(); virtual ~ServerNotifierThread(); diff --git a/chrome/browser/sync/profile_sync_factory_impl.cc b/chrome/browser/sync/profile_sync_factory_impl.cc index b70d112..1a707ec 100644 --- a/chrome/browser/sync/profile_sync_factory_impl.cc +++ b/chrome/browser/sync/profile_sync_factory_impl.cc @@ -61,23 +61,15 @@ using browser_sync::TypedUrlDataTypeController; using browser_sync::TypedUrlModelAssociator; using browser_sync::UnrecoverableErrorHandler; -ProfileSyncFactoryImpl::ProfileSyncFactoryImpl( - Profile* profile, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, - CommandLine* command_line) +ProfileSyncFactoryImpl::ProfileSyncFactoryImpl(Profile* profile, + CommandLine* command_line) : profile_(profile), - network_change_notifier_thread_(network_change_notifier_thread), command_line_(command_line) { - DCHECK(network_change_notifier_thread_); } ProfileSyncService* ProfileSyncFactoryImpl::CreateProfileSyncService() { - ProfileSyncService* pss = - new ProfileSyncService(this, - profile_, - network_change_notifier_thread_, - browser_defaults::kBootstrapSyncAuthentication); + ProfileSyncService* pss = new ProfileSyncService( + this, profile_, browser_defaults::kBootstrapSyncAuthentication); // Autofill sync is enabled by default. Register unless explicitly // disabled. diff --git a/chrome/browser/sync/profile_sync_factory_impl.h b/chrome/browser/sync/profile_sync_factory_impl.h index c26ba4f..31c0dea 100644 --- a/chrome/browser/sync/profile_sync_factory_impl.h +++ b/chrome/browser/sync/profile_sync_factory_impl.h @@ -11,17 +11,9 @@ class CommandLine; class Profile; -namespace chrome_common_net { -class NetworkChangeNotifierThread; -} - class ProfileSyncFactoryImpl : public ProfileSyncFactory { public: - ProfileSyncFactoryImpl( - Profile* profile, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, - CommandLine* command_line); + ProfileSyncFactoryImpl(Profile* profile, CommandLine* command_line); virtual ~ProfileSyncFactoryImpl() {} // ProfileSyncFactory interface. @@ -65,8 +57,6 @@ class ProfileSyncFactoryImpl : public ProfileSyncFactory { private: Profile* profile_; - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread_; CommandLine* command_line_; DISALLOW_COPY_AND_ASSIGN(ProfileSyncFactoryImpl); diff --git a/chrome/browser/sync/profile_sync_factory_impl_unittest.cc b/chrome/browser/sync/profile_sync_factory_impl_unittest.cc index 0034228..b63c23a 100644 --- a/chrome/browser/sync/profile_sync_factory_impl_unittest.cc +++ b/chrome/browser/sync/profile_sync_factory_impl_unittest.cc @@ -13,7 +13,6 @@ #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/profile_sync_factory_impl.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/net/fake_network_change_notifier_thread.h" #include "chrome/test/testing_profile.h" using browser_sync::DataTypeController; @@ -28,17 +27,13 @@ class ProfileSyncFactoryImplTest : public testing::Test { FilePath program_path(FILE_PATH_LITERAL("chrome.exe")); command_line_.reset(new CommandLine(program_path)); profile_sync_service_factory_.reset( - new ProfileSyncFactoryImpl(profile_.get(), - &fake_network_change_notifier_thread_, - command_line_.get())); + new ProfileSyncFactoryImpl(profile_.get(), command_line_.get())); } MessageLoop message_loop_; ChromeThread ui_thread_; scoped_ptr<Profile> profile_; scoped_ptr<CommandLine> command_line_; - chrome_common_net::FakeNetworkChangeNotifierThread - fake_network_change_notifier_thread_; scoped_ptr<ProfileSyncFactoryImpl> profile_sync_service_factory_; }; diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 7b4f3fb..f20c1e3 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -51,16 +51,12 @@ const char* ProfileSyncService::kSyncServerUrl = const char* ProfileSyncService::kDevServerUrl = "https://clients4.google.com/chrome-sync/dev"; -ProfileSyncService::ProfileSyncService( - ProfileSyncFactory* factory, - Profile* profile, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, - bool bootstrap_sync_authentication) +ProfileSyncService::ProfileSyncService(ProfileSyncFactory* factory, + Profile* profile, + bool bootstrap_sync_authentication) : last_auth_error_(AuthError::None()), factory_(factory), profile_(profile), - network_change_notifier_thread_(network_change_notifier_thread), bootstrap_sync_authentication_(bootstrap_sync_authentication), sync_service_url_(kDevServerUrl), backend_initialized_(false), @@ -72,7 +68,6 @@ ProfileSyncService::ProfileSyncService( ALLOW_THIS_IN_INITIALIZER_LIST(scoped_runnable_method_factory_(this)) { DCHECK(factory); DCHECK(profile); - DCHECK(network_change_notifier_thread_); registrar_.Add(this, NotificationType::SYNC_CONFIGURE_START, NotificationService::AllSources()); @@ -110,7 +105,6 @@ ProfileSyncService::ProfileSyncService() : last_auth_error_(AuthError::None()), factory_(NULL), profile_(NULL), - network_change_notifier_thread_(NULL), bootstrap_sync_authentication_(false), sync_service_url_(kSyncServerUrl), backend_initialized_(false), @@ -273,7 +267,6 @@ void ProfileSyncService::InitializeBackend(bool delete_sync_data_folder) { GetPreferredDataTypes(&types); backend_->Initialize(sync_service_url_, types, - network_change_notifier_thread_, profile_->GetRequestContext(), GetLsidForAuthBootstraping(), delete_sync_data_folder, diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 929d8bd..b496b12 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -31,10 +31,6 @@ class NotificationType; class Profile; class ProfileSyncFactory; -namespace chrome_common_net { -class NetworkChangeNotifierThread; -} - // Various UI components such as the New Tab page can be driven by observing // the ProfileSyncService through this interface. class ProfileSyncServiceObserver { @@ -128,8 +124,6 @@ class ProfileSyncService : public browser_sync::SyncFrontend, ProfileSyncService(ProfileSyncFactory* factory_, Profile* profile, - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread, bool bootstrap_sync_authentication); virtual ~ProfileSyncService(); @@ -382,9 +376,6 @@ class ProfileSyncService : public browser_sync::SyncFrontend, // The profile whose data we are synchronizing. Profile* profile_; - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread_; - // True if the profile sync service should attempt to use an LSID // cookie for authentication. This is typically set to true in // ChromiumOS since we want to use the system level authentication diff --git a/chrome/browser/sync/sync_setup_wizard_unittest.cc b/chrome/browser/sync/sync_setup_wizard_unittest.cc index ca63f97..7d2fa769f 100644 --- a/chrome/browser/sync/sync_setup_wizard_unittest.cc +++ b/chrome/browser/sync/sync_setup_wizard_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -14,7 +14,6 @@ #include "chrome/browser/sync/profile_sync_factory_mock.h" #include "chrome/browser/sync/profile_sync_service.h" #include "chrome/browser/sync/sync_setup_flow.h" -#include "chrome/common/net/fake_network_change_notifier_thread.h" #include "chrome/common/pref_names.h" #include "chrome/test/browser_with_test_window_test.h" #include "chrome/test/testing_profile.h" @@ -32,9 +31,7 @@ typedef GoogleServiceAuthError AuthError; class ProfileSyncServiceForWizardTest : public ProfileSyncService { public: ProfileSyncServiceForWizardTest(ProfileSyncFactory* factory, Profile* profile) - : ProfileSyncService(factory, profile, - &fake_network_change_notifier_thread_, - false), + : ProfileSyncService(factory, profile, false), user_accepted_merge_and_sync_(false), user_cancelled_dialog_(false) { RegisterPreferences(); @@ -81,9 +78,6 @@ class ProfileSyncServiceForWizardTest : public ProfileSyncService { bool user_cancelled_dialog_; private: - chrome_common_net::FakeNetworkChangeNotifierThread - fake_network_change_notifier_thread_; - DISALLOW_COPY_AND_ASSIGN(ProfileSyncServiceForWizardTest); }; diff --git a/chrome/browser/sync/test_profile_sync_service.h b/chrome/browser/sync/test_profile_sync_service.h index 6e04d0e..f795998 100644 --- a/chrome/browser/sync/test_profile_sync_service.h +++ b/chrome/browser/sync/test_profile_sync_service.h @@ -11,7 +11,6 @@ #include "chrome/browser/profile.h" #include "chrome/browser/sync/profile_sync_factory.h" #include "chrome/browser/sync/profile_sync_service.h" -#include "chrome/common/net/fake_network_change_notifier_thread.h" #include "chrome/test/sync/test_http_bridge_factory.h" class TestProfileSyncService : public ProfileSyncService { @@ -20,33 +19,21 @@ class TestProfileSyncService : public ProfileSyncService { Profile* profile, bool bootstrap_sync_authentication, bool synchronous_backend_initialization) - : ProfileSyncService(factory, profile, - &fake_network_change_notifier_thread_, - bootstrap_sync_authentication), + : ProfileSyncService(factory, profile, bootstrap_sync_authentication), synchronous_backend_initialization_( synchronous_backend_initialization) { - fake_network_change_notifier_thread_.Start(); RegisterPreferences(); SetSyncSetupCompleted(); } - virtual ~TestProfileSyncService() { - // This needs to happen before - // |fake_network_change_notifier_thread_| is stopped. This is - // also called again in ProfileSyncService's destructor, but - // calling it multiple times is okay. - Shutdown(false); - fake_network_change_notifier_thread_.Stop(); - } + virtual ~TestProfileSyncService() { } virtual void InitializeBackend(bool delete_sync_data_folder) { browser_sync::TestHttpBridgeFactory* factory = new browser_sync::TestHttpBridgeFactory(); browser_sync::TestHttpBridgeFactory* factory2 = new browser_sync::TestHttpBridgeFactory(); - backend()->InitializeForTestMode( - L"testuser", &fake_network_change_notifier_thread_, - factory, factory2, delete_sync_data_folder, - browser_sync::kDefaultNotificationMethod); + backend()->InitializeForTestMode(L"testuser", factory, factory2, + delete_sync_data_folder, browser_sync::kDefaultNotificationMethod); // TODO(akalin): Figure out a better way to do this. if (synchronous_backend_initialization_) { // The SyncBackend posts a task to the current loop when @@ -74,8 +61,6 @@ class TestProfileSyncService : public ProfileSyncService { } bool synchronous_backend_initialization_; - chrome_common_net::FakeNetworkChangeNotifierThread - fake_network_change_notifier_thread_; }; #endif // CHROME_BROWSER_SYNC_TEST_PROFILE_SYNC_SERVICE_H_ diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 8197f2f..b609d73 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1134,8 +1134,6 @@ 'service/cloud_print/printer_job_handler.h', 'service/gaia/service_gaia_authenticator.cc', 'service/gaia/service_gaia_authenticator.h', - 'service/net/service_network_change_notifier_thread.cc', - 'service/net/service_network_change_notifier_thread.h', 'service/net/service_url_request_context.cc', 'service/net/service_url_request_context.h', ], diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index eebf03b..3f49e89 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -2220,8 +2220,6 @@ 'browser/sync/glue/typed_url_model_associator.h', 'browser/sync/glue/ui_model_worker.cc', 'browser/sync/glue/ui_model_worker.h', - 'browser/sync/net/network_change_notifier_io_thread.cc', - 'browser/sync/net/network_change_notifier_io_thread.h', 'browser/sync/notification_method.h', 'browser/sync/notification_method.cc', 'browser/sync/profile_sync_service.cc', diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index f4a8e6e..444f881 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -324,11 +324,6 @@ 'common/net/http_return.h', 'common/net/net_resource_provider.cc', 'common/net/net_resource_provider.h', - 'common/net/network_change_notifier_proxy.cc', - 'common/net/network_change_notifier_proxy.h', - 'common/net/network_change_notifier_thread.h', - 'common/net/network_change_observer_proxy.cc', - 'common/net/network_change_observer_proxy.h', 'common/net/socket_stream.h', 'common/net/url_fetcher.cc', 'common/net/url_fetcher.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 0c96a6b..bb49425 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -520,7 +520,6 @@ 'chrome_resources', 'chrome_strings', 'common', - 'common_net_test_support', 'debugger', 'profile_import', 'renderer', @@ -964,7 +963,6 @@ 'browser/sync/glue/theme_util_unittest.cc', 'browser/sync/glue/typed_url_model_associator_unittest.cc', 'browser/sync/glue/ui_model_worker_unittest.cc', - 'browser/sync/net/network_change_notifier_io_thread_unittest.cc', 'browser/sync/profile_sync_factory_impl_unittest.cc', 'browser/sync/profile_sync_factory_mock.cc', 'browser/sync/profile_sync_factory_mock.h', @@ -1029,7 +1027,6 @@ 'common/json_pref_store_unittest.cc', 'common/json_value_serializer_unittest.cc', 'common/mru_cache_unittest.cc', - # TODO(sanjeevr): Move the 2 below files to common_net_unit_tests 'common/net/gaia/gaia_authenticator_unittest.cc', 'common/net/url_fetcher_unittest.cc', 'common/net/test_url_fetcher_factory.cc', @@ -1070,7 +1067,6 @@ 'renderer/spellchecker/spellcheck_worditerator_unittest.cc', 'renderer/translate_helper_unittest.cc', 'service/cloud_print/cloud_print_helpers_unittest.cc', - 'service/net/service_network_change_notifier_thread_unittest.cc', 'test/browser_with_test_window_test.cc', 'test/browser_with_test_window_test.h', 'test/file_test_utils.cc', @@ -1806,58 +1802,6 @@ ], # conditions }, { - 'target_name': 'common_net_test_support', - 'type': '<(library)', - 'sources': [ - 'common/net/fake_network_change_notifier_thread.cc', - 'common/net/fake_network_change_notifier_thread.h', - 'common/net/thread_blocker.cc', - 'common/net/thread_blocker.h', - ], - 'dependencies': [ - 'common_net', - '../base/base.gyp:base', - '../net/net.gyp:net_base', - ], - }, - { - # TODO(akalin): Add this to all.gyp. - 'target_name': 'common_net_unit_tests', - 'type': 'executable', - 'sources': [ - # TODO(akalin): Write our own test suite and runner. - '../base/test/run_all_unittests.cc', - '../base/test/test_suite.h', - 'common/net/fake_network_change_notifier_thread_unittest.cc', - 'common/net/mock_network_change_observer.h', - 'common/net/network_change_notifier_proxy_unittest.cc', - 'common/net/network_change_observer_proxy_unittest.cc', - 'common/net/thread_blocker_unittest.cc', - ], - 'include_dirs': [ - '..', - ], - 'dependencies': [ - 'common_net', - 'common_net_test_support', - '../build/temp_gyp/googleurl.gyp:googleurl', - '../testing/gmock.gyp:gmock', - '../testing/gtest.gyp:gtest', - ], - # TODO(akalin): Remove this once we have our own test suite and - # runner. - 'conditions': [ - ['OS == "linux" or OS == "freebsd" or OS == "openbsd" or OS == "solaris"', { - 'dependencies': [ - # Needed to handle the #include chain: - # base/test/test_suite.h - # gtk/gtk.h - '../build/linux/system.gyp:gtk', - ], - }], - ], - }, - { 'target_name': 'notifier_unit_tests', 'type': 'executable', 'sources': [ @@ -1873,7 +1817,6 @@ '..', ], 'dependencies': [ - 'common_net_test_support', 'notifier', '../base/base.gyp:base', '../testing/gmock.gyp:gmock', @@ -1948,7 +1891,6 @@ 'dependencies': [ 'browser/sync/protocol/sync_proto.gyp:sync_proto_cpp', 'common', - 'common_net_test_support', 'debugger', '../skia/skia.gyp:skia', '../testing/gmock.gyp:gmock', diff --git a/chrome/common/net/fake_network_change_notifier_thread.cc b/chrome/common/net/fake_network_change_notifier_thread.cc deleted file mode 100644 index b8059ab..0000000 --- a/chrome/common/net/fake_network_change_notifier_thread.cc +++ /dev/null @@ -1,77 +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. - -#include "chrome/common/net/fake_network_change_notifier_thread.h" - -#include "base/logging.h" -#include "base/message_loop.h" -#include "chrome/common/net/thread_blocker.h" -#include "net/base/mock_network_change_notifier.h" - -// We manage the lifetime of -// chrome_common_net::FakeNetworkChangeNotifierThread ourselves. -DISABLE_RUNNABLE_METHOD_REFCOUNT( - chrome_common_net::FakeNetworkChangeNotifierThread); - -namespace chrome_common_net { - -FakeNetworkChangeNotifierThread::FakeNetworkChangeNotifierThread() - : thread_("FakeNetworkChangeNotifierThread") {} - -FakeNetworkChangeNotifierThread::~FakeNetworkChangeNotifierThread() { - CHECK(!network_change_notifier_.get()); - CHECK(!thread_blocker_.get()); - CHECK(!thread_.IsRunning()); -} - -void FakeNetworkChangeNotifierThread::Start() { - network_change_notifier_.reset(new net::MockNetworkChangeNotifier()); - CHECK(thread_.Start()); - thread_blocker_.reset(new ThreadBlocker(&thread_)); - thread_blocker_->Block(); -} - -void FakeNetworkChangeNotifierThread::Pump() { - thread_blocker_->Unblock(); - thread_blocker_->Block(); -} - -void FakeNetworkChangeNotifierThread::Stop() { - thread_blocker_->Unblock(); - thread_blocker_.reset(); - thread_.Stop(); - network_change_notifier_.reset(); -} - -void FakeNetworkChangeNotifierThread::NotifyIPAddressChange() { - CHECK(thread_.IsRunning()); - GetMessageLoop()->PostTask( - FROM_HERE, - NewRunnableMethod( - this, - &FakeNetworkChangeNotifierThread:: - NotifyIPAddressChangeOnSourceThread)); -} - -void FakeNetworkChangeNotifierThread::NotifyIPAddressChangeOnSourceThread() { - CHECK_EQ(MessageLoop::current(), GetMessageLoop()); - CHECK(network_change_notifier_.get()); - network_change_notifier_->NotifyIPAddressChange(); -} - -MessageLoop* FakeNetworkChangeNotifierThread::GetMessageLoop() const { - CHECK(thread_.IsRunning()); - MessageLoop* message_loop = thread_.message_loop(); - CHECK(message_loop); - return message_loop; -} - -net::NetworkChangeNotifier* -FakeNetworkChangeNotifierThread::GetNetworkChangeNotifier() const { - CHECK_EQ(MessageLoop::current(), GetMessageLoop()); - CHECK(network_change_notifier_.get()); - return network_change_notifier_.get(); -} - -} // namespace chrome_common_net diff --git a/chrome/common/net/fake_network_change_notifier_thread.h b/chrome/common/net/fake_network_change_notifier_thread.h deleted file mode 100644 index 907a5b1..0000000 --- a/chrome/common/net/fake_network_change_notifier_thread.h +++ /dev/null @@ -1,67 +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 CHROME_COMMON_NET_FAKE_NETWORK_CHANGE_NOTIFIER_THREAD_H_ -#define CHROME_COMMON_NET_FAKE_NETWORK_CHANGE_NOTIFIER_THREAD_H_ - -// A fake implementation of NetworkChangeNotifierThread used for -// unit-testing. - -#include "base/basictypes.h" -#include "base/scoped_ptr.h" -#include "base/thread.h" -#include "chrome/common/net/network_change_notifier_thread.h" - -namespace net { -class MockNetworkChangeNotifier; -} // namespace net - -namespace chrome_common_net { - -class ThreadBlocker; - -class FakeNetworkChangeNotifierThread : public NetworkChangeNotifierThread { - public: - FakeNetworkChangeNotifierThread(); - - virtual ~FakeNetworkChangeNotifierThread(); - - // Starts the thread in a blocked state and initializes the network - // change notifier. - void Start(); - - // Runs the tasks that are currently blocked. After this call, - // thread remains in a blocked state. A call to this function is a - // memory barrier. - void Pump(); - - // Stops the thread. - void Stop(); - - // Trigger an IP address change notification on the owned network - // change notifier on the owned thread. - void NotifyIPAddressChange(); - - // Implementation of NetworkChangeNotifierThread. - - virtual MessageLoop* GetMessageLoop() const; - - virtual net::NetworkChangeNotifier* GetNetworkChangeNotifier() const; - - private: - // Used in unit tests. - friend class FakeNetworkChangeNotifierThreadDestructionObserver; - - void NotifyIPAddressChangeOnSourceThread(); - - scoped_ptr<net::MockNetworkChangeNotifier> network_change_notifier_; - base::Thread thread_; - scoped_ptr<ThreadBlocker> thread_blocker_; - - DISALLOW_COPY_AND_ASSIGN(FakeNetworkChangeNotifierThread); -}; - -} // namespace chrome_common_net - -#endif // CHROME_COMMON_NET_FAKE_NETWORK_CHANGE_NOTIFIER_THREAD_H_ diff --git a/chrome/common/net/fake_network_change_notifier_thread_unittest.cc b/chrome/common/net/fake_network_change_notifier_thread_unittest.cc deleted file mode 100644 index 25eb1ec9..0000000 --- a/chrome/common/net/fake_network_change_notifier_thread_unittest.cc +++ /dev/null @@ -1,164 +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. - -#include "chrome/common/net/fake_network_change_notifier_thread.h" - -#include "base/basictypes.h" -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/task.h" -#include "net/base/network_change_notifier.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace chrome_common_net { -class FlagToggler; -} // namespace chrome_common_net - -// We manage the lifetime of chrome_common_net::FlagToggler ourselves. -DISABLE_RUNNABLE_METHOD_REFCOUNT(chrome_common_net::FlagToggler); - -namespace chrome_common_net { - -// Utility class that toggles a flag every time it receives an IP -// address change notification. -class FlagToggler : public net::NetworkChangeNotifier::Observer { - public: - FlagToggler() : flag_(false) {} - - virtual ~FlagToggler() {} - - bool flag() const { return flag_; } - - void ToggleFlag() { - flag_ = !flag_; - } - - void Observe(NetworkChangeNotifierThread* thread) { - thread->GetNetworkChangeNotifier()->AddObserver(this); - } - - void Unobserve(NetworkChangeNotifierThread* thread) { - thread->GetNetworkChangeNotifier()->RemoveObserver(this); - } - - // net::NetworkChangeNotifier::Observer implementation. - virtual void OnIPAddressChanged() { - ToggleFlag(); - } - - private: - bool flag_; - - DISALLOW_COPY_AND_ASSIGN(FlagToggler); -}; - -// Utility class that sanity-checks a -// FakeNetworkChangeNotifierThread's member variables right before its -// message loop gets destroyed (used in DestructionRace test). -class FakeNetworkChangeNotifierThreadDestructionObserver - : public MessageLoop::DestructionObserver { - public: - explicit FakeNetworkChangeNotifierThreadDestructionObserver( - const FakeNetworkChangeNotifierThread& thread) - : thread_(thread) {} - - virtual ~FakeNetworkChangeNotifierThreadDestructionObserver() {} - - virtual void WillDestroyCurrentMessageLoop() { - EXPECT_FALSE(thread_.thread_blocker_.get()); - // We can't use - // FakeNetworkChangeNotifierThread::GetNetworkChangeNotifier() as - // it would CHECK-fail on the current thread's message loop being - // NULL. - EXPECT_TRUE(thread_.network_change_notifier_.get()); - delete this; - } - - private: - const FakeNetworkChangeNotifierThread& thread_; - - DISALLOW_COPY_AND_ASSIGN( - FakeNetworkChangeNotifierThreadDestructionObserver); -}; - -// Utility function to add the -// FakeNetworkChangeNotifierThreadDestructionObserver from the -// FakeNetworkChangeNotifierThread's thread. -void AddFakeNetworkChangeNotifierThreadDestructionObserver( - const FakeNetworkChangeNotifierThread* thread) { - CHECK_EQ(MessageLoop::current(), thread->GetMessageLoop()); - thread->GetMessageLoop()->AddDestructionObserver( - new FakeNetworkChangeNotifierThreadDestructionObserver(*thread)); -} - -namespace { - -class FakeNetworkChangeNotifierThreadTest : public testing::Test { - protected: - FakeNetworkChangeNotifierThreadTest() {} - - virtual ~FakeNetworkChangeNotifierThreadTest() {} - - virtual void SetUp() { - thread_.Start(); - } - - virtual void TearDown() { - thread_.Stop(); - } - - FakeNetworkChangeNotifierThread thread_; - FlagToggler flag_toggler_; - - private: - DISALLOW_COPY_AND_ASSIGN(FakeNetworkChangeNotifierThreadTest); -}; - -TEST_F(FakeNetworkChangeNotifierThreadTest, Pump) { - thread_.GetMessageLoop()->PostTask( - FROM_HERE, NewRunnableMethod(&flag_toggler_, &FlagToggler::ToggleFlag)); - EXPECT_FALSE(flag_toggler_.flag()); - thread_.Pump(); - EXPECT_TRUE(flag_toggler_.flag()); -} - -TEST_F(FakeNetworkChangeNotifierThreadTest, Basic) { - thread_.GetMessageLoop()->PostTask( - FROM_HERE, - NewRunnableMethod(&flag_toggler_, &FlagToggler::Observe, &thread_)); - thread_.NotifyIPAddressChange(); - thread_.GetMessageLoop()->PostTask( - FROM_HERE, - NewRunnableMethod(&flag_toggler_, &FlagToggler::Unobserve, &thread_)); - EXPECT_FALSE(flag_toggler_.flag()); - thread_.Pump(); - EXPECT_TRUE(flag_toggler_.flag()); -} - -TEST_F(FakeNetworkChangeNotifierThreadTest, Multiple) { - FlagToggler observer; - thread_.GetMessageLoop()->PostTask( - FROM_HERE, - NewRunnableMethod(&flag_toggler_, &FlagToggler::Observe, &thread_)); - thread_.NotifyIPAddressChange(); - thread_.NotifyIPAddressChange(); - thread_.GetMessageLoop()->PostTask( - FROM_HERE, - NewRunnableMethod(&flag_toggler_, &FlagToggler::Unobserve, &thread_)); - EXPECT_FALSE(flag_toggler_.flag()); - thread_.Pump(); - EXPECT_FALSE(flag_toggler_.flag()); -} - -TEST_F(FakeNetworkChangeNotifierThreadTest, DestructionRace) { - thread_.GetMessageLoop()->PostTask( - FROM_HERE, - NewRunnableFunction( - &AddFakeNetworkChangeNotifierThreadDestructionObserver, - &thread_)); -} - -} // namespace - -} // namespace chrome_common_net diff --git a/chrome/common/net/mock_network_change_observer.h b/chrome/common/net/mock_network_change_observer.h deleted file mode 100644 index 10a02a8..0000000 --- a/chrome/common/net/mock_network_change_observer.h +++ /dev/null @@ -1,32 +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 CHROME_COMMON_NET_MOCK_NETWORK_CHANGE_OBSERVER_H_ -#define CHROME_COMMON_NET_MOCK_NETWORK_CHANGE_OBSERVER_H_ - -#include "base/basictypes.h" -#include "net/base/network_change_notifier.h" -#include "testing/gmock/include/gmock/gmock.h" - -// This class is a mock net::NetworkChangeNotifier::Observer used in -// unit tests. - -namespace chrome_common_net { - -class MockNetworkChangeObserver - : public net::NetworkChangeNotifier::Observer { - public: - MockNetworkChangeObserver() {} - - virtual ~MockNetworkChangeObserver() {} - - MOCK_METHOD0(OnIPAddressChanged, void()); - - private: - DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeObserver); -}; - -} // namespace chrome_common_net - -#endif // CHROME_COMMON_NET_MOCK_NETWORK_CHANGE_OBSERVER_H_ diff --git a/chrome/common/net/network_change_notifier_proxy.cc b/chrome/common/net/network_change_notifier_proxy.cc deleted file mode 100644 index a0a1961..0000000 --- a/chrome/common/net/network_change_notifier_proxy.cc +++ /dev/null @@ -1,55 +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. - -#include "chrome/common/net/network_change_notifier_proxy.h" - -#include "base/logging.h" -#include "base/message_loop.h" -#include "chrome/common/net/network_change_observer_proxy.h" - -namespace chrome_common_net { - -NetworkChangeNotifierProxy::NetworkChangeNotifierProxy( - NetworkChangeNotifierThread* source_thread) - : observer_proxy_(new NetworkChangeObserverProxy( - source_thread, MessageLoop::current())), - observer_repeater_(&observers_) { - DCHECK(observer_proxy_); - observer_proxy_->Attach(&observer_repeater_); -} - -NetworkChangeNotifierProxy::~NetworkChangeNotifierProxy() { - DCHECK(CalledOnValidThread()); - observer_proxy_->Detach(); -} - -void NetworkChangeNotifierProxy::AddObserver( - net::NetworkChangeNotifier::Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.AddObserver(observer); -} - -void NetworkChangeNotifierProxy::RemoveObserver( - net::NetworkChangeNotifier::Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.RemoveObserver(observer); -} - -NetworkChangeNotifierProxy::ObserverRepeater::ObserverRepeater( - NetworkObserverList* observers) - : observers_(observers) { - DCHECK(observers_); -} - -NetworkChangeNotifierProxy::ObserverRepeater::~ObserverRepeater() { - DCHECK(CalledOnValidThread()); -} - -void NetworkChangeNotifierProxy::ObserverRepeater::OnIPAddressChanged() { - DCHECK(CalledOnValidThread()); - FOR_EACH_OBSERVER(net::NetworkChangeNotifier::Observer, *observers_, - OnIPAddressChanged()); -} - -} // namespace chrome_common_net diff --git a/chrome/common/net/network_change_notifier_proxy.h b/chrome/common/net/network_change_notifier_proxy.h deleted file mode 100644 index 7ed01a8..0000000 --- a/chrome/common/net/network_change_notifier_proxy.h +++ /dev/null @@ -1,70 +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 CHROME_COMMON_NET_NETWORK_CHANGE_NOTIFIER_PROXY_H_ -#define CHROME_COMMON_NET_NETWORK_CHANGE_NOTIFIER_PROXY_H_ - -// NetworkChangeNotifierProxy is a class that lets observers listen to -// a NetworkChangeNotifier that lives on another thread. - -#include "base/basictypes.h" -#include "base/non_thread_safe.h" -#include "base/observer_list.h" -#include "base/ref_counted.h" -#include "net/base/network_change_notifier.h" - -class MessageLoop; - -namespace chrome_common_net { - -class NetworkChangeNotifierThread; -class NetworkChangeObserverProxy; - -class NetworkChangeNotifierProxy : public net::NetworkChangeNotifier, - public NonThreadSafe { - public: - // |source_thread| must be guaranteed to outlive the current thread. - // Does not take ownership of any arguments. - explicit NetworkChangeNotifierProxy( - NetworkChangeNotifierThread* source_thread); - - virtual ~NetworkChangeNotifierProxy(); - - // net::NetworkChangeNotifier implementation. - virtual void AddObserver(net::NetworkChangeNotifier::Observer* observer); - virtual void RemoveObserver(net::NetworkChangeNotifier::Observer* observer); - - private: - typedef ObserverList<net::NetworkChangeNotifier::Observer, true> - NetworkObserverList; - - // Utility class that routes received notifications to a list of - // observers. - class ObserverRepeater : public net::NetworkChangeNotifier::Observer, - public NonThreadSafe { - public: - // Does not take ownership of the given observer list. - explicit ObserverRepeater(NetworkObserverList* observers); - - virtual ~ObserverRepeater(); - - // net::NetworkChangeNotifier::Observer implementation. - virtual void OnIPAddressChanged(); - - private: - NetworkObserverList* observers_; - - DISALLOW_COPY_AND_ASSIGN(ObserverRepeater); - }; - - scoped_refptr<NetworkChangeObserverProxy> observer_proxy_; - NetworkObserverList observers_; - ObserverRepeater observer_repeater_; - - DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierProxy); -}; - -} // namespace chrome_common_net - -#endif // CHROME_COMMON_NET_NETWORK_CHANGE_NOTIFIER_PROXY_H_ diff --git a/chrome/common/net/network_change_notifier_proxy_unittest.cc b/chrome/common/net/network_change_notifier_proxy_unittest.cc deleted file mode 100644 index a716798..0000000 --- a/chrome/common/net/network_change_notifier_proxy_unittest.cc +++ /dev/null @@ -1,101 +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. - -#include "chrome/common/net/network_change_notifier_proxy.h" - -#include "base/basictypes.h" -#include "base/logging.h" -#include "base/ref_counted.h" -#include "base/scoped_ptr.h" -#include "chrome/common/net/fake_network_change_notifier_thread.h" -#include "chrome/common/net/mock_network_change_observer.h" -#include "net/base/network_change_notifier.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace chrome_common_net { - -namespace { - -class NetworkChangeNotifierProxyTest : public testing::Test { - protected: - NetworkChangeNotifierProxyTest() {} - - virtual ~NetworkChangeNotifierProxyTest() {} - - virtual void SetUp() { - source_thread_.Start(); - notifier_proxy_.reset(new NetworkChangeNotifierProxy(&source_thread_)); - } - - virtual void TearDown() { - // Posts a task to the source thread. - notifier_proxy_.reset(); - source_thread_.Stop(); - } - - // Trigger an "IP address changed" event on the source network - // change notifier on the source thread and propagate any generated - // notifications to the target thread. - void NotifyIPAddressChange() { - source_thread_.NotifyIPAddressChange(); - source_thread_.Pump(); - target_message_loop_.RunAllPending(); - } - - FakeNetworkChangeNotifierThread source_thread_; - - MessageLoop target_message_loop_; - MockNetworkChangeObserver target_observer_; - - scoped_ptr<net::NetworkChangeNotifier> notifier_proxy_; - - private: - DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierProxyTest); -}; - -TEST_F(NetworkChangeNotifierProxyTest, Basic) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(1); - - notifier_proxy_->AddObserver(&target_observer_); - NotifyIPAddressChange(); - notifier_proxy_->RemoveObserver(&target_observer_); -} - -TEST_F(NetworkChangeNotifierProxyTest, IgnoresEventAfterRemoveObserver) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - notifier_proxy_->AddObserver(&target_observer_); - notifier_proxy_->RemoveObserver(&target_observer_); - NotifyIPAddressChange(); -} - -TEST_F(NetworkChangeNotifierProxyTest, IgnoresEventBeforeRemoveObserver) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - NotifyIPAddressChange(); - notifier_proxy_->AddObserver(&target_observer_); - notifier_proxy_->RemoveObserver(&target_observer_); -} - -TEST_F(NetworkChangeNotifierProxyTest, Multiple) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - const int kNumObservers = 5; - MockNetworkChangeObserver extra_observers[kNumObservers]; - for (int i = 0; i < kNumObservers; ++i) { - EXPECT_CALL(extra_observers[i], OnIPAddressChanged()).Times(1); - } - - for (int i = 0; i < kNumObservers; ++i) { - notifier_proxy_->AddObserver(&extra_observers[i]); - } - NotifyIPAddressChange(); - for (int i = 0; i < kNumObservers; ++i) { - notifier_proxy_->RemoveObserver(&extra_observers[i]); - } -} - -} // namespace - -} // namespace chrome_common_net diff --git a/chrome/common/net/network_change_notifier_thread.h b/chrome/common/net/network_change_notifier_thread.h deleted file mode 100644 index 950186c..0000000 --- a/chrome/common/net/network_change_notifier_thread.h +++ /dev/null @@ -1,37 +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 CHROME_COMMON_NET_NETWORK_CHANGE_NOTIFIER_THREAD_H_ -#define CHROME_COMMON_NET_NETWORK_CHANGE_NOTIFIER_THREAD_H_ - -// A simple interface that represents a thread which owns a -// NetworkChangeNotifier. - -class MessageLoop; - -namespace net { -class NetworkChangeNotifier; -} // namespace net - -namespace chrome_common_net { - -// An instance of this interface must live no longer than the thread -// it represents and its message loop and network change notifier. -class NetworkChangeNotifierThread { - public: - virtual ~NetworkChangeNotifierThread() {} - - // Returns the message loop for the thread that owns the - // NetworkChangeNotifier. Can be called on any thread. - virtual MessageLoop* GetMessageLoop() const = 0; - - // Returns the NetworkChangeNotifier of the thread. This method - // must be called only from the owning thread (i.e., by posting a - // task onto the message loop returned by GetMessageLoop()). - virtual net::NetworkChangeNotifier* GetNetworkChangeNotifier() const = 0; -}; - -} // namespace chrome_common_net - -#endif // CHROME_COMMON_NET_NETWORK_CHANGE_NOTIFIER_THREAD_H_ diff --git a/chrome/common/net/network_change_observer_proxy.cc b/chrome/common/net/network_change_observer_proxy.cc deleted file mode 100644 index a8db2d2..0000000 --- a/chrome/common/net/network_change_observer_proxy.cc +++ /dev/null @@ -1,137 +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. - -// Some notes that may help anyone trying to reason about this code: -// -// - The source thread must be guaranteed to outlive the target -// thread. This is so that it is guaranteed that any task posted to -// the source thread will eventually be run. In particular, we want -// to make sure that Detach() causes us to eventually be removed as -// an observer. -// -// Note that this implies that any task posted to the target thread -// from the source thread may not run. But we post only -// TargetObserverOnIPAddressChanged() tasks on the target thread, -// which we can safely drop. -// -// - The source NetworkChangeNotifier must be guaranteed to outlive -// the target thread. This is so that it is guaranteed that any -// task posted to the source thread can safely access the source -// NetworkChangeNotifier. -// -// - Ref-counting this class is necessary, although as a consequence -// we can't make any guarantees about which thread will destroy an -// instance. Earlier versions of this class tried to get away -// without ref-counting. One version deleted the class in -// Unobserve(); this didn't work because there may still be -// TargetObserverOnIPAddressChanged() tasks on the target thread. -// An attempt to fix this was to post a DeleteTask on the target -// thread from Unobserve(), but this meant that there would be no -// way of knowing when on the target thread the instance would be -// deleted. Indeed, as mentioned above, any tasks posted on the -// target thread may not run, so this introduced the possibility of -// a memory leak. -// -// - It is important that all posted tasks that work with a proxy be -// RunnableMethods so that the ref-counting guarantees that the -// proxy is still valid when the task runs. - -#include "chrome/common/net/network_change_observer_proxy.h" - -#include <cstddef> - -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/task.h" -#include "chrome/common/net/network_change_notifier_thread.h" -#include "net/base/network_change_notifier.h" - -namespace chrome_common_net { - -NetworkChangeObserverProxy::NetworkChangeObserverProxy( - const NetworkChangeNotifierThread* source_thread, - MessageLoop* target_message_loop) - : source_thread_(source_thread), - target_message_loop_(target_message_loop), - target_observer_(NULL) { - DCHECK(source_thread_); - MessageLoop* source_message_loop = source_thread_->GetMessageLoop(); - DCHECK(source_message_loop); - DCHECK(target_message_loop_); - DCHECK_NE(source_message_loop, target_message_loop_); - DCHECK_EQ(MessageLoop::current(), target_message_loop_); -} - -void NetworkChangeObserverProxy::Attach( - net::NetworkChangeNotifier::Observer* target_observer) { - DCHECK_EQ(MessageLoop::current(), target_message_loop_); - DCHECK(!target_observer_); - target_observer_ = target_observer; - DCHECK(target_observer_); - source_thread_->GetMessageLoop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &NetworkChangeObserverProxy::Observe)); -} - -void NetworkChangeObserverProxy::Detach() { - DCHECK_EQ(MessageLoop::current(), target_message_loop_); - DCHECK(target_observer_); - target_observer_ = NULL; - source_thread_->GetMessageLoop()->PostTask( - FROM_HERE, - NewRunnableMethod(this, &NetworkChangeObserverProxy::Unobserve)); -} - -NetworkChangeObserverProxy::~NetworkChangeObserverProxy() { - MessageLoop* current_message_loop = MessageLoop::current(); - // We can be deleted on either the source or target thread, so the - // best we can do is check that we're on either. - DCHECK((current_message_loop == source_thread_->GetMessageLoop()) || - (current_message_loop == target_message_loop_)); - // Even though only the target thread uses target_observer_, it - // should still be unset even if we're on the source thread; posting - // a task is effectively a memory barrier. - DCHECK(!target_observer_); -} - -void NetworkChangeObserverProxy::Observe() { - DCHECK_EQ(MessageLoop::current(), source_thread_->GetMessageLoop()); - net::NetworkChangeNotifier* source_network_change_notifier = - source_thread_->GetNetworkChangeNotifier(); - DCHECK(source_network_change_notifier); - source_network_change_notifier->AddObserver(this); -} - -// The Task from which this was called may hold the last reference to -// us (this is how we can get deleted on the source thread). -void NetworkChangeObserverProxy::Unobserve() { - DCHECK_EQ(MessageLoop::current(), source_thread_->GetMessageLoop()); - net::NetworkChangeNotifier* source_network_change_notifier = - source_thread_->GetNetworkChangeNotifier(); - DCHECK(source_network_change_notifier); - source_network_change_notifier->RemoveObserver(this); -} - -// Although we may get this event after Detach() has been called on -// the target thread, we know that Unobserve() hasn't been called yet. -// But we know that it has been posted, so it at least holds a -// reference to us. -void NetworkChangeObserverProxy::OnIPAddressChanged() { - DCHECK_EQ(MessageLoop::current(), source_thread_->GetMessageLoop()); - target_message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod( - this, - &NetworkChangeObserverProxy::TargetObserverOnIPAddressChanged)); -} - -// The Task from which this was called may hold the last reference to -// us (this is how we can get deleted on the target thread). -void NetworkChangeObserverProxy::TargetObserverOnIPAddressChanged() { - DCHECK_EQ(MessageLoop::current(), target_message_loop_); - if (target_observer_) - target_observer_->OnIPAddressChanged(); -} - -} // namespace chrome_common_net diff --git a/chrome/common/net/network_change_observer_proxy.h b/chrome/common/net/network_change_observer_proxy.h deleted file mode 100644 index 795b0c8..0000000 --- a/chrome/common/net/network_change_observer_proxy.h +++ /dev/null @@ -1,114 +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 CHROME_COMMON_NET_NETWORK_CHANGE_OBSERVER_PROXY_H_ -#define CHROME_COMMON_NET_NETWORK_CHANGE_OBSERVER_PROXY_H_ - -// NetworkChangeObserverProxy is a class that listens to a -// NetworkChangeNotifier on one thread (the source thread, which is -// usually the Chrome IO thread) and emits events to a target observer -// on another thread (the target thread). -// -// How to use: -// -// In the target thread, create the observer proxy: -// -// NetworkChangeNotifierThread* source_thread = ...; -// NetworkChangeObserverProxy* proxy = -// new NetworkChangeObserverProxy(source_thread, -// MessageLoop::current()); -// -// Both source_thread and its owned NetworkChangeNotifier must be -// guaranteed to outlive the target (current) thread. -// -// Then, attach the target observer: -// -// proxy->Attach(target_observer); -// -// target_observer will then begin to receive events on the target -// thread. -// -// If you call Attach(), you *must* call Detach() before releasing: -// -// proxy->Detach(); -// proxy->Release(); // omit if proxy is a scoped_refptr -// proxy = NULL; -// -// The proxy may be destroyed on either the source or the target -// thread (depending on which one ends up holding the last reference). - -#include "base/basictypes.h" -#include "base/message_loop.h" -#include "base/ref_counted.h" -#include "net/base/network_change_notifier.h" - -namespace chrome_common_net { - -class NetworkChangeNotifierThread; - -// TODO(akalin): Remove use of private inheritance. -class NetworkChangeObserverProxy - : public base::RefCountedThreadSafe<NetworkChangeObserverProxy>, - private net::NetworkChangeNotifier::Observer { - public: - // All public methods (including the constructor) must be called on - // the target thread. - - // Does not take ownership of any arguments. - NetworkChangeObserverProxy( - const NetworkChangeNotifierThread* source_thread, - MessageLoop* target_message_loop); - - // After this method is called, |target_observer| will start - // receiving events on the target thread. Once called, Detach() - // must be called before releasing and you cannot call Attach() - // again until you have done so. Does not take ownership of - // |target_observer|. - void Attach(net::NetworkChangeNotifier::Observer* target_observer); - - // After this method is called, the target observer will stop - // receiving events. You can call Attach() again after this method - // is called. - void Detach(); - - protected: - // May be called on either the source or the target thread. Marked - // protected instead of private so that this class can be subclassed - // for unit tests. - virtual ~NetworkChangeObserverProxy(); - - private: - friend class base::RefCountedThreadSafe<NetworkChangeObserverProxy>; - - // Adds ourselves as an observer of - // |source_network_change_notifier_|. Must be called on the source - // thread. - void Observe(); - - // Removes ourselves as an observer of - // |source_network_change_notifier_|. Must be called on the source - // thread. - void Unobserve(); - - // net::NetworkChangeNotifier::Observer implementation. - // - // Called on the source thread. Posts - // TargetObserverOnIPAddressChanged() on the target thread. - virtual void OnIPAddressChanged(); - - // Called on the target thread. Invokes OnIPAddressChanged() on - // |target_observer_|. - void TargetObserverOnIPAddressChanged(); - - const NetworkChangeNotifierThread* source_thread_; - MessageLoop* const target_message_loop_; - // |target_observer_| is used only by the target thread. - net::NetworkChangeNotifier::Observer* target_observer_; - - DISALLOW_COPY_AND_ASSIGN(NetworkChangeObserverProxy); -}; - -} // namespace chrome_common_net - -#endif // CHROME_COMMON_NET_NETWORK_CHANGE_OBSERVER_PROXY_H_ diff --git a/chrome/common/net/network_change_observer_proxy_unittest.cc b/chrome/common/net/network_change_observer_proxy_unittest.cc deleted file mode 100644 index 0fe3cc1..0000000 --- a/chrome/common/net/network_change_observer_proxy_unittest.cc +++ /dev/null @@ -1,230 +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. - -#include "chrome/common/net/network_change_observer_proxy.h" - -#include "base/basictypes.h" -#include "base/logging.h" -#include "base/ref_counted.h" -#include "chrome/common/net/fake_network_change_notifier_thread.h" -#include "chrome/common/net/mock_network_change_observer.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace chrome_common_net { - -namespace { - -// Version of NetworkChangeObserverProxy that records on what thread -// it was deleted. -class DeleteCheckingNetworkChangeObserverProxy - : public NetworkChangeObserverProxy { - public: - // *deleting_message_loop_ must be NULL. It is set to a non-NULL - // *value when this object is deleted. - DeleteCheckingNetworkChangeObserverProxy( - NetworkChangeNotifierThread* source_thread, - MessageLoop* target_message_loop, - MessageLoop** deleting_message_loop) - : NetworkChangeObserverProxy(source_thread, target_message_loop), - deleting_message_loop_(deleting_message_loop) { - CHECK(deleting_message_loop_); - EXPECT_TRUE(*deleting_message_loop_ == NULL); - } - - private: - virtual ~DeleteCheckingNetworkChangeObserverProxy() { - *deleting_message_loop_ = MessageLoop::current(); - } - - MessageLoop** deleting_message_loop_; - - DISALLOW_COPY_AND_ASSIGN(DeleteCheckingNetworkChangeObserverProxy); -}; - -class NetworkChangeObserverProxyTest : public testing::Test { - protected: - NetworkChangeObserverProxyTest() : proxy_deleting_message_loop_(NULL) {} - - virtual ~NetworkChangeObserverProxyTest() {} - - virtual void SetUp() { - source_thread_.Start(); - proxy_deleting_message_loop_ = NULL; - proxy_ = new DeleteCheckingNetworkChangeObserverProxy( - &source_thread_, &target_message_loop_, - &proxy_deleting_message_loop_); - } - - // On TearDown, |proxy_| must be released and both source and target - // must be pumped. - virtual void TearDown() { - EXPECT_TRUE(proxy_ == NULL); - EXPECT_TRUE(proxy_deleting_message_loop_ != NULL); - source_thread_.Stop(); - } - - // Pump any events posted on the source thread. - void PumpSource() { - source_thread_.Pump(); - } - - // Pump any events posted on the target thread (which is just the - // main test thread). - void PumpTarget() { - target_message_loop_.RunAllPending(); - } - - // Trigger an "IP address changed" event on the source network - // change notifier on the source thread. - void NotifyIPAddressChange() { - source_thread_.NotifyIPAddressChange(); - } - - FakeNetworkChangeNotifierThread source_thread_; - - MessageLoop target_message_loop_; - MockNetworkChangeObserver target_observer_; - - MessageLoop* proxy_deleting_message_loop_; - scoped_refptr<NetworkChangeObserverProxy> proxy_; - - private: - DISALLOW_COPY_AND_ASSIGN(NetworkChangeObserverProxyTest); -}; - -// Make sure nothing blows up if we don't attach the proxy. -TEST_F(NetworkChangeObserverProxyTest, DoNothing) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - proxy_ = NULL; - // No need to pump. - - EXPECT_EQ(proxy_deleting_message_loop_, &target_message_loop_); -} - -TEST_F(NetworkChangeObserverProxyTest, AttachDetach) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - proxy_->Attach(&target_observer_); - proxy_->Detach(); - proxy_ = NULL; - PumpSource(); - - EXPECT_EQ(proxy_deleting_message_loop_, source_thread_.GetMessageLoop()); -} - -TEST_F(NetworkChangeObserverProxyTest, AttachDetachReleaseAfterPump) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - proxy_->Attach(&target_observer_); - proxy_->Detach(); - PumpSource(); - proxy_ = NULL; - - EXPECT_EQ(proxy_deleting_message_loop_, &target_message_loop_); -} - -TEST_F(NetworkChangeObserverProxyTest, Basic) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(1); - - proxy_->Attach(&target_observer_); - NotifyIPAddressChange(); - PumpSource(); - PumpTarget(); - proxy_->Detach(); - proxy_ = NULL; - PumpSource(); - - EXPECT_EQ(proxy_deleting_message_loop_, source_thread_.GetMessageLoop()); -} - -TEST_F(NetworkChangeObserverProxyTest, Multiple) { - const int kTimes = 5; - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(kTimes); - - proxy_->Attach(&target_observer_); - for (int i = 0; i < kTimes; ++i) { - NotifyIPAddressChange(); - } - PumpSource(); - PumpTarget(); - proxy_->Detach(); - proxy_ = NULL; - PumpSource(); - - EXPECT_EQ(proxy_deleting_message_loop_, source_thread_.GetMessageLoop()); -} - -TEST_F(NetworkChangeObserverProxyTest, MultipleAttachDetach) { - const int kTimes = 5; - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(kTimes); - - for (int i = 0; i < kTimes; ++i) { - proxy_->Attach(&target_observer_); - NotifyIPAddressChange(); - PumpSource(); - PumpTarget(); - proxy_->Detach(); - } - proxy_ = NULL; - PumpSource(); - - EXPECT_EQ(proxy_deleting_message_loop_, source_thread_.GetMessageLoop()); -} - -TEST_F(NetworkChangeObserverProxyTest, IgnoresEventPostedAfterDetach) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - proxy_->Attach(&target_observer_); - NotifyIPAddressChange(); - proxy_->Detach(); - proxy_ = NULL; - PumpSource(); - PumpTarget(); - - EXPECT_EQ(proxy_deleting_message_loop_, &target_message_loop_); -} - -TEST_F(NetworkChangeObserverProxyTest, IgnoresEventPostedBeforeDetach) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - proxy_->Attach(&target_observer_); - NotifyIPAddressChange(); - PumpSource(); - proxy_->Detach(); - proxy_ = NULL; - PumpTarget(); - PumpSource(); - - EXPECT_EQ(proxy_deleting_message_loop_, source_thread_.GetMessageLoop()); -} - -TEST_F(NetworkChangeObserverProxyTest, IgnoresEventAfterDetach) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - proxy_->Attach(&target_observer_); - proxy_->Detach(); - proxy_ = NULL; - NotifyIPAddressChange(); - PumpSource(); - - EXPECT_EQ(proxy_deleting_message_loop_, source_thread_.GetMessageLoop()); -} - -TEST_F(NetworkChangeObserverProxyTest, IgnoresEventBeforeAttach) { - EXPECT_CALL(target_observer_, OnIPAddressChanged()).Times(0); - - NotifyIPAddressChange(); - PumpSource(); - proxy_->Attach(&target_observer_); - proxy_->Detach(); - proxy_ = NULL; - PumpSource(); - - EXPECT_EQ(proxy_deleting_message_loop_, source_thread_.GetMessageLoop()); -} - -} // namespace - -} // namespace chrome_common_net diff --git a/chrome/common/net/notifier/communicator/login.cc b/chrome/common/net/notifier/communicator/login.cc index 3566714..f1ed19a 100644 --- a/chrome/common/net/notifier/communicator/login.cc +++ b/chrome/common/net/notifier/communicator/login.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -14,7 +14,6 @@ #include "chrome/common/net/notifier/communicator/product_info.h" #include "chrome/common/net/notifier/communicator/single_login_attempt.h" #include "net/base/host_port_pair.h" -#include "net/base/network_change_notifier.h" #include "talk/base/common.h" #include "talk/base/firewallsocketserver.h" #include "talk/base/logging.h" @@ -42,7 +41,6 @@ Login::Login(talk_base::TaskParent* parent, net::HostResolver* host_resolver, ServerInformation* server_list, int server_count, - net::NetworkChangeNotifier* network_change_notifier, talk_base::FirewallManager* firewall, bool proxy_only, bool previous_login_successful) @@ -55,7 +53,6 @@ Login::Login(talk_base::TaskParent* parent, server_count, firewall, proxy_only)), - network_change_notifier_(network_change_notifier), single_attempt_(NULL), successful_connection_(previous_login_successful), state_(STATE_OPENING), @@ -63,9 +60,8 @@ Login::Login(talk_base::TaskParent* parent, unexpected_disconnect_occurred_(false), google_host_(user_settings.host()), google_user_(user_settings.user()) { - DCHECK(network_change_notifier_); // Hook up all the signals and observers. - network_change_notifier_->AddObserver(this); + net::NetworkChangeNotifier::AddObserver(this); auto_reconnect_.SignalStartConnection.connect(this, &Login::StartConnection); auto_reconnect_.SignalTimerStartStop.connect( @@ -89,7 +85,7 @@ Login::~Login() { single_attempt_->Abort(); single_attempt_ = NULL; } - network_change_notifier_->RemoveObserver(this); + net::NetworkChangeNotifier::RemoveObserver(this); } void Login::StartConnection() { diff --git a/chrome/common/net/notifier/communicator/login.h b/chrome/common/net/notifier/communicator/login.h index 06abef0..eff1cc5 100644 --- a/chrome/common/net/notifier/communicator/login.h +++ b/chrome/common/net/notifier/communicator/login.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -56,7 +56,6 @@ class Login : public net::NetworkChangeNotifier::Observer, net::HostResolver* host_resolver, ServerInformation* server_list, int server_count, - net::NetworkChangeNotifier* network_change_notifier, talk_base::FirewallManager* firewall, bool proxy_only, bool previous_login_successful); @@ -126,7 +125,6 @@ class Login : public net::NetworkChangeNotifier::Observer, talk_base::TaskParent* parent_; scoped_ptr<LoginSettings> login_settings_; - net::NetworkChangeNotifier* network_change_notifier_; AutoReconnect auto_reconnect_; SingleLoginAttempt* single_attempt_; bool successful_connection_; diff --git a/chrome/common/net/notifier/listener/mediator_thread_impl.cc b/chrome/common/net/notifier/listener/mediator_thread_impl.cc index 76c270e7..13de806 100644 --- a/chrome/common/net/notifier/listener/mediator_thread_impl.cc +++ b/chrome/common/net/notifier/listener/mediator_thread_impl.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -7,7 +7,6 @@ #include "base/logging.h" #include "base/message_loop.h" #include "base/task.h" -#include "chrome/common/net/network_change_notifier_proxy.h" #include "chrome/common/net/notifier/base/task_pump.h" #include "chrome/common/net/notifier/communicator/connection_options.h" #include "chrome/common/net/notifier/communicator/const_communicator.h" @@ -27,15 +26,11 @@ DISABLE_RUNNABLE_METHOD_REFCOUNT(notifier::MediatorThreadImpl); namespace notifier { -MediatorThreadImpl::MediatorThreadImpl( - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread) +MediatorThreadImpl::MediatorThreadImpl() : delegate_(NULL), parent_message_loop_(MessageLoop::current()), - network_change_notifier_thread_(network_change_notifier_thread), worker_thread_("MediatorThread worker thread") { DCHECK(parent_message_loop_); - DCHECK(network_change_notifier_thread_); } MediatorThreadImpl::~MediatorThreadImpl() { @@ -115,7 +110,6 @@ void MediatorThreadImpl::Logout() { parent_message_loop_->SetNestableTasksAllowed(old_state); // worker_thread_ should have cleaned all this up. CHECK(!login_.get()); - CHECK(!network_change_notifier_.get()); CHECK(!pump_.get()); } @@ -167,13 +161,9 @@ void MediatorThreadImpl::DoLogin( DCHECK_EQ(MessageLoop::current(), worker_message_loop()); LOG(INFO) << "P2P: Thread logging into talk network."; - network_change_notifier_.reset( - new chrome_common_net::NetworkChangeNotifierProxy( - network_change_notifier_thread_)); // TODO(akalin): Use an existing HostResolver from somewhere (maybe // the IOThread one). - host_resolver_ = - net::CreateSystemHostResolver(network_change_notifier_.get()); + host_resolver_ = net::CreateSystemHostResolver(); // Start a new pump for the login. login_.reset(); @@ -202,7 +192,6 @@ void MediatorThreadImpl::DoLogin( host_resolver_.get(), server_list, server_list_count, - network_change_notifier_.get(), // talk_base::FirewallManager* is NULL. NULL, // Both the proxy and a non-proxy route @@ -230,7 +219,6 @@ void MediatorThreadImpl::DoDisconnect() { pump_.reset(); host_resolver_ = NULL; - network_change_notifier_.reset(); } void MediatorThreadImpl::DoSubscribeForUpdates( diff --git a/chrome/common/net/notifier/listener/mediator_thread_impl.h b/chrome/common/net/notifier/listener/mediator_thread_impl.h index fb14d5b..df83ebd 100644 --- a/chrome/common/net/notifier/listener/mediator_thread_impl.h +++ b/chrome/common/net/notifier/listener/mediator_thread_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. // @@ -40,13 +40,8 @@ namespace buzz { class XmppClient; } // namespace buzz -namespace chrome_common_net { -class NetworkChangeNotifierThread; -} // namespace chrome_common_net - namespace net { class HostResolver; -class NetworkChangeNotifier; } // namespace net namespace notifier { @@ -64,9 +59,7 @@ class MediatorThreadImpl : public MediatorThread, public sigslot::has_slots<> { public: - explicit MediatorThreadImpl( - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread); + MediatorThreadImpl(); virtual ~MediatorThreadImpl(); virtual void SetDelegate(Delegate* delegate); @@ -128,10 +121,7 @@ class MediatorThreadImpl void OnSubscriptionStateChangeOnParentThread( bool success); - chrome_common_net::NetworkChangeNotifierThread* - network_change_notifier_thread_; base::Thread worker_thread_; - scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; scoped_refptr<net::HostResolver> host_resolver_; // All buzz::XmppClients are owned by their parent. The root parent is the diff --git a/chrome/common/net/notifier/listener/talk_mediator_unittest.cc b/chrome/common/net/notifier/listener/talk_mediator_unittest.cc index dd144b2..b90c577 100644 --- a/chrome/common/net/notifier/listener/talk_mediator_unittest.cc +++ b/chrome/common/net/notifier/listener/talk_mediator_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -7,7 +7,6 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/message_loop.h" -#include "chrome/common/net/fake_network_change_notifier_thread.h" #include "chrome/common/net/notifier/listener/mediator_thread_mock.h" #include "chrome/common/net/notifier/listener/mediator_thread_impl.h" #include "chrome/common/net/notifier/listener/talk_mediator_impl.h" @@ -43,9 +42,8 @@ class TalkMediatorImplTest : public testing::Test { const bool kInitializeSsl = true; const bool kConnectImmediately = false; const bool kInvalidateXmppAuthToken = false; - return new TalkMediatorImpl( - new MediatorThreadImpl(&fake_network_change_notifier_thread_), - kInitializeSsl, kConnectImmediately, kInvalidateXmppAuthToken); + return new TalkMediatorImpl(new MediatorThreadImpl(), kInitializeSsl, + kConnectImmediately, kInvalidateXmppAuthToken); } TalkMediatorImpl* NewMockedTalkMediator( @@ -58,8 +56,6 @@ class TalkMediatorImplTest : public testing::Test { kInvalidateXmppAuthToken); } - chrome_common_net::FakeNetworkChangeNotifierThread - fake_network_change_notifier_thread_; int last_message_; private: diff --git a/chrome/common/net/thread_blocker.cc b/chrome/common/net/thread_blocker.cc deleted file mode 100644 index 2291d33..0000000 --- a/chrome/common/net/thread_blocker.cc +++ /dev/null @@ -1,47 +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. - -#include "chrome/common/net/thread_blocker.h" - -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/task.h" -#include "base/thread.h" -#include "base/waitable_event.h" - -// Since a ThreadBlocker is outlived by its target thread, we don't -// have to ref-count it. -DISABLE_RUNNABLE_METHOD_REFCOUNT(chrome_common_net::ThreadBlocker); - -namespace chrome_common_net { - -ThreadBlocker::ThreadBlocker(base::Thread* target_thread) - : target_message_loop_(target_thread->message_loop()), - is_blocked_(false, false), is_finished_blocking_(false, false), - is_unblocked_(false, false) { - DCHECK(target_message_loop_); -} - -void ThreadBlocker::Block() { - DCHECK_NE(MessageLoop::current(), target_message_loop_); - target_message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod(this, &ThreadBlocker::BlockOnTargetThread)); - while (!is_blocked_.Wait()) {} -} - -void ThreadBlocker::Unblock() { - DCHECK_NE(MessageLoop::current(), target_message_loop_); - is_finished_blocking_.Signal(); - while (!is_unblocked_.Wait()) {} -} - -void ThreadBlocker::BlockOnTargetThread() { - DCHECK_EQ(MessageLoop::current(), target_message_loop_); - is_blocked_.Signal(); - while (!is_finished_blocking_.Wait()) {} - is_unblocked_.Signal(); -} - -} // namespace chrome_common_net diff --git a/chrome/common/net/thread_blocker.h b/chrome/common/net/thread_blocker.h deleted file mode 100644 index 89ff0d7..0000000 --- a/chrome/common/net/thread_blocker.h +++ /dev/null @@ -1,51 +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 CHROME_COMMON_NET_THREAD_BLOCKER_H_ -#define CHROME_COMMON_NET_THREAD_BLOCKER_H_ - -// This class (mainly used for testing) lets you block and unblock a -// thread at will. -// -// TODO(akalin): Consider moving this to base/ as this class is not -// sync-specific (ask darin about it). - -#include "base/basictypes.h" -#include "base/waitable_event.h" - -class MessageLoop; - -namespace base { -class Thread; -} // namespace base - -namespace chrome_common_net { - -class ThreadBlocker { - public: - // The given thread must already be started and it must outlive this - // instance. - explicit ThreadBlocker(base::Thread* target_thread); - - // When this function returns, the target thread will be blocked - // until Unblock() is called. Each call to Block() must be matched - // by a call to Unblock(). - void Block(); - - // When this function returns, the target thread is unblocked. - void Unblock(); - - private: - // On the target thread, blocks until Unblock() is called. - void BlockOnTargetThread(); - - MessageLoop* const target_message_loop_; - base::WaitableEvent is_blocked_, is_finished_blocking_, is_unblocked_; - - DISALLOW_COPY_AND_ASSIGN(ThreadBlocker); -}; - -} // namespace chrome_common_net - -#endif // CHROME_COMMON_NET_THREAD_BLOCKER_H_ diff --git a/chrome/common/net/thread_blocker_unittest.cc b/chrome/common/net/thread_blocker_unittest.cc deleted file mode 100644 index 7ce0668..0000000 --- a/chrome/common/net/thread_blocker_unittest.cc +++ /dev/null @@ -1,109 +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. - -#include "chrome/common/net/thread_blocker.h" - -#include "base/basictypes.h" -#include "base/lock.h" -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/scoped_ptr.h" -#include "base/task.h" -#include "base/thread.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace chrome_common_net { -class Flag; -}; // namespace chrome_common_net - -// We manage the lifetime of chrome_common_net::Flag ourselves. -DISABLE_RUNNABLE_METHOD_REFCOUNT(chrome_common_net::Flag); - -namespace chrome_common_net { - -// Utility class that is basically just a thread-safe boolean. -class Flag { - public: - Flag() : flag_(false) {} - - bool IsSet() const { - AutoLock auto_lock(lock_); - return flag_; - } - - void Set() { - AutoLock auto_lock(lock_); - flag_ = true; - } - - void Unset() { - AutoLock auto_lock(lock_); - flag_ = false; - } - - private: - mutable Lock lock_; - bool flag_; - - DISALLOW_COPY_AND_ASSIGN(Flag); -}; - -namespace { - -class ThreadBlockerTest : public testing::Test { - protected: - ThreadBlockerTest() : target_thread_("Target Thread") {} - - virtual ~ThreadBlockerTest() { - CHECK(!thread_blocker_.get()); - } - - virtual void SetUp() { - CHECK(target_thread_.Start()); - thread_blocker_.reset(new ThreadBlocker(&target_thread_)); - } - - virtual void TearDown() { - target_thread_.Stop(); - thread_blocker_.reset(); - } - - base::Thread target_thread_; - scoped_ptr<ThreadBlocker> thread_blocker_; - Flag flag_; - - private: - DISALLOW_COPY_AND_ASSIGN(ThreadBlockerTest); -}; - -TEST_F(ThreadBlockerTest, Basic) { - thread_blocker_->Block(); - target_thread_.message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(&flag_, &Flag::Set)); - EXPECT_FALSE(flag_.IsSet()); - thread_blocker_->Unblock(); - // Need to block again to make sure this thread waits for the posted - // method to run. - thread_blocker_->Block(); - EXPECT_TRUE(flag_.IsSet()); - thread_blocker_->Unblock(); -} - -TEST_F(ThreadBlockerTest, SetUnset) { - thread_blocker_->Block(); - target_thread_.message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(&flag_, &Flag::Set)); - target_thread_.message_loop()->PostTask( - FROM_HERE, NewRunnableMethod(&flag_, &Flag::Unset)); - EXPECT_FALSE(flag_.IsSet()); - thread_blocker_->Unblock(); - // Need to block again here too. - thread_blocker_->Block(); - EXPECT_FALSE(flag_.IsSet()); - thread_blocker_->Unblock(); -} - -} // namespace - -} // namespace chrome_common_net diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc index 683584d..c30d588 100644 --- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc +++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc @@ -15,7 +15,6 @@ #include "chrome/common/net/notifier/listener/mediator_thread_impl.h" #include "chrome/common/net/notifier/listener/talk_mediator_impl.h" #include "chrome/service/gaia/service_gaia_authenticator.h" -#include "chrome/service/net/service_network_change_notifier_thread.h" #include "chrome/service/service_process.h" #include "googleurl/src/gurl.h" @@ -305,9 +304,8 @@ void CloudPrintProxyBackend::Core::DoInitializeWithToken( const bool kConnectImmediately = false; const bool kInvalidateXmppAuthToken = false; talk_mediator_.reset(new notifier::TalkMediatorImpl( - new notifier::MediatorThreadImpl( - g_service_process->network_change_notifier_thread()), - kInitializeSsl, kConnectImmediately, kInvalidateXmppAuthToken)); + new notifier::MediatorThreadImpl(), kInitializeSsl, kConnectImmediately, + kInvalidateXmppAuthToken)); talk_mediator_->AddSubscribedServiceUrl(kCloudPrintTalkServiceUrl); talk_mediator_->SetDelegate(this); talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token, diff --git a/chrome/service/net/service_network_change_notifier_thread.cc b/chrome/service/net/service_network_change_notifier_thread.cc deleted file mode 100644 index 3ccd146..0000000 --- a/chrome/service/net/service_network_change_notifier_thread.cc +++ /dev/null @@ -1,46 +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. - -#include "chrome/service/net/service_network_change_notifier_thread.h" - -#include "base/logging.h" -#include "base/message_loop.h" -#include "net/base/network_change_notifier.h" - -ServiceNetworkChangeNotifierThread::ServiceNetworkChangeNotifierThread( - MessageLoop* io_thread_message_loop) - : io_thread_message_loop_(io_thread_message_loop) { - DCHECK(io_thread_message_loop_); -} - -ServiceNetworkChangeNotifierThread::~ServiceNetworkChangeNotifierThread() { - io_thread_message_loop_->DeleteSoon(FROM_HERE, - network_change_notifier_.release()); -} - -void ServiceNetworkChangeNotifierThread::Initialize() { - io_thread_message_loop_->PostTask( - FROM_HERE, - NewRunnableMethod( - this, - &ServiceNetworkChangeNotifierThread::CreateNetworkChangeNotifier)); -} - -MessageLoop* ServiceNetworkChangeNotifierThread::GetMessageLoop() const { - DCHECK(io_thread_message_loop_); - return io_thread_message_loop_; -} - -net::NetworkChangeNotifier* -ServiceNetworkChangeNotifierThread::GetNetworkChangeNotifier() const { - DCHECK(MessageLoop::current() == io_thread_message_loop_); - return network_change_notifier_.get(); -} - -void ServiceNetworkChangeNotifierThread::CreateNetworkChangeNotifier() { - DCHECK(MessageLoop::current() == io_thread_message_loop_); - network_change_notifier_.reset( - net::NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier()); -} - diff --git a/chrome/service/net/service_network_change_notifier_thread.h b/chrome/service/net/service_network_change_notifier_thread.h deleted file mode 100644 index 14975a6..0000000 --- a/chrome/service/net/service_network_change_notifier_thread.h +++ /dev/null @@ -1,50 +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 CHROME_SERVICE_NET_SERVICE_NETWORK_CHANGE_NOTIFIER_THREAD_H_ -#define CHROME_SERVICE_NET_SERVICE_NETWORK_CHANGE_NOTIFIER_THREAD_H_ - -#include "base/basictypes.h" -#include "base/ref_counted.h" -#include "base/scoped_ptr.h" -#include "chrome/common/net/network_change_notifier_thread.h" - -class MessageLoop; - -namespace net { -class NetworkChangeNotifier; -} // namespace net - -// This is a simple implementation of NetworkChangeNotifierThread. -// Note that Initialize MUST be called before this class can be used. -class ServiceNetworkChangeNotifierThread - : public chrome_common_net::NetworkChangeNotifierThread, - public base::RefCountedThreadSafe<ServiceNetworkChangeNotifierThread> { - public: - // Does not take ownership of |io_thread_message_loop|. This instance must - // live no longer than |io_thread_message_loop|. - // TODO(sanjeevr): Change NetworkChangeNotifierThread to use MessageLoopProxy - explicit ServiceNetworkChangeNotifierThread( - MessageLoop* io_thread_message_loop); - virtual ~ServiceNetworkChangeNotifierThread(); - - // Initialize MUST be called before this class can be used. - void Initialize(); - - // chrome_common_net::NetworkChangeNotifierThread implementation. - - virtual MessageLoop* GetMessageLoop() const; - - virtual net::NetworkChangeNotifier* GetNetworkChangeNotifier() const; - - private: - MessageLoop* const io_thread_message_loop_; - scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; - - void CreateNetworkChangeNotifier(); - DISALLOW_COPY_AND_ASSIGN(ServiceNetworkChangeNotifierThread); -}; - -#endif // CHROME_SERVICE_NET_SERVICE_NETWORK_CHANGE_NOTIFIER_THREAD_H_ - diff --git a/chrome/service/net/service_network_change_notifier_thread_unittest.cc b/chrome/service/net/service_network_change_notifier_thread_unittest.cc deleted file mode 100644 index 917d51a..0000000 --- a/chrome/service/net/service_network_change_notifier_thread_unittest.cc +++ /dev/null @@ -1,100 +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. - -#include "chrome/service/net/service_network_change_notifier_thread.h" - -#include "base/basictypes.h" -#include "base/message_loop.h" -#include "base/scoped_ptr.h" -#include "base/task.h" -#include "base/thread.h" -#include "chrome/common/net/thread_blocker.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -class ServiceNetworkChangeNotifierThreadTest : public testing::Test { - protected: - ServiceNetworkChangeNotifierThreadTest() - : io_thread_("ServiceNetworkChangeNotifierThreadTest_IO") { - } - - virtual ~ServiceNetworkChangeNotifierThreadTest() {} - - virtual void SetUp() { - // We need to set the message loop type explicitly because - // IOThread doesn't do it for us and the Linux - // NetworkChangeNotifier expects it. - base::Thread::Options options; - options.message_loop_type = MessageLoop::TYPE_IO; - EXPECT_TRUE(io_thread_.StartWithOptions(options)); - thread_blocker_.reset(new chrome_common_net::ThreadBlocker(&io_thread_)); - thread_blocker_->Block(); - } - - virtual void TearDown() { - // Nothing should be posted on |io_thread_| at this point. - thread_blocker_->Unblock(); - thread_blocker_.reset(); - io_thread_.Stop(); - } - - base::Thread io_thread_; - scoped_ptr<chrome_common_net::ThreadBlocker> thread_blocker_; - - private: - DISALLOW_COPY_AND_ASSIGN(ServiceNetworkChangeNotifierThreadTest); -}; - -void CheckNonNullNetworkChangeNotifier( - ServiceNetworkChangeNotifierThread* network_change_notifier_thread) { - EXPECT_EQ(network_change_notifier_thread->GetMessageLoop(), - MessageLoop::current()); - EXPECT_TRUE( - network_change_notifier_thread->GetNetworkChangeNotifier() != NULL); -} - -void CheckNullNetworkChangeNotifier( - ServiceNetworkChangeNotifierThread* network_change_notifier_thread) { - EXPECT_EQ(network_change_notifier_thread->GetMessageLoop(), - MessageLoop::current()); - EXPECT_TRUE( - network_change_notifier_thread->GetNetworkChangeNotifier() == NULL); -} - -TEST_F(ServiceNetworkChangeNotifierThreadTest, Basic) { - scoped_refptr<ServiceNetworkChangeNotifierThread> change_notifier_thread = - new ServiceNetworkChangeNotifierThread(io_thread_.message_loop()); - EXPECT_EQ(io_thread_.message_loop(), - change_notifier_thread->GetMessageLoop()); - change_notifier_thread->Initialize(); - io_thread_.message_loop()->PostTask( - FROM_HERE, - NewRunnableFunction(&CheckNonNullNetworkChangeNotifier, - change_notifier_thread.get())); - // Pump the thread to make sure the task we just posted is run - // before this test ends. - thread_blocker_->Unblock(); - thread_blocker_->Block(); -} - -TEST_F(ServiceNetworkChangeNotifierThreadTest, Uninitialized) { - scoped_refptr<ServiceNetworkChangeNotifierThread> change_notifier_thread = - new ServiceNetworkChangeNotifierThread(io_thread_.message_loop()); - EXPECT_EQ(io_thread_.message_loop(), - change_notifier_thread->GetMessageLoop()); - // We have not called Initialize. Expect the GetNetworkChangeNotifier() call - // to return NULL. - io_thread_.message_loop()->PostTask( - FROM_HERE, - NewRunnableFunction(&CheckNullNetworkChangeNotifier, - change_notifier_thread.get())); - // Pump the thread to make sure the task we just posted is run - // before this test ends. - thread_blocker_->Unblock(); - thread_blocker_->Block(); -} - -} // namespace - diff --git a/chrome/service/net/service_url_request_context.cc b/chrome/service/net/service_url_request_context.cc index 3ca57cd..ee416fe 100644 --- a/chrome/service/net/service_url_request_context.cc +++ b/chrome/service/net/service_url_request_context.cc @@ -21,7 +21,7 @@ ServiceURLRequestContextGetter::ServiceURLRequestContextGetter() } ServiceURLRequestContext::ServiceURLRequestContext() { - host_resolver_ = net::CreateSystemHostResolver(NULL); + host_resolver_ = net::CreateSystemHostResolver(); DCHECK(g_service_process); // TODO(sanjeevr): Change CreateSystemProxyConfigService to accept a // MessageLoopProxy* instead of MessageLoop*. @@ -30,13 +30,13 @@ ServiceURLRequestContext::ServiceURLRequestContext() { net::ProxyService::CreateSystemProxyConfigService( g_service_process->io_thread()->message_loop(), g_service_process->file_thread()->message_loop()); - proxy_service_ = net::ProxyService::Create(proxy_config_service, false, this, - NULL, NULL, NULL); + proxy_service_ = + net::ProxyService::Create(proxy_config_service, false, this, NULL, NULL); ftp_transaction_factory_ = new net::FtpNetworkLayer(host_resolver_); ssl_config_service_ = new net::SSLConfigServiceDefaults; http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault(); http_transaction_factory_ = new net::HttpCache( - net::HttpNetworkLayer::CreateFactory(NULL, host_resolver_, + net::HttpNetworkLayer::CreateFactory(host_resolver_, proxy_service_, ssl_config_service_, http_auth_handler_factory_, diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index 6e9baf2..09399f0 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -6,7 +6,7 @@ #include "base/stl_util-inl.h" #include "chrome/service/cloud_print/cloud_print_proxy.h" -#include "chrome/service/net/service_network_change_notifier_thread.h" +#include "net/base/network_change_notifier.h" ServiceProcess* g_service_process = NULL; @@ -16,6 +16,7 @@ ServiceProcess::ServiceProcess() { } bool ServiceProcess::Initialize() { + network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); base::Thread::Options options; options.message_loop_type = MessageLoop::TYPE_IO; io_thread_.reset(new base::Thread("ServiceProcess_IO")); @@ -26,17 +27,16 @@ bool ServiceProcess::Initialize() { Teardown(); return false; } - network_change_notifier_thread_ = - new ServiceNetworkChangeNotifierThread(io_thread_->message_loop()); - network_change_notifier_thread_->Initialize(); return true; } bool ServiceProcess::Teardown() { - network_change_notifier_thread_ = NULL; io_thread_.reset(); file_thread_.reset(); STLDeleteElements(&cloud_print_proxy_list_); + // The NetworkChangeNotifier must be destroyed after all other threads that + // might use it have been shut down. + network_change_notifier_.reset(); return true; } diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h index 287ecb2..10757fe 100644 --- a/chrome/service/service_process.h +++ b/chrome/service/service_process.h @@ -12,7 +12,9 @@ class CloudPrintProxy; class JsonPrefStore; -class ServiceNetworkChangeNotifierThread; +namespace net { +class NetworkChangeNotifier; +} // The ServiceProcess does not inherit from ChildProcess because this // process can live independently of the browser process. @@ -46,16 +48,12 @@ class ServiceProcess { return file_thread_.get(); } CloudPrintProxy* CreateCloudPrintProxy(JsonPrefStore* service_prefs); - ServiceNetworkChangeNotifierThread* network_change_notifier_thread() const { - return network_change_notifier_thread_.get(); - } private: + scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; scoped_ptr<base::Thread> io_thread_; scoped_ptr<base::Thread> file_thread_; std::vector<CloudPrintProxy*> cloud_print_proxy_list_; - scoped_refptr<ServiceNetworkChangeNotifierThread> - network_change_notifier_thread_; DISALLOW_COPY_AND_ASSIGN(ServiceProcess); }; diff --git a/chrome_frame/test/test_server_test.cc b/chrome_frame/test/test_server_test.cc index f658f0f..3e762a0 100644 --- a/chrome_frame/test/test_server_test.cc +++ b/chrome_frame/test/test_server_test.cc @@ -61,19 +61,14 @@ class ScopedInternet { class URLRequestTestContext : public URLRequestContext { public: URLRequestTestContext() { - host_resolver_ = net::CreateSystemHostResolver(NULL); + host_resolver_ = net::CreateSystemHostResolver(); proxy_service_ = net::ProxyService::CreateNull(); ssl_config_service_ = new net::SSLConfigServiceDefaults; http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault(); - http_transaction_factory_ = - new net::HttpCache( - net::HttpNetworkLayer::CreateFactory(NULL, host_resolver_, - proxy_service_, - ssl_config_service_, - http_auth_handler_factory_, - NULL, - NULL), - net::HttpCache::DefaultBackend::InMemory(0)); + http_transaction_factory_ = new net::HttpCache( + net::HttpNetworkLayer::CreateFactory(host_resolver_, proxy_service_, + ssl_config_service_, http_auth_handler_factory_, NULL, NULL), + net::HttpCache::DefaultBackend::InMemory(0)); // In-memory cookie store. cookie_store_ = new net::CookieMonster(NULL, NULL); } diff --git a/net/base/host_resolver.h b/net/base/host_resolver.h index d798688..395fc65 100644 --- a/net/base/host_resolver.h +++ b/net/base/host_resolver.h @@ -21,7 +21,6 @@ class AddressList; class BoundNetLog; class HostCache; class HostResolverImpl; -class NetworkChangeNotifier; // This class represents the task of resolving hostnames (or IP address // literal) to an AddressList object. @@ -236,10 +235,7 @@ class SingleRequestHostResolver { // Creates a HostResolver implementation that queries the underlying system. // (Except if a unit-test has changed the global HostResolverProc using // ScopedHostResolverProc to intercept requests to the system). -// |network_change_notifier| must outlive HostResolver. It can optionally be -// NULL, in which case HostResolver will not respond to network changes. -HostResolver* CreateSystemHostResolver( - NetworkChangeNotifier* network_change_notifier); +HostResolver* CreateSystemHostResolver(); } // namespace net diff --git a/net/base/host_resolver_impl.cc b/net/base/host_resolver_impl.cc index c018a7a..5685fc4 100644 --- a/net/base/host_resolver_impl.cc +++ b/net/base/host_resolver_impl.cc @@ -29,7 +29,6 @@ #include "net/base/net_log.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" -#include "net/base/network_change_notifier.h" #if defined(OS_WIN) #include "net/base/winsock_init.h" @@ -52,14 +51,13 @@ HostCache* CreateDefaultCache() { } // anonymous namespace -HostResolver* CreateSystemHostResolver( - NetworkChangeNotifier* network_change_notifier) { +HostResolver* CreateSystemHostResolver() { // Maximum of 50 concurrent threads. // TODO(eroman): Adjust this, do some A/B experiments. static const size_t kMaxJobs = 50u; - HostResolverImpl* resolver = new HostResolverImpl( - NULL, CreateDefaultCache(), network_change_notifier, kMaxJobs); + HostResolverImpl* resolver = + new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs); return resolver; } @@ -704,7 +702,6 @@ class HostResolverImpl::JobPool { HostResolverImpl::HostResolverImpl( HostResolverProc* resolver_proc, HostCache* cache, - NetworkChangeNotifier* network_change_notifier, size_t max_jobs) : cache_(cache), max_jobs_(max_jobs), @@ -713,7 +710,6 @@ HostResolverImpl::HostResolverImpl( resolver_proc_(resolver_proc), default_address_family_(ADDRESS_FAMILY_UNSPECIFIED), shutdown_(false), - network_change_notifier_(network_change_notifier), ipv6_probe_monitoring_(false) { DCHECK_GT(max_jobs, 0u); @@ -724,8 +720,7 @@ HostResolverImpl::HostResolverImpl( #if defined(OS_WIN) EnsureWinsockInit(); #endif - if (network_change_notifier_) - network_change_notifier_->AddObserver(this); + NetworkChangeNotifier::AddObserver(this); } HostResolverImpl::~HostResolverImpl() { @@ -740,8 +735,7 @@ HostResolverImpl::~HostResolverImpl() { if (cur_completing_job_) cur_completing_job_->Cancel(); - if (network_change_notifier_) - network_change_notifier_->RemoveObserver(this); + NetworkChangeNotifier::RemoveObserver(this); // Delete the job pools. for (size_t i = 0u; i < arraysize(job_pools_); ++i) diff --git a/net/base/host_resolver_impl.h b/net/base/host_resolver_impl.h index a0e34ca..2a751fb 100644 --- a/net/base/host_resolver_impl.h +++ b/net/base/host_resolver_impl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -73,13 +73,10 @@ class HostResolverImpl : public HostResolver, // thread-safe since it is run from multiple worker threads. If // |resolver_proc| is NULL then the default host resolver procedure is // used (which is SystemHostResolverProc except if overridden). - // |notifier| must outlive HostResolverImpl. It can optionally be NULL, in - // which case HostResolverImpl will not respond to network changes. // |max_jobs| specifies the maximum number of threads that the host resolver // will use. Use SetPoolConstraints() to specify finer-grain settings. HostResolverImpl(HostResolverProc* resolver_proc, HostCache* cache, - NetworkChangeNotifier* notifier, size_t max_jobs); // HostResolver methods: @@ -247,8 +244,6 @@ class HostResolverImpl : public HostResolver, // TODO(eroman): hack for http://crbug.com/15513 bool shutdown_; - NetworkChangeNotifier* const network_change_notifier_; - // Indicate if probing is done after each network change event to set address // family. // When false, explicit setting of address family is used. diff --git a/net/base/host_resolver_impl_unittest.cc b/net/base/host_resolver_impl_unittest.cc index 3d7e02a..6b33a56 100644 --- a/net/base/host_resolver_impl_unittest.cc +++ b/net/base/host_resolver_impl_unittest.cc @@ -13,7 +13,6 @@ #include "net/base/address_list.h" #include "net/base/completion_callback.h" #include "net/base/mock_host_resolver.h" -#include "net/base/mock_network_change_notifier.h" #include "net/base/net_errors.h" #include "net/base/net_log_unittest.h" #include "net/base/net_util.h" @@ -39,11 +38,7 @@ HostCache* CreateDefaultCache() { static const size_t kMaxJobs = 10u; HostResolverImpl* CreateHostResolverImpl(HostResolverProc* resolver_proc) { - return new HostResolverImpl( - resolver_proc, - CreateDefaultCache(), - NULL, // network_change_notifier - kMaxJobs); + return new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs); } // Helper to create a HostResolver::RequestInfo. @@ -748,7 +743,7 @@ TEST_F(HostResolverImplTest, StartWithinCallback) { // Turn off caching for this host resolver. scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, NULL, NULL, kMaxJobs)); + new HostResolverImpl(resolver_proc, NULL, kMaxJobs)); // The class will receive callbacks for when each resolve completes. It // checks that the right things happened. @@ -1044,11 +1039,8 @@ TEST_F(HostResolverImplTest, CancellationObserver) { // Test that IP address changes flush the cache. TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { - MockNetworkChangeNotifier mock_network_change_notifier; scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(NULL, CreateDefaultCache(), - &mock_network_change_notifier, - kMaxJobs)); + new HostResolverImpl(NULL, CreateDefaultCache(), kMaxJobs)); AddressList addrlist; @@ -1066,7 +1058,8 @@ TEST_F(HostResolverImplTest, FlushCacheOnIPAddressChange) { ASSERT_EQ(OK, rv); // Should complete synchronously. // Flush cache by triggering an IP address change. - mock_network_change_notifier.NotifyIPAddressChange(); + NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); + MessageLoop::current()->RunAllPending(); // Notification happens async. // Resolve "host1" again -- this time it won't be served from cache, so it // will complete asynchronously. @@ -1084,8 +1077,7 @@ TEST_F(HostResolverImplTest, HigherPriorityRequestsStartedFirst) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. size_t kMaxJobs = 1u; scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, CreateDefaultCache(), - NULL, kMaxJobs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs)); CapturingObserver observer; host_resolver->AddObserver(&observer); @@ -1169,8 +1161,7 @@ TEST_F(HostResolverImplTest, CancelPendingRequest) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxJobs = 1u; scoped_refptr<HostResolver> host_resolver( - new HostResolverImpl(resolver_proc, CreateDefaultCache(), - NULL, kMaxJobs)); + new HostResolverImpl(resolver_proc, CreateDefaultCache(), kMaxJobs)); // Note that at this point the CapturingHostResolverProc is blocked, so any // requests we make will not complete. @@ -1231,9 +1222,8 @@ TEST_F(HostResolverImplTest, QueueOverflow) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxOutstandingJobs = 1u; - scoped_refptr<HostResolverImpl> host_resolver( - new HostResolverImpl(resolver_proc, CreateDefaultCache(), - NULL, kMaxOutstandingJobs)); + scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( + resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); // Only allow up to 3 requests to be enqueued at a time. const size_t kMaxPendingRequests = 3u; @@ -1310,9 +1300,8 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv4) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxOutstandingJobs = 1u; - scoped_refptr<HostResolverImpl> host_resolver( - new HostResolverImpl(resolver_proc, CreateDefaultCache(), - NULL, kMaxOutstandingJobs)); + scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( + resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); @@ -1379,9 +1368,8 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_IPv6) { // This HostResolverImpl will only allow 1 outstanding resolve at a time. const size_t kMaxOutstandingJobs = 1u; - scoped_refptr<HostResolverImpl> host_resolver( - new HostResolverImpl(resolver_proc, CreateDefaultCache(), - NULL, kMaxOutstandingJobs)); + scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( + resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV6); @@ -1446,9 +1434,8 @@ TEST_F(HostResolverImplTest, SetDefaultAddressFamily_Synchronous) { new CapturingHostResolverProc(new EchoingHostResolverProc); const size_t kMaxOutstandingJobs = 10u; - scoped_refptr<HostResolverImpl> host_resolver( - new HostResolverImpl(resolver_proc, CreateDefaultCache(), - NULL, kMaxOutstandingJobs)); + scoped_refptr<HostResolverImpl> host_resolver(new HostResolverImpl( + resolver_proc, CreateDefaultCache(), kMaxOutstandingJobs)); host_resolver->SetDefaultAddressFamily(ADDRESS_FAMILY_IPV4); diff --git a/net/base/mock_host_resolver.cc b/net/base/mock_host_resolver.cc index 1ee9bb1..8d1fd89 100644 --- a/net/base/mock_host_resolver.cc +++ b/net/base/mock_host_resolver.cc @@ -98,7 +98,7 @@ void MockHostResolverBase::Reset(HostResolverProc* interceptor) { base::TimeDelta::FromSeconds(0)); } - impl_ = new HostResolverImpl(proc, cache, NULL, 50u); + impl_ = new HostResolverImpl(proc, cache, 50u); } //----------------------------------------------------------------------------- diff --git a/net/base/mock_network_change_notifier.h b/net/base/mock_network_change_notifier.h deleted file mode 100644 index 7d1b38e..0000000 --- a/net/base/mock_network_change_notifier.h +++ /dev/null @@ -1,46 +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_BASE_MOCK_NETWORK_CHANGE_NOTIFIER_H_ -#define NET_BASE_MOCK_NETWORK_CHANGE_NOTIFIER_H_ - -#include "base/basictypes.h" -#include "base/non_thread_safe.h" -#include "net/base/network_change_notifier.h" - -namespace net { - -class MockNetworkChangeNotifier : public NetworkChangeNotifier, - public NonThreadSafe { - public: - MockNetworkChangeNotifier() : observer_(NULL) {} - - virtual ~MockNetworkChangeNotifier() { - CHECK(!observer_); - } - - void NotifyIPAddressChange() { - if (observer_) - observer_->OnIPAddressChanged(); - } - - virtual void AddObserver(Observer* observer) { - CHECK(!observer_); - observer_ = observer; - } - - virtual void RemoveObserver(Observer* observer) { - CHECK(observer_ == observer); - observer_ = NULL; - } - - private: - Observer* observer_; - - DISALLOW_COPY_AND_ASSIGN(MockNetworkChangeNotifier); -}; - -} // namespace net - -#endif // NET_BASE_MOCK_NETWORK_CHANGE_NOTIFIER_H_ diff --git a/net/base/net_test_suite.h b/net/base/net_test_suite.h index af58ca7..cc4ed2a 100644 --- a/net/base/net_test_suite.h +++ b/net/base/net_test_suite.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -25,6 +25,8 @@ class NetTestSuite : public TestSuite { // TestSuite::Initialize(). TestSuite::Initialize() performs some global // initialization that can only be done once. void InitializeTestThread() { + network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); + host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL); scoped_host_resolver_proc_.Init(host_resolver_proc_.get()); // In case any attempts are made to resolve host names, force them all to @@ -44,6 +46,7 @@ class NetTestSuite : public TestSuite { } private: + scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; scoped_ptr<MessageLoop> message_loop_; scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc index aeca2ab..a0bc6b5 100644 --- a/net/base/network_change_notifier.cc +++ b/net/base/network_change_notifier.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -14,9 +14,22 @@ namespace net { -// static -NetworkChangeNotifier* -NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier() { +namespace { + +// The actual singleton notifier. The class contract forbids usage of the API +// in ways that would require us to place locks around access to this object. +// (The prohibition on global non-POD objects makes it tricky to do such a thing +// anyway.) +NetworkChangeNotifier* g_network_change_notifier = NULL; + +} // namespace + +NetworkChangeNotifier::~NetworkChangeNotifier() { + DCHECK_EQ(this, g_network_change_notifier); + g_network_change_notifier = NULL; +} + +NetworkChangeNotifier* NetworkChangeNotifier::Create() { #if defined(OS_WIN) return new NetworkChangeNotifierWin(); #elif defined(OS_LINUX) @@ -29,4 +42,27 @@ NetworkChangeNotifier::CreateDefaultNetworkChangeNotifier() { #endif } +void NetworkChangeNotifier::AddObserver(Observer* observer) { + if (g_network_change_notifier) + g_network_change_notifier->observer_list_->AddObserver(observer); +} + +void NetworkChangeNotifier::RemoveObserver(Observer* observer) { + if (g_network_change_notifier) + g_network_change_notifier->observer_list_->RemoveObserver(observer); +} + +NetworkChangeNotifier::NetworkChangeNotifier() + : observer_list_(new ObserverListThreadSafe<Observer>()) { + DCHECK(!g_network_change_notifier); + g_network_change_notifier = this; +} + +void NetworkChangeNotifier::NotifyObserversOfIPAddressChange() { + if (g_network_change_notifier) { + g_network_change_notifier->observer_list_->Notify( + &Observer::OnIPAddressChanged); + } +} + } // namespace net diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h index 70b195d..e0a8800 100644 --- a/net/base/network_change_notifier.h +++ b/net/base/network_change_notifier.h @@ -6,11 +6,13 @@ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ #include "base/basictypes.h" +#include "base/observer_list_threadsafe.h" namespace net { // NetworkChangeNotifier monitors the system for network changes, and notifies -// observers on those events. +// registered observers of those events. Observers may register on any thread, +// and will be called back on the thread from which they registered. class NetworkChangeNotifier { public: class Observer { @@ -28,21 +30,58 @@ class NetworkChangeNotifier { DISALLOW_COPY_AND_ASSIGN(Observer); }; - NetworkChangeNotifier() {} - virtual ~NetworkChangeNotifier() {} + virtual ~NetworkChangeNotifier(); - // These functions add and remove observers to/from the NetworkChangeNotifier. - // Each call to AddObserver() must be matched with a corresponding call to - // RemoveObserver() with the same parameter. Observers must remove themselves - // before they get deleted, otherwise the NetworkChangeNotifier may try to - // notify the wrong object. - virtual void AddObserver(Observer* observer) = 0; - virtual void RemoveObserver(Observer* observer) = 0; + // Creates the process-wide, platform-specific NetworkChangeNotifier. The + // caller owns the returned pointer. You may call this on any thread. You + // may also avoid creating this entirely (in which case nothing will be + // monitored), but if you do create it, you must do so before any other + // threads try to access the API below, and it must outlive all other threads + // which might try to use it. + static NetworkChangeNotifier* Create(); - // This will create the platform specific default NetworkChangeNotifier. - static NetworkChangeNotifier* CreateDefaultNetworkChangeNotifier(); +#ifdef UNIT_TEST + // Like Create(), but for use in tests. The mock object doesn't monitor any + // events, it merely rebroadcasts notifications when requested. + static NetworkChangeNotifier* CreateMock() { + return new NetworkChangeNotifier(); + } +#endif + + // Registers |observer| to receive notifications of network changes. The + // thread on which this is called is the thread on which |observer| will be + // called back with notifications. This is safe to call if Create() has not + // been called (as long as it doesn't race the Create() call on another + // thread), in which case it will simply do nothing. + static void AddObserver(Observer* observer); + + // Unregisters |observer| from receiving notifications. This must be called + // on the same thread on which AddObserver() was called. Like AddObserver(), + // this is safe to call if Create() has not been called (as long as it doesn't + // race the Create() call on another thread), in which case it will simply do + // nothing. Technically, it's also safe to call after the notifier object has + // been destroyed, if the call doesn't race the notifier's destruction, but + // there's no reason to use the API in this risky way, so don't do it. + static void RemoveObserver(Observer* observer); + +#ifdef UNIT_TEST + // Allow unit tests to trigger notifications. + static void NotifyObserversOfIPAddressChangeForTests() { + NotifyObserversOfIPAddressChange(); + } +#endif + + protected: + NetworkChangeNotifier(); + + // Broadcasts a notification to all registered observers. Note that this + // happens asynchronously, even for observers on the current thread, even in + // tests. + static void NotifyObserversOfIPAddressChange(); private: + const scoped_refptr<ObserverListThreadSafe<Observer> > observer_list_; + DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); }; diff --git a/net/base/network_change_notifier_linux.cc b/net/base/network_change_notifier_linux.cc index 9821be5..aa58c14 100644 --- a/net/base/network_change_notifier_linux.cc +++ b/net/base/network_change_notifier_linux.cc @@ -7,13 +7,15 @@ #include <errno.h> #include <sys/socket.h> -#include "base/basictypes.h" #include "base/eintr_wrapper.h" -#include "base/logging.h" -#include "base/message_loop.h" +#include "base/task.h" +#include "base/thread.h" #include "net/base/net_errors.h" #include "net/base/network_change_notifier_netlink_linux.h" +// We only post tasks to a child thread we own, so we don't need refcounting. +DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkChangeNotifierLinux); + namespace net { namespace { @@ -23,122 +25,115 @@ const int kInvalidSocket = -1; } // namespace NetworkChangeNotifierLinux::NetworkChangeNotifierLinux() - : netlink_fd_(kInvalidSocket), -#if defined(OS_CHROMEOS) - ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), -#endif - loop_(MessageLoopForIO::current()) { - netlink_fd_ = InitializeNetlinkSocket(); - if (netlink_fd_ < 0) { - netlink_fd_ = kInvalidSocket; - return; - } - - ListenForNotifications(); - loop_->AddDestructionObserver(this); + : notifier_thread_(new base::Thread("NetworkChangeNotifier")), + netlink_fd_(kInvalidSocket) { + // We create this notifier thread because the notification implementation + // needs a MessageLoopForIO, and there's no guarantee that + // MessageLoop::current() meets that criterion. + base::Thread::Options thread_options(MessageLoop::TYPE_IO, 0); + notifier_thread_->StartWithOptions(thread_options); + notifier_thread_->message_loop()->PostTask(FROM_HERE, + NewRunnableMethod(this, &NetworkChangeNotifierLinux::Init)); } NetworkChangeNotifierLinux::~NetworkChangeNotifierLinux() { - DCHECK(CalledOnValidThread()); - StopWatching(); - - if (loop_) - loop_->RemoveDestructionObserver(this); + // We don't need to explicitly Stop(), but doing so allows us to sanity- + // check that the notifier thread shut down properly. + notifier_thread_->Stop(); + DCHECK_EQ(kInvalidSocket, netlink_fd_); } -void NetworkChangeNotifierLinux::AddObserver(Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.AddObserver(observer); -} +void NetworkChangeNotifierLinux::WillDestroyCurrentMessageLoop() { + DCHECK(notifier_thread_ != NULL); + // We can't check the notifier_thread_'s message_loop(), as it's now 0. + // DCHECK_EQ(notifier_thread_->message_loop(), MessageLoop::current()); -void NetworkChangeNotifierLinux::RemoveObserver(Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.RemoveObserver(observer); + if (netlink_fd_ != kInvalidSocket) { + if (HANDLE_EINTR(close(netlink_fd_)) != 0) + PLOG(ERROR) << "Failed to close socket"; + netlink_fd_ = kInvalidSocket; + netlink_watcher_.StopWatchingFileDescriptor(); + } } void NetworkChangeNotifierLinux::OnFileCanReadWithoutBlocking(int fd) { - DCHECK(CalledOnValidThread()); - DCHECK_EQ(fd, netlink_fd_); + DCHECK(notifier_thread_ != NULL); + DCHECK_EQ(notifier_thread_->message_loop(), MessageLoop::current()); + DCHECK_EQ(fd, netlink_fd_); ListenForNotifications(); } void NetworkChangeNotifierLinux::OnFileCanWriteWithoutBlocking(int /* fd */) { - DCHECK(CalledOnValidThread()); + DCHECK(notifier_thread_ != NULL); + DCHECK_EQ(notifier_thread_->message_loop(), MessageLoop::current()); + NOTREACHED(); } -void NetworkChangeNotifierLinux::WillDestroyCurrentMessageLoop() { - DCHECK(CalledOnValidThread()); - StopWatching(); - loop_ = NULL; +void NetworkChangeNotifierLinux::Init() { + DCHECK(notifier_thread_ != NULL); + DCHECK_EQ(notifier_thread_->message_loop(), MessageLoop::current()); + + netlink_fd_ = InitializeNetlinkSocket(); + if (netlink_fd_ < 0) { + netlink_fd_ = kInvalidSocket; + return; + } + MessageLoop::current()->AddDestructionObserver(this); + ListenForNotifications(); } void NetworkChangeNotifierLinux::ListenForNotifications() { - DCHECK(CalledOnValidThread()); + DCHECK(notifier_thread_ != NULL); + DCHECK_EQ(notifier_thread_->message_loop(), MessageLoop::current()); + char buf[4096]; int rv = ReadNotificationMessage(buf, arraysize(buf)); - while (rv > 0 ) { + while (rv > 0) { if (HandleNetlinkMessage(buf, rv)) { LOG(INFO) << "Detected IP address changes."; - #if defined(OS_CHROMEOS) // TODO(zelidrag): chromium-os:3996 - introduced artificial delay to // work around the issue of proxy initialization before name resolving // is functional in ChromeOS. This should be removed once this bug // is properly fixed. - MessageLoop::current()->PostDelayedTask( - FROM_HERE, - factory_.NewRunnableMethod( - &NetworkChangeNotifierLinux::NotifyObserversIPAddressChanged), - 500); + const int kObserverNotificationDelayMS = 500; + MessageLoop::current()->PostDelayedTask(FROM_HERE, NewRunnableMethod( + &NetworkChangeNotifier::NotifyObserversOfIPAddressChange), + kObserverNotificationDelayMS); #else - NotifyObserversIPAddressChanged(); + NotifyObserversOfIPAddressChange(); #endif } rv = ReadNotificationMessage(buf, arraysize(buf)); } if (rv == ERR_IO_PENDING) { - rv = loop_->WatchFileDescriptor( - netlink_fd_, false, MessageLoopForIO::WATCH_READ, &netlink_watcher_, - this); + rv = MessageLoopForIO::current()->WatchFileDescriptor(netlink_fd_, false, + MessageLoopForIO::WATCH_READ, &netlink_watcher_, this); LOG_IF(ERROR, !rv) << "Failed to watch netlink socket: " << netlink_fd_; } } -void NetworkChangeNotifierLinux::NotifyObserversIPAddressChanged() { - FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged()); -} - int NetworkChangeNotifierLinux::ReadNotificationMessage(char* buf, size_t len) { - DCHECK(CalledOnValidThread()); + DCHECK(notifier_thread_ != NULL); + DCHECK_EQ(notifier_thread_->message_loop(), MessageLoop::current()); + DCHECK_NE(len, 0u); DCHECK(buf); - memset(buf, 0, sizeof(buf)); int rv = recv(netlink_fd_, buf, len, 0); - if (rv > 0) { + if (rv > 0) return rv; - } else { - DCHECK_NE(rv, 0); - if (errno != EAGAIN && errno != EWOULDBLOCK) { - PLOG(DFATAL) << "recv"; - return ERR_FAILED; - } - return ERR_IO_PENDING; + DCHECK_NE(rv, 0); + if (errno != EAGAIN && errno != EWOULDBLOCK) { + PLOG(DFATAL) << "recv"; + return ERR_FAILED; } -} -void NetworkChangeNotifierLinux::StopWatching() { - DCHECK(CalledOnValidThread()); - if (netlink_fd_ != kInvalidSocket) { - if (HANDLE_EINTR(close(netlink_fd_)) != 0) - PLOG(ERROR) << "Failed to close socket"; - netlink_fd_ = kInvalidSocket; - netlink_watcher_.StopWatchingFileDescriptor(); - } + return ERR_IO_PENDING; } } // namespace net diff --git a/net/base/network_change_notifier_linux.h b/net/base/network_change_notifier_linux.h index dcedbf4..aca9377 100644 --- a/net/base/network_change_notifier_linux.h +++ b/net/base/network_change_notifier_linux.h @@ -7,37 +7,34 @@ #include "base/basictypes.h" #include "base/message_loop.h" -#include "base/non_thread_safe.h" -#include "base/observer_list.h" +#include "base/scoped_ptr.h" #include "net/base/network_change_notifier.h" -#if defined(OS_CHROMEOS) -#include "base/task.h" -#endif +namespace base { +class Thread; +} namespace net { -class NetworkChangeNotifierLinux - : public NetworkChangeNotifier, - public NonThreadSafe, - public MessageLoopForIO::Watcher, - public MessageLoop::DestructionObserver { +class NetworkChangeNotifierLinux : public MessageLoop::DestructionObserver, + public MessageLoopForIO::Watcher, + public NetworkChangeNotifier { public: NetworkChangeNotifierLinux(); - // NetworkChangeNotifier methods: - virtual void AddObserver(Observer* observer); - virtual void RemoveObserver(Observer* observer); + private: + virtual ~NetworkChangeNotifierLinux(); + + // MessageLoop::DestructionObserver: + virtual void WillDestroyCurrentMessageLoop(); - // MessageLoopForIO::Watcher methods: + // MessageLoopForIO::Watcher: virtual void OnFileCanReadWithoutBlocking(int fd); virtual void OnFileCanWriteWithoutBlocking(int /* fd */); - // MessageLoop::DestructionObserver methods: - virtual void WillDestroyCurrentMessageLoop(); - - private: - virtual ~NetworkChangeNotifierLinux(); + // Called on the notifier thread to initialize the notification + // implementation. + void Init(); // Starts listening for netlink messages. Also handles the messages if there // are any available on the netlink socket. @@ -48,21 +45,14 @@ class NetworkChangeNotifierLinux // recv() would block. Otherwise, it returns a net error code. int ReadNotificationMessage(char* buf, size_t len); - // Stops watching the netlink file descriptor. - void StopWatching(); - - void NotifyObserversIPAddressChanged(); - - // http://crbug.com/36890. - ObserverList<Observer, false> observers_; - - int netlink_fd_; // This is the netlink socket descriptor. + // The thread used to listen for notifications. This relays the notification + // to the registered observers without posting back to the thread the object + // was created on. + scoped_ptr<base::Thread> notifier_thread_; -#if defined(OS_CHROMEOS) - ScopedRunnableMethodFactory<NetworkChangeNotifierLinux> factory_; -#endif + // The netlink socket descriptor. + int netlink_fd_; - MessageLoopForIO* loop_; MessageLoopForIO::FileDescriptorWatcher netlink_watcher_; DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierLinux); diff --git a/net/base/network_change_notifier_mac.cc b/net/base/network_change_notifier_mac.cc index ba38907..797de6d 100644 --- a/net/base/network_change_notifier_mac.cc +++ b/net/base/network_change_notifier_mac.cc @@ -2,168 +2,116 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// There are three classes involved here. There's NetworkChangeNotifierMac, -// which is the Mac specific implementation of NetworkChangeNotifier. It is the -// class with which clients can register themselves as network change -// observers. There's NetworkChangeNotifierThread, which is a base::Thread -// subclass of MessageLoop::TYPE_UI (since it needs a CFRunLoop) that contains -// the NetworkChangeNotifierImpl. NetworkChangeNotifierImpl is the object -// that receives the actual OS X notifications and posts them to the -// NetworkChangeNotifierMac's message loop, so that NetworkChangeNotifierMac -// can notify all its observers. -// -// When NetworkChangeNotifierMac is being deleted, it will delete the -// NetworkChangeNotifierThread, which will Stop() it and also delete the -// NetworkChangeNotifierImpl. Therefore, NetworkChangeNotifierImpl and -// NetworkChangeNotifierThread's lifetimes generally begin after and end before -// NetworkChangeNotifierMac. There is an edge case where a notification task -// gets posted to the IO thread, thereby maintaining a reference to -// NetworkChangeNotifierImpl beyond the lifetime of NetworkChangeNotifierThread. -// In this case, the notification is cancelled, and NetworkChangeNotifierImpl -// will be deleted once all notification tasks that reference it have been run. - #include "net/base/network_change_notifier_mac.h" -#include <SystemConfiguration/SCDynamicStore.h> + #include <SystemConfiguration/SCDynamicStoreKey.h> #include <SystemConfiguration/SCSchemaDefinitions.h> #include <algorithm> -#include "base/logging.h" -#include "base/message_loop.h" -#include "base/scoped_cftyperef.h" -#include "base/thread.h" - -namespace net { -namespace { - -// NetworkChangeNotifierImpl should be created on a thread with a CFRunLoop, -// since it requires one to pump notifications. However, it also runs some -// methods on |notifier_loop_|, because it cannot post calls to |notifier_| -// since NetworkChangeNotifier is not ref counted in a thread safe manner. -class NetworkChangeNotifierImpl - : public base::RefCountedThreadSafe<NetworkChangeNotifierImpl> { - public: - NetworkChangeNotifierImpl(MessageLoop* notifier_loop, - NetworkChangeNotifierMac* notifier); +#include "base/thread.h" - void Shutdown(); +// We only post tasks to a child thread we own, so we don't need refcounting. +DISABLE_RUNNABLE_METHOD_REFCOUNT(net::NetworkChangeNotifierMac); - private: - friend class base::RefCountedThreadSafe<NetworkChangeNotifierImpl>; - ~NetworkChangeNotifierImpl(); +namespace net { - static void DynamicStoreCallback(SCDynamicStoreRef /* store */, - CFArrayRef changed_keys, - void* config); +NetworkChangeNotifierMac::NetworkChangeNotifierMac() + : notifier_thread_(new base::Thread("NetworkChangeNotifier")) { + // We create this notifier thread because the notification implementation + // needs a thread with a CFRunLoop, and there's no guarantee that + // MessageLoop::current() meets that criterion. + base::Thread::Options thread_options(MessageLoop::TYPE_UI, 0); + notifier_thread_->StartWithOptions(thread_options); + // TODO(willchan): Look to see if there's a better signal for when it's ok to + // initialize this, rather than just delaying it by a fixed time. + const int kNotifierThreadInitializationDelayMS = 1000; + notifier_thread_->message_loop()->PostDelayedTask(FROM_HERE, + NewRunnableMethod(this, &NetworkChangeNotifierMac::Init), + kNotifierThreadInitializationDelayMS); +} - void OnNetworkConfigChange(CFArrayRef changed_keys); +NetworkChangeNotifierMac::~NetworkChangeNotifierMac() { + // We don't need to explicitly Stop(), but doing so allows us to sanity- + // check that the notifier thread shut down properly. + notifier_thread_->Stop(); + DCHECK(run_loop_source_ == NULL); +} - // Runs on |notifier_loop_|. - void OnIPAddressChanged(); +// static +void NetworkChangeNotifierMac::DynamicStoreCallback( + SCDynamicStoreRef /* store */, + CFArrayRef changed_keys, + void* config) { + NetworkChangeNotifierMac* net_config = + static_cast<NetworkChangeNotifierMac*>(config); + net_config->OnNetworkConfigChange(changed_keys); +} - // Raw pointers. Note that |notifier_| _must_ outlive the - // NetworkChangeNotifierImpl. For lifecycle management details, read the - // comment at the top of the file. - MessageLoop* const notifier_loop_; - NetworkChangeNotifierMac* notifier_; +void NetworkChangeNotifierMac::WillDestroyCurrentMessageLoop() { + DCHECK(notifier_thread_ != NULL); + // We can't check the notifier_thread_'s message_loop(), as it's now 0. + // DCHECK_EQ(notifier_thread_->message_loop(), MessageLoop::current()); - scoped_cftyperef<CFRunLoopSourceRef> source_; + DCHECK(run_loop_source_ != NULL); + CFRunLoopRemoveSource(CFRunLoopGetCurrent(), run_loop_source_.get(), + kCFRunLoopCommonModes); + run_loop_source_.reset(); +} - DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierImpl); -}; +void NetworkChangeNotifierMac::Init() { + DCHECK(notifier_thread_ != NULL); + DCHECK_EQ(notifier_thread_->message_loop(), MessageLoop::current()); -NetworkChangeNotifierImpl::NetworkChangeNotifierImpl( - MessageLoop* notifier_loop, NetworkChangeNotifierMac* notifier) - : notifier_loop_(notifier_loop), - notifier_(notifier) { - DCHECK_EQ(MessageLoop::TYPE_UI, MessageLoop::current()->type()); + // Add a run loop source for a dynamic store to the current run loop. SCDynamicStoreContext context = { - 0, // Version 0. - this, // User data. - NULL, // This is not reference counted. No retain function. - NULL, // This is not reference counted. No release function. - NULL, // No description for this. + 0, // Version 0. + this, // User data. + NULL, // This is not reference counted. No retain function. + NULL, // This is not reference counted. No release function. + NULL, // No description for this. }; - - // Get a reference to the dynamic store. - scoped_cftyperef<SCDynamicStoreRef> store( - SCDynamicStoreCreate(NULL /* use default allocator */, - CFSTR("org.chromium"), - DynamicStoreCallback, &context)); - - // Create a run loop source for the dynamic store. - source_.reset(SCDynamicStoreCreateRunLoopSource( - NULL /* use default allocator */, - store.get(), - 0 /* 0 sounds like a fine source order to me! */)); - - // Add the run loop source to the current run loop. - CFRunLoopAddSource(CFRunLoopGetCurrent(), - source_.get(), + scoped_cftyperef<SCDynamicStoreRef> store(SCDynamicStoreCreate( + NULL, CFSTR("org.chromium"), DynamicStoreCallback, &context)); + run_loop_source_.reset(SCDynamicStoreCreateRunLoopSource( + NULL, store.get(), 0)); + CFRunLoopAddSource(CFRunLoopGetCurrent(), run_loop_source_.get(), kCFRunLoopCommonModes); - // Set up the notification keys. + // Set up notifications for interface and IP address changes. scoped_cftyperef<CFMutableArrayRef> notification_keys( CFArrayCreateMutable(kCFAllocatorDefault, 0, &kCFTypeArrayCallBacks)); - - // Monitor interface changes. - scoped_cftyperef<CFStringRef> key( - SCDynamicStoreKeyCreateNetworkGlobalEntity( - NULL /* default allocator */, kSCDynamicStoreDomainState, - kSCEntNetInterface)); + scoped_cftyperef<CFStringRef> key(SCDynamicStoreKeyCreateNetworkGlobalEntity( + NULL, kSCDynamicStoreDomainState, kSCEntNetInterface)); CFArrayAppendValue(notification_keys.get(), key.get()); - - // Monitor IP address changes. - key.reset(SCDynamicStoreKeyCreateNetworkGlobalEntity( - NULL /* default allocator */, kSCDynamicStoreDomainState, - kSCEntNetIPv4)); + NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4)); CFArrayAppendValue(notification_keys.get(), key.get()); - key.reset(SCDynamicStoreKeyCreateNetworkGlobalEntity( - NULL /* default allocator */, kSCDynamicStoreDomainState, - kSCEntNetIPv6)); + NULL, kSCDynamicStoreDomainState, kSCEntNetIPv6)); CFArrayAppendValue(notification_keys.get(), key.get()); - // Ok, let's ask for notifications! + // Set the notification keys. This starts us receiving notifications. + bool ret = SCDynamicStoreSetNotificationKeys( + store.get(), notification_keys.get(), NULL); // TODO(willchan): Figure out a proper way to handle this rather than crash. - CHECK(SCDynamicStoreSetNotificationKeys( - store.get(), notification_keys.get(), NULL)); -} + CHECK(ret); -NetworkChangeNotifierImpl::~NetworkChangeNotifierImpl() { - CFRunLoopRemoveSource(CFRunLoopGetCurrent(), - source_.get(), - kCFRunLoopCommonModes); -} - -void NetworkChangeNotifierImpl::Shutdown() { - CHECK(notifier_); - notifier_ = NULL; + MessageLoop::current()->AddDestructionObserver(this); } -// static -void NetworkChangeNotifierImpl::DynamicStoreCallback( - SCDynamicStoreRef /* store */, - CFArrayRef changed_keys, - void* config) { - NetworkChangeNotifierImpl* net_config = - static_cast<NetworkChangeNotifierImpl*>(config); - net_config->OnNetworkConfigChange(changed_keys); -} +void NetworkChangeNotifierMac::OnNetworkConfigChange(CFArrayRef changed_keys) { + DCHECK(notifier_thread_ != NULL); + DCHECK_EQ(notifier_thread_->message_loop(), MessageLoop::current()); -void NetworkChangeNotifierImpl::OnNetworkConfigChange(CFArrayRef changed_keys) { for (CFIndex i = 0; i < CFArrayGetCount(changed_keys); ++i) { CFStringRef key = static_cast<CFStringRef>( CFArrayGetValueAtIndex(changed_keys, i)); if (CFStringHasSuffix(key, kSCEntNetIPv4) || CFStringHasSuffix(key, kSCEntNetIPv6)) { - notifier_loop_->PostTask( - FROM_HERE, - NewRunnableMethod( - this, - &NetworkChangeNotifierImpl::OnIPAddressChanged)); - } else if (CFStringHasSuffix(key, kSCEntNetInterface)) { + NotifyObserversOfIPAddressChange(); + return; + } + if (CFStringHasSuffix(key, kSCEntNetInterface)) { // TODO(willchan): Does not appear to be working. Look into this. // Perhaps this isn't needed anyway. } else { @@ -172,91 +120,4 @@ void NetworkChangeNotifierImpl::OnNetworkConfigChange(CFArrayRef changed_keys) { } } -void NetworkChangeNotifierImpl::OnIPAddressChanged() { - // If |notifier_| doesn't exist, then that means we're shutting down, so - // notifications are all cancelled. - if (notifier_) - notifier_->OnIPAddressChanged(); -} - -class NetworkChangeNotifierThread : public base::Thread { - public: - NetworkChangeNotifierThread(MessageLoop* notifier_loop, - NetworkChangeNotifierMac* notifier); - ~NetworkChangeNotifierThread(); - - protected: - virtual void Init(); - - private: - MessageLoop* const notifier_loop_; - NetworkChangeNotifierMac* const notifier_; - scoped_refptr<NetworkChangeNotifierImpl> notifier_impl_; - - DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierThread); -}; - -NetworkChangeNotifierThread::NetworkChangeNotifierThread( - MessageLoop* notifier_loop, NetworkChangeNotifierMac* notifier) - : base::Thread("NetworkChangeNotifier"), - notifier_loop_(notifier_loop), - notifier_(notifier) {} - -NetworkChangeNotifierThread::~NetworkChangeNotifierThread() { - notifier_impl_->Shutdown(); - Stop(); -} - -// Note that |notifier_impl_| is initialized on the network change -// notifier thread, not whatever thread constructs the -// NetworkChangeNotifierThread object. This is important, because this thread -// is the one that has a CFRunLoop. -void NetworkChangeNotifierThread::Init() { - notifier_impl_ = - new NetworkChangeNotifierImpl(notifier_loop_, notifier_); -} - -} // namespace - -NetworkChangeNotifierMac::NetworkChangeNotifierMac() - : notifier_thread_(NULL), - method_factory_(this) { - // TODO(willchan): Look to see if there's a better signal for when it's ok to - // initialize this, rather than just delaying it by a fixed time. - const int kNotifierThreadInitializationDelayMS = 1000; - MessageLoop* loop = MessageLoop::current(); - loop->PostDelayedTask( - FROM_HERE, - method_factory_.NewRunnableMethod( - &NetworkChangeNotifierMac::InitializeNotifierThread, loop), - kNotifierThreadInitializationDelayMS); -} - -void NetworkChangeNotifierMac::OnIPAddressChanged() { - DCHECK(CalledOnValidThread()); - FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged()); -} - -void NetworkChangeNotifierMac::AddObserver(Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.AddObserver(observer); -} - -void NetworkChangeNotifierMac::RemoveObserver(Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.RemoveObserver(observer); -} - -NetworkChangeNotifierMac::~NetworkChangeNotifierMac() { - DCHECK(CalledOnValidThread()); -} - -void NetworkChangeNotifierMac::InitializeNotifierThread(MessageLoop* loop) { - DCHECK(CalledOnValidThread()); - notifier_thread_.reset(new NetworkChangeNotifierThread(loop, this)); - base::Thread::Options thread_options; - thread_options.message_loop_type = MessageLoop::TYPE_UI; - notifier_thread_->StartWithOptions(thread_options); -} - } // namespace net diff --git a/net/base/network_change_notifier_mac.h b/net/base/network_change_notifier_mac.h index 2ffaaba..c85f244 100644 --- a/net/base/network_change_notifier_mac.h +++ b/net/base/network_change_notifier_mac.h @@ -5,52 +5,52 @@ #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_MAC_H_ +#include <SystemConfiguration/SCDynamicStore.h> + #include "base/basictypes.h" -#include "base/non_thread_safe.h" -#include "base/observer_list.h" -#include "base/ref_counted.h" +#include "base/message_loop.h" +#include "base/scoped_cftyperef.h" #include "base/scoped_ptr.h" -#include "base/task.h" #include "net/base/network_change_notifier.h" -class MessageLoop; namespace base { class Thread; -} // namespace base +} namespace net { -class NetworkChangeNotifierMac : public NetworkChangeNotifier, - public NonThreadSafe { +class NetworkChangeNotifierMac : public MessageLoop::DestructionObserver, + public NetworkChangeNotifier { public: NetworkChangeNotifierMac(); - void OnIPAddressChanged(); + private: + virtual ~NetworkChangeNotifierMac(); - // NetworkChangeNotifier methods: - virtual void AddObserver(Observer* observer); - virtual void RemoveObserver(Observer* observer); + // Called back by OS. Calls OnNetworkConfigChange(). + static void DynamicStoreCallback(SCDynamicStoreRef /* store */, + CFArrayRef changed_keys, + void* config); - private: - friend class base::RefCounted<NetworkChangeNotifierMac>; + // MessageLoop::DestructionObserver: + virtual void WillDestroyCurrentMessageLoop(); - virtual ~NetworkChangeNotifierMac(); + // Called on the notifier thread to initialize the notification + // implementation. The SystemConfiguration calls in this function can lead to + // contention early on, so we invoke this function later on in startup to keep + // it fast. + void Init(); - // Initializes the notifier thread. The SystemConfiguration calls in this - // function can lead to contention early on, so we invoke this function later - // on in startup to keep it fast. - // See http://crbug.com/34926 for details. - void InitializeNotifierThread(MessageLoop* loop); + // Called by DynamicStoreCallback() when something about the network config + // changes. + void OnNetworkConfigChange(CFArrayRef changed_keys); - // Receives the OS X network change notifications on this thread. + // The thread used to listen for notifications. This relays the notification + // to the registered observers without posting back to the thread the object + // was created on. scoped_ptr<base::Thread> notifier_thread_; - // TODO(willchan): Fix the URLRequestContextGetter leaks and flip the false to - // true so we assert that all observers have been removed. - ObserverList<Observer, false> observers_; - - // Used to initialize the notifier thread. - ScopedRunnableMethodFactory<NetworkChangeNotifierMac> method_factory_; + scoped_cftyperef<CFRunLoopSourceRef> run_loop_source_; DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); }; diff --git a/net/base/network_change_notifier_win.cc b/net/base/network_change_notifier_win.cc index bed361c..e0e0892 100644 --- a/net/base/network_change_notifier_win.cc +++ b/net/base/network_change_notifier_win.cc @@ -5,84 +5,35 @@ #include "net/base/network_change_notifier_win.h" #include <iphlpapi.h> -#include <windows.h> #include <winsock2.h> -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/logging.h" -#include "base/object_watcher.h" +#pragma comment(lib, "iphlpapi.lib") namespace net { -class NetworkChangeNotifierWin::Impl - : public base::ObjectWatcher::Delegate { - public: - explicit Impl(NetworkChangeNotifierWin* notifier); - virtual ~Impl(); - - void WatchForAddressChange(); - - // ObjectWatcher::Delegate methods: - - virtual void OnObjectSignaled(HANDLE object); - - private: - NetworkChangeNotifierWin* const notifier_; - base::ObjectWatcher addr_watcher_; - OVERLAPPED addr_overlapped_; - - DISALLOW_COPY_AND_ASSIGN(Impl); -}; - -NetworkChangeNotifierWin::Impl::Impl(NetworkChangeNotifierWin* notifier) - : notifier_(notifier) { - memset(&addr_overlapped_, 0, sizeof(addr_overlapped_)); +NetworkChangeNotifierWin::NetworkChangeNotifierWin() { + memset(&addr_overlapped_, 0, sizeof addr_overlapped_); addr_overlapped_.hEvent = WSACreateEvent(); } -NetworkChangeNotifierWin::Impl::~Impl() { +NetworkChangeNotifierWin::~NetworkChangeNotifierWin() { CancelIPChangeNotify(&addr_overlapped_); addr_watcher_.StopWatching(); WSACloseEvent(addr_overlapped_.hEvent); - memset(&addr_overlapped_, 0, sizeof(addr_overlapped_)); -} - -void NetworkChangeNotifierWin::Impl::WatchForAddressChange() { - HANDLE handle = NULL; - DWORD ret = NotifyAddrChange(&handle, &addr_overlapped_); - CHECK(ret == ERROR_IO_PENDING); - addr_watcher_.StartWatching(addr_overlapped_.hEvent, this); } -void NetworkChangeNotifierWin::Impl::OnObjectSignaled(HANDLE object) { - notifier_->OnIPAddressChanged(); +void NetworkChangeNotifierWin::OnObjectSignaled(HANDLE object) { + NotifyObserversOfIPAddressChange(); - // Start watching for further address changes. + // Start watching for the next address change. WatchForAddressChange(); } -NetworkChangeNotifierWin::NetworkChangeNotifierWin() - : impl_(new Impl(ALLOW_THIS_IN_INITIALIZER_LIST(this))) { - impl_->WatchForAddressChange(); -} -void NetworkChangeNotifierWin::OnIPAddressChanged() { - DCHECK(CalledOnValidThread()); - FOR_EACH_OBSERVER(Observer, observers_, OnIPAddressChanged()); -} - -void NetworkChangeNotifierWin::AddObserver(Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.AddObserver(observer); -} - -void NetworkChangeNotifierWin::RemoveObserver(Observer* observer) { - DCHECK(CalledOnValidThread()); - observers_.RemoveObserver(observer); -} - -NetworkChangeNotifierWin::~NetworkChangeNotifierWin() { - DCHECK(CalledOnValidThread()); +void NetworkChangeNotifierWin::WatchForAddressChange() { + HANDLE handle = NULL; + DWORD ret = NotifyAddrChange(&handle, &addr_overlapped_); + CHECK(ret == ERROR_IO_PENDING); + addr_watcher_.StartWatching(addr_overlapped_.hEvent, this); } } // namespace net diff --git a/net/base/network_change_notifier_win.h b/net/base/network_change_notifier_win.h index ba2f53dc..2077ca8 100644 --- a/net/base/network_change_notifier_win.h +++ b/net/base/network_change_notifier_win.h @@ -5,35 +5,30 @@ #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ #define NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ +#include <windows.h> + #include "base/basictypes.h" -#include "base/non_thread_safe.h" #include "base/object_watcher.h" -#include "base/observer_list.h" #include "net/base/network_change_notifier.h" namespace net { class NetworkChangeNotifierWin : public NetworkChangeNotifier, - public NonThreadSafe { + public base::ObjectWatcher::Delegate { public: NetworkChangeNotifierWin(); - // Called by NetworkChangeNotifierWin::Impl. - void OnIPAddressChanged(); - - // NetworkChangeNotifier methods: - virtual void AddObserver(Observer* observer); - virtual void RemoveObserver(Observer* observer); - private: - class Impl; - virtual ~NetworkChangeNotifierWin(); - // TODO(willchan): Fix the URLRequestContextGetter leaks and flip the false to - // true so we assert that all observers have been removed. - ObserverList<Observer, false> observers_; - scoped_ptr<Impl> impl_; + // ObjectWatcher::Delegate methods: + virtual void OnObjectSignaled(HANDLE object); + + // Begins listening for a single subsequent address change. + void WatchForAddressChange(); + + base::ObjectWatcher addr_watcher_; + OVERLAPPED addr_overlapped_; DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierWin); }; 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"; diff --git a/net/net.gyp b/net/net.gyp index 1ed0833..5a25071 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -590,11 +590,6 @@ 'third_party/nss/ssl.gyp:ssl', 'tld_cleanup', ], - 'link_settings': { - 'libraries': [ - '-lIphlpapi.lib', - ], - }, }, { # else: OS != "win" 'dependencies': [ @@ -662,9 +657,9 @@ 'base/mapped_host_resolver_unittest.cc', 'base/mime_sniffer_unittest.cc', 'base/mime_util_unittest.cc', - 'base/mock_network_change_notifier.h', 'base/net_log_unittest.h', 'base/net_test_constants.h', + 'base/net_test_suite.h', 'base/net_util_unittest.cc', 'base/registry_controlled_domain_unittest.cc', 'base/run_all_unittests.cc', diff --git a/net/proxy/proxy_script_fetcher_unittest.cc b/net/proxy/proxy_script_fetcher_unittest.cc index ff12ebc..c3925e3 100644 --- a/net/proxy/proxy_script_fetcher_unittest.cc +++ b/net/proxy/proxy_script_fetcher_unittest.cc @@ -32,16 +32,14 @@ class RequestContext : public URLRequestContext { public: RequestContext() { net::ProxyConfig no_proxy; - host_resolver_ = net::CreateSystemHostResolver(NULL); + host_resolver_ = net::CreateSystemHostResolver(); proxy_service_ = net::ProxyService::CreateFixed(no_proxy); ssl_config_service_ = new net::SSLConfigServiceDefaults; - http_transaction_factory_ = - new net::HttpCache( - net::HttpNetworkLayer::CreateFactory( - NULL, host_resolver_, proxy_service_, ssl_config_service_, - NULL, NULL, NULL), - net::HttpCache::DefaultBackend::InMemory(0)); + http_transaction_factory_ = new net::HttpCache( + net::HttpNetworkLayer::CreateFactory(host_resolver_, proxy_service_, + ssl_config_service_, NULL, NULL, NULL), + net::HttpCache::DefaultBackend::InMemory(0)); } private: diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 002c514..cb7da0c 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -200,7 +200,6 @@ class ProxyService::PacRequest ProxyService::ProxyService(ProxyConfigService* config_service, ProxyResolver* resolver, - NetworkChangeNotifier* network_change_notifier, NetLog* net_log) : config_service_(config_service), resolver_(resolver), @@ -208,11 +207,8 @@ ProxyService::ProxyService(ProxyConfigService* config_service, should_use_proxy_resolver_(false), ALLOW_THIS_IN_INITIALIZER_LIST(init_proxy_resolver_callback_( this, &ProxyService::OnInitProxyResolverComplete)), - net_log_(net_log), - network_change_notifier_(network_change_notifier) { - // Register to receive network change notifications. - if (network_change_notifier_) - network_change_notifier_->AddObserver(this); + net_log_(net_log) { + NetworkChangeNotifier::AddObserver(this); } // static @@ -220,7 +216,6 @@ ProxyService* ProxyService::Create( ProxyConfigService* proxy_config_service, bool use_v8_resolver, URLRequestContext* url_request_context, - NetworkChangeNotifier* network_change_notifier, NetLog* net_log, MessageLoop* io_loop) { ProxyResolver* proxy_resolver = NULL; @@ -249,9 +244,8 @@ ProxyService* ProxyService::Create( new SingleThreadedProxyResolver(CreateNonV8ProxyResolver()); } - ProxyService* proxy_service = new ProxyService( - proxy_config_service, proxy_resolver, network_change_notifier, - net_log); + ProxyService* proxy_service = + new ProxyService(proxy_config_service, proxy_resolver, net_log); if (proxy_resolver->expects_pac_bytes()) { // Configure PAC script downloads to be issued using |url_request_context|. @@ -265,16 +259,13 @@ ProxyService* ProxyService::Create( // static ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { - return Create(new ProxyConfigServiceFixed(pc), false, NULL, NULL, - NULL, NULL); + return Create(new ProxyConfigServiceFixed(pc), false, NULL, NULL, NULL); } // static ProxyService* ProxyService::CreateNull() { // Use a configuration fetcher and proxy resolver which always fail. - return new ProxyService(new ProxyConfigServiceNull, - new ProxyResolverNull, - NULL, + return new ProxyService(new ProxyConfigServiceNull, new ProxyResolverNull, NULL); } @@ -341,9 +332,7 @@ int ProxyService::TryToCompleteSynchronously(const GURL& url, } ProxyService::~ProxyService() { - // Unregister to receive network change notifications. - if (network_change_notifier_) - network_change_notifier_->RemoveObserver(this); + NetworkChangeNotifier::RemoveObserver(this); // Cancel any inprogress requests. for (PendingRequests::iterator it = pending_requests_.begin(); @@ -675,8 +664,6 @@ void ProxyService::UpdateConfigIfOld(const BoundNetLog& net_log) { void ProxyService::OnIPAddressChanged() { - DCHECK(network_change_notifier_); - // Mark the current configuration as being un-initialized. // // This will force us to re-fetch the configuration (and re-run all of diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h index 49c7979..22435e4 100644 --- a/net/proxy/proxy_service.h +++ b/net/proxy/proxy_service.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -36,13 +36,10 @@ class ProxyService : public base::RefCountedThreadSafe<ProxyService>, public NetworkChangeNotifier::Observer { public: // The instance takes ownership of |config_service| and |resolver|. - // If |network_change_notifier| is non-NULL, the proxy service will register - // with it to detect when the network setup has changed. This is used to - // decide when to re-configure the proxy discovery. // |net_log| is a possibly NULL destination to send log events to. It must // remain alive for the lifetime of this ProxyService. - ProxyService(ProxyConfigService* config_service, ProxyResolver* resolver, - NetworkChangeNotifier* network_change_notifier, + ProxyService(ProxyConfigService* config_service, + ProxyResolver* resolver, NetLog* net_log); // Used internally to handle PAC queries. @@ -143,8 +140,6 @@ class ProxyService : public base::RefCountedThreadSafe<ProxyService>, // |url_request_context| is only used when use_v8_resolver is true: // it specifies the URL request context that will be used if a PAC // script needs to be fetched. - // |network_change_notifier| may be NULL. Otherwise it will be used to - // signal the ProxyService when the network setup has changed. // |io_loop| points to the IO thread's message loop. It is only used // when pc is NULL. // ########################################################################## @@ -156,7 +151,6 @@ class ProxyService : public base::RefCountedThreadSafe<ProxyService>, ProxyConfigService* proxy_config_service, bool use_v8_resolver, URLRequestContext* url_request_context, - NetworkChangeNotifier* network_change_notifier, NetLog* net_log, MessageLoop* io_loop); @@ -244,7 +238,8 @@ class ProxyService : public base::RefCountedThreadSafe<ProxyService>, int result_code, const BoundNetLog& net_log); - // NetworkChangeNotifier::Observer methods: + // NetworkChangeNotifier::Observer + // When this is called, we re-fetch PAC scripts and re-run WPAD. virtual void OnIPAddressChanged(); scoped_ptr<ProxyConfigService> config_service_; @@ -287,10 +282,6 @@ class ProxyService : public base::RefCountedThreadSafe<ProxyService>, // sent to. NetLog* net_log_; - // The (possibly NULL) network change notifier that we use to decide when - // to refetch PAC scripts or re-run WPAD. - NetworkChangeNotifier* const network_change_notifier_; - DISALLOW_COPY_AND_ASSIGN(ProxyService); }; @@ -301,9 +292,12 @@ class SyncProxyServiceHelper SyncProxyServiceHelper(MessageLoop* io_message_loop, ProxyService* proxy_service); - int ResolveProxy(const GURL& url, ProxyInfo* proxy_info, const BoundNetLog& net_log); + int ResolveProxy(const GURL& url, + ProxyInfo* proxy_info, + const BoundNetLog& net_log); int ReconsiderProxyAfterError(const GURL& url, - ProxyInfo* proxy_info, const BoundNetLog& net_log); + ProxyInfo* proxy_info, + const BoundNetLog& net_log); private: friend class base::RefCountedThreadSafe<SyncProxyServiceHelper>; diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index f5e76d9..3cf80cd 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -12,7 +12,6 @@ #include "googleurl/src/gurl.h" #include "net/base/net_log.h" #include "net/base/net_log_unittest.h" -#include "net/base/mock_network_change_notifier.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/proxy/mock_proxy_resolver.h" @@ -92,7 +91,7 @@ class MockProxyScriptFetcher : public ProxyScriptFetcher { TEST(ProxyServiceTest, Direct) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(new MockProxyConfigService, resolver, NULL, NULL)); + new ProxyService(new MockProxyConfigService, resolver, NULL)); GURL url("http://www.google.com/"); @@ -120,7 +119,7 @@ TEST(ProxyServiceTest, PAC) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); GURL url("http://www.google.com/"); @@ -167,7 +166,7 @@ TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); GURL url("http://username:password@www.google.com/?ref#hash#hash"); @@ -195,7 +194,7 @@ TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); GURL url("http://www.google.com/"); @@ -253,7 +252,7 @@ TEST(ProxyServiceTest, PAC_FailoverAfterDirect) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); GURL url("http://www.google.com/"); @@ -319,7 +318,7 @@ TEST(ProxyServiceTest, ProxyResolverFails) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); // Start first resolve request. GURL url("http://www.google.com/"); @@ -372,7 +371,7 @@ TEST(ProxyServiceTest, ProxyFallback) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); GURL url("http://www.google.com/"); @@ -462,7 +461,7 @@ TEST(ProxyServiceTest, ProxyFallbackToDirect) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); GURL url("http://www.google.com/"); @@ -525,7 +524,7 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); GURL url("http://www.google.com/"); @@ -617,7 +616,7 @@ TEST(ProxyServiceTest, ProxyFallback_BadConfig) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); GURL url("http://www.google.com/"); @@ -704,8 +703,7 @@ TEST(ProxyServiceTest, ProxyBypassList) { config.proxy_rules().bypass_rules.ParseFromString("*.org"); scoped_refptr<ProxyService> service(new ProxyService( - new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL, - NULL)); + new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL)); int rv; GURL url1("http://www.webkit.org"); @@ -729,8 +727,7 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { config.set_auto_detect(false); { scoped_refptr<ProxyService> service(new ProxyService( - new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL, - NULL)); + new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL)); GURL test_url("http://www.msn.com"); ProxyInfo info; TestCompletionCallback callback; @@ -742,8 +739,7 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { } { scoped_refptr<ProxyService> service(new ProxyService( - new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL, - NULL)); + new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL)); GURL test_url("ftp://ftp.google.com"); ProxyInfo info; TestCompletionCallback callback; @@ -755,8 +751,7 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { } { scoped_refptr<ProxyService> service(new ProxyService( - new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL, - NULL)); + new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL)); GURL test_url("https://webbranch.techcu.com"); ProxyInfo info; TestCompletionCallback callback; @@ -769,8 +764,7 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { { config.proxy_rules().ParseFromString("foopy1:8080"); scoped_refptr<ProxyService> service(new ProxyService( - new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL, - NULL)); + new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL)); GURL test_url("http://www.microsoft.com"); ProxyInfo info; TestCompletionCallback callback; @@ -793,8 +787,7 @@ TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { { scoped_refptr<ProxyService> service(new ProxyService( - new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL, - NULL)); + new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL)); GURL test_url("http://www.msn.com"); ProxyInfo info; TestCompletionCallback callback; @@ -806,8 +799,7 @@ TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { } { scoped_refptr<ProxyService> service(new ProxyService( - new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL, - NULL)); + new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL)); GURL test_url("ftp://ftp.google.com"); ProxyInfo info; TestCompletionCallback callback; @@ -819,8 +811,7 @@ TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { } { scoped_refptr<ProxyService> service(new ProxyService( - new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL, - NULL)); + new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL)); GURL test_url("https://webbranch.techcu.com"); ProxyInfo info; TestCompletionCallback callback; @@ -832,8 +823,7 @@ TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { } { scoped_refptr<ProxyService> service(new ProxyService( - new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL, - NULL)); + new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL)); GURL test_url("unknown://www.microsoft.com"); ProxyInfo info; TestCompletionCallback callback; @@ -853,7 +843,7 @@ TEST(ProxyServiceTest, CancelInProgressRequest) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); // Start 3 requests. @@ -928,7 +918,7 @@ TEST(ProxyServiceTest, InitialPACScriptDownload) { new MockAsyncProxyResolverExpectsBytes; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1007,7 +997,7 @@ TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { new MockAsyncProxyResolverExpectsBytes; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1064,7 +1054,7 @@ TEST(ProxyServiceTest, CancelWhilePACFetching) { new MockAsyncProxyResolverExpectsBytes; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1152,7 +1142,7 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { MockAsyncProxyResolverExpectsBytes* resolver = new MockAsyncProxyResolverExpectsBytes; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1223,7 +1213,7 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { MockAsyncProxyResolverExpectsBytes* resolver = new MockAsyncProxyResolverExpectsBytes; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1299,7 +1289,7 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { MockAsyncProxyResolverExpectsBytes* resolver = new MockAsyncProxyResolverExpectsBytes; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1357,7 +1347,7 @@ TEST(ProxyServiceTest, BypassDoesntApplyToPac) { MockAsyncProxyResolverExpectsBytes* resolver = new MockAsyncProxyResolverExpectsBytes; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1425,7 +1415,7 @@ TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { MockAsyncProxyResolverExpectsBytes* resolver = new MockAsyncProxyResolverExpectsBytes; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1461,7 +1451,7 @@ TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); GURL url("http://www.google.com/"); @@ -1483,8 +1473,7 @@ TEST(ProxyServiceTest, ResetProxyConfigService) { config1.set_auto_detect(false); scoped_refptr<ProxyService> service(new ProxyService( new MockProxyConfigService(config1), - new MockAsyncProxyResolverExpectsBytes, - NULL, NULL)); + new MockAsyncProxyResolverExpectsBytes, NULL)); ProxyInfo info; TestCompletionCallback callback1; @@ -1516,7 +1505,7 @@ TEST(ProxyServiceTest, UpdateConfigAfterFailedAutodetect) { MockProxyConfigService* config_service = new MockProxyConfigService(config); MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); // Start 1 requests. @@ -1562,7 +1551,7 @@ TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { MockProxyConfigService* config_service = new MockProxyConfigService(config); MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL, NULL)); + new ProxyService(config_service, resolver, NULL)); // Start 1 request. @@ -1614,11 +1603,8 @@ TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { MockAsyncProxyResolverExpectsBytes* resolver = new MockAsyncProxyResolverExpectsBytes; - MockNetworkChangeNotifier network_change_notifier; - scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, &network_change_notifier, - NULL)); + new ProxyService(config_service, resolver, NULL)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1662,8 +1648,8 @@ TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { // Now simluate a change in the network. The ProxyConfigService is still // going to return the same PAC URL as before, but this URL needs to be // refetched on the new network. - - network_change_notifier.NotifyIPAddressChange(); + NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); + MessageLoop::current()->RunAllPending(); // Notification happens async. // Start a second request. ProxyInfo info2; diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc index 1ff2789..40daa35 100644 --- a/net/socket/client_socket_pool_base.cc +++ b/net/socket/client_socket_pool_base.cc @@ -128,8 +128,7 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( int max_sockets_per_group, base::TimeDelta unused_idle_socket_timeout, base::TimeDelta used_idle_socket_timeout, - ConnectJobFactory* connect_job_factory, - NetworkChangeNotifier* network_change_notifier) + ConnectJobFactory* connect_job_factory) : idle_socket_count_(0), connecting_socket_count_(0), handed_out_socket_count_(0), @@ -140,15 +139,13 @@ ClientSocketPoolBaseHelper::ClientSocketPoolBaseHelper( used_idle_socket_timeout_(used_idle_socket_timeout), may_have_stalled_group_(false), connect_job_factory_(connect_job_factory), - network_change_notifier_(network_change_notifier), backup_jobs_enabled_(false), ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), pool_generation_number_(0) { DCHECK_LE(0, max_sockets_per_group); DCHECK_LE(max_sockets_per_group, max_sockets); - if (network_change_notifier_) - network_change_notifier_->AddObserver(this); + NetworkChangeNotifier::AddObserver(this); } ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { @@ -161,8 +158,7 @@ ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() { CHECK(group_map_.empty()); DCHECK_EQ(0, connecting_socket_count_); - if (network_change_notifier_) - network_change_notifier_->RemoveObserver(this); + NetworkChangeNotifier::RemoveObserver(this); } // InsertRequestIntoQueue inserts the request into the queue based on @@ -383,8 +379,8 @@ void ClientSocketPoolBaseHelper::ReleaseSocket(const std::string& group_name, // Run this asynchronously to allow the caller to finish before we let // another to begin doing work. This also avoids nasty recursion issues. // NOTE: We cannot refer to the handle argument after this method returns. - MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( - this, &ClientSocketPoolBaseHelper::DoReleaseSocket, group_name, socket, id)); + MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this, + &ClientSocketPoolBaseHelper::DoReleaseSocket, group_name, socket, id)); } void ClientSocketPoolBaseHelper::CloseIdleSockets() { @@ -640,6 +636,10 @@ void ClientSocketPoolBaseHelper::OnConnectJobComplete( } } +void ClientSocketPoolBaseHelper::OnIPAddressChanged() { + Flush(); +} + void ClientSocketPoolBaseHelper::Flush() { pool_generation_number_++; CancelAllConnectJobs(); diff --git a/net/socket/client_socket_pool_base.h b/net/socket/client_socket_pool_base.h index 942142d..deb405d 100644 --- a/net/socket/client_socket_pool_base.h +++ b/net/socket/client_socket_pool_base.h @@ -174,8 +174,7 @@ class ClientSocketPoolBaseHelper int max_sockets_per_group, base::TimeDelta unused_idle_socket_timeout, base::TimeDelta used_idle_socket_timeout, - ConnectJobFactory* connect_job_factory, - NetworkChangeNotifier* network_change_notifier); + ConnectJobFactory* connect_job_factory); // See ClientSocketPool::RequestSocket for documentation on this function. // ClientSocketPoolBaseHelper takes ownership of |request|, which must be @@ -220,7 +219,7 @@ class ClientSocketPoolBaseHelper virtual void OnConnectJobComplete(int result, ConnectJob* job); // NetworkChangeNotifier::Observer methods: - virtual void OnIPAddressChanged() { Flush(); } + virtual void OnIPAddressChanged(); // For testing. bool may_have_stalled_group() const { return may_have_stalled_group_; } @@ -460,8 +459,6 @@ class ClientSocketPoolBaseHelper const scoped_ptr<ConnectJobFactory> connect_job_factory_; - NetworkChangeNotifier* const network_change_notifier_; - // TODO(vandebo) Remove when backup jobs move to TCPClientSocketPool bool backup_jobs_enabled_; @@ -527,14 +524,12 @@ class ClientSocketPoolBase { const scoped_refptr<ClientSocketPoolHistograms>& histograms, base::TimeDelta unused_idle_socket_timeout, base::TimeDelta used_idle_socket_timeout, - ConnectJobFactory* connect_job_factory, - NetworkChangeNotifier* network_change_notifier) + ConnectJobFactory* connect_job_factory) : histograms_(histograms), helper_(new internal::ClientSocketPoolBaseHelper( max_sockets, max_sockets_per_group, unused_idle_socket_timeout, used_idle_socket_timeout, - new ConnectJobFactoryAdaptor(connect_job_factory), - network_change_notifier)) {} + new ConnectJobFactoryAdaptor(connect_job_factory))) {} virtual ~ClientSocketPoolBase() {} diff --git a/net/socket/client_socket_pool_base_unittest.cc b/net/socket/client_socket_pool_base_unittest.cc index c9ad282..7b84d94 100644 --- a/net/socket/client_socket_pool_base_unittest.cc +++ b/net/socket/client_socket_pool_base_unittest.cc @@ -293,7 +293,7 @@ class TestClientSocketPool : public ClientSocketPool { TestClientSocketPoolBase::ConnectJobFactory* connect_job_factory) : base_(max_sockets, max_sockets_per_group, histograms, unused_idle_socket_timeout, used_idle_socket_timeout, - connect_job_factory, NULL) {} + connect_job_factory) {} virtual int RequestSocket( const std::string& group_name, diff --git a/net/socket/socks_client_socket_pool.cc b/net/socket/socks_client_socket_pool.cc index 455b671..3e025cb 100644 --- a/net/socket/socks_client_socket_pool.cc +++ b/net/socket/socks_client_socket_pool.cc @@ -163,14 +163,13 @@ SOCKSClientSocketPool::SOCKSClientSocketPool( const scoped_refptr<ClientSocketPoolHistograms>& histograms, const scoped_refptr<HostResolver>& host_resolver, const scoped_refptr<TCPClientSocketPool>& tcp_pool, - NetworkChangeNotifier* network_change_notifier, NetLog* net_log) : base_(max_sockets, max_sockets_per_group, histograms, base::TimeDelta::FromSeconds( ClientSocketPool::unused_idle_socket_timeout()), base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), - new SOCKSConnectJobFactory(tcp_pool, host_resolver, net_log), - network_change_notifier) {} + new SOCKSConnectJobFactory(tcp_pool, host_resolver, net_log)) { +} SOCKSClientSocketPool::~SOCKSClientSocketPool() {} diff --git a/net/socket/socks_client_socket_pool.h b/net/socket/socks_client_socket_pool.h index b0b9b4b..7da2af54 100644 --- a/net/socket/socks_client_socket_pool.h +++ b/net/socket/socks_client_socket_pool.h @@ -111,7 +111,6 @@ class SOCKSClientSocketPool : public ClientSocketPool { const scoped_refptr<ClientSocketPoolHistograms>& histograms, const scoped_refptr<HostResolver>& host_resolver, const scoped_refptr<TCPClientSocketPool>& tcp_pool, - NetworkChangeNotifier* network_change_notifier, NetLog* net_log); // ClientSocketPool methods: diff --git a/net/socket/socks_client_socket_pool_unittest.cc b/net/socket/socks_client_socket_pool_unittest.cc index 452fbcc..fb83d96 100644 --- a/net/socket/socks_client_socket_pool_unittest.cc +++ b/net/socket/socks_client_socket_pool_unittest.cc @@ -10,7 +10,6 @@ #include "base/compiler_specific.h" #include "base/time.h" #include "net/base/mock_host_resolver.h" -#include "net/base/mock_network_change_notifier.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/socket/client_socket_factory.h" @@ -82,12 +81,13 @@ class MockTCPClientSocketPool : public TCPClientSocketPool { DISALLOW_COPY_AND_ASSIGN(MockConnectJob); }; - MockTCPClientSocketPool(int max_sockets, int max_sockets_per_group, + MockTCPClientSocketPool( + int max_sockets, + int max_sockets_per_group, const scoped_refptr<ClientSocketPoolHistograms>& histograms, - ClientSocketFactory* socket_factory, - NetworkChangeNotifier* network_change_notifier) + ClientSocketFactory* socket_factory) : TCPClientSocketPool(max_sockets, max_sockets_per_group, histograms, - NULL, NULL, network_change_notifier, NULL), + NULL, NULL, NULL), client_socket_factory_(socket_factory), release_count_(0), cancel_count_(0) {} @@ -174,16 +174,13 @@ class SOCKSClientSocketPoolTest : public ClientSocketPoolTest { : ignored_tcp_socket_params_( HostPortPair("proxy", 80), MEDIUM, GURL(), false), tcp_histograms_(new ClientSocketPoolHistograms("MockTCP")), - tcp_socket_pool_(new MockTCPClientSocketPool( - kMaxSockets, kMaxSocketsPerGroup, tcp_histograms_, - &tcp_client_socket_factory_, &tcp_notifier_)), + tcp_socket_pool_(new MockTCPClientSocketPool(kMaxSockets, + kMaxSocketsPerGroup, tcp_histograms_, &tcp_client_socket_factory_)), ignored_socket_params_(ignored_tcp_socket_params_, true, - HostPortPair("host", 80), - MEDIUM, GURL()), + HostPortPair("host", 80), MEDIUM, GURL()), socks_histograms_(new ClientSocketPoolHistograms("SOCKSUnitTest")), - pool_(new SOCKSClientSocketPool( - kMaxSockets, kMaxSocketsPerGroup, socks_histograms_, NULL, - tcp_socket_pool_, &socks_notifier_, NULL)) { + pool_(new SOCKSClientSocketPool(kMaxSockets, kMaxSocketsPerGroup, + socks_histograms_, NULL, tcp_socket_pool_, NULL)) { } int StartRequest(const std::string& group_name, RequestPriority priority) { @@ -194,12 +191,10 @@ class SOCKSClientSocketPoolTest : public ClientSocketPoolTest { TCPSocketParams ignored_tcp_socket_params_; scoped_refptr<ClientSocketPoolHistograms> tcp_histograms_; MockClientSocketFactory tcp_client_socket_factory_; - MockNetworkChangeNotifier tcp_notifier_; scoped_refptr<MockTCPClientSocketPool> tcp_socket_pool_; SOCKSSocketParams ignored_socket_params_; scoped_refptr<ClientSocketPoolHistograms> socks_histograms_; - MockNetworkChangeNotifier socks_notifier_; scoped_refptr<SOCKSClientSocketPool> pool_; }; diff --git a/net/socket/ssl_client_socket_unittest.cc b/net/socket/ssl_client_socket_unittest.cc index 7eec8fa..68016e0 100644 --- a/net/socket/ssl_client_socket_unittest.cc +++ b/net/socket/ssl_client_socket_unittest.cc @@ -26,7 +26,7 @@ const net::SSLConfig kDefaultSSLConfig; class SSLClientSocketTest : public PlatformTest { public: SSLClientSocketTest() - : resolver_(net::CreateSystemHostResolver(NULL)), + : resolver_(net::CreateSystemHostResolver()), socket_factory_(net::ClientSocketFactory::GetDefaultFactory()) { } diff --git a/net/socket/ssl_test_util.cc b/net/socket/ssl_test_util.cc index 7ef1a83..f2999f0 100644 --- a/net/socket/ssl_test_util.cc +++ b/net/socket/ssl_test_util.cc @@ -229,8 +229,7 @@ bool TestServerLauncher::WaitToStart(const std::string& host_name, int port) { // Verify that the webserver is actually started. // Otherwise tests can fail if they run faster than Python can start. net::AddressList addr; - scoped_refptr<net::HostResolver> resolver( - net::CreateSystemHostResolver(NULL)); + scoped_refptr<net::HostResolver> resolver(net::CreateSystemHostResolver()); net::HostResolver::RequestInfo info(host_name, port); int rv = resolver->Resolve(info, &addr, NULL, NULL, BoundNetLog()); if (rv != net::OK) @@ -369,7 +368,7 @@ bool LaunchTestServerAsJob(const std::wstring& cmdline, PROCESS_INFORMATION process_info; // If this code is run under a debugger, the test server process is - // automatically associated with a job object created by the debugger. + // automatically associated with a job object created by the debugger. // The CREATE_BREAKAWAY_FROM_JOB flag is used to prevent this. if (!CreateProcess(NULL, const_cast<wchar_t*>(cmdline.c_str()), NULL, NULL, diff --git a/net/socket/tcp_client_socket_pool.cc b/net/socket/tcp_client_socket_pool.cc index f2e9609..7937ef9 100644 --- a/net/socket/tcp_client_socket_pool.cc +++ b/net/socket/tcp_client_socket_pool.cc @@ -178,15 +178,13 @@ TCPClientSocketPool::TCPClientSocketPool( const scoped_refptr<ClientSocketPoolHistograms>& histograms, HostResolver* host_resolver, ClientSocketFactory* client_socket_factory, - NetworkChangeNotifier* network_change_notifier, NetLog* net_log) : base_(max_sockets, max_sockets_per_group, histograms, base::TimeDelta::FromSeconds( ClientSocketPool::unused_idle_socket_timeout()), base::TimeDelta::FromSeconds(kUsedIdleSocketTimeout), new TCPConnectJobFactory(client_socket_factory, - host_resolver, net_log), - network_change_notifier) { + host_resolver, net_log)) { base_.EnableBackupJobs(); } diff --git a/net/socket/tcp_client_socket_pool.h b/net/socket/tcp_client_socket_pool.h index 07ce3fa..6c7d483 100644 --- a/net/socket/tcp_client_socket_pool.h +++ b/net/socket/tcp_client_socket_pool.h @@ -118,7 +118,6 @@ class TCPClientSocketPool : public ClientSocketPool { const scoped_refptr<ClientSocketPoolHistograms>& histograms, HostResolver* host_resolver, ClientSocketFactory* client_socket_factory, - NetworkChangeNotifier* network_change_notifier, NetLog* net_log); // ClientSocketPool methods: diff --git a/net/socket/tcp_client_socket_pool_unittest.cc b/net/socket/tcp_client_socket_pool_unittest.cc index 25e7fdd..60ef667 100644 --- a/net/socket/tcp_client_socket_pool_unittest.cc +++ b/net/socket/tcp_client_socket_pool_unittest.cc @@ -8,7 +8,6 @@ #include "base/compiler_specific.h" #include "base/message_loop.h" #include "net/base/mock_host_resolver.h" -#include "net/base/mock_network_change_notifier.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" #include "net/socket/client_socket.h" @@ -272,7 +271,6 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { histograms_, host_resolver_, &client_socket_factory_, - ¬ifier_, NULL)) { } @@ -285,7 +283,6 @@ class TCPClientSocketPoolTest : public ClientSocketPoolTest { scoped_refptr<ClientSocketPoolHistograms> histograms_; scoped_refptr<MockHostResolver> host_resolver_; MockClientSocketFactory client_socket_factory_; - MockNetworkChangeNotifier notifier_; scoped_refptr<TCPClientSocketPool> pool_; }; @@ -684,7 +681,9 @@ TEST_F(TCPClientSocketPoolTest, ResetIdleSocketsOnIPAddressChange) { EXPECT_EQ(1, pool_->IdleSocketCount()); // After an IP address change, we should have 0 idle sockets. - notifier_.NotifyIPAddressChange(); + NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); + MessageLoop::current()->RunAllPending(); // Notification happens async. + EXPECT_EQ(0, pool_->IdleSocketCount()); } @@ -742,13 +741,8 @@ TEST_F(TCPClientSocketPoolTest, BackupSocketConnect) { EXPECT_EQ(0, pool_->IdleSocketCount()); handle.Reset(); - pool_ = new TCPClientSocketPool(kMaxSockets, - kMaxSocketsPerGroup, - histograms_, - host_resolver_, - &client_socket_factory_, - NULL, - NULL); + pool_ = new TCPClientSocketPool(kMaxSockets, kMaxSocketsPerGroup, + histograms_, host_resolver_, &client_socket_factory_, NULL); } } diff --git a/net/socket/tcp_client_socket_unittest.cc b/net/socket/tcp_client_socket_unittest.cc index a2b584a..30628d3 100644 --- a/net/socket/tcp_client_socket_unittest.cc +++ b/net/socket/tcp_client_socket_unittest.cc @@ -89,7 +89,7 @@ void TCPClientSocketTest::SetUp() { listen_port_ = port; AddressList addr; - scoped_refptr<HostResolver> resolver(CreateSystemHostResolver(NULL)); + scoped_refptr<HostResolver> resolver(CreateSystemHostResolver()); HostResolver::RequestInfo info("localhost", listen_port_); int rv = resolver->Resolve(info, &addr, NULL, NULL, BoundNetLog()); CHECK_EQ(rv, OK); diff --git a/net/socket/tcp_pinger_unittest.cc b/net/socket/tcp_pinger_unittest.cc index 29fd78e..8cd4ed4 100644 --- a/net/socket/tcp_pinger_unittest.cc +++ b/net/socket/tcp_pinger_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// 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. @@ -65,8 +65,7 @@ void TCPPingerTest::SetUp() { TEST_F(TCPPingerTest, Ping) { net::AddressList addr; - scoped_refptr<net::HostResolver> resolver( - net::CreateSystemHostResolver(NULL)); + scoped_refptr<net::HostResolver> resolver(net::CreateSystemHostResolver()); net::HostResolver::RequestInfo info("localhost", listen_port_); int rv = resolver->Resolve(info, &addr, NULL, NULL, net::BoundNetLog()); @@ -79,8 +78,7 @@ TEST_F(TCPPingerTest, Ping) { TEST_F(TCPPingerTest, PingFail) { net::AddressList addr; - scoped_refptr<net::HostResolver> resolver( - net::CreateSystemHostResolver(NULL)); + scoped_refptr<net::HostResolver> resolver(net::CreateSystemHostResolver()); // "Kill" "server" listen_sock_ = NULL; diff --git a/net/spdy/spdy_http_stream_unittest.cc b/net/spdy/spdy_http_stream_unittest.cc index c3b321a..d1d3546 100644 --- a/net/spdy/spdy_http_stream_unittest.cc +++ b/net/spdy/spdy_http_stream_unittest.cc @@ -55,7 +55,7 @@ class SessionDependencies { proxy_service(CreateNullProxyService()), 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) @@ -63,7 +63,7 @@ class 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; @@ -74,8 +74,7 @@ class SessionDependencies { }; 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, diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc index c6e1cb0..e912b78 100644 --- a/net/spdy/spdy_network_transaction_unittest.cc +++ b/net/spdy/spdy_network_transaction_unittest.cc @@ -55,7 +55,7 @@ class 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()) { // Note: The CancelledTransaction test does cleanup by running all tasks // in the message loop (RunAllPending). Unfortunately, that doesn't clean // up tasks on the host resolver thread; and TCPConnectJob is currently @@ -71,7 +71,7 @@ class 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; @@ -82,8 +82,7 @@ class SessionDependencies { }; 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, diff --git a/net/spdy/spdy_session_pool.cc b/net/spdy/spdy_session_pool.cc index c7e2e79..3374a2e 100644 --- a/net/spdy/spdy_session_pool.cc +++ b/net/spdy/spdy_session_pool.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -14,17 +14,14 @@ static const size_t kMaxSessionsPerDomain = 1; int SpdySessionPool::g_max_sessions_per_domain = kMaxSessionsPerDomain; -SpdySessionPool::SpdySessionPool(NetworkChangeNotifier* notifier) - : network_change_notifier_(notifier) { - if (network_change_notifier_) - network_change_notifier_->AddObserver(this); +SpdySessionPool::SpdySessionPool() { + NetworkChangeNotifier::AddObserver(this); } SpdySessionPool::~SpdySessionPool() { CloseAllSessions(); - if (network_change_notifier_) - network_change_notifier_->RemoveObserver(this); + NetworkChangeNotifier::RemoveObserver(this); } scoped_refptr<SpdySession> SpdySessionPool::Get( @@ -85,6 +82,10 @@ void SpdySessionPool::Remove(const scoped_refptr<SpdySession>& session) { RemoveSessionList(session->host_port_pair()); } +void SpdySessionPool::OnIPAddressChanged() { + ClearSessions(); +} + SpdySessionPool::SpdySessionList* SpdySessionPool::AddSessionList(const HostPortPair& host_port_pair) { DCHECK(sessions_.find(host_port_pair) == sessions_.end()); diff --git a/net/spdy/spdy_session_pool.h b/net/spdy/spdy_session_pool.h index 08d01e0..3ea97f3 100644 --- a/net/spdy/spdy_session_pool.h +++ b/net/spdy/spdy_session_pool.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -21,7 +21,6 @@ namespace net { class BoundNetLog; class ClientSocketHandle; class HttpNetworkSession; -class NetworkChangeNotifier; class SpdySession; // This is a very simple pool for open SpdySessions. @@ -30,7 +29,7 @@ class SpdySessionPool : public base::RefCounted<SpdySessionPool>, public NetworkChangeNotifier::Observer { public: - explicit SpdySessionPool(NetworkChangeNotifier* notifier); + SpdySessionPool(); // Either returns an existing SpdySession or creates a new SpdySession for // use. @@ -72,7 +71,7 @@ class SpdySessionPool // We flush all idle sessions and release references to the active ones so // they won't get re-used. The active ones will either complete successfully // or error out due to the IP address change. - virtual void OnIPAddressChanged() { ClearSessions(); } + virtual void OnIPAddressChanged(); private: friend class base::RefCounted<SpdySessionPool>; @@ -100,8 +99,6 @@ class SpdySessionPool // This is our weak session pool - one session per domain. SpdySessionsMap sessions_; - NetworkChangeNotifier* const network_change_notifier_; - static int g_max_sessions_per_domain; DISALLOW_COPY_AND_ASSIGN(SpdySessionPool); diff --git a/net/spdy/spdy_session_unittest.cc b/net/spdy/spdy_session_unittest.cc index 67dcb94..20b73d9 100644 --- a/net/spdy/spdy_session_unittest.cc +++ b/net/spdy/spdy_session_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -41,7 +41,7 @@ class SessionDependencies { : host_resolver(new MockHostResolver), proxy_service(ProxyService::CreateNull()), ssl_config_service(new SSLConfigServiceDefaults), - spdy_session_pool(new SpdySessionPool(NULL)) { + spdy_session_pool(new SpdySessionPool()) { } scoped_refptr<MockHostResolverBase> host_resolver; @@ -52,8 +52,7 @@ class SessionDependencies { }; 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, diff --git a/net/tools/fetch/fetch_client.cc b/net/tools/fetch/fetch_client.cc index d6ba673..9e2a21c 100644 --- a/net/tools/fetch/fetch_client.cc +++ b/net/tools/fetch/fetch_client.cc @@ -133,7 +133,7 @@ int main(int argc, char**argv) { MessageLoop loop(MessageLoop::TYPE_IO); scoped_refptr<net::HostResolver> host_resolver( - net::CreateSystemHostResolver(NULL)); + net::CreateSystemHostResolver()); scoped_refptr<net::ProxyService> proxy_service( net::ProxyService::CreateNull()); @@ -143,18 +143,14 @@ int main(int argc, char**argv) { scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory( net::HttpAuthHandlerFactory::CreateDefault()); if (use_cache) { - factory = new net::HttpCache(NULL, host_resolver, proxy_service, - ssl_config_service, - http_auth_handler_factory.get(), - NULL, - NULL, - net::HttpCache::DefaultBackend::InMemory(0)); + factory = new net::HttpCache(host_resolver, proxy_service, + ssl_config_service, http_auth_handler_factory.get(), NULL, NULL, + net::HttpCache::DefaultBackend::InMemory(0)); } else { factory = new net::HttpNetworkLayer( - net::ClientSocketFactory::GetDefaultFactory(), NULL, host_resolver, + net::ClientSocketFactory::GetDefaultFactory(), host_resolver, proxy_service, ssl_config_service, http_auth_handler_factory.get(), - NULL, - NULL); + NULL, NULL); } { diff --git a/net/tools/hresolv/hresolv.cc b/net/tools/hresolv/hresolv.cc index c3858ad..9c67070 100644 --- a/net/tools/hresolv/hresolv.cc +++ b/net/tools/hresolv/hresolv.cc @@ -447,7 +447,7 @@ int main(int argc, char** argv) { base::TimeDelta::FromSeconds(0)); scoped_refptr<net::HostResolver> host_resolver( - new net::HostResolverImpl(NULL, cache, NULL, 100u)); + new net::HostResolverImpl(NULL, cache, 100u)); ResolverInvoker invoker(host_resolver.get()); invoker.ResolveAll(hosts_and_times, options.async); diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index 02f8ab0..411e32a 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -131,13 +131,13 @@ class TestCookiePolicy : public net::CookiePolicy { class TestURLRequestContext : public URLRequestContext { public: TestURLRequestContext() { - host_resolver_ = net::CreateSystemHostResolver(NULL); + host_resolver_ = net::CreateSystemHostResolver(); proxy_service_ = net::ProxyService::CreateNull(); Init(); } explicit TestURLRequestContext(const std::string& proxy) { - host_resolver_ = net::CreateSystemHostResolver(NULL); + host_resolver_ = net::CreateSystemHostResolver(); net::ProxyConfig proxy_config; proxy_config.proxy_rules().ParseFromString(proxy); proxy_service_ = net::ProxyService::CreateFixed(proxy_config); @@ -160,15 +160,14 @@ class TestURLRequestContext : public URLRequestContext { ftp_transaction_factory_ = new net::FtpNetworkLayer(host_resolver_); ssl_config_service_ = new net::SSLConfigServiceDefaults; http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault(); - http_transaction_factory_ = - new net::HttpCache( - net::HttpNetworkLayer::CreateFactory(NULL, host_resolver_, - proxy_service_, - ssl_config_service_, - http_auth_handler_factory_, - network_delegate_, - NULL), - net::HttpCache::DefaultBackend::InMemory(0)); + http_transaction_factory_ = new net::HttpCache( + net::HttpNetworkLayer::CreateFactory(host_resolver_, + proxy_service_, + ssl_config_service_, + http_auth_handler_factory_, + network_delegate_, + NULL), + net::HttpCache::DefaultBackend::InMemory(0)); // In-memory cookie store. cookie_store_ = new net::CookieMonster(NULL, NULL); accept_language_ = "en-us,fr"; diff --git a/webkit/tools/test_shell/test_shell_request_context.cc b/webkit/tools/test_shell/test_shell_request_context.cc index 33ed651..a39e259 100644 --- a/webkit/tools/test_shell/test_shell_request_context.cc +++ b/webkit/tools/test_shell/test_shell_request_context.cc @@ -57,9 +57,9 @@ void TestShellRequestContext::Init( scoped_ptr<net::ProxyConfigService> proxy_config_service( net::ProxyService::CreateSystemProxyConfigService(NULL, NULL)); #endif - host_resolver_ = net::CreateSystemHostResolver(NULL); + host_resolver_ = net::CreateSystemHostResolver(); proxy_service_ = net::ProxyService::Create(proxy_config_service.release(), - false, NULL, NULL, NULL, NULL); + false, NULL, NULL, NULL); ssl_config_service_ = net::SSLConfigService::CreateSystemSSLConfigService(); http_auth_handler_factory_ = net::HttpAuthHandlerFactory::CreateDefault(); @@ -69,9 +69,8 @@ void TestShellRequestContext::Init( cache_path, 0, SimpleResourceLoaderBridge::GetCacheThread()); net::HttpCache* cache = - new net::HttpCache(NULL, host_resolver_, proxy_service_, - ssl_config_service_, http_auth_handler_factory_, - NULL, NULL, backend); + new net::HttpCache(host_resolver_, proxy_service_, ssl_config_service_, + http_auth_handler_factory_, NULL, NULL, backend); cache->set_mode(cache_mode); http_transaction_factory_ = cache; |