summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 22:36:25 +0000
committerwillchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-10 22:36:25 +0000
commit3846529d6b381db42568fe6b6ab0b3c8dcdc02f7 (patch)
tree0e534aeed6fc32025227364656a150b7ff2855e6 /net
parent905ecef378b26e9a91ef5d5dc9dddeb19cf1625e (diff)
downloadchromium_src-3846529d6b381db42568fe6b6ab0b3c8dcdc02f7.zip
chromium_src-3846529d6b381db42568fe6b6ab0b3c8dcdc02f7.tar.gz
chromium_src-3846529d6b381db42568fe6b6ab0b3c8dcdc02f7.tar.bz2
Wait a second before initializing the Mac notifier thread.
This should prevent slowing down Mac startup. BUG=34926 Review URL: http://codereview.chromium.org/593039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38679 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/base/network_change_notifier_mac.cc28
-rw-r--r--net/base/network_change_notifier_mac.h13
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);
};