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/metrics_log.h" | 5 #include "chrome/browser/metrics/metrics_log.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 void MetricsLog::RecordIncrementalStabilityElements( | 413 void MetricsLog::RecordIncrementalStabilityElements( |
414 const std::vector<webkit::WebPluginInfo>& plugin_list) { | 414 const std::vector<webkit::WebPluginInfo>& plugin_list) { |
415 DCHECK(!locked()); | 415 DCHECK(!locked()); |
416 | 416 |
417 PrefService* pref = GetPrefService(); | 417 PrefService* pref = GetPrefService(); |
418 DCHECK(pref); | 418 DCHECK(pref); |
419 | 419 |
420 OPEN_ELEMENT_FOR_SCOPE("profile"); | 420 OPEN_ELEMENT_FOR_SCOPE("profile"); |
421 WriteCommonEventAttributes(); | 421 WriteCommonEventAttributes(); |
422 | 422 |
423 WriteInstallElement(); | |
424 | |
425 { | 423 { |
426 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. | 424 OPEN_ELEMENT_FOR_SCOPE("stability"); // Minimal set of stability elements. |
427 WriteRequiredStabilityAttributes(pref); | 425 WriteRequiredStabilityAttributes(pref); |
428 WriteRealtimeStabilityAttributes(pref); | 426 WriteRealtimeStabilityAttributes(pref); |
429 WritePluginStabilityElements(plugin_list, pref); | 427 WritePluginStabilityElements(plugin_list, pref); |
430 } | 428 } |
431 } | 429 } |
432 | 430 |
433 PrefService* MetricsLog::GetPrefService() { | 431 PrefService* MetricsLog::GetPrefService() { |
434 return g_browser_process->local_state(); | 432 return g_browser_process->local_state(); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 #endif // OS_CHROMEOS | 679 #endif // OS_CHROMEOS |
682 | 680 |
683 int64 recent_duration = GetIncrementalUptime(pref); | 681 int64 recent_duration = GetIncrementalUptime(pref); |
684 if (recent_duration) { | 682 if (recent_duration) { |
685 WriteInt64Attribute("uptimesec", recent_duration); | 683 WriteInt64Attribute("uptimesec", recent_duration); |
686 stability->set_uptime_sec(recent_duration); | 684 stability->set_uptime_sec(recent_duration); |
687 } | 685 } |
688 } | 686 } |
689 | 687 |
690 void MetricsLog::WritePluginList( | 688 void MetricsLog::WritePluginList( |
691 const std::vector<webkit::WebPluginInfo>& plugin_list, | 689 const std::vector<webkit::WebPluginInfo>& plugin_list) { |
692 bool write_as_xml) { | |
693 DCHECK(!locked()); | 690 DCHECK(!locked()); |
694 | 691 |
695 OPEN_ELEMENT_FOR_SCOPE("plugins"); | |
696 | |
697 #if defined(ENABLE_PLUGINS) | 692 #if defined(ENABLE_PLUGINS) |
698 PluginPrefs* plugin_prefs = GetPluginPrefs(); | 693 PluginPrefs* plugin_prefs = GetPluginPrefs(); |
699 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); | 694 SystemProfileProto* system_profile = uma_proto()->mutable_system_profile(); |
700 for (std::vector<webkit::WebPluginInfo>::const_iterator iter = | 695 for (std::vector<webkit::WebPluginInfo>::const_iterator iter = |
701 plugin_list.begin(); | 696 plugin_list.begin(); |
702 iter != plugin_list.end(); ++iter) { | 697 iter != plugin_list.end(); ++iter) { |
703 if (write_as_xml) { | 698 SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); |
704 std::string base64_name_hash; | 699 SetPluginInfo(*iter, plugin_prefs, plugin); |
705 uint64 numeric_hash_ignored; | |
706 CreateHashes(UTF16ToUTF8(iter->name), &base64_name_hash, | |
707 &numeric_hash_ignored); | |
708 | |
709 std::string filename_bytes = iter->path.BaseName().AsUTF8Unsafe(); | |
710 std::string base64_filename_hash; | |
711 CreateHashes(filename_bytes, &base64_filename_hash, | |
712 &numeric_hash_ignored); | |
713 | |
714 // Write the XML version. | |
715 OPEN_ELEMENT_FOR_SCOPE("plugin"); | |
716 | |
717 // Plugin name and filename are hashed for the privacy of those | |
718 // testing unreleased new extensions. | |
719 WriteAttribute("name", base64_name_hash); | |
720 WriteAttribute("filename", base64_filename_hash); | |
721 WriteAttribute("version", UTF16ToUTF8(iter->version)); | |
722 if (plugin_prefs) | |
723 WriteIntAttribute("disabled", !plugin_prefs->IsPluginEnabled(*iter)); | |
724 } else { | |
725 // Write the protobuf version. | |
726 SystemProfileProto::Plugin* plugin = system_profile->add_plugin(); | |
727 SetPluginInfo(*iter, plugin_prefs, plugin); | |
728 } | |
729 } | 700 } |
730 #endif // defined(ENABLE_PLUGINS) | 701 #endif // defined(ENABLE_PLUGINS) |
731 } | 702 } |
732 | 703 |
733 void MetricsLog::WriteInstallElement() { | |
734 // Write the XML version. | |
735 // We'll write the protobuf version in RecordEnvironmentProto(). | |
736 OPEN_ELEMENT_FOR_SCOPE("install"); | |
737 WriteAttribute("installdate", GetMetricsEnabledDate(GetPrefService())); | |
738 WriteIntAttribute("buildid", 0); // We're using appversion instead. | |
739 } | |
740 | |
741 void MetricsLog::RecordEnvironment( | 704 void MetricsLog::RecordEnvironment( |
742 const std::vector<webkit::WebPluginInfo>& plugin_list, | 705 const std::vector<webkit::WebPluginInfo>& plugin_list, |
743 const GoogleUpdateMetrics& google_update_metrics, | 706 const GoogleUpdateMetrics& google_update_metrics, |
744 const DictionaryValue* profile_metrics) { | 707 const DictionaryValue* profile_metrics) { |
745 DCHECK(!locked()); | 708 DCHECK(!locked()); |
746 | 709 |
747 PrefService* pref = GetPrefService(); | 710 PrefService* pref = GetPrefService(); |
748 | 711 |
749 OPEN_ELEMENT_FOR_SCOPE("profile"); | 712 OPEN_ELEMENT_FOR_SCOPE("profile"); |
750 WriteCommonEventAttributes(); | 713 WriteCommonEventAttributes(); |
751 | 714 |
752 WriteInstallElement(); | |
753 | |
754 // Write the XML version. | |
755 // We'll write the protobuf version in RecordEnvironmentProto(). | |
756 bool write_as_xml = true; | |
757 WritePluginList(plugin_list, write_as_xml); | |
758 | |
759 WriteStabilityElement(plugin_list, pref); | 715 WriteStabilityElement(plugin_list, pref); |
760 | 716 |
761 { | 717 { |
762 // Write the XML version. | 718 // Write the XML version. |
763 // We'll write the protobuf version in RecordEnvironmentProto(). | 719 // We'll write the protobuf version in RecordEnvironmentProto(). |
764 OPEN_ELEMENT_FOR_SCOPE("cpu"); | 720 OPEN_ELEMENT_FOR_SCOPE("cpu"); |
765 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture()); | 721 WriteAttribute("arch", base::SysInfo::OperatingSystemArchitecture()); |
766 } | 722 } |
767 | 723 |
768 { | 724 { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 hardware->set_primary_screen_height(display_size.height()); | 861 hardware->set_primary_screen_height(display_size.height()); |
906 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor()); | 862 hardware->set_primary_screen_scale_factor(GetScreenDeviceScaleFactor()); |
907 hardware->set_screen_count(GetScreenCount()); | 863 hardware->set_screen_count(GetScreenCount()); |
908 | 864 |
909 #if defined(OS_WIN) | 865 #if defined(OS_WIN) |
910 WriteScreenDPIInformationProto(hardware); | 866 WriteScreenDPIInformationProto(hardware); |
911 #endif | 867 #endif |
912 | 868 |
913 WriteGoogleUpdateProto(google_update_metrics); | 869 WriteGoogleUpdateProto(google_update_metrics); |
914 | 870 |
915 bool write_as_xml = false; | 871 WritePluginList(plugin_list); |
916 WritePluginList(plugin_list, write_as_xml); | |
917 | 872 |
918 std::vector<ActiveGroupId> field_trial_ids; | 873 std::vector<ActiveGroupId> field_trial_ids; |
919 GetFieldTrialIds(&field_trial_ids); | 874 GetFieldTrialIds(&field_trial_ids); |
920 WriteFieldTrials(field_trial_ids, system_profile); | 875 WriteFieldTrials(field_trial_ids, system_profile); |
921 | 876 |
922 #if defined(OS_CHROMEOS) | 877 #if defined(OS_CHROMEOS) |
923 PerfDataProto perf_data_proto; | 878 PerfDataProto perf_data_proto; |
924 if (perf_provider_.GetPerfData(&perf_data_proto)) | 879 if (perf_provider_.GetPerfData(&perf_data_proto)) |
925 uma_proto()->add_perf_data()->Swap(&perf_data_proto); | 880 uma_proto()->add_perf_data()->Swap(&perf_data_proto); |
926 | 881 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 default: | 968 default: |
1014 NOTREACHED(); | 969 NOTREACHED(); |
1015 break; | 970 break; |
1016 } | 971 } |
1017 } | 972 } |
1018 } | 973 } |
1019 | 974 |
1020 void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) { | 975 void MetricsLog::RecordOmniboxOpenedURL(const OmniboxLog& log) { |
1021 DCHECK(!locked()); | 976 DCHECK(!locked()); |
1022 | 977 |
1023 // Write the XML version. | |
1024 OPEN_ELEMENT_FOR_SCOPE("uielement"); | |
1025 WriteAttribute("action", "autocomplete"); | |
1026 WriteAttribute("targetidhash", std::string()); | |
1027 // TODO(kochi): Properly track windows. | |
1028 WriteIntAttribute("window", 0); | |
1029 if (log.tab_id != -1) { | |
1030 // If we know what tab the autocomplete URL was opened in, log it. | |
1031 WriteIntAttribute("tab", static_cast<int>(log.tab_id)); | |
1032 } | |
1033 WriteCommonEventAttributes(); | |
1034 | |
1035 std::vector<string16> terms; | 978 std::vector<string16> terms; |
1036 const int num_terms = | 979 const int num_terms = |
1037 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms)); | 980 static_cast<int>(Tokenize(log.text, kWhitespaceUTF16, &terms)); |
1038 { | |
1039 OPEN_ELEMENT_FOR_SCOPE("autocomplete"); | |
1040 | 981 |
1041 WriteIntAttribute("typedlength", static_cast<int>(log.text.length())); | |
1042 WriteIntAttribute("numterms", num_terms); | |
1043 WriteIntAttribute("selectedindex", static_cast<int>(log.selected_index)); | |
1044 WriteIntAttribute("completedlength", | |
1045 log.completed_length != string16::npos ? | |
1046 static_cast<int>(log.completed_length) : 0); | |
1047 if (log.elapsed_time_since_user_first_modified_omnibox != | |
1048 base::TimeDelta::FromMilliseconds(-1)) { | |
1049 // Only upload the typing duration if it is set/valid. | |
1050 WriteInt64Attribute("typingduration", | |
1051 log.elapsed_time_since_user_first_modified_omnibox.InMilliseconds()); | |
1052 } | |
1053 const std::string input_type( | |
1054 AutocompleteInput::TypeToString(log.input_type)); | |
1055 if (!input_type.empty()) | |
1056 WriteAttribute("inputtype", input_type); | |
1057 | |
1058 for (AutocompleteResult::const_iterator i(log.result.begin()); | |
1059 i != log.result.end(); ++i) { | |
1060 OPEN_ELEMENT_FOR_SCOPE("autocompleteitem"); | |
1061 if (i->provider) | |
1062 WriteAttribute("provider", i->provider->GetName()); | |
1063 const std::string result_type(AutocompleteMatchType::ToString(i->type)); | |
1064 if (!result_type.empty()) | |
1065 WriteAttribute("resulttype", result_type); | |
1066 WriteIntAttribute("relevance", i->relevance); | |
1067 WriteIntAttribute("isstarred", i->starred ? 1 : 0); | |
1068 } | |
1069 } | |
1070 | |
1071 // Write the protobuf version. | |
1072 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event(); | 982 OmniboxEventProto* omnibox_event = uma_proto()->add_omnibox_event(); |
1073 omnibox_event->set_time(MetricsLogBase::GetCurrentTime()); | 983 omnibox_event->set_time(MetricsLogBase::GetCurrentTime()); |
1074 if (log.tab_id != -1) { | 984 if (log.tab_id != -1) { |
1075 // If we know what tab the autocomplete URL was opened in, log it. | 985 // If we know what tab the autocomplete URL was opened in, log it. |
1076 omnibox_event->set_tab_id(log.tab_id); | 986 omnibox_event->set_tab_id(log.tab_id); |
1077 } | 987 } |
1078 omnibox_event->set_typed_length(log.text.length()); | 988 omnibox_event->set_typed_length(log.text.length()); |
1079 omnibox_event->set_just_deleted_text(log.just_deleted_text); | 989 omnibox_event->set_just_deleted_text(log.just_deleted_text); |
1080 omnibox_event->set_num_typed_terms(num_terms); | 990 omnibox_event->set_num_typed_terms(num_terms); |
1081 omnibox_event->set_selected_index(log.selected_index); | 991 omnibox_event->set_selected_index(log.selected_index); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 | 1089 |
1180 paired_device->set_vendor_prefix(vendor_prefix); | 1090 paired_device->set_vendor_prefix(vendor_prefix); |
1181 } | 1091 } |
1182 | 1092 |
1183 paired_device->set_vendor_id(device->GetVendorID()); | 1093 paired_device->set_vendor_id(device->GetVendorID()); |
1184 paired_device->set_product_id(device->GetProductID()); | 1094 paired_device->set_product_id(device->GetProductID()); |
1185 paired_device->set_device_id(device->GetDeviceID()); | 1095 paired_device->set_device_id(device->GetDeviceID()); |
1186 } | 1096 } |
1187 #endif // defined(OS_CHROMEOS) | 1097 #endif // defined(OS_CHROMEOS) |
1188 } | 1098 } |
OLD | NEW |