Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: chrome/browser/metrics/thread_watcher_unittest.cc

Issue 1058603004: [Approach 3] Pre-allocate IncomigTaskQueue before MessageLoop for faster thread startup Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <math.h> 5 #include <math.h>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 CustomThreadWatcher* io_watcher_; 250 CustomThreadWatcher* io_watcher_;
251 CustomThreadWatcher* db_watcher_; 251 CustomThreadWatcher* db_watcher_;
252 ThreadWatcherList* thread_watcher_list_; 252 ThreadWatcherList* thread_watcher_list_;
253 253
254 ThreadWatcherTest() 254 ThreadWatcherTest()
255 : setup_complete_(&lock_), 255 : setup_complete_(&lock_),
256 initialized_(false) { 256 initialized_(false) {
257 db_thread_.reset(new content::TestBrowserThread(BrowserThread::DB)); 257 db_thread_.reset(new content::TestBrowserThread(BrowserThread::DB));
258 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO)); 258 io_thread_.reset(new content::TestBrowserThread(BrowserThread::IO));
259 watchdog_thread_.reset(new WatchDogThread()); 259 watchdog_thread_.reset(new WatchDogThread());
260 db_thread_->Start(); 260 db_thread_->StartAndWait();
261 io_thread_->Start(); 261 io_thread_->StartAndWait();
262 watchdog_thread_->Start(); 262 watchdog_thread_->StartAndWait();
263 263
264 WatchDogThread::PostTask( 264 WatchDogThread::PostTask(
265 FROM_HERE, 265 FROM_HERE,
266 base::Bind(&ThreadWatcherTest::SetUpObjects, base::Unretained(this))); 266 base::Bind(&ThreadWatcherTest::SetUpObjects, base::Unretained(this)));
267 267
268 WaitForSetUp(TimeDelta::FromMinutes(1)); 268 WaitForSetUp(TimeDelta::FromMinutes(1));
269 } 269 }
270 270
271 void SetUpObjects() { 271 void SetUpObjects() {
272 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); 272 DCHECK(WatchDogThread::CurrentlyOnWatchDogThread());
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 bool stopped_; 683 bool stopped_;
684 }; 684 };
685 685
686 TEST_F(ThreadWatcherListTest, Restart) { 686 TEST_F(ThreadWatcherListTest, Restart) {
687 ThreadWatcherList::g_initialize_delay_seconds = 1; 687 ThreadWatcherList::g_initialize_delay_seconds = 1;
688 688
689 base::MessageLoopForUI message_loop_for_ui; 689 base::MessageLoopForUI message_loop_for_ui;
690 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); 690 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui);
691 691
692 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); 692 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread());
693 watchdog_thread_->Start(); 693 watchdog_thread_->StartAndWait();
694 694
695 // See http://crbug.com/347887. 695 // See http://crbug.com/347887.
696 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, 696 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_,
697 // whilst StopWatchingAll() will just PostTask to destroy it. 697 // whilst StopWatchingAll() will just PostTask to destroy it.
698 // Ensure that when Stop is called, Start will NOT create 698 // Ensure that when Stop is called, Start will NOT create
699 // g_thread_watcher_list_ later on. 699 // g_thread_watcher_list_ later on.
700 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); 700 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess());
701 ThreadWatcherList::StopWatchingAll(); 701 ThreadWatcherList::StopWatchingAll();
702 message_loop_for_ui.PostDelayedTask( 702 message_loop_for_ui.PostDelayedTask(
703 FROM_HERE, 703 FROM_HERE,
(...skipping 25 matching lines...) Expand all
729 FROM_HERE, 729 FROM_HERE,
730 message_loop_for_ui.QuitClosure(), 730 message_loop_for_ui.QuitClosure(),
731 base::TimeDelta::FromSeconds( 731 base::TimeDelta::FromSeconds(
732 ThreadWatcherList::g_initialize_delay_seconds)); 732 ThreadWatcherList::g_initialize_delay_seconds));
733 message_loop_for_ui.Run(); 733 message_loop_for_ui.Run();
734 734
735 CheckState(false /* has_thread_watcher_list */, 735 CheckState(false /* has_thread_watcher_list */,
736 true /* stopped */, 736 true /* stopped */,
737 "Stopped"); 737 "Stopped");
738 } 738 }
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | chrome/browser/sync/glue/sync_backend_registrar_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698