OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 is | 10 // A MetricsService instance is typically created at application startup. It is |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 | 220 |
221 // If an upload fails, and the transmission was over this byte count, then we | 221 // If an upload fails, and the transmission was over this byte count, then we |
222 // will discard the log, and not try to retransmit it. We also don't persist | 222 // will discard the log, and not try to retransmit it. We also don't persist |
223 // the log to the prefs for transmission during the next chrome session if this | 223 // the log to the prefs for transmission during the next chrome session if this |
224 // limit is exceeded. | 224 // limit is exceeded. |
225 const size_t kUploadLogAvoidRetransmitSize = 100 * 1024; | 225 const size_t kUploadLogAvoidRetransmitSize = 100 * 1024; |
226 | 226 |
227 // Interval, in minutes, between state saves. | 227 // Interval, in minutes, between state saves. |
228 const int kSaveStateIntervalMinutes = 5; | 228 const int kSaveStateIntervalMinutes = 5; |
229 | 229 |
230 // The metrics server's URL. | |
231 const char kServerUrl[] = "https://clients4.google.com/uma/v2"; | |
232 | |
233 // The MIME type for the uploaded metrics data. | |
234 const char kMimeType[] = "application/vnd.chrome.uma"; | |
235 | |
236 enum ResponseStatus { | 230 enum ResponseStatus { |
237 UNKNOWN_FAILURE, | 231 UNKNOWN_FAILURE, |
238 SUCCESS, | 232 SUCCESS, |
239 BAD_REQUEST, // Invalid syntax or log too large. | 233 BAD_REQUEST, // Invalid syntax or log too large. |
240 NO_RESPONSE, | 234 NO_RESPONSE, |
241 NUM_RESPONSE_STATUSES | 235 NUM_RESPONSE_STATUSES |
242 }; | 236 }; |
243 | 237 |
244 ResponseStatus ResponseCodeToStatus(int response_code) { | 238 ResponseStatus ResponseCodeToStatus(int response_code) { |
245 switch (response_code) { | 239 switch (response_code) { |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1014 void MetricsService::SendStagedLog() { | 1008 void MetricsService::SendStagedLog() { |
1015 DCHECK(log_manager_.has_staged_log()); | 1009 DCHECK(log_manager_.has_staged_log()); |
1016 if (!log_manager_.has_staged_log()) | 1010 if (!log_manager_.has_staged_log()) |
1017 return; | 1011 return; |
1018 | 1012 |
1019 DCHECK(!log_upload_in_progress_); | 1013 DCHECK(!log_upload_in_progress_); |
1020 log_upload_in_progress_ = true; | 1014 log_upload_in_progress_ = true; |
1021 | 1015 |
1022 if (!log_uploader_) { | 1016 if (!log_uploader_) { |
1023 log_uploader_ = client_->CreateUploader( | 1017 log_uploader_ = client_->CreateUploader( |
1024 kServerUrl, kMimeType, | |
1025 base::Bind(&MetricsService::OnLogUploadComplete, | 1018 base::Bind(&MetricsService::OnLogUploadComplete, |
1026 self_ptr_factory_.GetWeakPtr())); | 1019 self_ptr_factory_.GetWeakPtr())); |
1027 } | 1020 } |
1028 | 1021 |
1029 const std::string hash = | 1022 const std::string hash = |
1030 base::HexEncode(log_manager_.staged_log_hash().data(), | 1023 base::HexEncode(log_manager_.staged_log_hash().data(), |
1031 log_manager_.staged_log_hash().size()); | 1024 log_manager_.staged_log_hash().size()); |
1032 bool success = log_uploader_->UploadLog(log_manager_.staged_log(), hash); | 1025 bool success = log_uploader_->UploadLog(log_manager_.staged_log(), hash); |
1033 UMA_HISTOGRAM_BOOLEAN("UMA.UploadCreation", success); | 1026 UMA_HISTOGRAM_BOOLEAN("UMA.UploadCreation", success); |
1034 if (!success) { | 1027 if (!success) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 local_state_->SetBoolean(path, value); | 1250 local_state_->SetBoolean(path, value); |
1258 RecordCurrentState(local_state_); | 1251 RecordCurrentState(local_state_); |
1259 } | 1252 } |
1260 | 1253 |
1261 void MetricsService::RecordCurrentState(PrefService* pref) { | 1254 void MetricsService::RecordCurrentState(PrefService* pref) { |
1262 pref->SetInt64(prefs::kStabilityLastTimestampSec, | 1255 pref->SetInt64(prefs::kStabilityLastTimestampSec, |
1263 base::Time::Now().ToTimeT()); | 1256 base::Time::Now().ToTimeT()); |
1264 } | 1257 } |
1265 | 1258 |
1266 } // namespace metrics | 1259 } // namespace metrics |
OLD | NEW |