| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 | 49 |
| 50 #include "base/basictypes.h" | 50 #include "base/basictypes.h" |
| 51 #include "base/command_line.h" | 51 #include "base/command_line.h" |
| 52 #include "base/gtest_prod_util.h" | 52 #include "base/gtest_prod_util.h" |
| 53 #include "base/memory/ref_counted.h" | 53 #include "base/memory/ref_counted.h" |
| 54 #include "base/memory/scoped_ptr.h" | 54 #include "base/memory/scoped_ptr.h" |
| 55 #include "base/memory/weak_ptr.h" | 55 #include "base/memory/weak_ptr.h" |
| 56 #include "base/message_loop.h" | 56 #include "base/message_loop.h" |
| 57 #include "base/metrics/histogram.h" | 57 #include "base/metrics/histogram.h" |
| 58 #include "base/synchronization/lock.h" | 58 #include "base/synchronization/lock.h" |
| 59 #include "base/threading/platform_thread.h" |
| 59 #include "base/threading/thread.h" | 60 #include "base/threading/thread.h" |
| 60 #include "base/threading/watchdog.h" | 61 #include "base/threading/watchdog.h" |
| 61 #include "base/time.h" | 62 #include "base/time.h" |
| 62 #include "content/public/browser/browser_thread.h" | 63 #include "content/public/browser/browser_thread.h" |
| 63 #include "content/public/browser/notification_observer.h" | 64 #include "content/public/browser/notification_observer.h" |
| 64 #include "content/public/browser/notification_registrar.h" | 65 #include "content/public/browser/notification_registrar.h" |
| 65 | 66 |
| 66 class CustomThreadWatcher; | 67 class CustomThreadWatcher; |
| 67 class StartupTimeBomb; | 68 class StartupTimeBomb; |
| 68 class ThreadWatcherList; | 69 class ThreadWatcherList; |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 const base::Closure& task, | 487 const base::Closure& task, |
| 487 int64 delay_ms); | 488 int64 delay_ms); |
| 488 | 489 |
| 489 DISALLOW_COPY_AND_ASSIGN(WatchDogThread); | 490 DISALLOW_COPY_AND_ASSIGN(WatchDogThread); |
| 490 }; | 491 }; |
| 491 | 492 |
| 492 // This is a wrapper class for getting the crash dumps of the hangs during | 493 // This is a wrapper class for getting the crash dumps of the hangs during |
| 493 // startup. | 494 // startup. |
| 494 class StartupTimeBomb { | 495 class StartupTimeBomb { |
| 495 public: | 496 public: |
| 497 // This singleton is instantiated when the browser process is launched. |
| 498 StartupTimeBomb(); |
| 499 |
| 500 // Destructor disarm's startup_watchdog_ (if it is arm'ed) so that alarm |
| 501 // doesn't go off. |
| 502 ~StartupTimeBomb(); |
| 503 |
| 496 // Constructs |startup_watchdog_| which spawns a thread and starts timer. | 504 // Constructs |startup_watchdog_| which spawns a thread and starts timer. |
| 497 // |duration| specifies how long |startup_watchdog_| will wait before it | 505 // |duration| specifies how long |startup_watchdog_| will wait before it |
| 498 // calls alarm. | 506 // calls alarm. |
| 499 static void Arm(const base::TimeDelta& duration); | 507 void Arm(const base::TimeDelta& duration); |
| 500 | 508 |
| 501 // Disarms |startup_watchdog_| thread and then deletes it which stops the | 509 // Disarms |startup_watchdog_| thread and then deletes it which stops the |
| 502 // Watchdog thread. | 510 // Watchdog thread. |
| 503 static void Disarm(); | 511 void Disarm(); |
| 512 |
| 513 // Disarms |g_startup_timebomb_|. |
| 514 static void DisarmStartupTimeBomb(); |
| 504 | 515 |
| 505 private: | 516 private: |
| 517 // The singleton of this class. |
| 518 static StartupTimeBomb* g_startup_timebomb_; |
| 519 |
| 506 // Watches for hangs during startup until it is disarm'ed. | 520 // Watches for hangs during startup until it is disarm'ed. |
| 507 static base::Watchdog* startup_watchdog_; | 521 base::Watchdog* startup_watchdog_; |
| 522 |
| 523 // The |thread_id_| on which this object is constructed. |
| 524 const base::PlatformThreadId thread_id_; |
| 508 | 525 |
| 509 DISALLOW_COPY_AND_ASSIGN(StartupTimeBomb); | 526 DISALLOW_COPY_AND_ASSIGN(StartupTimeBomb); |
| 510 }; | 527 }; |
| 511 | 528 |
| 512 // This is a wrapper class for detecting hangs during shutdown. | 529 // This is a wrapper class for detecting hangs during shutdown. |
| 513 class ShutdownWatcherHelper { | 530 class ShutdownWatcherHelper { |
| 514 public: | 531 public: |
| 515 // Create an empty holder for |shutdown_watchdog_|. | 532 // Create an empty holder for |shutdown_watchdog_|. |
| 516 ShutdownWatcherHelper(); | 533 ShutdownWatcherHelper(); |
| 517 | 534 |
| 518 // Destructor disarm's shutdown_watchdog_ so that alarm doesn't go off. | 535 // Destructor disarm's shutdown_watchdog_ so that alarm doesn't go off. |
| 519 ~ShutdownWatcherHelper(); | 536 ~ShutdownWatcherHelper(); |
| 520 | 537 |
| 521 // Constructs ShutdownWatchDogThread which spawns a thread and starts timer. | 538 // Constructs ShutdownWatchDogThread which spawns a thread and starts timer. |
| 522 // |duration| specifies how long it will wait before it calls alarm. | 539 // |duration| specifies how long it will wait before it calls alarm. |
| 523 void Arm(const base::TimeDelta& duration); | 540 void Arm(const base::TimeDelta& duration); |
| 524 | 541 |
| 525 private: | 542 private: |
| 526 // shutdown_watchdog_ watches for hangs during shutdown. | 543 // shutdown_watchdog_ watches for hangs during shutdown. |
| 527 base::Watchdog* shutdown_watchdog_; | 544 base::Watchdog* shutdown_watchdog_; |
| 528 | 545 |
| 546 // The |thread_id_| on which this object is constructed. |
| 547 const base::PlatformThreadId thread_id_; |
| 548 |
| 529 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); | 549 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); |
| 530 }; | 550 }; |
| 531 | 551 |
| 532 // DISABLE_RUNNABLE_METHOD_REFCOUNT is a convenience macro for disabling | 552 // DISABLE_RUNNABLE_METHOD_REFCOUNT is a convenience macro for disabling |
| 533 // refcounting of ThreadWatcher and ThreadWatcherList classes. | 553 // refcounting of ThreadWatcher and ThreadWatcherList classes. |
| 534 DISABLE_RUNNABLE_METHOD_REFCOUNT(ThreadWatcher); | 554 DISABLE_RUNNABLE_METHOD_REFCOUNT(ThreadWatcher); |
| 535 DISABLE_RUNNABLE_METHOD_REFCOUNT(ThreadWatcherList); | 555 DISABLE_RUNNABLE_METHOD_REFCOUNT(ThreadWatcherList); |
| 536 | 556 |
| 537 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ | 557 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ |
| OLD | NEW |