diff options
-rw-r--r-- | chrome/browser/browser_main.cc | 6 | ||||
-rw-r--r-- | chrome/browser/metrics/thread_watcher.cc | 20 | ||||
-rw-r--r-- | chrome/browser/metrics/thread_watcher.h | 3 |
3 files changed, 22 insertions, 7 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 3e481a2..7c3ce0f 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -1318,9 +1318,6 @@ int BrowserMain(const MainFunctionParams& parameters) { CreateChildThreads(browser_process.get()); - // Start watching all browser threads for responsiveness. - ThreadWatcherList::StartWatchingAll(); - #if defined(OS_CHROMEOS) // Now that the file thread exists we can record our stats. chromeos::BootTimesLoader::Get()->RecordChromeMainStats(); @@ -1752,6 +1749,9 @@ int BrowserMain(const MainFunctionParams& parameters) { GpuDataManager* gpu_data_manager = GpuDataManager::GetInstance(); DCHECK(gpu_data_manager); + // Start watching all browser threads for responsiveness. + ThreadWatcherList::StartWatchingAll(); + int result_code = ResultCodes::NORMAL_EXIT; if (parameters.ui_task) { // We are in test mode. Run one task and enter the main message loop. diff --git a/chrome/browser/metrics/thread_watcher.cc b/chrome/browser/metrics/thread_watcher.cc index b1597f7..84bc71b 100644 --- a/chrome/browser/metrics/thread_watcher.cc +++ b/chrome/browser/metrics/thread_watcher.cc @@ -61,6 +61,10 @@ void ThreadWatcher::StartWatching(const BrowserThread::ID thread_id, ThreadWatcher* watcher = new ThreadWatcher(thread_id, thread_name, sleep_time, unresponsive_time); DCHECK(watcher); + // If we couldn't register the thread watcher object, we are shutting down, + // then don't activate thread watching. + if (!ThreadWatcherList::IsRegistered(thread_id)) + return; watcher->ActivateThreadWatching(); } @@ -207,22 +211,27 @@ ThreadWatcherList::~ThreadWatcherList() { // static void ThreadWatcherList::Register(ThreadWatcher* watcher) { - DCHECK(global_); + if (!global_) + return; base::AutoLock auto_lock(global_->lock_); DCHECK(!global_->PreLockedFind(watcher->thread_id())); global_->registered_[watcher->thread_id()] = watcher; } // static +bool ThreadWatcherList::IsRegistered(const BrowserThread::ID thread_id) { + return NULL != ThreadWatcherList::Find(thread_id); +} + +// static void ThreadWatcherList::StartWatchingAll() { if (!WatchDogThread::CurrentlyOnWatchDogThread()) { WatchDogThread::PostDelayedTask( FROM_HERE, NewRunnableFunction(&ThreadWatcherList::StartWatchingAll), - base::TimeDelta::FromSeconds(10).InMilliseconds()); + base::TimeDelta::FromSeconds(5).InMilliseconds()); return; } - DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); const base::TimeDelta kSleepTime = base::TimeDelta::FromSeconds(5); const base::TimeDelta kUnresponsiveTime = base::TimeDelta::FromSeconds(10); @@ -309,6 +318,8 @@ void ThreadWatcherList::Observe(NotificationType type, void ThreadWatcherList::WakeUpAll() { DCHECK(WatchDogThread::CurrentlyOnWatchDogThread()); + if (!global_) + return; base::AutoLock auto_lock(lock_); for (RegistrationList::iterator it = global_->registered_.begin(); global_->registered_.end() != it; @@ -318,7 +329,8 @@ void ThreadWatcherList::WakeUpAll() { // static ThreadWatcher* ThreadWatcherList::Find(const BrowserThread::ID thread_id) { - DCHECK(global_); + if (!global_) + return NULL; base::AutoLock auto_lock(global_->lock_); return global_->PreLockedFind(thread_id); } diff --git a/chrome/browser/metrics/thread_watcher.h b/chrome/browser/metrics/thread_watcher.h index b9fb6e0..43768d3 100644 --- a/chrome/browser/metrics/thread_watcher.h +++ b/chrome/browser/metrics/thread_watcher.h @@ -208,6 +208,9 @@ class ThreadWatcherList : public NotificationObserver { // Register() stores a pointer to the given ThreadWatcher in a global map. static void Register(ThreadWatcher* watcher); + // This method returns true if the ThreadWatcher object is registerd. + static bool IsRegistered(const BrowserThread::ID thread_id); + // This method posts a task on WatchDogThread to start watching all browser // threads. // This method is accessible on UI thread. |