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/unregistration_request.h" | 5 #include "google_apis/gcm/engine/unregistration_request.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 const char kRequestContentType[] = "application/x-www-form-urlencoded"; | 29 const char kRequestContentType[] = "application/x-www-form-urlencoded"; |
30 | 30 |
31 // Request constants. | 31 // Request constants. |
32 const char kCategoryKey[] = "app"; | 32 const char kCategoryKey[] = "app"; |
33 const char kSubtypeKey[] = "X-subtype"; | 33 const char kSubtypeKey[] = "X-subtype"; |
34 const char kDeleteKey[] = "delete"; | 34 const char kDeleteKey[] = "delete"; |
35 const char kDeleteValue[] = "true"; | 35 const char kDeleteValue[] = "true"; |
36 const char kDeviceIdKey[] = "device"; | 36 const char kDeviceIdKey[] = "device"; |
37 const char kLoginHeader[] = "AidLogin"; | 37 const char kLoginHeader[] = "AidLogin"; |
38 | 38 |
| 39 // Determines whether to retry based on the status of the last request. |
| 40 bool ShouldRetryWithStatus(UnregistrationRequest::Status status) { |
| 41 switch (status) { |
| 42 case UnregistrationRequest::URL_FETCHING_FAILED: |
| 43 case UnregistrationRequest::NO_RESPONSE_BODY: |
| 44 case UnregistrationRequest::RESPONSE_PARSING_FAILED: |
| 45 case UnregistrationRequest::INCORRECT_APP_ID: |
| 46 case UnregistrationRequest::SERVICE_UNAVAILABLE: |
| 47 case UnregistrationRequest::INTERNAL_SERVER_ERROR: |
| 48 case UnregistrationRequest::HTTP_NOT_OK: |
| 49 return true; |
| 50 case UnregistrationRequest::SUCCESS: |
| 51 case UnregistrationRequest::INVALID_PARAMETERS: |
| 52 case UnregistrationRequest::UNKNOWN_ERROR: |
| 53 case UnregistrationRequest::REACHED_MAX_RETRIES: |
| 54 return false; |
| 55 case UnregistrationRequest::UNREGISTRATION_STATUS_COUNT: |
| 56 NOTREACHED(); |
| 57 break; |
| 58 } |
| 59 return false; |
| 60 } |
| 61 |
39 } // namespace | 62 } // namespace |
40 | 63 |
41 UnregistrationRequest::RequestInfo::RequestInfo(uint64_t android_id, | 64 UnregistrationRequest::RequestInfo::RequestInfo(uint64_t android_id, |
42 uint64_t security_token, | 65 uint64_t security_token, |
43 const std::string& category, | 66 const std::string& category, |
44 const std::string& subtype) | 67 const std::string& subtype) |
45 : android_id(android_id), | 68 : android_id(android_id), |
46 security_token(security_token), | 69 security_token(security_token), |
47 category(category), | 70 category(category), |
48 subtype(subtype) { | 71 subtype(subtype) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 DCHECK(!weak_ptr_factory_.HasWeakPtrs()); | 193 DCHECK(!weak_ptr_factory_.HasWeakPtrs()); |
171 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 194 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
172 FROM_HERE, | 195 FROM_HERE, |
173 base::Bind(&UnregistrationRequest::Start, weak_ptr_factory_.GetWeakPtr()), | 196 base::Bind(&UnregistrationRequest::Start, weak_ptr_factory_.GetWeakPtr()), |
174 backoff_entry_.GetTimeUntilRelease()); | 197 backoff_entry_.GetTimeUntilRelease()); |
175 } | 198 } |
176 | 199 |
177 void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { | 200 void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { |
178 UnregistrationRequest::Status status = ParseResponse(source); | 201 UnregistrationRequest::Status status = ParseResponse(source); |
179 | 202 |
180 DVLOG(1) << "UnregistrationRequestStauts: " << status; | 203 DVLOG(1) << "UnregistrationRequestStatus: " << status; |
181 | 204 |
182 DCHECK(custom_request_handler_.get()); | 205 DCHECK(custom_request_handler_.get()); |
183 custom_request_handler_->ReportUMAs( | 206 custom_request_handler_->ReportUMAs( |
184 status, | 207 status, |
185 backoff_entry_.failure_count(), | 208 backoff_entry_.failure_count(), |
186 base::TimeTicks::Now() - request_start_time_); | 209 base::TimeTicks::Now() - request_start_time_); |
187 | 210 |
188 recorder_->RecordUnregistrationResponse(request_info_.app_id(), | 211 recorder_->RecordUnregistrationResponse(request_info_.app_id(), |
189 source_to_record_, status); | 212 source_to_record_, status); |
190 | 213 |
191 if (status == URL_FETCHING_FAILED || | 214 if (ShouldRetryWithStatus(status)) { |
192 status == HTTP_NOT_OK || | |
193 status == NO_RESPONSE_BODY || | |
194 status == SERVICE_UNAVAILABLE || | |
195 status == INTERNAL_SERVER_ERROR || | |
196 status == INCORRECT_APP_ID || | |
197 status == RESPONSE_PARSING_FAILED) { | |
198 if (retries_left_ > 0) { | 215 if (retries_left_ > 0) { |
199 RetryWithBackoff(); | 216 RetryWithBackoff(); |
200 return; | 217 return; |
201 } | 218 } |
202 | 219 |
203 status = REACHED_MAX_RETRIES; | 220 status = REACHED_MAX_RETRIES; |
204 recorder_->RecordUnregistrationResponse(request_info_.app_id(), | 221 recorder_->RecordUnregistrationResponse(request_info_.app_id(), |
205 source_to_record_, status); | 222 source_to_record_, status); |
206 | 223 |
207 // Only REACHED_MAX_RETRIES is reported because the function will skip | 224 // Only REACHED_MAX_RETRIES is reported because the function will skip |
208 // reporting count and time when status is not SUCCESS. | 225 // reporting count and time when status is not SUCCESS. |
209 DCHECK(custom_request_handler_.get()); | 226 DCHECK(custom_request_handler_.get()); |
210 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta()); | 227 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta()); |
211 } | 228 } |
212 | 229 |
213 // status == SUCCESS || INVALID_PARAMETERS || UNKNOWN_ERROR || | |
214 // REACHED_MAX_RETRIES | |
215 | |
216 callback_.Run(status); | 230 callback_.Run(status); |
217 } | 231 } |
218 | 232 |
219 } // namespace gcm | 233 } // namespace gcm |
OLD | NEW |