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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 waiting_for_asynchronous_reporting_step_(false), | 525 waiting_for_asynchronous_reporting_step_(false), |
526 entropy_source_returned_(LAST_ENTROPY_NONE) { | 526 entropy_source_returned_(LAST_ENTROPY_NONE) { |
527 DCHECK(IsSingleThreaded()); | 527 DCHECK(IsSingleThreaded()); |
528 InitializeMetricsState(); | 528 InitializeMetricsState(); |
529 | 529 |
530 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, | 530 base::Closure callback = base::Bind(&MetricsService::StartScheduledUpload, |
531 self_ptr_factory_.GetWeakPtr()); | 531 self_ptr_factory_.GetWeakPtr()); |
532 scheduler_.reset(new MetricsReportingScheduler(callback)); | 532 scheduler_.reset(new MetricsReportingScheduler(callback)); |
533 log_manager_.set_log_serializer(new MetricsLogSerializer()); | 533 log_manager_.set_log_serializer(new MetricsLogSerializer()); |
534 log_manager_.set_max_ongoing_log_store_size(kUploadLogAvoidRetransmitSize); | 534 log_manager_.set_max_ongoing_log_store_size(kUploadLogAvoidRetransmitSize); |
| 535 |
| 536 BrowserChildProcessObserver::Add(this); |
535 } | 537 } |
536 | 538 |
537 MetricsService::~MetricsService() { | 539 MetricsService::~MetricsService() { |
538 DisableRecording(); | 540 DisableRecording(); |
| 541 |
| 542 BrowserChildProcessObserver::Remove(this); |
539 } | 543 } |
540 | 544 |
541 void MetricsService::Start() { | 545 void MetricsService::Start() { |
542 HandleIdleSinceLastTransmission(false); | 546 HandleIdleSinceLastTransmission(false); |
543 EnableRecording(); | 547 EnableRecording(); |
544 EnableReporting(); | 548 EnableReporting(); |
545 } | 549 } |
546 | 550 |
547 void MetricsService::StartRecordingForTests() { | 551 void MetricsService::StartRecordingForTests() { |
548 test_mode_active_ = true; | 552 test_mode_active_ = true; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING, | 673 registrar->Add(observer, chrome::NOTIFICATION_TAB_CLOSING, |
670 content::NotificationService::AllSources()); | 674 content::NotificationService::AllSources()); |
671 registrar->Add(observer, content::NOTIFICATION_LOAD_START, | 675 registrar->Add(observer, content::NOTIFICATION_LOAD_START, |
672 content::NotificationService::AllSources()); | 676 content::NotificationService::AllSources()); |
673 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, | 677 registrar->Add(observer, content::NOTIFICATION_LOAD_STOP, |
674 content::NotificationService::AllSources()); | 678 content::NotificationService::AllSources()); |
675 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, | 679 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, |
676 content::NotificationService::AllSources()); | 680 content::NotificationService::AllSources()); |
677 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_HANG, | 681 registrar->Add(observer, content::NOTIFICATION_RENDERER_PROCESS_HANG, |
678 content::NotificationService::AllSources()); | 682 content::NotificationService::AllSources()); |
679 registrar->Add(observer, content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED, | |
680 content::NotificationService::AllSources()); | |
681 registrar->Add(observer, content::NOTIFICATION_CHILD_INSTANCE_CREATED, | |
682 content::NotificationService::AllSources()); | |
683 registrar->Add(observer, content::NOTIFICATION_CHILD_PROCESS_CRASHED, | |
684 content::NotificationService::AllSources()); | |
685 registrar->Add(observer, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, | 683 registrar->Add(observer, chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED, |
686 content::NotificationService::AllSources()); | 684 content::NotificationService::AllSources()); |
687 registrar->Add(observer, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 685 registrar->Add(observer, chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
688 content::NotificationService::AllSources()); | 686 content::NotificationService::AllSources()); |
689 } | 687 } |
690 | 688 |
| 689 void MetricsService::BrowserChildProcessHostConnected( |
| 690 const content::ChildProcessData& data) { |
| 691 GetChildProcessStats(data).process_launches++; |
| 692 } |
| 693 |
| 694 void MetricsService::BrowserChildProcessCrashed( |
| 695 const content::ChildProcessData& data) { |
| 696 GetChildProcessStats(data).process_crashes++; |
| 697 // Exclude plugin crashes from the count below because we report them via |
| 698 // a separate UMA metric. |
| 699 if (!IsPluginProcess(data.type)) |
| 700 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); |
| 701 } |
| 702 |
| 703 void MetricsService::BrowserChildProcessInstanceCreated( |
| 704 const content::ChildProcessData& data) { |
| 705 GetChildProcessStats(data).instances++; |
| 706 } |
| 707 |
691 void MetricsService::Observe(int type, | 708 void MetricsService::Observe(int type, |
692 const content::NotificationSource& source, | 709 const content::NotificationSource& source, |
693 const content::NotificationDetails& details) { | 710 const content::NotificationDetails& details) { |
694 DCHECK(log_manager_.current_log()); | 711 DCHECK(log_manager_.current_log()); |
695 DCHECK(IsSingleThreaded()); | 712 DCHECK(IsSingleThreaded()); |
696 | 713 |
697 if (!CanLogNotification()) | 714 if (!CanLogNotification()) |
698 return; | 715 return; |
699 | 716 |
700 switch (type) { | 717 switch (type) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 content::Source<content::RenderProcessHost>(source).ptr(); | 754 content::Source<content::RenderProcessHost>(source).ptr(); |
738 LogRendererCrash( | 755 LogRendererCrash( |
739 host, process_details->status, process_details->exit_code); | 756 host, process_details->status, process_details->exit_code); |
740 } | 757 } |
741 break; | 758 break; |
742 | 759 |
743 case content::NOTIFICATION_RENDERER_PROCESS_HANG: | 760 case content::NOTIFICATION_RENDERER_PROCESS_HANG: |
744 LogRendererHang(); | 761 LogRendererHang(); |
745 break; | 762 break; |
746 | 763 |
747 case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: | |
748 case content::NOTIFICATION_CHILD_PROCESS_CRASHED: | |
749 case content::NOTIFICATION_CHILD_INSTANCE_CREATED: | |
750 LogChildProcessChange(type, source, details); | |
751 break; | |
752 | |
753 case chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED: | 764 case chrome::NOTIFICATION_TEMPLATE_URL_SERVICE_LOADED: |
754 LogKeywordCount(content::Source<TemplateURLService>( | 765 LogKeywordCount(content::Source<TemplateURLService>( |
755 source)->GetTemplateURLs().size()); | 766 source)->GetTemplateURLs().size()); |
756 break; | 767 break; |
757 | 768 |
758 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { | 769 case chrome::NOTIFICATION_OMNIBOX_OPENED_URL: { |
759 MetricsLog* current_log = | 770 MetricsLog* current_log = |
760 static_cast<MetricsLog*>(log_manager_.current_log()); | 771 static_cast<MetricsLog*>(log_manager_.current_log()); |
761 DCHECK(current_log); | 772 DCHECK(current_log); |
762 current_log->RecordOmniboxOpenedURL( | 773 current_log->RecordOmniboxOpenedURL( |
(...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1756 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { | 1767 if (stats.process_type == content::PROCESS_TYPE_UNKNOWN) { |
1757 // The plug-in process might not actually of type PLUGIN (which means | 1768 // The plug-in process might not actually of type PLUGIN (which means |
1758 // NPAPI), but we only care that it is *a* plug-in process. | 1769 // NPAPI), but we only care that it is *a* plug-in process. |
1759 stats.process_type = content::PROCESS_TYPE_PLUGIN; | 1770 stats.process_type = content::PROCESS_TYPE_PLUGIN; |
1760 } else { | 1771 } else { |
1761 DCHECK(IsPluginProcess(stats.process_type)); | 1772 DCHECK(IsPluginProcess(stats.process_type)); |
1762 } | 1773 } |
1763 stats.loading_errors++; | 1774 stats.loading_errors++; |
1764 } | 1775 } |
1765 | 1776 |
1766 void MetricsService::LogChildProcessChange( | 1777 MetricsService::ChildProcessStats& MetricsService::GetChildProcessStats( |
1767 int type, | 1778 const content::ChildProcessData& data) { |
1768 const content::NotificationSource& source, | 1779 const string16& child_name = data.name; |
1769 const content::NotificationDetails& details) { | 1780 if (!ContainsKey(child_process_stats_buffer_, child_name)) |
1770 content::Details<ChildProcessData> child_details(details); | 1781 child_process_stats_buffer_[child_name] = ChildProcessStats(data.type); |
1771 const string16& child_name = child_details->name; | 1782 return child_process_stats_buffer_[child_name]; |
1772 | |
1773 if (child_process_stats_buffer_.find(child_name) == | |
1774 child_process_stats_buffer_.end()) { | |
1775 child_process_stats_buffer_[child_name] = | |
1776 ChildProcessStats(child_details->type); | |
1777 } | |
1778 | |
1779 ChildProcessStats& stats = child_process_stats_buffer_[child_name]; | |
1780 switch (type) { | |
1781 case content::NOTIFICATION_CHILD_PROCESS_HOST_CONNECTED: | |
1782 stats.process_launches++; | |
1783 break; | |
1784 | |
1785 case content::NOTIFICATION_CHILD_INSTANCE_CREATED: | |
1786 stats.instances++; | |
1787 break; | |
1788 | |
1789 case content::NOTIFICATION_CHILD_PROCESS_CRASHED: | |
1790 stats.process_crashes++; | |
1791 // Exclude plugin crashes from the count below because we report them via | |
1792 // a separate UMA metric. | |
1793 if (!IsPluginProcess(child_details->type)) { | |
1794 IncrementPrefValue(prefs::kStabilityChildProcessCrashCount); | |
1795 } | |
1796 break; | |
1797 | |
1798 default: | |
1799 NOTREACHED() << "Unexpected notification type " << type; | |
1800 return; | |
1801 } | |
1802 } | 1783 } |
1803 | 1784 |
1804 void MetricsService::LogKeywordCount(size_t keyword_count) { | 1785 void MetricsService::LogKeywordCount(size_t keyword_count) { |
1805 PrefService* pref = g_browser_process->local_state(); | 1786 PrefService* pref = g_browser_process->local_state(); |
1806 DCHECK(pref); | 1787 DCHECK(pref); |
1807 pref->SetInteger(prefs::kNumKeywords, static_cast<int>(keyword_count)); | 1788 pref->SetInteger(prefs::kNumKeywords, static_cast<int>(keyword_count)); |
1808 ScheduleNextStateSave(); | 1789 ScheduleNextStateSave(); |
1809 } | 1790 } |
1810 | 1791 |
1811 void MetricsService::RecordPluginChanges(PrefService* pref) { | 1792 void MetricsService::RecordPluginChanges(PrefService* pref) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1940 if (local_state) { | 1921 if (local_state) { |
1941 const PrefService::Preference* uma_pref = | 1922 const PrefService::Preference* uma_pref = |
1942 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1923 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
1943 if (uma_pref) { | 1924 if (uma_pref) { |
1944 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1925 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
1945 DCHECK(success); | 1926 DCHECK(success); |
1946 } | 1927 } |
1947 } | 1928 } |
1948 return result; | 1929 return result; |
1949 } | 1930 } |
OLD | NEW |