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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 #include "chrome/browser/metrics/metrics_service.h" | 145 #include "chrome/browser/metrics/metrics_service.h" |
146 | 146 |
147 #include "base/bind.h" | 147 #include "base/bind.h" |
148 #include "base/callback.h" | 148 #include "base/callback.h" |
149 #include "base/command_line.h" | 149 #include "base/command_line.h" |
150 #include "base/md5.h" | 150 #include "base/md5.h" |
151 #include "base/metrics/histogram.h" | 151 #include "base/metrics/histogram.h" |
152 #include "base/string_number_conversions.h" | 152 #include "base/string_number_conversions.h" |
153 #include "base/threading/platform_thread.h" | 153 #include "base/threading/platform_thread.h" |
154 #include "base/threading/thread.h" | 154 #include "base/threading/thread.h" |
155 #include "base/tracked_objects.h" | |
156 #include "base/utf_string_conversions.h" | 155 #include "base/utf_string_conversions.h" |
157 #include "base/values.h" | 156 #include "base/values.h" |
158 #include "chrome/browser/bookmarks/bookmark_model.h" | 157 #include "chrome/browser/bookmarks/bookmark_model.h" |
159 #include "chrome/browser/browser_process.h" | 158 #include "chrome/browser/browser_process.h" |
160 #include "chrome/browser/extensions/extension_service.h" | 159 #include "chrome/browser/extensions/extension_service.h" |
161 #include "chrome/browser/extensions/process_map.h" | 160 #include "chrome/browser/extensions/process_map.h" |
162 #include "chrome/browser/io_thread.h" | 161 #include "chrome/browser/io_thread.h" |
163 #include "chrome/browser/memory_details.h" | 162 #include "chrome/browser/memory_details.h" |
164 #include "chrome/browser/metrics/histogram_synchronizer.h" | 163 #include "chrome/browser/metrics/histogram_synchronizer.h" |
165 #include "chrome/browser/metrics/metrics_log.h" | 164 #include "chrome/browser/metrics/metrics_log.h" |
166 #include "chrome/browser/metrics/metrics_log_serializer.h" | 165 #include "chrome/browser/metrics/metrics_log_serializer.h" |
167 #include "chrome/browser/metrics/metrics_reporting_scheduler.h" | 166 #include "chrome/browser/metrics/metrics_reporting_scheduler.h" |
168 #include "chrome/browser/metrics/tracking_synchronizer.h" | |
169 #include "chrome/browser/net/http_pipelining_compatibility_client.h" | 167 #include "chrome/browser/net/http_pipelining_compatibility_client.h" |
170 #include "chrome/browser/net/network_stats.h" | 168 #include "chrome/browser/net/network_stats.h" |
171 #include "chrome/browser/prefs/pref_service.h" | 169 #include "chrome/browser/prefs/pref_service.h" |
172 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 170 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
173 #include "chrome/browser/profiles/profile.h" | 171 #include "chrome/browser/profiles/profile.h" |
174 #include "chrome/browser/search_engines/template_url_service.h" | 172 #include "chrome/browser/search_engines/template_url_service.h" |
175 #include "chrome/browser/ui/browser_list.h" | 173 #include "chrome/browser/ui/browser_list.h" |
176 #include "chrome/common/child_process_logging.h" | 174 #include "chrome/common/child_process_logging.h" |
177 #include "chrome/common/chrome_notification_types.h" | 175 #include "chrome/common/chrome_notification_types.h" |
178 #include "chrome/common/chrome_switches.h" | 176 #include "chrome/common/chrome_switches.h" |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 "hardware_class", &hardware_class); | 766 "hardware_class", &hardware_class); |
769 #endif // OS_CHROMEOS | 767 #endif // OS_CHROMEOS |
770 | 768 |
771 target_loop->PostTask(FROM_HERE, | 769 target_loop->PostTask(FROM_HERE, |
772 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, | 770 base::Bind(&MetricsService::OnInitTaskGotHardwareClass, |
773 self, hardware_class)); | 771 self, hardware_class)); |
774 } | 772 } |
775 | 773 |
776 void MetricsService::OnInitTaskGotHardwareClass( | 774 void MetricsService::OnInitTaskGotHardwareClass( |
777 const std::string& hardware_class) { | 775 const std::string& hardware_class) { |
778 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 776 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); |
779 hardware_class_ = hardware_class; | 777 hardware_class_ = hardware_class; |
780 | 778 |
781 // Start the next part of the init task: loading plugin information. | 779 // Start the next part of the init task: loading plugin information. |
782 PluginService::GetInstance()->GetPlugins( | 780 PluginService::GetInstance()->GetPlugins( |
783 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, | 781 base::Bind(&MetricsService::OnInitTaskGotPluginInfo, |
784 self_ptr_factory_.GetWeakPtr())); | 782 self_ptr_factory_.GetWeakPtr())); |
785 } | 783 } |
786 | 784 |
787 void MetricsService::OnInitTaskGotPluginInfo( | 785 void MetricsService::OnInitTaskGotPluginInfo( |
788 const std::vector<webkit::WebPluginInfo>& plugins) { | 786 const std::vector<webkit::WebPluginInfo>& plugins) { |
789 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | 787 DCHECK_EQ(state_, INIT_TASK_SCHEDULED); |
790 plugins_ = plugins; | 788 plugins_ = plugins; |
791 | 789 |
792 // Start the next part of the init task: fetching performance data. This will | 790 if (state_ == INIT_TASK_SCHEDULED) |
793 // call into |FinishedReceivingProfilerData()| when the task completes. | 791 state_ = INIT_TASK_DONE; |
794 chrome_browser_metrics::TrackingSynchronizer::FetchProfilerDataAsynchronously( | |
795 self_ptr_factory_.GetWeakPtr()); | |
796 } | |
797 | |
798 void MetricsService::ReceivedProfilerData( | |
799 const tracked_objects::ProcessDataSnapshot& process_data, | |
800 content::ProcessType process_type) { | |
801 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | |
802 | |
803 // Upon the first callback, create the initial log so that we can immediately | |
804 // save the profiler data. | |
805 if (!initial_log_.get()) | |
806 initial_log_.reset(new MetricsLog(client_id_, session_id_)); | |
807 | |
808 initial_log_->RecordProfilerData(process_data, process_type); | |
809 } | |
810 | |
811 void MetricsService::FinishedReceivingProfilerData() { | |
812 DCHECK_EQ(INIT_TASK_SCHEDULED, state_); | |
813 state_ = INIT_TASK_DONE; | |
814 } | 792 } |
815 | 793 |
816 std::string MetricsService::GenerateClientID() { | 794 std::string MetricsService::GenerateClientID() { |
817 return guid::GenerateGUID(); | 795 return guid::GenerateGUID(); |
818 } | 796 } |
819 | 797 |
820 //------------------------------------------------------------------------------ | 798 //------------------------------------------------------------------------------ |
821 // State save methods | 799 // State save methods |
822 | 800 |
823 void MetricsService::ScheduleNextStateSave() { | 801 void MetricsService::ScheduleNextStateSave() { |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 case INITIALIZED: | 1007 case INITIALIZED: |
1030 case INIT_TASK_SCHEDULED: // We should be further along by now. | 1008 case INIT_TASK_SCHEDULED: // We should be further along by now. |
1031 DCHECK(false); | 1009 DCHECK(false); |
1032 return; | 1010 return; |
1033 | 1011 |
1034 case INIT_TASK_DONE: | 1012 case INIT_TASK_DONE: |
1035 // We need to wait for the initial log to be ready before sending | 1013 // We need to wait for the initial log to be ready before sending |
1036 // anything, because the server will tell us whether it wants to hear | 1014 // anything, because the server will tell us whether it wants to hear |
1037 // from us. | 1015 // from us. |
1038 PrepareInitialLog(); | 1016 PrepareInitialLog(); |
1039 DCHECK_EQ(INIT_TASK_DONE, state_); | 1017 DCHECK(state_ == INIT_TASK_DONE); |
1040 log_manager_.LoadPersistedUnsentLogs(); | 1018 log_manager_.LoadPersistedUnsentLogs(); |
1041 state_ = INITIAL_LOG_READY; | 1019 state_ = INITIAL_LOG_READY; |
1042 break; | 1020 break; |
1043 | 1021 |
1044 case SENDING_OLD_LOGS: | 1022 case SENDING_OLD_LOGS: |
1045 if (log_manager_.has_unsent_logs()) { | 1023 if (log_manager_.has_unsent_logs()) { |
1046 log_manager_.StageNextLogForUpload(); | 1024 log_manager_.StageNextLogForUpload(); |
1047 break; | 1025 break; |
1048 } | 1026 } |
1049 state_ = SENDING_CURRENT_LOGS; | 1027 state_ = SENDING_CURRENT_LOGS; |
1050 // Fall through. | 1028 // Fall through. |
1051 | 1029 |
1052 case SENDING_CURRENT_LOGS: | 1030 case SENDING_CURRENT_LOGS: |
1053 StopRecording(); | 1031 StopRecording(); |
1054 StartRecording(); | 1032 StartRecording(); |
1055 log_manager_.StageNextLogForUpload(); | 1033 log_manager_.StageNextLogForUpload(); |
1056 break; | 1034 break; |
1057 | 1035 |
1058 default: | 1036 default: |
1059 NOTREACHED(); | 1037 NOTREACHED(); |
1060 return; | 1038 return; |
1061 } | 1039 } |
1062 | 1040 |
1063 DCHECK(log_manager_.has_staged_log()); | 1041 DCHECK(log_manager_.has_staged_log()); |
1064 } | 1042 } |
1065 | 1043 |
1066 void MetricsService::PrepareInitialLog() { | 1044 void MetricsService::PrepareInitialLog() { |
1067 DCHECK_EQ(INIT_TASK_DONE, state_); | 1045 DCHECK(state_ == INIT_TASK_DONE); |
1068 | 1046 |
1069 DCHECK(initial_log_.get()); | 1047 MetricsLog* log = new MetricsLog(client_id_, session_id_); |
1070 initial_log_->set_hardware_class(hardware_class_); | 1048 log->set_hardware_class(hardware_class_); // Adds to initial log. |
1071 initial_log_->RecordEnvironment(plugins_, profile_dictionary_.get()); | 1049 log->RecordEnvironment(plugins_, profile_dictionary_.get()); |
1072 | 1050 |
1073 // Histograms only get written to the current log, so make the new log current | 1051 // Histograms only get written to the current log, so make the new log current |
1074 // before writing them. | 1052 // before writing them. |
1075 log_manager_.PauseCurrentLog(); | 1053 log_manager_.PauseCurrentLog(); |
1076 log_manager_.BeginLoggingWithLog(initial_log_.release(), | 1054 log_manager_.BeginLoggingWithLog(log, MetricsLogManager::INITIAL_LOG); |
1077 MetricsLogManager::INITIAL_LOG); | |
1078 RecordCurrentHistograms(); | 1055 RecordCurrentHistograms(); |
1079 log_manager_.FinishCurrentLog(); | 1056 log_manager_.FinishCurrentLog(); |
1080 log_manager_.ResumePausedLog(); | 1057 log_manager_.ResumePausedLog(); |
1081 | 1058 |
1082 DCHECK(!log_manager_.has_staged_log()); | 1059 DCHECK(!log_manager_.has_staged_log()); |
1083 log_manager_.StageNextLogForUpload(); | 1060 log_manager_.StageNextLogForUpload(); |
1084 } | 1061 } |
1085 | 1062 |
1086 void MetricsService::StoreUnsentLogs() { | 1063 void MetricsService::StoreUnsentLogs() { |
1087 if (state_ < INITIAL_LOG_READY) | 1064 if (state_ < INITIAL_LOG_READY) |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 break; | 1249 break; |
1273 | 1250 |
1274 default: | 1251 default: |
1275 NOTREACHED(); | 1252 NOTREACHED(); |
1276 break; | 1253 break; |
1277 } | 1254 } |
1278 | 1255 |
1279 log_manager_.DiscardStagedLog(); | 1256 log_manager_.DiscardStagedLog(); |
1280 | 1257 |
1281 if (log_manager_.has_unsent_logs()) | 1258 if (log_manager_.has_unsent_logs()) |
1282 DCHECK_LT(state_, SENDING_CURRENT_LOGS); | 1259 DCHECK(state_ < SENDING_CURRENT_LOGS); |
1283 } | 1260 } |
1284 | 1261 |
1285 // Error 400 indicates a problem with the log, not with the server, so | 1262 // Error 400 indicates a problem with the log, not with the server, so |
1286 // don't consider that a sign that the server is in trouble. | 1263 // don't consider that a sign that the server is in trouble. |
1287 bool server_is_healthy = upload_succeeded || response_code_ == 400; | 1264 bool server_is_healthy = upload_succeeded || response_code_ == 400; |
1288 | 1265 |
1289 scheduler_->UploadFinished(server_is_healthy, | 1266 scheduler_->UploadFinished(server_is_healthy, |
1290 log_manager_.has_unsent_logs()); | 1267 log_manager_.has_unsent_logs()); |
1291 | 1268 |
1292 // Collect network stats if UMA upload succeeded. | 1269 // Collect network stats if UMA upload succeeded. |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1693 if (local_state) { | 1670 if (local_state) { |
1694 const PrefService::Preference* uma_pref = | 1671 const PrefService::Preference* uma_pref = |
1695 local_state->FindPreference(prefs::kMetricsReportingEnabled); | 1672 local_state->FindPreference(prefs::kMetricsReportingEnabled); |
1696 if (uma_pref) { | 1673 if (uma_pref) { |
1697 bool success = uma_pref->GetValue()->GetAsBoolean(&result); | 1674 bool success = uma_pref->GetValue()->GetAsBoolean(&result); |
1698 DCHECK(success); | 1675 DCHECK(success); |
1699 } | 1676 } |
1700 } | 1677 } |
1701 return result; | 1678 return result; |
1702 } | 1679 } |
OLD | NEW |