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 //------------------------------------------------------------------------------ | 5 //------------------------------------------------------------------------------ |
6 // Description of the life cycle of a instance of MetricsService. | 6 // Description of the life cycle of a instance of MetricsService. |
7 // | 7 // |
8 // OVERVIEW | 8 // OVERVIEW |
9 // | 9 // |
10 // A MetricsService instance is typically created at application startup. It | 10 // A MetricsService instance is typically created at application startup. It |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 } | 661 } |
662 | 662 |
663 // static | 663 // static |
664 void MetricsService::SetUpNotifications( | 664 void MetricsService::SetUpNotifications( |
665 content::NotificationRegistrar* registrar, | 665 content::NotificationRegistrar* registrar, |
666 content::NotificationObserver* observer) { | 666 content::NotificationObserver* observer) { |
667 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED, | 667 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED, |
668 content::NotificationService::AllBrowserContextsAndSources()); | 668 content::NotificationService::AllBrowserContextsAndSources()); |
669 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED, | 669 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED, |
670 content::NotificationService::AllSources()); | 670 content::NotificationService::AllSources()); |
671 registrar->Add(observer, content::NOTIFICATION_USER_ACTION, | |
672 content::NotificationService::AllSources()); | |
673 registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED, | 671 registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED, |
674 content::NotificationService::AllSources()); | 672 content::NotificationService::AllSources()); |
675 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING, | 673 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING, |
676 content::NotificationService::AllSources()); | 674 content::NotificationService::AllSources()); |
677 registrar->Add(observer, content::NOTIFICATION_LOAD_START, | 675 registrar->Add(observer, content::NOTIFICATION_LOAD_START, |
678 content::NotificationService::AllSources()); | 676 content::NotificationService::AllSources()); |
679 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, | 677 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, |
680 content::NotificationService::AllSources()); | 678 content::NotificationService::AllSources()); |
681 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 679 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
682 content::NotificationService::AllSources()); | 680 content::NotificationService::AllSources()); |
(...skipping 12 matching lines...) Expand all Loading... |
695 registrar->Add(observer, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 693 registrar->Add(observer, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
696 content::NotificationService::AllBrowserContextsAndSources()); | 694 content::NotificationService::AllBrowserContextsAndSources()); |
697 } | 695 } |
698 | 696 |
699 void MetricsService::Observe(int type, | 697 void MetricsService::Observe(int type, |
700 const content::NotificationSource& source, | 698 const content::NotificationSource& source, |
701 const content::NotificationDetails& details) { | 699 const content::NotificationDetails& details) { |
702 DCHECK(log_manager_.current_log()); | 700 DCHECK(log_manager_.current_log()); |
703 DCHECK(IsSingleThreaded()); | 701 DCHECK(IsSingleThreaded()); |
704 | 702 |
705 if (!CanLogNotification(type, source, details)) | 703 if (!CanLogNotification()) |
706 return; | 704 return; |
707 | 705 |
708 switch (type) { | 706 switch (type) { |
709 case content::NOTIFICATION_USER_ACTION: | |
710 log_manager_.current_log()->RecordUserAction( | |
711 *content::Details<const char*>(details).ptr()); | |
712 break; | |
713 | |
714 case chrome::NOTIFICATION_BROWSER_OPENED: | 707 case chrome::NOTIFICATION_BROWSER_OPENED: |
715 case chrome::NOTIFICATION_BROWSER_CLOSED: { | 708 case chrome::NOTIFICATION_BROWSER_CLOSED: { |
716 Browser* browser = content::Source<Browser>(source).ptr(); | 709 Browser* browser = content::Source<Browser>(source).ptr(); |
717 LogWindowOrTabChange(type, reinterpret_cast<uintptr_t>(browser)); | 710 LogWindowOrTabChange(type, reinterpret_cast<uintptr_t>(browser)); |
718 break; | 711 break; |
719 } | 712 } |
720 | 713 |
721 case chrome::NOTIFICATION_TAB_PARENTED: { | 714 case chrome::NOTIFICATION_TAB_PARENTED: { |
722 content::WebContents* web_contents = | 715 content::WebContents* web_contents = |
723 content::Source<content::WebContents>(source).ptr(); | 716 content::Source<content::WebContents>(source).ptr(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 break; | 777 break; |
785 } | 778 } |
786 default: | 779 default: |
787 NOTREACHED(); | 780 NOTREACHED(); |
788 break; | 781 break; |
789 } | 782 } |
790 | 783 |
791 HandleIdleSinceLastTransmission(false); | 784 HandleIdleSinceLastTransmission(false); |
792 } | 785 } |
793 | 786 |
| 787 void MetricsService::UserAction(const std::string& action) { |
| 788 if (!CanLogNotification()) |
| 789 return; |
| 790 |
| 791 log_manager_.current_log()->RecordUserAction(action.c_str()); |
| 792 HandleIdleSinceLastTransmission(false); |
| 793 } |
| 794 |
794 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { | 795 void MetricsService::HandleIdleSinceLastTransmission(bool in_idle) { |
795 // If there wasn't a lot of action, maybe the computer was asleep, in which | 796 // If there wasn't a lot of action, maybe the computer was asleep, in which |
796 // case, the log transmissions should have stopped. Here we start them up | 797 // case, the log transmissions should have stopped. Here we start them up |
797 // again. | 798 // again. |
798 if (!in_idle && idle_since_last_transmission_) | 799 if (!in_idle && idle_since_last_transmission_) |
799 StartSchedulerIfNecessary(); | 800 StartSchedulerIfNecessary(); |
800 idle_since_last_transmission_ = in_idle; | 801 idle_since_last_transmission_ = in_idle; |
801 } | 802 } |
802 | 803 |
803 void MetricsService::RecordStartOfSessionEnd() { | 804 void MetricsService::RecordStartOfSessionEnd() { |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 stats.process_crashes); | 1939 stats.process_crashes); |
1939 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, | 1940 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, |
1940 stats.instances); | 1941 stats.instances); |
1941 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, | 1942 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, |
1942 stats.loading_errors); | 1943 stats.loading_errors); |
1943 plugins->Append(plugin_dict); | 1944 plugins->Append(plugin_dict); |
1944 } | 1945 } |
1945 child_process_stats_buffer_.clear(); | 1946 child_process_stats_buffer_.clear(); |
1946 } | 1947 } |
1947 | 1948 |
1948 bool MetricsService::CanLogNotification( | 1949 bool MetricsService::CanLogNotification() { |
1949 int type, | |
1950 const content::NotificationSource& source, | |
1951 const content::NotificationDetails& details) { | |
1952 // We simply don't log anything to UMA if there is a single incognito | 1950 // We simply don't log anything to UMA if there is a single incognito |
1953 // session visible. The problem is that we always notify using the orginal | 1951 // session visible. The problem is that we always notify using the orginal |
1954 // profile in order to simplify notification processing. | 1952 // profile in order to simplify notification processing. |
1955 return !chrome::IsOffTheRecordSessionActive(); | 1953 return !chrome::IsOffTheRecordSessionActive(); |
1956 } | 1954 } |
1957 | 1955 |
1958 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1956 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1959 DCHECK(IsSingleThreaded()); | 1957 DCHECK(IsSingleThreaded()); |
1960 | 1958 |
1961 PrefService* pref = g_browser_process->local_state(); | 1959 PrefService* pref = g_browser_process->local_state(); |
(...skipping 30 matching lines...) Expand all Loading... |
1992 if (local_state) { | 1990 if (local_state) { |
1993 const PrefService::Preference* uma_pref = | 1991 const PrefService::Preference* uma_pref = |
1994 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1992 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
1995 if (uma_pref) { | 1993 if (uma_pref) { |
1996 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1994 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
1997 DCHECK(success); | 1995 DCHECK(success); |
1998 } | 1996 } |
1999 } | 1997 } |
2000 return result; | 1998 return result; |
2001 } | 1999 } |
OLD | NEW |