summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-25 21:30:38 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-25 21:30:38 +0000
commit66761b95332549f825999e482c17c94675275f49 (patch)
treefc5307808a2c62f1eff2a9f37db3aff11c5455d9 /chrome
parente313f3b11360902a3da9b3b1cc0df2a4792d0867 (diff)
downloadchromium_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')
-rw-r--r--chrome/browser/browser_main.cc3
-rw-r--r--chrome/browser/io_thread.cc12
-rw-r--r--chrome/browser/io_thread.h2
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc27
-rw-r--r--chrome/browser/net/connection_tester.cc22
-rw-r--r--chrome/browser/net/resolve_proxy_msg_helper_unittest.cc8
-rw-r--r--chrome/browser/profile.cc7
-rw-r--r--chrome/browser/profile.h7
-rw-r--r--chrome/browser/sync/engine/syncapi.cc46
-rw-r--r--chrome/browser/sync/engine/syncapi.h11
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.cc6
-rw-r--r--chrome/browser/sync/glue/sync_backend_host.h28
-rw-r--r--chrome/browser/sync/net/network_change_notifier_io_thread.cc24
-rw-r--r--chrome/browser/sync/net/network_change_notifier_io_thread.h38
-rw-r--r--chrome/browser/sync/net/network_change_notifier_io_thread_unittest.cc80
-rw-r--r--chrome/browser/sync/notifier/server_notifier_thread.cc5
-rw-r--r--chrome/browser/sync/notifier/server_notifier_thread.h8
-rw-r--r--chrome/browser/sync/profile_sync_factory_impl.cc16
-rw-r--r--chrome/browser/sync/profile_sync_factory_impl.h12
-rw-r--r--chrome/browser/sync/profile_sync_factory_impl_unittest.cc7
-rw-r--r--chrome/browser/sync/profile_sync_service.cc15
-rw-r--r--chrome/browser/sync/profile_sync_service.h11
-rw-r--r--chrome/browser/sync/sync_setup_wizard_unittest.cc10
-rw-r--r--chrome/browser/sync/test_profile_sync_service.h23
-rw-r--r--chrome/chrome.gyp2
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_common.gypi5
-rw-r--r--chrome/chrome_tests.gypi58
-rw-r--r--chrome/common/net/fake_network_change_notifier_thread.cc77
-rw-r--r--chrome/common/net/fake_network_change_notifier_thread.h67
-rw-r--r--chrome/common/net/fake_network_change_notifier_thread_unittest.cc164
-rw-r--r--chrome/common/net/mock_network_change_observer.h32
-rw-r--r--chrome/common/net/network_change_notifier_proxy.cc55
-rw-r--r--chrome/common/net/network_change_notifier_proxy.h70
-rw-r--r--chrome/common/net/network_change_notifier_proxy_unittest.cc101
-rw-r--r--chrome/common/net/network_change_notifier_thread.h37
-rw-r--r--chrome/common/net/network_change_observer_proxy.cc137
-rw-r--r--chrome/common/net/network_change_observer_proxy.h114
-rw-r--r--chrome/common/net/network_change_observer_proxy_unittest.cc230
-rw-r--r--chrome/common/net/notifier/communicator/login.cc10
-rw-r--r--chrome/common/net/notifier/communicator/login.h4
-rw-r--r--chrome/common/net/notifier/listener/mediator_thread_impl.cc18
-rw-r--r--chrome/common/net/notifier/listener/mediator_thread_impl.h14
-rw-r--r--chrome/common/net/notifier/listener/talk_mediator_unittest.cc10
-rw-r--r--chrome/common/net/thread_blocker.cc47
-rw-r--r--chrome/common/net/thread_blocker.h51
-rw-r--r--chrome/common/net/thread_blocker_unittest.cc109
-rw-r--r--chrome/service/cloud_print/cloud_print_proxy_backend.cc6
-rw-r--r--chrome/service/net/service_network_change_notifier_thread.cc46
-rw-r--r--chrome/service/net/service_network_change_notifier_thread.h50
-rw-r--r--chrome/service/net/service_network_change_notifier_thread_unittest.cc100
-rw-r--r--chrome/service/net/service_url_request_context.cc8
-rw-r--r--chrome/service/service_process.cc10
-rw-r--r--chrome/service/service_process.h10
54 files changed, 93 insertions, 1979 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_
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);
};