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
diff --git a/net/socket/client_socket_pool_base.cc b/net/socket/client_socket_pool_base.cc
index 1ff2789..40daa35 100644
--- a/net/socket/client_socket_pool_base.cc
+++ b/net/socket/client_socket_pool_base.cc
@@ -128,8 +128,7 @@
int max_sockets_per_group,
base::TimeDelta unused_idle_socket_timeout,
base::TimeDelta used_idle_socket_timeout,
- ConnectJobFactory* connect_job_factory,
- NetworkChangeNotifier* network_change_notifier)
+ ConnectJobFactory* connect_job_factory)
: idle_socket_count_(0),
connecting_socket_count_(0),
handed_out_socket_count_(0),
@@ -140,15 +139,13 @@
used_idle_socket_timeout_(used_idle_socket_timeout),
may_have_stalled_group_(false),
connect_job_factory_(connect_job_factory),
- network_change_notifier_(network_change_notifier),
backup_jobs_enabled_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)),
pool_generation_number_(0) {
DCHECK_LE(0, max_sockets_per_group);
DCHECK_LE(max_sockets_per_group, max_sockets);
- if (network_change_notifier_)
- network_change_notifier_->AddObserver(this);
+ NetworkChangeNotifier::AddObserver(this);
}
ClientSocketPoolBaseHelper::~ClientSocketPoolBaseHelper() {
@@ -161,8 +158,7 @@
CHECK(group_map_.empty());
DCHECK_EQ(0, connecting_socket_count_);
- if (network_change_notifier_)
- network_change_notifier_->RemoveObserver(this);
+ NetworkChangeNotifier::RemoveObserver(this);
}
// InsertRequestIntoQueue inserts the request into the queue based on
@@ -383,8 +379,8 @@
// Run this asynchronously to allow the caller to finish before we let
// another to begin doing work. This also avoids nasty recursion issues.
// NOTE: We cannot refer to the handle argument after this method returns.
- MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(
- this, &ClientSocketPoolBaseHelper::DoReleaseSocket, group_name, socket, id));
+ MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod(this,
+ &ClientSocketPoolBaseHelper::DoReleaseSocket, group_name, socket, id));
}
void ClientSocketPoolBaseHelper::CloseIdleSockets() {
@@ -640,6 +636,10 @@
}
}
+void ClientSocketPoolBaseHelper::OnIPAddressChanged() {
+ Flush();
+}
+
void ClientSocketPoolBaseHelper::Flush() {
pool_generation_number_++;
CancelAllConnectJobs();