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 <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 } | 62 } |
63 | 63 |
64 // Determines whether to retry based on the status of the last request. | 64 // Determines whether to retry based on the status of the last request. |
65 bool ShouldRetryWithStatus(RegistrationRequest::Status status) { | 65 bool ShouldRetryWithStatus(RegistrationRequest::Status status) { |
66 switch (status) { | 66 switch (status) { |
67 case RegistrationRequest::AUTHENTICATION_FAILED: | 67 case RegistrationRequest::AUTHENTICATION_FAILED: |
68 case RegistrationRequest::DEVICE_REGISTRATION_ERROR: | 68 case RegistrationRequest::DEVICE_REGISTRATION_ERROR: |
69 case RegistrationRequest::UNKNOWN_ERROR: | 69 case RegistrationRequest::UNKNOWN_ERROR: |
70 case RegistrationRequest::URL_FETCHING_FAILED: | 70 case RegistrationRequest::URL_FETCHING_FAILED: |
71 case RegistrationRequest::HTTP_NOT_OK: | 71 case RegistrationRequest::HTTP_NOT_OK: |
72 case RegistrationRequest::RESPONSE_PARSING_FAILED: | 72 case RegistrationRequest::NO_RESPONSE_BODY: |
73 return true; | 73 return true; |
74 case RegistrationRequest::SUCCESS: | 74 case RegistrationRequest::SUCCESS: |
75 case RegistrationRequest::INVALID_PARAMETERS: | 75 case RegistrationRequest::INVALID_PARAMETERS: |
76 case RegistrationRequest::INVALID_SENDER: | 76 case RegistrationRequest::INVALID_SENDER: |
77 case RegistrationRequest::REACHED_MAX_RETRIES: | 77 case RegistrationRequest::REACHED_MAX_RETRIES: |
78 return false; | 78 return false; |
79 case RegistrationRequest::STATUS_COUNT: | 79 case RegistrationRequest::STATUS_COUNT: |
80 NOTREACHED(); | 80 NOTREACHED(); |
81 break; | 81 break; |
82 } | 82 } |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 RegistrationRequest::Status RegistrationRequest::ParseResponse( | 199 RegistrationRequest::Status RegistrationRequest::ParseResponse( |
200 const net::URLFetcher* source, std::string* token) { | 200 const net::URLFetcher* source, std::string* token) { |
201 if (!source->GetStatus().is_success()) { | 201 if (!source->GetStatus().is_success()) { |
202 LOG(ERROR) << "URL fetching failed."; | 202 LOG(ERROR) << "URL fetching failed."; |
203 return URL_FETCHING_FAILED; | 203 return URL_FETCHING_FAILED; |
204 } | 204 } |
205 | 205 |
206 std::string response; | 206 std::string response; |
207 if (!source->GetResponseAsString(&response)) { | 207 if (!source->GetResponseAsString(&response)) { |
208 LOG(ERROR) << "Failed to parse registration response as a string."; | 208 LOG(ERROR) << "Failed to parse registration response as a string."; |
209 return RESPONSE_PARSING_FAILED; | 209 return NO_RESPONSE_BODY; |
210 } | 210 } |
211 | 211 |
212 if (source->GetResponseCode() == net::HTTP_OK) { | 212 if (source->GetResponseCode() == net::HTTP_OK) { |
213 size_t token_pos = response.find(kTokenPrefix); | 213 size_t token_pos = response.find(kTokenPrefix); |
214 if (token_pos != std::string::npos) { | 214 if (token_pos != std::string::npos) { |
215 *token = response.substr(token_pos + arraysize(kTokenPrefix) - 1); | 215 *token = response.substr(token_pos + arraysize(kTokenPrefix) - 1); |
216 return SUCCESS; | 216 return SUCCESS; |
217 } | 217 } |
218 } | 218 } |
219 | 219 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 // Only REACHED_MAX_RETRIES is reported because the function will skip | 262 // Only REACHED_MAX_RETRIES is reported because the function will skip |
263 // reporting count and time when status is not SUCCESS. | 263 // reporting count and time when status is not SUCCESS. |
264 DCHECK(custom_request_handler_.get()); | 264 DCHECK(custom_request_handler_.get()); |
265 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta()); | 265 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta()); |
266 } | 266 } |
267 | 267 |
268 callback_.Run(status, token); | 268 callback_.Run(status, token); |
269 } | 269 } |
270 | 270 |
271 } // namespace gcm | 271 } // namespace gcm |
OLD | NEW |