| 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/location.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 12 #include "base/message_loop/message_loop_proxy.h" | |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 16 #include "base/strings/string_tokenizer.h" | 17 #include "base/strings/string_tokenizer.h" |
| 17 #include "base/synchronization/condition_variable.h" | 18 #include "base/synchronization/condition_variable.h" |
| 18 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 19 #include "base/threading/platform_thread.h" | 20 #include "base/threading/platform_thread.h" |
| 20 #include "base/time/time.h" | 21 #include "base/time/time.h" |
| 21 #include "build/build_config.h" | 22 #include "build/build_config.h" |
| 22 #include "chrome/browser/metrics/thread_watcher.h" | 23 #include "chrome/browser/metrics/thread_watcher.h" |
| 23 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 693 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); | 694 scoped_ptr<WatchDogThread> watchdog_thread_(new WatchDogThread()); |
| 694 watchdog_thread_->StartAndWaitForTesting(); | 695 watchdog_thread_->StartAndWaitForTesting(); |
| 695 | 696 |
| 696 // See http://crbug.com/347887. | 697 // See http://crbug.com/347887. |
| 697 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, | 698 // StartWatchingAll() will PostDelayedTask to create g_thread_watcher_list_, |
| 698 // whilst StopWatchingAll() will just PostTask to destroy it. | 699 // whilst StopWatchingAll() will just PostTask to destroy it. |
| 699 // Ensure that when Stop is called, Start will NOT create | 700 // Ensure that when Stop is called, Start will NOT create |
| 700 // g_thread_watcher_list_ later on. | 701 // g_thread_watcher_list_ later on. |
| 701 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); | 702 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); |
| 702 ThreadWatcherList::StopWatchingAll(); | 703 ThreadWatcherList::StopWatchingAll(); |
| 703 message_loop_for_ui.PostDelayedTask( | 704 message_loop_for_ui.task_runner()->PostDelayedTask( |
| 704 FROM_HERE, | 705 FROM_HERE, message_loop_for_ui.QuitClosure(), |
| 705 message_loop_for_ui.QuitClosure(), | |
| 706 base::TimeDelta::FromSeconds( | 706 base::TimeDelta::FromSeconds( |
| 707 ThreadWatcherList::g_initialize_delay_seconds)); | 707 ThreadWatcherList::g_initialize_delay_seconds)); |
| 708 message_loop_for_ui.Run(); | 708 message_loop_for_ui.Run(); |
| 709 | 709 |
| 710 CheckState(false /* has_thread_watcher_list */, | 710 CheckState(false /* has_thread_watcher_list */, |
| 711 true /* stopped */, | 711 true /* stopped */, |
| 712 "Start / Stopped"); | 712 "Start / Stopped"); |
| 713 | 713 |
| 714 // Proceed with just |StartWatchingAll| and ensure it'll be started. | 714 // Proceed with just |StartWatchingAll| and ensure it'll be started. |
| 715 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); | 715 ThreadWatcherList::StartWatchingAll(*base::CommandLine::ForCurrentProcess()); |
| 716 message_loop_for_ui.PostDelayedTask( | 716 message_loop_for_ui.task_runner()->PostDelayedTask( |
| 717 FROM_HERE, | 717 FROM_HERE, message_loop_for_ui.QuitClosure(), |
| 718 message_loop_for_ui.QuitClosure(), | |
| 719 base::TimeDelta::FromSeconds( | 718 base::TimeDelta::FromSeconds( |
| 720 ThreadWatcherList::g_initialize_delay_seconds + 1)); | 719 ThreadWatcherList::g_initialize_delay_seconds + 1)); |
| 721 message_loop_for_ui.Run(); | 720 message_loop_for_ui.Run(); |
| 722 | 721 |
| 723 CheckState(true /* has_thread_watcher_list */, | 722 CheckState(true /* has_thread_watcher_list */, |
| 724 false /* stopped */, | 723 false /* stopped */, |
| 725 "Started"); | 724 "Started"); |
| 726 | 725 |
| 727 // Finally, StopWatchingAll() must stop. | 726 // Finally, StopWatchingAll() must stop. |
| 728 ThreadWatcherList::StopWatchingAll(); | 727 ThreadWatcherList::StopWatchingAll(); |
| 729 message_loop_for_ui.PostDelayedTask( | 728 message_loop_for_ui.task_runner()->PostDelayedTask( |
| 730 FROM_HERE, | 729 FROM_HERE, message_loop_for_ui.QuitClosure(), |
| 731 message_loop_for_ui.QuitClosure(), | |
| 732 base::TimeDelta::FromSeconds( | 730 base::TimeDelta::FromSeconds( |
| 733 ThreadWatcherList::g_initialize_delay_seconds)); | 731 ThreadWatcherList::g_initialize_delay_seconds)); |
| 734 message_loop_for_ui.Run(); | 732 message_loop_for_ui.Run(); |
| 735 | 733 |
| 736 CheckState(false /* has_thread_watcher_list */, | 734 CheckState(false /* has_thread_watcher_list */, |
| 737 true /* stopped */, | 735 true /* stopped */, |
| 738 "Stopped"); | 736 "Stopped"); |
| 739 } | 737 } |
| OLD | NEW |