| 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/checkin_request.h" | 5 #include "google_apis/gcm/engine/checkin_request.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" | 11 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
| 12 #include "google_apis/gcm/protocol/checkin.pb.h" | 12 #include "google_apis/gcm/protocol/checkin.pb.h" |
| 13 #include "net/base/load_flags.h" | 13 #include "net/base/load_flags.h" |
| 14 #include "net/http/http_status_code.h" | |
| 15 #include "net/url_request/url_fetcher.h" | 14 #include "net/url_request/url_fetcher.h" |
| 16 #include "net/url_request/url_request_status.h" | 15 #include "net/url_request/url_request_status.h" |
| 17 | 16 |
| 18 namespace gcm { | 17 namespace gcm { |
| 19 | 18 |
| 20 namespace { | 19 namespace { |
| 21 const char kRequestContentType[] = "application/x-protobuf"; | 20 const char kRequestContentType[] = "application/x-protobuf"; |
| 22 const int kRequestVersionValue = 3; | 21 const int kRequestVersionValue = 3; |
| 23 const int kDefaultUserSerialNumber = 0; | 22 const int kDefaultUserSerialNumber = 0; |
| 24 | 23 |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 source->GetResponseCode()); | 186 source->GetResponseCode()); |
| 188 if (response_status == net::HTTP_BAD_REQUEST || | 187 if (response_status == net::HTTP_BAD_REQUEST || |
| 189 response_status == net::HTTP_UNAUTHORIZED) { | 188 response_status == net::HTTP_UNAUTHORIZED) { |
| 190 // BAD_REQUEST indicates that the request was malformed. | 189 // BAD_REQUEST indicates that the request was malformed. |
| 191 // UNAUTHORIZED indicates that security token didn't match the android id. | 190 // UNAUTHORIZED indicates that security token didn't match the android id. |
| 192 LOG(ERROR) << "No point retrying the checkin with status: " | 191 LOG(ERROR) << "No point retrying the checkin with status: " |
| 193 << response_status << ". Checkin failed."; | 192 << response_status << ". Checkin failed."; |
| 194 CheckinRequestStatus status = response_status == net::HTTP_BAD_REQUEST ? | 193 CheckinRequestStatus status = response_status == net::HTTP_BAD_REQUEST ? |
| 195 HTTP_BAD_REQUEST : HTTP_UNAUTHORIZED; | 194 HTTP_BAD_REQUEST : HTTP_UNAUTHORIZED; |
| 196 RecordCheckinStatusAndReportUMA(status, recorder_, false); | 195 RecordCheckinStatusAndReportUMA(status, recorder_, false); |
| 197 callback_.Run(response_proto); | 196 callback_.Run(response_status, response_proto); |
| 198 return; | 197 return; |
| 199 } | 198 } |
| 200 | 199 |
| 201 if (response_status != net::HTTP_OK || | 200 if (response_status != net::HTTP_OK || |
| 202 !source->GetResponseAsString(&response_string) || | 201 !source->GetResponseAsString(&response_string) || |
| 203 !response_proto.ParseFromString(response_string)) { | 202 !response_proto.ParseFromString(response_string)) { |
| 204 LOG(ERROR) << "Failed to get checkin response. HTTP Status: " | 203 LOG(ERROR) << "Failed to get checkin response. HTTP Status: " |
| 205 << response_status << ". Retrying."; | 204 << response_status << ". Retrying."; |
| 206 CheckinRequestStatus status = response_status != net::HTTP_OK ? | 205 CheckinRequestStatus status = response_status != net::HTTP_OK ? |
| 207 HTTP_NOT_OK : RESPONSE_PARSING_FAILED; | 206 HTTP_NOT_OK : RESPONSE_PARSING_FAILED; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 218 RecordCheckinStatusAndReportUMA(ZERO_ID_OR_TOKEN, recorder_, true); | 217 RecordCheckinStatusAndReportUMA(ZERO_ID_OR_TOKEN, recorder_, true); |
| 219 RetryWithBackoff(); | 218 RetryWithBackoff(); |
| 220 return; | 219 return; |
| 221 } | 220 } |
| 222 | 221 |
| 223 RecordCheckinStatusAndReportUMA(SUCCESS, recorder_, false); | 222 RecordCheckinStatusAndReportUMA(SUCCESS, recorder_, false); |
| 224 UMA_HISTOGRAM_COUNTS("GCM.CheckinRetryCount", | 223 UMA_HISTOGRAM_COUNTS("GCM.CheckinRetryCount", |
| 225 backoff_entry_.failure_count()); | 224 backoff_entry_.failure_count()); |
| 226 UMA_HISTOGRAM_TIMES("GCM.CheckinCompleteTime", | 225 UMA_HISTOGRAM_TIMES("GCM.CheckinCompleteTime", |
| 227 base::TimeTicks::Now() - request_start_time_); | 226 base::TimeTicks::Now() - request_start_time_); |
| 228 callback_.Run(response_proto); | 227 callback_.Run(response_status, response_proto); |
| 229 } | 228 } |
| 230 | 229 |
| 231 } // namespace gcm | 230 } // namespace gcm |
| OLD | NEW |