Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Side by Side Diff: chrome/browser/metrics/metrics_service.cc

Issue 8375039: Create a content::UrlFetcher interface that lives in content/public/common and convert users to i... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: review comments Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/net/gaia/gaia_oauth_fetcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 1022 matching lines...) Expand 10 before | Expand all | Expand 10 after
1033 log_manager_.PersistUnsentLogs(); 1033 log_manager_.PersistUnsentLogs();
1034 } 1034 }
1035 1035
1036 void MetricsService::PrepareFetchWithStagedLog() { 1036 void MetricsService::PrepareFetchWithStagedLog() {
1037 DCHECK(!log_manager_.staged_log_text().empty()); 1037 DCHECK(!log_manager_.staged_log_text().empty());
1038 DCHECK(!current_fetch_.get()); 1038 DCHECK(!current_fetch_.get());
1039 1039
1040 current_fetch_.reset(new URLFetcher(GURL(WideToUTF16(server_url_)), 1040 current_fetch_.reset(new URLFetcher(GURL(WideToUTF16(server_url_)),
1041 URLFetcher::POST, 1041 URLFetcher::POST,
1042 this)); 1042 this));
1043 current_fetch_->set_request_context( 1043 current_fetch_->SetRequestContext(
1044 g_browser_process->system_request_context()); 1044 g_browser_process->system_request_context());
1045 current_fetch_->set_upload_data(kMetricsType, 1045 current_fetch_->SetUploadData(kMetricsType, log_manager_.staged_log_text());
1046 log_manager_.staged_log_text());
1047 } 1046 }
1048 1047
1049 static const char* StatusToString(const net::URLRequestStatus& status) { 1048 static const char* StatusToString(const net::URLRequestStatus& status) {
1050 switch (status.status()) { 1049 switch (status.status()) {
1051 case net::URLRequestStatus::SUCCESS: 1050 case net::URLRequestStatus::SUCCESS:
1052 return "SUCCESS"; 1051 return "SUCCESS";
1053 1052
1054 case net::URLRequestStatus::IO_PENDING: 1053 case net::URLRequestStatus::IO_PENDING:
1055 return "IO_PENDING"; 1054 return "IO_PENDING";
1056 1055
1057 case net::URLRequestStatus::HANDLED_EXTERNALLY: 1056 case net::URLRequestStatus::HANDLED_EXTERNALLY:
1058 return "HANDLED_EXTERNALLY"; 1057 return "HANDLED_EXTERNALLY";
1059 1058
1060 case net::URLRequestStatus::CANCELED: 1059 case net::URLRequestStatus::CANCELED:
1061 return "CANCELED"; 1060 return "CANCELED";
1062 1061
1063 case net::URLRequestStatus::FAILED: 1062 case net::URLRequestStatus::FAILED:
1064 return "FAILED"; 1063 return "FAILED";
1065 1064
1066 default: 1065 default:
1067 NOTREACHED(); 1066 NOTREACHED();
1068 return "Unknown"; 1067 return "Unknown";
1069 } 1068 }
1070 } 1069 }
1071 1070
1072 void MetricsService::OnURLFetchComplete(const URLFetcher* source) { 1071 void MetricsService::OnURLFetchComplete(const content::URLFetcher* source) {
1073 DCHECK(waiting_for_asynchronus_reporting_step_); 1072 DCHECK(waiting_for_asynchronus_reporting_step_);
1074 waiting_for_asynchronus_reporting_step_ = false; 1073 waiting_for_asynchronus_reporting_step_ = false;
1075 DCHECK(current_fetch_.get()); 1074 DCHECK(current_fetch_.get());
1076 current_fetch_.reset(NULL); // We're not allowed to re-use it. 1075 current_fetch_.reset(NULL); // We're not allowed to re-use it.
1077 1076
1078 // Confirm send so that we can move on. 1077 // Confirm send so that we can move on.
1079 VLOG(1) << "METRICS RESPONSE CODE: " << source->response_code() 1078 VLOG(1) << "METRICS RESPONSE CODE: " << source->GetResponseCode()
1080 << " status=" << StatusToString(source->status()); 1079 << " status=" << StatusToString(source->GetStatus());
1081 1080
1082 bool upload_succeeded = source->response_code() == 200; 1081 bool upload_succeeded = source->GetResponseCode() == 200;
1083 1082
1084 // Provide boolean for error recovery (allow us to ignore response_code). 1083 // Provide boolean for error recovery (allow us to ignore response_code).
1085 bool discard_log = false; 1084 bool discard_log = false;
1086 1085
1087 if (!upload_succeeded && 1086 if (!upload_succeeded &&
1088 (log_manager_.staged_log_text().length() > 1087 (log_manager_.staged_log_text().length() >
1089 static_cast<size_t>(kUploadLogAvoidRetransmitSize))) { 1088 static_cast<size_t>(kUploadLogAvoidRetransmitSize))) {
1090 UMA_HISTOGRAM_COUNTS( 1089 UMA_HISTOGRAM_COUNTS(
1091 "UMA.Large Rejected Log was Discarded", 1090 "UMA.Large Rejected Log was Discarded",
1092 static_cast<int>(log_manager_.staged_log_text().length())); 1091 static_cast<int>(log_manager_.staged_log_text().length()));
1093 discard_log = true; 1092 discard_log = true;
1094 } else if (source->response_code() == 400) { 1093 } else if (source->GetResponseCode() == 400) {
1095 // Bad syntax. Retransmission won't work. 1094 // Bad syntax. Retransmission won't work.
1096 UMA_HISTOGRAM_COUNTS("UMA.Unacceptable_Log_Discarded", state_); 1095 UMA_HISTOGRAM_COUNTS("UMA.Unacceptable_Log_Discarded", state_);
1097 discard_log = true; 1096 discard_log = true;
1098 } 1097 }
1099 1098
1100 if (!upload_succeeded && !discard_log) { 1099 if (!upload_succeeded && !discard_log) {
1101 VLOG(1) << "METRICS: transmission attempt returned a failure code: " 1100 VLOG(1) << "METRICS: transmission attempt returned a failure code: "
1102 << source->response_code() << ". Verify network connectivity"; 1101 << source->GetResponseCode() << ". Verify network connectivity";
1103 LogBadResponseCode(); 1102 LogBadResponseCode();
1104 } else { // Successful receipt (or we are discarding log). 1103 } else { // Successful receipt (or we are discarding log).
1105 std::string data; 1104 std::string data;
1106 source->GetResponseAsString(&data); 1105 source->GetResponseAsString(&data);
1107 VLOG(1) << "METRICS RESPONSE DATA: " << data; 1106 VLOG(1) << "METRICS RESPONSE DATA: " << data;
1108 switch (state_) { 1107 switch (state_) {
1109 case INITIAL_LOG_READY: 1108 case INITIAL_LOG_READY:
1110 state_ = SENDING_OLD_LOGS; 1109 state_ = SENDING_OLD_LOGS;
1111 break; 1110 break;
1112 1111
(...skipping 16 matching lines...) Expand all
1129 DCHECK(local_state); 1128 DCHECK(local_state);
1130 if (local_state) 1129 if (local_state)
1131 local_state->ScheduleSavePersistentPrefs(); 1130 local_state->ScheduleSavePersistentPrefs();
1132 1131
1133 if (log_manager_.has_unsent_logs()) 1132 if (log_manager_.has_unsent_logs())
1134 DCHECK(state_ < SENDING_CURRENT_LOGS); 1133 DCHECK(state_ < SENDING_CURRENT_LOGS);
1135 } 1134 }
1136 1135
1137 // Error 400 indicates a problem with the log, not with the server, so 1136 // Error 400 indicates a problem with the log, not with the server, so
1138 // don't consider that a sign that the server is in trouble. 1137 // don't consider that a sign that the server is in trouble.
1139 bool server_is_healthy = upload_succeeded || source->response_code() == 400; 1138 bool server_is_healthy = upload_succeeded || source->GetResponseCode() == 400;
1140 1139
1141 scheduler_->UploadFinished(server_is_healthy, 1140 scheduler_->UploadFinished(server_is_healthy,
1142 log_manager_.has_unsent_logs()); 1141 log_manager_.has_unsent_logs());
1143 1142
1144 // Collect network stats if UMA upload succeeded. 1143 // Collect network stats if UMA upload succeeded.
1145 if (server_is_healthy && io_thread_) 1144 if (server_is_healthy && io_thread_)
1146 chrome_browser_net::CollectNetworkStats(network_stats_server_, io_thread_); 1145 chrome_browser_net::CollectNetworkStats(network_stats_server_, io_thread_);
1147 } 1146 }
1148 1147
1149 void MetricsService::LogBadResponseCode() { 1148 void MetricsService::LogBadResponseCode() {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1542 if (local_state) { 1541 if (local_state) {
1543 const PrefService::Preference* uma_pref = 1542 const PrefService::Preference* uma_pref =
1544 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1543 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1545 if (uma_pref) { 1544 if (uma_pref) {
1546 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1545 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1547 DCHECK(success); 1546 DCHECK(success);
1548 } 1547 }
1549 } 1548 }
1550 return result; 1549 return result;
1551 } 1550 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_service.h ('k') | chrome/browser/net/gaia/gaia_oauth_fetcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698