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 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 | 513 |
514 // Removes all ints from |registrar_| and deletes | 514 // Removes all ints from |registrar_| and deletes |
515 // |g_thread_watcher_observer_|. This method is accessible on UI thread. | 515 // |g_thread_watcher_observer_|. This method is accessible on UI thread. |
516 static void RemoveNotifications(); | 516 static void RemoveNotifications(); |
517 | 517 |
518 private: | 518 private: |
519 // Constructor of |g_thread_watcher_observer_| singleton. | 519 // Constructor of |g_thread_watcher_observer_| singleton. |
520 explicit ThreadWatcherObserver(const base::TimeDelta& wakeup_interval); | 520 explicit ThreadWatcherObserver(const base::TimeDelta& wakeup_interval); |
521 | 521 |
522 // Destructor of |g_thread_watcher_observer_| singleton. | 522 // Destructor of |g_thread_watcher_observer_| singleton. |
523 virtual ~ThreadWatcherObserver(); | 523 ~ThreadWatcherObserver() override; |
524 | 524 |
525 // This ensures all thread watchers are active because there is some user | 525 // This ensures all thread watchers are active because there is some user |
526 // activity. It will wake up all thread watchers every |wakeup_interval_| | 526 // activity. It will wake up all thread watchers every |wakeup_interval_| |
527 // seconds. This is the implementation of content::NotificationObserver. When | 527 // seconds. This is the implementation of content::NotificationObserver. When |
528 // a matching notification is posted to the notification service, this method | 528 // a matching notification is posted to the notification service, this method |
529 // is called. | 529 // is called. |
530 virtual void Observe(int type, | 530 void Observe(int type, |
531 const content::NotificationSource& source, | 531 const content::NotificationSource& source, |
532 const content::NotificationDetails& details) override; | 532 const content::NotificationDetails& details) override; |
533 | 533 |
534 // The singleton of this class. | 534 // The singleton of this class. |
535 static ThreadWatcherObserver* g_thread_watcher_observer_; | 535 static ThreadWatcherObserver* g_thread_watcher_observer_; |
536 | 536 |
537 // The registrar that holds ints to be observed. | 537 // The registrar that holds ints to be observed. |
538 content::NotificationRegistrar registrar_; | 538 content::NotificationRegistrar registrar_; |
539 | 539 |
540 // This is the last time when woke all thread watchers up. | 540 // This is the last time when woke all thread watchers up. |
541 base::TimeTicks last_wakeup_time_; | 541 base::TimeTicks last_wakeup_time_; |
542 | 542 |
543 // It is the time interval between wake up calls to thread watchers. | 543 // It is the time interval between wake up calls to thread watchers. |
544 const base::TimeDelta wakeup_interval_; | 544 const base::TimeDelta wakeup_interval_; |
545 | 545 |
546 DISALLOW_COPY_AND_ASSIGN(ThreadWatcherObserver); | 546 DISALLOW_COPY_AND_ASSIGN(ThreadWatcherObserver); |
547 }; | 547 }; |
548 | 548 |
549 // Class for WatchDogThread and in its Init method, we start watching UI, IO, | 549 // Class for WatchDogThread and in its Init method, we start watching UI, IO, |
550 // DB, FILE, CACHED threads. | 550 // DB, FILE, CACHED threads. |
551 class WatchDogThread : public base::Thread { | 551 class WatchDogThread : public base::Thread { |
552 public: | 552 public: |
553 // Constructor. | 553 // Constructor. |
554 WatchDogThread(); | 554 WatchDogThread(); |
555 | 555 |
556 // Destroys the thread and stops the thread. | 556 // Destroys the thread and stops the thread. |
557 virtual ~WatchDogThread(); | 557 ~WatchDogThread() override; |
558 | 558 |
559 // Callable on any thread. Returns whether you're currently on a | 559 // Callable on any thread. Returns whether you're currently on a |
560 // WatchDogThread. | 560 // WatchDogThread. |
561 static bool CurrentlyOnWatchDogThread(); | 561 static bool CurrentlyOnWatchDogThread(); |
562 | 562 |
563 // These are the same methods in message_loop.h, but are guaranteed to either | 563 // These are the same methods in message_loop.h, but are guaranteed to either |
564 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. | 564 // get posted to the MessageLoop if it's still alive, or be deleted otherwise. |
565 // They return true iff the watchdog thread existed and the task was posted. | 565 // They return true iff the watchdog thread existed and the task was posted. |
566 // Note that even if the task is posted, there's no guarantee that it will | 566 // Note that even if the task is posted, there's no guarantee that it will |
567 // run, since the target thread may already have a Quit message in its queue. | 567 // run, since the target thread may already have a Quit message in its queue. |
568 static bool PostTask(const tracked_objects::Location& from_here, | 568 static bool PostTask(const tracked_objects::Location& from_here, |
569 const base::Closure& task); | 569 const base::Closure& task); |
570 static bool PostDelayedTask(const tracked_objects::Location& from_here, | 570 static bool PostDelayedTask(const tracked_objects::Location& from_here, |
571 const base::Closure& task, | 571 const base::Closure& task, |
572 base::TimeDelta delay); | 572 base::TimeDelta delay); |
573 | 573 |
574 protected: | 574 protected: |
575 virtual void Init() override; | 575 void Init() override; |
576 virtual void CleanUp() override; | 576 void CleanUp() override; |
577 | 577 |
578 private: | 578 private: |
579 static bool PostTaskHelper( | 579 static bool PostTaskHelper( |
580 const tracked_objects::Location& from_here, | 580 const tracked_objects::Location& from_here, |
581 const base::Closure& task, | 581 const base::Closure& task, |
582 base::TimeDelta delay); | 582 base::TimeDelta delay); |
583 | 583 |
584 DISALLOW_COPY_AND_ASSIGN(WatchDogThread); | 584 DISALLOW_COPY_AND_ASSIGN(WatchDogThread); |
585 }; | 585 }; |
586 | 586 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
641 // shutdown_watchdog_ watches for hangs during shutdown. | 641 // shutdown_watchdog_ watches for hangs during shutdown. |
642 base::Watchdog* shutdown_watchdog_; | 642 base::Watchdog* shutdown_watchdog_; |
643 | 643 |
644 // The |thread_id_| on which this object is constructed. | 644 // The |thread_id_| on which this object is constructed. |
645 const base::PlatformThreadId thread_id_; | 645 const base::PlatformThreadId thread_id_; |
646 | 646 |
647 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); | 647 DISALLOW_COPY_AND_ASSIGN(ShutdownWatcherHelper); |
648 }; | 648 }; |
649 | 649 |
650 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ | 650 #endif // CHROME_BROWSER_METRICS_THREAD_WATCHER_H_ |
OLD | NEW |