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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 | 67 |
68 // Indicates whether a retry attempt should be made based on the status of the | 68 // Indicates whether a retry attempt should be made based on the status of the |
69 // last request. | 69 // last request. |
70 bool ShouldRetryWithStatus(RegistrationRequest::Status status) { | 70 bool ShouldRetryWithStatus(RegistrationRequest::Status status) { |
71 return status == RegistrationRequest::UNKNOWN_ERROR || | 71 return status == RegistrationRequest::UNKNOWN_ERROR || |
72 status == RegistrationRequest::AUTHENTICATION_FAILED || | 72 status == RegistrationRequest::AUTHENTICATION_FAILED || |
73 status == RegistrationRequest::DEVICE_REGISTRATION_ERROR; | 73 status == RegistrationRequest::DEVICE_REGISTRATION_ERROR; |
74 } | 74 } |
75 | 75 |
| 76 void RecordRegistrationStatusToUMA(RegistrationRequest::Status status) { |
| 77 UMA_HISTOGRAM_ENUMERATION("GCM.RegistrationRequestStatus", status, |
| 78 RegistrationRequest::STATUS_COUNT); |
| 79 } |
| 80 |
76 } // namespace | 81 } // namespace |
77 | 82 |
78 RegistrationRequest::RequestInfo::RequestInfo( | 83 RegistrationRequest::RequestInfo::RequestInfo( |
79 uint64 android_id, | 84 uint64 android_id, |
80 uint64 security_token, | 85 uint64 security_token, |
81 const std::string& app_id, | 86 const std::string& app_id, |
82 const std::string& cert, | 87 const std::string& cert, |
83 const std::vector<std::string>& sender_ids) | 88 const std::vector<std::string>& sender_ids) |
84 : android_id(android_id), | 89 : android_id(android_id), |
85 security_token(security_token), | 90 security_token(security_token), |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 << source->GetResponseCode(); | 185 << source->GetResponseCode(); |
181 RetryWithBackoff(true); | 186 RetryWithBackoff(true); |
182 return; | 187 return; |
183 } | 188 } |
184 | 189 |
185 DVLOG(1) << "Parsing registration response: " << response; | 190 DVLOG(1) << "Parsing registration response: " << response; |
186 size_t token_pos = response.find(kTokenPrefix); | 191 size_t token_pos = response.find(kTokenPrefix); |
187 if (token_pos != std::string::npos) { | 192 if (token_pos != std::string::npos) { |
188 std::string token = | 193 std::string token = |
189 response.substr(token_pos + arraysize(kTokenPrefix) - 1); | 194 response.substr(token_pos + arraysize(kTokenPrefix) - 1); |
| 195 RecordRegistrationStatusToUMA(SUCCESS); |
190 callback_.Run(SUCCESS, token); | 196 callback_.Run(SUCCESS, token); |
191 return; | 197 return; |
192 } | 198 } |
193 | 199 |
194 size_t error_pos = response.find(kErrorPrefix); | 200 size_t error_pos = response.find(kErrorPrefix); |
195 Status status = UNKNOWN_ERROR; | 201 Status status = UNKNOWN_ERROR; |
196 if (error_pos != std::string::npos) { | 202 if (error_pos != std::string::npos) { |
197 std::string error = | 203 std::string error = |
198 response.substr(error_pos + arraysize(kErrorPrefix) - 1); | 204 response.substr(error_pos + arraysize(kErrorPrefix) - 1); |
199 status = GetStatusFromError(error); | 205 status = GetStatusFromError(error); |
200 } | 206 } |
201 UMA_HISTOGRAM_ENUMERATION("GCM.RegistrationRequestStatus", status, | 207 RecordRegistrationStatusToUMA(status); |
202 RegistrationRequest::STATUS_COUNT); | |
203 | 208 |
204 if (ShouldRetryWithStatus(status)) { | 209 if (ShouldRetryWithStatus(status)) { |
205 RetryWithBackoff(true); | 210 RetryWithBackoff(true); |
206 return; | 211 return; |
207 } | 212 } |
208 | 213 |
209 callback_.Run(status, std::string()); | 214 callback_.Run(status, std::string()); |
210 } | 215 } |
211 | 216 |
212 } // namespace gcm | 217 } // namespace gcm |
OLD | NEW |