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

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

Issue 2296793003: ThreadWatcher: fix use-after-delete bug. (Closed)
Patch Set: Created 4 years, 3 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
« no previous file with comments | « chrome/browser/metrics/thread_watcher.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); 879 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId());
880 DCHECK(!startup_watchdog_); 880 DCHECK(!startup_watchdog_);
881 startup_watchdog_ = new StartupWatchDogThread(duration); 881 startup_watchdog_ = new StartupWatchDogThread(duration);
882 startup_watchdog_->Arm(); 882 startup_watchdog_->Arm();
883 return; 883 return;
884 } 884 }
885 885
886 void StartupTimeBomb::Disarm() { 886 void StartupTimeBomb::Disarm() {
887 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); 887 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId());
888 if (startup_watchdog_) { 888 if (startup_watchdog_) {
889 startup_watchdog_->Disarm(); 889 base::Watchdog* startup_watchdog = startup_watchdog_;
890 startup_watchdog_->Cleanup(); 890 startup_watchdog_ = nullptr;
891 DeleteStartupWatchdog(); 891
892 startup_watchdog->Disarm();
893 startup_watchdog->Cleanup();
894 DeleteStartupWatchdog(thread_id_, startup_watchdog);
892 } 895 }
893 } 896 }
894 897
895 void StartupTimeBomb::DeleteStartupWatchdog() { 898 // static
896 DCHECK_EQ(thread_id_, base::PlatformThread::CurrentId()); 899 void StartupTimeBomb::DeleteStartupWatchdog(
897 if (startup_watchdog_->IsJoinable()) { 900 const base::PlatformThreadId thread_id,
wzhong 2016/08/30 23:08:39 Nit: const is not needed.
901 base::Watchdog* startup_watchdog) {
902 DCHECK_EQ(thread_id, base::PlatformThread::CurrentId());
903 if (startup_watchdog->IsJoinable()) {
898 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns 904 // Allow the watchdog thread to shutdown on UI. Watchdog thread shutdowns
899 // very fast. 905 // very fast.
900 base::ThreadRestrictions::ScopedAllowIO allow_io; 906 base::ThreadRestrictions::ScopedAllowIO allow_io;
901 delete startup_watchdog_; 907 delete startup_watchdog;
902 startup_watchdog_ = nullptr;
903 return; 908 return;
904 } 909 }
905 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 910 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
906 FROM_HERE, base::Bind(&StartupTimeBomb::DeleteStartupWatchdog, 911 FROM_HERE, base::Bind(&StartupTimeBomb::DeleteStartupWatchdog, thread_id,
907 base::Unretained(this)), 912 base::Unretained(startup_watchdog)),
908 base::TimeDelta::FromSeconds(10)); 913 base::TimeDelta::FromSeconds(10));
909 } 914 }
910 915
911 // static 916 // static
912 void StartupTimeBomb::DisarmStartupTimeBomb() { 917 void StartupTimeBomb::DisarmStartupTimeBomb() {
913 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 918 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
914 if (g_startup_timebomb_) 919 if (g_startup_timebomb_)
915 g_startup_timebomb_->Disarm(); 920 g_startup_timebomb_->Disarm();
916 } 921 }
917 922
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
999 1004
1000 #if defined(OS_WIN) 1005 #if defined(OS_WIN)
1001 // On Windows XP, give twice the time for shutdown. 1006 // On Windows XP, give twice the time for shutdown.
1002 if (base::win::GetVersion() <= base::win::VERSION_XP) 1007 if (base::win::GetVersion() <= base::win::VERSION_XP)
1003 actual_duration *= 2; 1008 actual_duration *= 2;
1004 #endif 1009 #endif
1005 1010
1006 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); 1011 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration);
1007 shutdown_watchdog_->Arm(); 1012 shutdown_watchdog_->Arm();
1008 } 1013 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/thread_watcher.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698