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 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 if (recording_active_) | 629 if (recording_active_) |
630 return; | 630 return; |
631 recording_active_ = true; | 631 recording_active_ = true; |
632 | 632 |
633 ForceClientIdCreation(); | 633 ForceClientIdCreation(); |
634 child_process_logging::SetClientId(client_id_); | 634 child_process_logging::SetClientId(client_id_); |
635 if (!log_manager_.current_log()) | 635 if (!log_manager_.current_log()) |
636 OpenNewLog(); | 636 OpenNewLog(); |
637 | 637 |
638 SetUpNotifications(®istrar_, this); | 638 SetUpNotifications(®istrar_, this); |
| 639 content::RemoveActionCallback(action_callback_); |
| 640 action_callback_ = base::Bind(&MetricsService::OnUserAction, |
| 641 base::Unretained(this)); |
| 642 content::AddActionCallback(action_callback_); |
639 } | 643 } |
640 | 644 |
641 void MetricsService::DisableRecording() { | 645 void MetricsService::DisableRecording() { |
642 DCHECK(IsSingleThreaded()); | 646 DCHECK(IsSingleThreaded()); |
643 | 647 |
644 if (!recording_active_) | 648 if (!recording_active_) |
645 return; | 649 return; |
646 recording_active_ = false; | 650 recording_active_ = false; |
647 | 651 |
| 652 content::RemoveActionCallback(action_callback_); |
648 registrar_.RemoveAll(); | 653 registrar_.RemoveAll(); |
649 PushPendingLogsToPersistentStorage(); | 654 PushPendingLogsToPersistentStorage(); |
650 DCHECK(!log_manager_.has_staged_log()); | 655 DCHECK(!log_manager_.has_staged_log()); |
651 } | 656 } |
652 | 657 |
653 bool MetricsService::recording_active() const { | 658 bool MetricsService::recording_active() const { |
654 DCHECK(IsSingleThreaded()); | 659 DCHECK(IsSingleThreaded()); |
655 return recording_active_; | 660 return recording_active_; |
656 } | 661 } |
657 | 662 |
658 bool MetricsService::reporting_active() const { | 663 bool MetricsService::reporting_active() const { |
659 DCHECK(IsSingleThreaded()); | 664 DCHECK(IsSingleThreaded()); |
660 return reporting_active_; | 665 return reporting_active_; |
661 } | 666 } |
662 | 667 |
663 // static | 668 // static |
664 void MetricsService::SetUpNotifications( | 669 void MetricsService::SetUpNotifications( |
665 content::NotificationRegistrar* registrar, | 670 content::NotificationRegistrar* registrar, |
666 content::NotificationObserver* observer) { | 671 content::NotificationObserver* observer) { |
667 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED, | 672 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_OPENED, |
668 content::NotificationService::AllBrowserContextsAndSources()); | 673 content::NotificationService::AllBrowserContextsAndSources()); |
669 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED, | 674 registrar->Add(observer, chrome::NOTIFICATION_BROWSER_CLOSED, |
670 content::NotificationService::AllSources()); | 675 content::NotificationService::AllSources()); |
671 registrar->Add(observer, content::NOTIFICATION_USER_ACTION, | |
672 content::NotificationService::AllSources()); | |
673 registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED, | 676 registrar->Add(observer, chrome::NOTIFICATION_TAB_PARENTED, |
674 content::NotificationService::AllSources()); | 677 content::NotificationService::AllSources()); |
675 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING, | 678 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING, |
676 content::NotificationService::AllSources()); | 679 content::NotificationService::AllSources()); |
677 registrar->Add(observer, content::NOTIFICATION_LOAD_START, | 680 registrar->Add(observer, content::NOTIFICATION_LOAD_START, |
678 content::NotificationService::AllSources()); | 681 content::NotificationService::AllSources()); |
679 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, | 682 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, |
680 content::NotificationService::AllSources()); | 683 content::NotificationService::AllSources()); |
681 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 684 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
682 content::NotificationService::AllSources()); | 685 content::NotificationService::AllSources()); |
(...skipping 12 matching lines...) Expand all Loading... |
695 registrar->Add(observer, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, | 698 registrar->Add(observer, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, |
696 content::NotificationService::AllBrowserContextsAndSources()); | 699 content::NotificationService::AllBrowserContextsAndSources()); |
697 } | 700 } |
698 | 701 |
699 void MetricsService::Observe(int type, | 702 void MetricsService::Observe(int type, |
700 const content::NotificationSource& source, | 703 const content::NotificationSource& source, |
701 const content::NotificationDetails& details) { | 704 const content::NotificationDetails& details) { |
702 DCHECK(log_manager_.current_log()); | 705 DCHECK(log_manager_.current_log()); |
703 DCHECK(IsSingleThreaded()); | 706 DCHECK(IsSingleThreaded()); |
704 | 707 |
705 if (!CanLogNotification(type, source, details)) | 708 if (!CanLogNotification()) |
706 return; | 709 return; |
707 | 710 |
708 switch (type) { | 711 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: | 712 case chrome::NOTIFICATION_BROWSER_OPENED: |
715 case chrome::NOTIFICATION_BROWSER_CLOSED: { | 713 case chrome::NOTIFICATION_BROWSER_CLOSED: { |
716 Browser* browser = content::Source<Browser>(source).ptr(); | 714 Browser* browser = content::Source<Browser>(source).ptr(); |
717 LogWindowOrTabChange(type, reinterpret_cast<uintptr_t>(browser)); | 715 LogWindowOrTabChange(type, reinterpret_cast<uintptr_t>(browser)); |
718 break; | 716 break; |
719 } | 717 } |
720 | 718 |
721 case chrome::NOTIFICATION_TAB_PARENTED: { | 719 case chrome::NOTIFICATION_TAB_PARENTED: { |
722 content::WebContents* web_contents = | 720 content::WebContents* web_contents = |
723 content::Source<content::WebContents>(source).ptr(); | 721 content::Source<content::WebContents>(source).ptr(); |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1043 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 1041 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
1044 | 1042 |
1045 google_update_metrics_ = google_update_metrics; | 1043 google_update_metrics_ = google_update_metrics; |
1046 | 1044 |
1047 // Start the next part of the init task: fetching performance data. This will | 1045 // Start the next part of the init task: fetching performance data. This will |
1048 // call into |FinishedReceivingProfilerData()| when the task completes. | 1046 // call into |FinishedReceivingProfilerData()| when the task completes. |
1049 chrome_browser_metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously( | 1047 chrome_browser_metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously( |
1050 self_ptr_factory_.GetWeakPtr()); | 1048 self_ptr_factory_.GetWeakPtr()); |
1051 } | 1049 } |
1052 | 1050 |
| 1051 void MetricsService::OnUserAction(const std::string& action) { |
| 1052 if (!CanLogNotification()) |
| 1053 return; |
| 1054 |
| 1055 log_manager_.current_log()->RecordUserAction(action.c_str()); |
| 1056 HandleIdleSinceLastTransmission(false); |
| 1057 } |
| 1058 |
1053 void MetricsService::ReceivedProfilerData( | 1059 void MetricsService::ReceivedProfilerData( |
1054 const tracked_objects::ProcessDataSnapshot& process_data, | 1060 const tracked_objects::ProcessDataSnapshot& process_data, |
1055 content::ProcessType process_type) { | 1061 content::ProcessType process_type) { |
1056 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 1062 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); |
1057 | 1063 |
1058 // Upon the first callback, create the initial log so that we can immediately | 1064 // Upon the first callback, create the initial log so that we can immediately |
1059 // save the profiler data. | 1065 // save the profiler data. |
1060 if (!initial_log_.get()) | 1066 if (!initial_log_.get()) |
1061 initial_log_.reset(new MetricsLog(client_id_, session_id_)); | 1067 initial_log_.reset(new MetricsLog(client_id_, session_id_)); |
1062 | 1068 |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1938 stats.process_crashes); | 1944 stats.process_crashes); |
1939 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, | 1945 plugin_dict->SetInteger(prefs::kStabilityPluginInstances, |
1940 stats.instances); | 1946 stats.instances); |
1941 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, | 1947 plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, |
1942 stats.loading_errors); | 1948 stats.loading_errors); |
1943 plugins->Append(plugin_dict); | 1949 plugins->Append(plugin_dict); |
1944 } | 1950 } |
1945 child_process_stats_buffer_.clear(); | 1951 child_process_stats_buffer_.clear(); |
1946 } | 1952 } |
1947 | 1953 |
1948 bool MetricsService::CanLogNotification( | 1954 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 | 1955 // 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 | 1956 // session visible. The problem is that we always notify using the orginal |
1954 // profile in order to simplify notification processing. | 1957 // profile in order to simplify notification processing. |
1955 return !chrome::IsOffTheRecordSessionActive(); | 1958 return !chrome::IsOffTheRecordSessionActive(); |
1956 } | 1959 } |
1957 | 1960 |
1958 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { | 1961 void MetricsService::RecordBooleanPrefValue(const char* path, bool value) { |
1959 DCHECK(IsSingleThreaded()); | 1962 DCHECK(IsSingleThreaded()); |
1960 | 1963 |
1961 PrefService* pref = g_browser_process->local_state(); | 1964 PrefService* pref = g_browser_process->local_state(); |
(...skipping 30 matching lines...) Expand all Loading... |
1992 if (local_state) { | 1995 if (local_state) { |
1993 const PrefService::Preference* uma_pref = | 1996 const PrefService::Preference* uma_pref = |
1994 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1997 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
1995 if (uma_pref) { | 1998 if (uma_pref) { |
1996 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1999 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
1997 DCHECK(success); | 2000 DCHECK(success); |
1998 } | 2001 } |
1999 } | 2002 } |
2000 return result; | 2003 return result; |
2001 } | 2004 } |
OLD | NEW |