diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 21:30:38 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-25 21:30:38 +0000 |
commit | 66761b95332549f825999e482c17c94675275f49 (patch) | |
tree | fc5307808a2c62f1eff2a9f37db3aff11c5455d9 /chrome/browser | |
parent | e313f3b11360902a3da9b3b1cc0df2a4792d0867 (diff) | |
download | chromium_src-66761b95332549f825999e482c17c94675275f49.zip chromium_src-66761b95332549f825999e482c17c94675275f49.tar.gz chromium_src-66761b95332549f825999e482c17c94675275f49.tar.bz2 |
Massively simplify the NetworkChangeNotifier infrastructure:
* Use a process-wide object (singleton pattern)
* Create/destroy this object on the main thread, make it outlive all consumers
* Make observer-related functions threadsafe
As a result, the notifier can now be used by any thread (eliminating things like NetworkChangeObserverProxy and NetworkChangeNotifierProxy, and expanding its usefulness); its creation and inner workings are much simplified (eliminating implementation-specific classes); and it is simpler to access (eliminating things like NetworkChangeNotifierThread and a LOT of passing pointers around).
BUG=none
TEST=Unittests; network changes still trigger notifications
Review URL: http://codereview.chromium.org/2802015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50895 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
24 files changed, 66 insertions, 362 deletions
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_ |