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 "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 15 matching lines...) Expand all Loading... |
26 #if defined(OS_WIN) | 26 #if defined(OS_WIN) |
27 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
28 #endif | 28 #endif |
29 | 29 |
30 using content::BrowserThread; | 30 using content::BrowserThread; |
31 | 31 |
32 // ThreadWatcher methods and members. | 32 // ThreadWatcher methods and members. |
33 ThreadWatcher::ThreadWatcher(const WatchingParams& params) | 33 ThreadWatcher::ThreadWatcher(const WatchingParams& params) |
34 : thread_id_(params.thread_id), | 34 : thread_id_(params.thread_id), |
35 thread_name_(params.thread_name), | 35 thread_name_(params.thread_name), |
36 watched_loop_( | 36 watched_runner_( |
37 BrowserThread::GetMessageLoopProxyForThread(params.thread_id)), | 37 BrowserThread::GetMessageLoopProxyForThread(params.thread_id)), |
38 sleep_time_(params.sleep_time), | 38 sleep_time_(params.sleep_time), |
39 unresponsive_time_(params.unresponsive_time), | 39 unresponsive_time_(params.unresponsive_time), |
40 ping_time_(base::TimeTicks::Now()), | 40 ping_time_(base::TimeTicks::Now()), |
41 pong_time_(ping_time_), | 41 pong_time_(ping_time_), |
42 ping_sequence_number_(0), | 42 ping_sequence_number_(0), |
43 active_(false), | 43 active_(false), |
44 ping_count_(params.unresponsive_threshold), | 44 ping_count_(params.unresponsive_threshold), |
45 response_time_histogram_(NULL), | 45 response_time_histogram_(NULL), |
46 unresponsive_time_histogram_(NULL), | 46 unresponsive_time_histogram_(NULL), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 return; | 134 return; |
135 | 135 |
136 // Save the current time when we have sent ping message. | 136 // Save the current time when we have sent ping message. |
137 ping_time_ = base::TimeTicks::Now(); | 137 ping_time_ = base::TimeTicks::Now(); |
138 | 138 |
139 // Send a ping message to the watched thread. Callback will be called on | 139 // Send a ping message to the watched thread. Callback will be called on |
140 // the WatchDogThread. | 140 // the WatchDogThread. |
141 base::Closure callback( | 141 base::Closure callback( |
142 base::Bind(&ThreadWatcher::OnPongMessage, weak_ptr_factory_.GetWeakPtr(), | 142 base::Bind(&ThreadWatcher::OnPongMessage, weak_ptr_factory_.GetWeakPtr(), |
143 ping_sequence_number_)); | 143 ping_sequence_number_)); |
144 if (watched_loop_->PostTask( | 144 if (watched_runner_->PostTask( |
145 FROM_HERE, | 145 FROM_HERE, |
146 base::Bind(&ThreadWatcher::OnPingMessage, thread_id_, | 146 base::Bind(&ThreadWatcher::OnPingMessage, thread_id_, |
147 callback))) { | 147 callback))) { |
148 // Post a task to check the responsiveness of watched thread. | 148 // Post a task to check the responsiveness of watched thread. |
149 base::MessageLoop::current()->PostDelayedTask( | 149 base::MessageLoop::current()->PostDelayedTask( |
150 FROM_HERE, | 150 FROM_HERE, |
151 base::Bind(&ThreadWatcher::OnCheckResponsiveness, | 151 base::Bind(&ThreadWatcher::OnCheckResponsiveness, |
152 weak_ptr_factory_.GetWeakPtr(), ping_sequence_number_), | 152 weak_ptr_factory_.GetWeakPtr(), ping_sequence_number_), |
153 unresponsive_time_); | 153 unresponsive_time_); |
154 } else { | 154 } else { |
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
928 | 928 |
929 #if defined(OS_WIN) | 929 #if defined(OS_WIN) |
930 // On Windows XP, give twice the time for shutdown. | 930 // On Windows XP, give twice the time for shutdown. |
931 if (base::win::GetVersion() <= base::win::VERSION_XP) | 931 if (base::win::GetVersion() <= base::win::VERSION_XP) |
932 actual_duration *= 2; | 932 actual_duration *= 2; |
933 #endif | 933 #endif |
934 | 934 |
935 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 935 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
936 shutdown_watchdog_->Arm(); | 936 shutdown_watchdog_->Arm(); |
937 } | 937 } |
OLD | NEW |