| 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 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 content::NotificationService::AllSources()); | 681 content::NotificationService::AllSources()); |
| 682 observer->registrar_.Add(observer, | 682 observer->registrar_.Add(observer, |
| 683 content::NOTIFICATION_LOAD_STOP, | 683 content::NOTIFICATION_LOAD_STOP, |
| 684 content::NotificationService::AllSources()); | 684 content::NotificationService::AllSources()); |
| 685 observer->registrar_.Add(observer, | 685 observer->registrar_.Add(observer, |
| 686 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 686 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 687 content::NotificationService::AllSources()); | 687 content::NotificationService::AllSources()); |
| 688 observer->registrar_.Add(observer, | 688 observer->registrar_.Add(observer, |
| 689 content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, | 689 content::NOTIFICATION_RENDER_WIDGET_HOST_HANG, |
| 690 content::NotificationService::AllSources()); | 690 content::NotificationService::AllSources()); |
| 691 observer->registrar_.Add(observer, | 691 observer->omnibox_url_opened_subscription_ = |
| 692 chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 692 OmniboxEventGlobalTracker::GetInstance()->RegisterCallback( |
| 693 content::NotificationService::AllSources()); | 693 base::Bind(&ThreadWatcherObserver::OnURLOpenedFromOmnibox, |
| 694 base::Unretained(observer))); |
| 694 } | 695 } |
| 695 | 696 |
| 696 // static | 697 // static |
| 697 void ThreadWatcherObserver::RemoveNotifications() { | 698 void ThreadWatcherObserver::RemoveNotifications() { |
| 698 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 699 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 699 if (!g_thread_watcher_observer_) | 700 if (!g_thread_watcher_observer_) |
| 700 return; | 701 return; |
| 701 g_thread_watcher_observer_->registrar_.RemoveAll(); | 702 g_thread_watcher_observer_->registrar_.RemoveAll(); |
| 702 delete g_thread_watcher_observer_; | 703 delete g_thread_watcher_observer_; |
| 703 } | 704 } |
| 704 | 705 |
| 705 void ThreadWatcherObserver::Observe( | 706 void ThreadWatcherObserver::Observe( |
| 706 int type, | 707 int type, |
| 707 const content::NotificationSource& source, | 708 const content::NotificationSource& source, |
| 708 const content::NotificationDetails& details) { | 709 const content::NotificationDetails& details) { |
| 710 OnUserActivityDetected(); |
| 711 } |
| 712 |
| 713 void ThreadWatcherObserver::OnURLOpenedFromOmnibox(OmniboxLog* log) { |
| 714 OnUserActivityDetected(); |
| 715 } |
| 716 |
| 717 void ThreadWatcherObserver::OnUserActivityDetected() { |
| 709 // There is some user activity, see if thread watchers are to be awakened. | 718 // There is some user activity, see if thread watchers are to be awakened. |
| 710 base::TimeTicks now = base::TimeTicks::Now(); | 719 base::TimeTicks now = base::TimeTicks::Now(); |
| 711 if ((now - last_wakeup_time_) < wakeup_interval_) | 720 if ((now - last_wakeup_time_) < wakeup_interval_) |
| 712 return; | 721 return; |
| 713 last_wakeup_time_ = now; | 722 last_wakeup_time_ = now; |
| 714 WatchDogThread::PostTask( | 723 WatchDogThread::PostTask( |
| 715 FROM_HERE, | 724 FROM_HERE, |
| 716 base::Bind(&ThreadWatcherList::WakeUpAll)); | 725 base::Bind(&ThreadWatcherList::WakeUpAll)); |
| 717 } | 726 } |
| 718 | 727 |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 930 | 939 |
| 931 #if defined(OS_WIN) | 940 #if defined(OS_WIN) |
| 932 // On Windows XP, give twice the time for shutdown. | 941 // On Windows XP, give twice the time for shutdown. |
| 933 if (base::win::GetVersion() <= base::win::VERSION_XP) | 942 if (base::win::GetVersion() <= base::win::VERSION_XP) |
| 934 actual_duration *= 2; | 943 actual_duration *= 2; |
| 935 #endif | 944 #endif |
| 936 | 945 |
| 937 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); | 946 shutdown_watchdog_ = new ShutdownWatchDogThread(actual_duration); |
| 938 shutdown_watchdog_->Arm(); | 947 shutdown_watchdog_->Arm(); |
| 939 } | 948 } |
| OLD | NEW |