| OLD | NEW |
| 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 Loading... |
| 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_->StartAndWaitForTesting(); | 260 db_thread_->Start(); |
| 261 io_thread_->StartAndWaitForTesting(); | 261 io_thread_->Start(); |
| 262 watchdog_thread_->StartAndWaitForTesting(); | 262 watchdog_thread_->Start(); |
| 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 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 690 bool stopped_; | 690 bool stopped_; |
| 691 }; | 691 }; |
| 692 | 692 |
| 693 TEST_F(ThreadWatcherListTest, Restart) { | 693 TEST_F(ThreadWatcherListTest, Restart) { |
| 694 ThreadWatcherList::g_initialize_delay_seconds = 1; | 694 ThreadWatcherList::g_initialize_delay_seconds = 1; |
| 695 | 695 |
| 696 base::MessageLoopForUI message_loop_for_ui; | 696 base::MessageLoopForUI message_loop_for_ui; |
| 697 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); | 697 content::TestBrowserThread ui_thread(BrowserThread::UI, &message_loop_for_ui); |
| 698 | 698 |
| 699 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); | 699 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); |
| 700 watchdog_thread_->StartAndWaitForTesting(); | 700 watchdog_thread_->Start(); |
| 701 | 701 |
| 702 // See http://crbug.com/347887. | 702 // See http://crbug.com/347887. |
| 703 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, | 703 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, |
| 704 // whilst StopWatchingAll() will just PostTask to destroy it. | 704 // whilst StopWatchingAll() will just PostTask to destroy it. |
| 705 // Ensure that when Stop is called, Start will NOT create | 705 // Ensure that when Stop is called, Start will NOT create |
| 706 // g_thread_watcher_list_ later on. | 706 // g_thread_watcher_list_ later on. |
| 707 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); | 707 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); |
| 708 ThreadWatcherList::StopWatchingAll(); | 708 ThreadWatcherList::StopWatchingAll(); |
| 709 message_loop_for_ui.PostDelayedTask( | 709 message_loop_for_ui.PostDelayedTask( |
| 710 FROM_HERE, | 710 FROM_HERE, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 736 FROM_HERE, | 736 FROM_HERE, |
| 737 message_loop_for_ui.QuitClosure(), | 737 message_loop_for_ui.QuitClosure(), |
| 738 base::TimeDelta::FromSeconds( | 738 base::TimeDelta::FromSeconds( |
| 739 ThreadWatcherList::g_initialize_delay_seconds)); | 739 ThreadWatcherList::g_initialize_delay_seconds)); |
| 740 message_loop_for_ui.Run(); | 740 message_loop_for_ui.Run(); |
| 741 | 741 |
| 742 CheckState(false /* has_thread_watcher_list */, | 742 CheckState(false /* has_thread_watcher_list */, |
| 743 true /* stopped */, | 743 true /* stopped */, |
| 744 "Stopped"); | 744 "Stopped"); |
| 745 } | 745 } |
| OLD | NEW |