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 // This file defines a WatchDog thread that monitors the responsiveness of other | 5 // This file defines a WatchDog thread that monitors the responsiveness of other |
6 // browser threads like UI, IO, DB, FILE and CACHED threads. It also defines | 6 // browser threads like UI, IO, DB, FILE and CACHED threads. It also defines |
7 // ThreadWatcher class which performs health check on threads that would like to | 7 // ThreadWatcher class which performs health check on threads that would like to |
8 // be watched. This file also defines ThreadWatcherList class that has list of | 8 // be watched. This file also defines ThreadWatcherList class that has list of |
9 // all active ThreadWatcher objects. | 9 // all active ThreadWatcher objects. |
10 // | 10 // |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
131 | 131 |
132 // Returns true if we are montioring the thread. | 132 // Returns true if we are montioring the thread. |
133 bool active() const { return active_; } | 133 bool active() const { return active_; } |
134 | 134 |
135 // Returns |ping_time_| (used by unit tests). | 135 // Returns |ping_time_| (used by unit tests). |
136 base::TimeTicks ping_time() const { return ping_time_; } | 136 base::TimeTicks ping_time() const { return ping_time_; } |
137 | 137 |
138 // Returns |ping_sequence_number_| (used by unit tests). | 138 // Returns |ping_sequence_number_| (used by unit tests). |
139 uint64_t ping_sequence_number() const { return ping_sequence_number_; } | 139 uint64_t ping_sequence_number() const { return ping_sequence_number_; } |
140 | 140 |
141 virtual ~ThreadWatcher(); | |
Ilya Sherman
2016/08/31 03:54:42
nit: Please move this to the top of the class defi
Joshua LeVasseur
2016/08/31 19:06:50
Done.
| |
142 | |
141 protected: | 143 protected: |
142 // Construct a ThreadWatcher for the given |thread_id|. |sleep_time| is the | 144 // Construct a ThreadWatcher for the given |thread_id|. |sleep_time| is the |
143 // wait time between ping messages. |unresponsive_time| is the wait time after | 145 // wait time between ping messages. |unresponsive_time| is the wait time after |
144 // ping message is sent, to check if we have received pong message or not. | 146 // ping message is sent, to check if we have received pong message or not. |
145 explicit ThreadWatcher(const WatchingParams& params); | 147 explicit ThreadWatcher(const WatchingParams& params); |
146 | 148 |
147 virtual ~ThreadWatcher(); | |
148 | |
149 // This method activates the thread watching which starts ping/pong messaging. | 149 // This method activates the thread watching which starts ping/pong messaging. |
150 virtual void ActivateThreadWatching(); | 150 virtual void ActivateThreadWatching(); |
151 | 151 |
152 // This method de-activates the thread watching and revokes all tasks. | 152 // This method de-activates the thread watching and revokes all tasks. |
153 virtual void DeActivateThreadWatching(); | 153 virtual void DeActivateThreadWatching(); |
154 | 154 |
155 // This will ensure that the watching is actively taking place, and awaken | 155 // This will ensure that the watching is actively taking place, and awaken |
156 // (i.e., post a PostPingMessage()) if the watcher has stopped pinging due to | 156 // (i.e., post a PostPingMessage()) if the watcher has stopped pinging due to |
157 // lack of user activity. It will also reset |ping_count_| to | 157 // lack of user activity. It will also reset |ping_count_| to |
158 // |unresponsive_threshold_|. | 158 // |unresponsive_threshold_|. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 // This method is accessible on UI thread. | 387 // This method is accessible on UI thread. |
388 static void StartWatchingAll(const base::CommandLine& command_line); | 388 static void StartWatchingAll(const base::CommandLine& command_line); |
389 | 389 |
390 // This method posts a task on WatchDogThread to RevokeAll tasks and to | 390 // This method posts a task on WatchDogThread to RevokeAll tasks and to |
391 // deactive thread watching of other threads and tell NotificationService to | 391 // deactive thread watching of other threads and tell NotificationService to |
392 // stop calling Observe. | 392 // stop calling Observe. |
393 // This method is accessible on UI thread. | 393 // This method is accessible on UI thread. |
394 static void StopWatchingAll(); | 394 static void StopWatchingAll(); |
395 | 395 |
396 // Register() stores a pointer to the given ThreadWatcher in a global map. | 396 // Register() stores a pointer to the given ThreadWatcher in a global map. |
397 static void Register(ThreadWatcher* watcher); | 397 // It takes ownership of the ThreadWatcher. Returns true if it was |
Ilya Sherman
2016/08/31 03:54:42
nit: No need to document the ownership transfer --
Joshua LeVasseur
2016/08/31 19:06:50
Done.
| |
398 | 398 // successfully registered. |
399 // This method returns true if the ThreadWatcher object is registerd. | 399 static bool Register(std::unique_ptr<ThreadWatcher> watcher); |
400 static bool IsRegistered(const content::BrowserThread::ID thread_id); | |
401 | 400 |
402 // This method returns number of responsive and unresponsive watched threads. | 401 // This method returns number of responsive and unresponsive watched threads. |
403 static void GetStatusOfThreads(uint32_t* responding_thread_count, | 402 static void GetStatusOfThreads(uint32_t* responding_thread_count, |
404 uint32_t* unresponding_thread_count); | 403 uint32_t* unresponding_thread_count); |
405 | 404 |
406 // This will ensure that the watching is actively taking place, and awaken | 405 // This will ensure that the watching is actively taking place, and awaken |
407 // all thread watchers that are registered. | 406 // all thread watchers that are registered. |
408 static void WakeUpAll(); | 407 static void WakeUpAll(); |
409 | 408 |
410 private: | 409 private: |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
687 // shutdown_watchdog_ watches for hangs during shutdown. | 686 // shutdown_watchdog_ watches for hangs during shutdown. |
688 base::Watchdog* shutdown_watchdog_; | 687 base::Watchdog* shutdown_watchdog_; |
689 | 688 |
690 // The |thread_id_| on which this object is constructed. | 689 // The |thread_id_| on which this object is constructed. |
691 const base::PlatformThreadId thread_id_; | 690 const base::PlatformThreadId thread_id_; |
692 | 691 |
693 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); | 692 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); |
694 }; | 693 }; |
695 | 694 |
696 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ | 695 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ |
OLD | NEW |