diff options
Diffstat (limited to 'net/base')
-rw-r--r-- | net/base/network_change_notifier_mac.cc | 28 | ||||
-rw-r--r-- | net/base/network_change_notifier_mac.h | 13 |
2 files changed, 32 insertions, 9 deletions
diff --git a/net/base/network_change_notifier_mac.cc b/net/base/network_change_notifier_mac.cc index f0583db..2dd1b4d 100644 --- a/net/base/network_change_notifier_mac.cc +++ b/net/base/network_change_notifier_mac.cc @@ -28,6 +28,7 @@ #include <SystemConfiguration/SCSchemaDefinitions.h> #include <algorithm> #include "base/logging.h" +#include "base/message_loop.h" #include "base/scoped_cftyperef.h" #include "base/thread.h" @@ -218,15 +219,26 @@ void NetworkChangeNotifierThread::Init() { } // namespace NetworkChangeNotifierMac::NetworkChangeNotifierMac() -// http://crbug.com/34926: This might be slowing down Mac startup. Disable the -// helper thread to see if that improves mac startup times. -// : notifier_thread_( -// new NetworkChangeNotifierThread(MessageLoop::current(), this)) { -// base::Thread::Options thread_options; -// thread_options.message_loop_type = MessageLoop::TYPE_UI; -// notifier_thread_->StartWithOptions(thread_options); - : notifier_thread_(NULL) {} + : notifier_thread_(NULL), + method_factory_(this) { + // TODO(willchan): Look to see if there's a better signal for when it's ok to + // initialize this, rather than just delaying it by a fixed time. + const int kNotifierThreadInitializationDelayMS = 1000; + MessageLoop* loop = MessageLoop::current(); + loop->PostDelayedTask( + FROM_HERE, + method_factory_.NewRunnableMethod( + &NetworkChangeNotifierMac::InitializeNotifierThread, loop), + kNotifierThreadInitializationDelayMS); +} NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {} +void NetworkChangeNotifierMac::InitializeNotifierThread(MessageLoop* loop) { + notifier_thread_.reset(new NetworkChangeNotifierThread(loop, this)); + base::Thread::Options thread_options; + thread_options.message_loop_type = MessageLoop::TYPE_UI; + notifier_thread_->StartWithOptions(thread_options); +} + } // namespace net diff --git a/net/base/network_change_notifier_mac.h b/net/base/network_change_notifier_mac.h index cbf0128f..5e777f4 100644 --- a/net/base/network_change_notifier_mac.h +++ b/net/base/network_change_notifier_mac.h @@ -8,9 +8,11 @@ #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/task.h" #include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier_helper.h" +class MessageLoop; namespace base { class Thread; } // namespace base @@ -38,11 +40,20 @@ class NetworkChangeNotifierMac : public NetworkChangeNotifier { virtual ~NetworkChangeNotifierMac(); + // Initializes the notifier thread. The SystemConfiguration calls in this + // function can lead to contention early on, so we invoke this function later + // on in startup to keep it fast. + // See http://crbug.com/34926 for details. + void InitializeNotifierThread(MessageLoop* loop); + // Receives the OS X network change notifications on this thread. - const scoped_ptr<base::Thread> notifier_thread_; + scoped_ptr<base::Thread> notifier_thread_; internal::NetworkChangeNotifierHelper helper_; + // Used to initialize the notifier thread. + ScopedRunnableMethodFactory<NetworkChangeNotifierMac> method_factory_; + DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); }; |