| OLD | NEW |
| 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 // 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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 // DB, FILE, CACHED threads. | 455 // DB, FILE, CACHED threads. |
| 456 class WatchDogThread : public base::Thread { | 456 class WatchDogThread : public base::Thread { |
| 457 public: | 457 public: |
| 458 // Constructor. | 458 // Constructor. |
| 459 WatchDogThread(); | 459 WatchDogThread(); |
| 460 | 460 |
| 461 // Destroys the thread and stops the thread. | 461 // Destroys the thread and stops the thread. |
| 462 virtual ~WatchDogThread(); | 462 virtual ~WatchDogThread(); |
| 463 | 463 |
| 464 // Callable on any thread. Returns whether you're currently on a | 464 // Callable on any thread. Returns whether you're currently on a |
| 465 // WatchDogThread. | 465 // watchdog_thread_. |
| 466 static bool CurrentlyOnWatchDogThread(); | 466 static bool CurrentlyOnWatchDogThread(); |
| 467 | 467 |
| 468 // These are the same methods in message_loop.h, but are guaranteed to either | 468 // These are the same methods in message_loop.h, but are guaranteed to either |
| 469 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. | 469 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. |
| 470 // They return true iff the watchdog thread existed and the task was posted. | 470 // They return true iff the watchdog thread existed and the task was posted. |
| 471 // Note that even if the task is posted, there's no guarantee that it will | 471 // Note that even if the task is posted, there's no guarantee that it will |
| 472 // run, since the target thread may already have a Quit message in its queue. | 472 // run, since the target thread may already have a Quit message in its queue. |
| 473 static bool PostTask(const tracked_objects::Location& from_here, | 473 static bool PostTask(const tracked_objects::Location& from_here, |
| 474 const base::Closure& task); | 474 const base::Closure& task); |
| 475 static bool PostDelayedTask(const tracked_objects::Location& from_here, | 475 static bool PostDelayedTask(const tracked_objects::Location& from_here, |
| 476 const base::Closure& task, | 476 const base::Closure& task, |
| 477 int64 delay_ms); | 477 int64 delay_ms); |
| 478 | 478 |
| 479 protected: | 479 protected: |
| 480 virtual void Init(); | 480 virtual void Init(); |
| 481 virtual void CleanUp(); | 481 virtual void CleanUp(); |
| 482 | 482 |
| 483 private: | 483 private: |
| 484 static bool PostTaskHelper( | 484 static bool PostTaskHelper( |
| 485 const tracked_objects::Location& from_here, | 485 const tracked_objects::Location& from_here, |
| 486 const base::Closure& task, | 486 const base::Closure& task, |
| 487 int64 delay_ms); | 487 int64 delay_ms); |
| 488 | 488 |
| 489 // This lock protects watchdog_thread_. |
| 490 static base::Lock lock_; |
| 491 |
| 492 static WatchDogThread* watchdog_thread_; // The singleton of this class. |
| 493 |
| 489 DISALLOW_COPY_AND_ASSIGN(WatchDogThread); | 494 DISALLOW_COPY_AND_ASSIGN(WatchDogThread); |
| 490 }; | 495 }; |
| 491 | 496 |
| 492 // This is a wrapper class for getting the crash dumps of the hangs during | 497 // This is a wrapper class for getting the crash dumps of the hangs during |
| 493 // startup. | 498 // startup. |
| 494 class StartupTimeBomb { | 499 class StartupTimeBomb { |
| 495 public: | 500 public: |
| 496 // Constructs |startup_watchdog_| which spawns a thread and starts timer. | 501 // Constructs |startup_watchdog_| which spawns a thread and starts timer. |
| 497 // |duration| specifies how long |startup_watchdog_| will wait before it | 502 // |duration| specifies how long |startup_watchdog_| will wait before it |
| 498 // calls alarm. | 503 // calls alarm. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 528 | 533 |
| 529 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); | 534 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); |
| 530 }; | 535 }; |
| 531 | 536 |
| 532 // DISABLE_RUNNABLE_METHOD_REFCOUNT is a convenience macro for disabling | 537 // DISABLE_RUNNABLE_METHOD_REFCOUNT is a convenience macro for disabling |
| 533 // refcounting of ThreadWatcher and ThreadWatcherList classes. | 538 // refcounting of ThreadWatcher and ThreadWatcherList classes. |
| 534 DISABLE_RUNNABLE_METHOD_REFCOUNT(ThreadWatcher); | 539 DISABLE_RUNNABLE_METHOD_REFCOUNT(ThreadWatcher); |
| 535 DISABLE_RUNNABLE_METHOD_REFCOUNT(ThreadWatcherList); | 540 DISABLE_RUNNABLE_METHOD_REFCOUNT(ThreadWatcherList); |
| 536 | 541 |
| 537 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ | 542 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ |
| OLD | NEW |