| 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 #include "google_apis/gcm/engine/registration_request.h" | 5 #include "google_apis/gcm/engine/registration_request.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 // last request. | 58 // last request. |
| 59 bool ShouldRetryWithStatus(RegistrationRequest::Status status) { | 59 bool ShouldRetryWithStatus(RegistrationRequest::Status status) { |
| 60 return status == RegistrationRequest::UNKNOWN_ERROR || | 60 return status == RegistrationRequest::UNKNOWN_ERROR || |
| 61 status == RegistrationRequest::AUTHENTICATION_FAILED || | 61 status == RegistrationRequest::AUTHENTICATION_FAILED || |
| 62 status == RegistrationRequest::DEVICE_REGISTRATION_ERROR || | 62 status == RegistrationRequest::DEVICE_REGISTRATION_ERROR || |
| 63 status == RegistrationRequest::HTTP_NOT_OK || | 63 status == RegistrationRequest::HTTP_NOT_OK || |
| 64 status == RegistrationRequest::URL_FETCHING_FAILED || | 64 status == RegistrationRequest::URL_FETCHING_FAILED || |
| 65 status == RegistrationRequest::RESPONSE_PARSING_FAILED; | 65 status == RegistrationRequest::RESPONSE_PARSING_FAILED; |
| 66 } | 66 } |
| 67 | 67 |
| 68 void RecordRegistrationStatusToUMA(RegistrationRequest::Status status) { | |
| 69 UMA_HISTOGRAM_ENUMERATION("GCM.RegistrationRequestStatus", status, | |
| 70 RegistrationRequest::STATUS_COUNT); | |
| 71 } | |
| 72 | |
| 73 } // namespace | 68 } // namespace |
| 74 | 69 |
| 75 RegistrationRequest::RequestInfo::RequestInfo( | 70 RegistrationRequest::RequestInfo::RequestInfo( |
| 76 uint64 android_id, | 71 uint64 android_id, |
| 77 uint64 security_token, | 72 uint64 security_token, |
| 78 const std::string& app_id) | 73 const std::string& app_id) |
| 79 : android_id(android_id), | 74 : android_id(android_id), |
| 80 security_token(security_token), | 75 security_token(security_token), |
| 81 app_id(app_id) { | 76 app_id(app_id) { |
| 82 DCHECK(android_id != 0UL); | 77 DCHECK(android_id != 0UL); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 << source->GetResponseCode(); | 216 << source->GetResponseCode(); |
| 222 return HTTP_NOT_OK; | 217 return HTTP_NOT_OK; |
| 223 } | 218 } |
| 224 | 219 |
| 225 return UNKNOWN_ERROR; | 220 return UNKNOWN_ERROR; |
| 226 } | 221 } |
| 227 | 222 |
| 228 void RegistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { | 223 void RegistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { |
| 229 std::string token; | 224 std::string token; |
| 230 Status status = ParseResponse(source, &token); | 225 Status status = ParseResponse(source, &token); |
| 231 RecordRegistrationStatusToUMA(status); | |
| 232 recorder_->RecordRegistrationResponse( | 226 recorder_->RecordRegistrationResponse( |
| 233 request_info_.app_id, | 227 request_info_.app_id, |
| 234 source_to_record_, | 228 source_to_record_, |
| 235 status); | 229 status); |
| 236 | 230 |
| 231 DCHECK(custom_request_handler_.get()); |
| 232 custom_request_handler_->ReportUMAs( |
| 233 status, |
| 234 backoff_entry_.failure_count(), |
| 235 base::TimeTicks::Now() - request_start_time_); |
| 236 |
| 237 if (ShouldRetryWithStatus(status)) { | 237 if (ShouldRetryWithStatus(status)) { |
| 238 if (retries_left_ > 0) { | 238 if (retries_left_ > 0) { |
| 239 recorder_->RecordRegistrationRetryRequested( | 239 recorder_->RecordRegistrationRetryRequested( |
| 240 request_info_.app_id, | 240 request_info_.app_id, |
| 241 source_to_record_, | 241 source_to_record_, |
| 242 retries_left_); | 242 retries_left_); |
| 243 RetryWithBackoff(true); | 243 RetryWithBackoff(true); |
| 244 return; | 244 return; |
| 245 } | 245 } |
| 246 | 246 |
| 247 status = REACHED_MAX_RETRIES; | 247 status = REACHED_MAX_RETRIES; |
| 248 recorder_->RecordRegistrationResponse( | 248 recorder_->RecordRegistrationResponse( |
| 249 request_info_.app_id, | 249 request_info_.app_id, |
| 250 source_to_record_, | 250 source_to_record_, |
| 251 status); | 251 status); |
| 252 RecordRegistrationStatusToUMA(status); | 252 |
| 253 // Only REACHED_MAX_RETRIES is reported because the function will skip |
| 254 // reporting count and time when status is not SUCCESS. |
| 255 DCHECK(custom_request_handler_.get()); |
| 256 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta()); |
| 253 } | 257 } |
| 254 | 258 |
| 255 if (status == SUCCESS) { | |
| 256 UMA_HISTOGRAM_COUNTS("GCM.RegistrationRetryCount", | |
| 257 backoff_entry_.failure_count()); | |
| 258 UMA_HISTOGRAM_TIMES("GCM.RegistrationCompleteTime", | |
| 259 base::TimeTicks::Now() - request_start_time_); | |
| 260 } | |
| 261 callback_.Run(status, token); | 259 callback_.Run(status, token); |
| 262 } | 260 } |
| 263 | 261 |
| 264 } // namespace gcm | 262 } // namespace gcm |
| OLD | NEW |