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

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

Issue 8728035: Disarm StartupTimeBomb when it is deleted (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/metrics/thread_watcher.h" 5 #include "chrome/browser/metrics/thread_watcher.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/compiler_specific.h" 10 #include "base/compiler_specific.h"
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 StartWatching(BrowserThread::FILE, "FILE", kSleepTime, kUnresponsiveTime, 583 StartWatching(BrowserThread::FILE, "FILE", kSleepTime, kUnresponsiveTime,
584 unresponsive_threshold, crash_on_hang_thread_names, 584 unresponsive_threshold, crash_on_hang_thread_names,
585 live_threads_threshold); 585 live_threads_threshold);
586 StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, kUnresponsiveTime, 586 StartWatching(BrowserThread::CACHE, "CACHE", kSleepTime, kUnresponsiveTime,
587 unresponsive_threshold, crash_on_hang_thread_names, 587 unresponsive_threshold, crash_on_hang_thread_names,
588 live_threads_threshold); 588 live_threads_threshold);
589 589
590 BrowserThread::PostTask( 590 BrowserThread::PostTask(
591 BrowserThread::UI, 591 BrowserThread::UI,
592 FROM_HERE, 592 FROM_HERE,
593 base::Bind(StartupTimeBomb::Disarm)); 593 base::Bind(&StartupTimeBomb::Disarm,
594 base::Unretained(StartupTimeBomb::g_startup_timebomb_)));
594 } 595 }
595 596
596 // static 597 // static
597 void ThreadWatcherList::StartWatching( 598 void ThreadWatcherList::StartWatching(
598 const BrowserThread::ID& thread_id, 599 const BrowserThread::ID& thread_id,
599 const std::string& thread_name, 600 const std::string& thread_name,
600 const base::TimeDelta& sleep_time, 601 const base::TimeDelta& sleep_time,
601 const base::TimeDelta& unresponsive_time, 602 const base::TimeDelta& unresponsive_time,
602 uint32 unresponsive_threshold, 603 uint32 unresponsive_threshold,
603 const std::set<std::string>& crash_on_hang_thread_names, 604 const std::set<std::string>& crash_on_hang_thread_names,
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 CHECK(false); 822 CHECK(false);
822 } 823 }
823 824
824 DISALLOW_COPY_AND_ASSIGN(ShutdownWatchDogThread); 825 DISALLOW_COPY_AND_ASSIGN(ShutdownWatchDogThread);
825 }; 826 };
826 } // namespace 827 } // namespace
827 828
828 // StartupTimeBomb methods and members. 829 // StartupTimeBomb methods and members.
829 // 830 //
830 // static 831 // static
831 base::Watchdog* StartupTimeBomb::startup_watchdog_ = NULL; 832 StartupTimeBomb* StartupTimeBomb::g_startup_timebomb_ = NULL;
832 833
833 // static 834 StartupTimeBomb::StartupTimeBomb() : startup_watchdog_(NULL) {
835 CHECK(!g_startup_timebomb_);
836 g_startup_timebomb_ = this;
837 }
838
839 StartupTimeBomb::~StartupTimeBomb() {
840 DCHECK(this == g_startup_timebomb_);
841 Disarm();
842 g_startup_timebomb_ = NULL;
843 }
844
834 void StartupTimeBomb::Arm(const base::TimeDelta& duration) { 845 void StartupTimeBomb::Arm(const base::TimeDelta& duration) {
835 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 846 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
836 DCHECK(!startup_watchdog_); 847 DCHECK(!startup_watchdog_);
837 startup_watchdog_ = new StartupWatchDogThread(duration); 848 startup_watchdog_ = new StartupWatchDogThread(duration);
838 startup_watchdog_->Arm(); 849 startup_watchdog_->Arm();
839 } 850 }
840 851
841 // static
842 void StartupTimeBomb::Disarm() { 852 void StartupTimeBomb::Disarm() {
843 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 853 // This could be disarm'ed during shutdown when we are not on UI thread.
844 if (startup_watchdog_) { 854 if (startup_watchdog_) {
845 startup_watchdog_->Disarm(); 855 startup_watchdog_->Disarm();
846 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns 856 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns
847 // very fast. 857 // very fast.
848 base::ThreadRestrictions::SetIOAllowed(true); 858 base::ThreadRestrictions::SetIOAllowed(true);
849 delete startup_watchdog_; 859 delete startup_watchdog_;
850 startup_watchdog_ = NULL; 860 startup_watchdog_ = NULL;
851 } 861 }
852 } 862 }
853 863
(...skipping 26 matching lines...) Expand all
880 890
881 #if defined(OS_WIN) 891 #if defined(OS_WIN)
882 // On Windows XP, give twice the time for shutdown. 892 // On Windows XP, give twice the time for shutdown.
883 if (base::win::GetVersion() <= base::win::VERSION_XP) 893 if (base::win::GetVersion() <= base::win::VERSION_XP)
884 actual_duration *= 2; 894 actual_duration *= 2;
885 #endif 895 #endif
886 896
887 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); 897 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration);
888 shutdown_watchdog_->Arm(); 898 shutdown_watchdog_->Arm();
889 } 899 }
OLDNEW
« chrome/browser/metrics/thread_watcher.h ('K') | « chrome/browser/metrics/thread_watcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698