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

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

Issue 8373021: Convert URLFetcher::Delegates to use an interface in content/public/common. Also remove the old U... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync and remove unncessary forward declares Created 9 years, 2 months 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
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 #include "chrome/common/chrome_notification_types.h" 172 #include "chrome/common/chrome_notification_types.h"
173 #include "chrome/common/chrome_switches.h" 173 #include "chrome/common/chrome_switches.h"
174 #include "chrome/common/guid.h" 174 #include "chrome/common/guid.h"
175 #include "chrome/common/metrics_log_manager.h" 175 #include "chrome/common/metrics_log_manager.h"
176 #include "chrome/common/pref_names.h" 176 #include "chrome/common/pref_names.h"
177 #include "chrome/common/render_messages.h" 177 #include "chrome/common/render_messages.h"
178 #include "content/browser/load_notification_details.h" 178 #include "content/browser/load_notification_details.h"
179 #include "content/browser/plugin_service.h" 179 #include "content/browser/plugin_service.h"
180 #include "content/browser/renderer_host/render_process_host.h" 180 #include "content/browser/renderer_host/render_process_host.h"
181 #include "content/common/child_process_info.h" 181 #include "content/common/child_process_info.h"
182 #include "content/common/net/url_fetcher.h"
182 #include "content/public/browser/notification_service.h" 183 #include "content/public/browser/notification_service.h"
183 #include "webkit/plugins/npapi/plugin_list.h" 184 #include "webkit/plugins/npapi/plugin_list.h"
184 #include "webkit/plugins/webplugininfo.h" 185 #include "webkit/plugins/webplugininfo.h"
185 186
186 // TODO(port): port browser_distribution.h. 187 // TODO(port): port browser_distribution.h.
187 #if !defined(OS_POSIX) 188 #if !defined(OS_POSIX)
188 #include "chrome/installer/util/browser_distribution.h" 189 #include "chrome/installer/util/browser_distribution.h"
189 #endif 190 #endif
190 191
191 #if defined(OS_CHROMEOS) 192 #if defined(OS_CHROMEOS)
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
1061 1062
1062 case net::URLRequestStatus::FAILED: 1063 case net::URLRequestStatus::FAILED:
1063 return "FAILED"; 1064 return "FAILED";
1064 1065
1065 default: 1066 default:
1066 NOTREACHED(); 1067 NOTREACHED();
1067 return "Unknown"; 1068 return "Unknown";
1068 } 1069 }
1069 } 1070 }
1070 1071
1071 void MetricsService::OnURLFetchComplete(const URLFetcher* source, 1072 void MetricsService::OnURLFetchComplete(const URLFetcher* source) {
1072 const GURL& url,
1073 const net::URLRequestStatus& status,
1074 int response_code,
1075 const net::ResponseCookies& cookies,
1076 const std::string& data) {
1077 DCHECK(waiting_for_asynchronus_reporting_step_); 1073 DCHECK(waiting_for_asynchronus_reporting_step_);
1078 waiting_for_asynchronus_reporting_step_ = false; 1074 waiting_for_asynchronus_reporting_step_ = false;
1079 DCHECK(current_fetch_.get()); 1075 DCHECK(current_fetch_.get());
1080 current_fetch_.reset(NULL); // We're not allowed to re-use it. 1076 current_fetch_.reset(NULL); // We're not allowed to re-use it.
willchan no longer on Chromium 2011/10/25 18:09:39 Here's the URLFetcher getting deleted. current_fet
1081 1077
1082 // Confirm send so that we can move on. 1078 // Confirm send so that we can move on.
1083 VLOG(1) << "METRICS RESPONSE CODE: " << response_code 1079 VLOG(1) << "METRICS RESPONSE CODE: " << source->response_code()
1084 << " status=" << StatusToString(status); 1080 << " status=" << StatusToString(source->status());
1085 1081
1086 bool upload_succeeded = response_code == 200; 1082 bool upload_succeeded = source->response_code() == 200;
1087 1083
1088 // Provide boolean for error recovery (allow us to ignore response_code). 1084 // Provide boolean for error recovery (allow us to ignore response_code).
1089 bool discard_log = false; 1085 bool discard_log = false;
1090 1086
1091 if (!upload_succeeded && 1087 if (!upload_succeeded &&
1092 (log_manager_.staged_log_text().length() > 1088 (log_manager_.staged_log_text().length() >
1093 static_cast<size_t>(kUploadLogAvoidRetransmitSize))) { 1089 static_cast<size_t>(kUploadLogAvoidRetransmitSize))) {
1094 UMA_HISTOGRAM_COUNTS( 1090 UMA_HISTOGRAM_COUNTS(
1095 "UMA.Large Rejected Log was Discarded", 1091 "UMA.Large Rejected Log was Discarded",
1096 static_cast<int>(log_manager_.staged_log_text().length())); 1092 static_cast<int>(log_manager_.staged_log_text().length()));
1097 discard_log = true; 1093 discard_log = true;
1098 } else if (response_code == 400) { 1094 } else if (source->response_code() == 400) {
1099 // Bad syntax. Retransmission won't work. 1095 // Bad syntax. Retransmission won't work.
1100 UMA_HISTOGRAM_COUNTS("UMA.Unacceptable_Log_Discarded", state_); 1096 UMA_HISTOGRAM_COUNTS("UMA.Unacceptable_Log_Discarded", state_);
1101 discard_log = true; 1097 discard_log = true;
1102 } 1098 }
1103 1099
1104 if (!upload_succeeded && !discard_log) { 1100 if (!upload_succeeded && !discard_log) {
1105 VLOG(1) << "METRICS: transmission attempt returned a failure code: " 1101 VLOG(1) << "METRICS: transmission attempt returned a failure code: "
1106 << response_code << ". Verify network connectivity"; 1102 << source->response_code() << ". Verify network connectivity";
1107 LogBadResponseCode(); 1103 LogBadResponseCode();
1108 } else { // Successful receipt (or we are discarding log). 1104 } else { // Successful receipt (or we are discarding log).
1105 std::string data;
1106 source->GetResponseAsString(&data);
1109 VLOG(1) << "METRICS RESPONSE DATA: " << data; 1107 VLOG(1) << "METRICS RESPONSE DATA: " << data;
1110 switch (state_) { 1108 switch (state_) {
1111 case INITIAL_LOG_READY: 1109 case INITIAL_LOG_READY:
1112 state_ = SENDING_OLD_LOGS; 1110 state_ = SENDING_OLD_LOGS;
1113 break; 1111 break;
1114 1112
1115 case SENDING_OLD_LOGS: 1113 case SENDING_OLD_LOGS:
1116 // Store the updated list to disk now that the removed log is uploaded. 1114 // Store the updated list to disk now that the removed log is uploaded.
1117 StoreUnsentLogs(); 1115 StoreUnsentLogs();
1118 break; 1116 break;
(...skipping 12 matching lines...) Expand all
1131 DCHECK(local_state); 1129 DCHECK(local_state);
1132 if (local_state) 1130 if (local_state)
1133 local_state->ScheduleSavePersistentPrefs(); 1131 local_state->ScheduleSavePersistentPrefs();
1134 1132
1135 if (log_manager_.has_unsent_logs()) 1133 if (log_manager_.has_unsent_logs())
1136 DCHECK(state_ < SENDING_CURRENT_LOGS); 1134 DCHECK(state_ < SENDING_CURRENT_LOGS);
1137 } 1135 }
1138 1136
1139 // Error 400 indicates a problem with the log, not with the server, so 1137 // Error 400 indicates a problem with the log, not with the server, so
1140 // don't consider that a sign that the server is in trouble. 1138 // don't consider that a sign that the server is in trouble.
1141 bool server_is_healthy = upload_succeeded || response_code == 400; 1139 bool server_is_healthy = upload_succeeded || source->response_code() == 400;
1142 1140
1143 scheduler_->UploadFinished(server_is_healthy, 1141 scheduler_->UploadFinished(server_is_healthy,
1144 log_manager_.has_unsent_logs()); 1142 log_manager_.has_unsent_logs());
1145 1143
1146 // Collect network stats if UMA upload succeeded. 1144 // Collect network stats if UMA upload succeeded.
1147 if (server_is_healthy && io_thread_) 1145 if (server_is_healthy && io_thread_)
1148 chrome_browser_net::CollectNetworkStats(network_stats_server_, io_thread_); 1146 chrome_browser_net::CollectNetworkStats(network_stats_server_, io_thread_);
1149 } 1147 }
1150 1148
1151 void MetricsService::LogBadResponseCode() { 1149 void MetricsService::LogBadResponseCode() {
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 if (local_state) { 1542 if (local_state) {
1545 const PrefService::Preference* uma_pref = 1543 const PrefService::Preference* uma_pref =
1546 local_state->FindPreference(prefs::kMetricsReportingEnabled); 1544 local_state->FindPreference(prefs::kMetricsReportingEnabled);
1547 if (uma_pref) { 1545 if (uma_pref) {
1548 bool success = uma_pref->GetValue()->GetAsBoolean(&result); 1546 bool success = uma_pref->GetValue()->GetAsBoolean(&result);
1549 DCHECK(success); 1547 DCHECK(success);
1550 } 1548 }
1551 } 1549 }
1552 return result; 1550 return result;
1553 } 1551 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698