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/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 "google_apis/gcm/protocol/checkin.pb.h" | 10 #include "google_apis/gcm/protocol/checkin.pb.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 CheckinRequest::CheckinRequest( | 49 CheckinRequest::CheckinRequest( |
50 const CheckinRequestCallback& callback, | 50 const CheckinRequestCallback& callback, |
51 const net::BackoffEntry::Policy& backoff_policy, | 51 const net::BackoffEntry::Policy& backoff_policy, |
52 const checkin_proto::ChromeBuildProto& chrome_build_proto, | 52 const checkin_proto::ChromeBuildProto& chrome_build_proto, |
53 uint64 android_id, | 53 uint64 android_id, |
54 uint64 security_token, | 54 uint64 security_token, |
55 const std::vector<std::string>& account_ids, | 55 const std::vector<std::string>& account_ids, |
56 net::URLRequestContextGetter* request_context_getter) | 56 net::URLRequestContextGetter* request_context_getter, |
| 57 GCMStatsRecorder* recorder) |
57 : request_context_getter_(request_context_getter), | 58 : request_context_getter_(request_context_getter), |
58 callback_(callback), | 59 callback_(callback), |
59 backoff_entry_(&backoff_policy), | 60 backoff_entry_(&backoff_policy), |
60 chrome_build_proto_(chrome_build_proto), | 61 chrome_build_proto_(chrome_build_proto), |
61 android_id_(android_id), | 62 android_id_(android_id), |
62 security_token_(security_token), | 63 security_token_(security_token), |
63 account_ids_(account_ids), | 64 account_ids_(account_ids), |
| 65 recorder_(recorder), |
64 weak_ptr_factory_(this) { | 66 weak_ptr_factory_(this) { |
65 } | 67 } |
66 | 68 |
67 CheckinRequest::~CheckinRequest() {} | 69 CheckinRequest::~CheckinRequest() {} |
68 | 70 |
69 void CheckinRequest::Start() { | 71 void CheckinRequest::Start() { |
70 DCHECK(!url_fetcher_.get()); | 72 DCHECK(!url_fetcher_.get()); |
71 | 73 |
72 checkin_proto::AndroidCheckinRequest request; | 74 checkin_proto::AndroidCheckinRequest request; |
73 request.set_id(android_id_); | 75 request.set_id(android_id_); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 << " milliseconds."; | 113 << " milliseconds."; |
112 base::MessageLoop::current()->PostDelayedTask( | 114 base::MessageLoop::current()->PostDelayedTask( |
113 FROM_HERE, | 115 FROM_HERE, |
114 base::Bind(&CheckinRequest::RetryWithBackoff, | 116 base::Bind(&CheckinRequest::RetryWithBackoff, |
115 weak_ptr_factory_.GetWeakPtr(), | 117 weak_ptr_factory_.GetWeakPtr(), |
116 false), | 118 false), |
117 backoff_entry_.GetTimeUntilRelease()); | 119 backoff_entry_.GetTimeUntilRelease()); |
118 return; | 120 return; |
119 } | 121 } |
120 | 122 |
| 123 recorder_->RecordCheckin(android_id_, GCMStatsRecorder::Retry); |
121 Start(); | 124 Start(); |
122 } | 125 } |
123 | 126 |
124 void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) { | 127 void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) { |
125 std::string response_string; | 128 std::string response_string; |
126 checkin_proto::AndroidCheckinResponse response_proto; | 129 checkin_proto::AndroidCheckinResponse response_proto; |
127 if (!source->GetStatus().is_success()) { | 130 if (!source->GetStatus().is_success()) { |
128 LOG(ERROR) << "Failed to get checkin response. Fetcher failed. Retrying."; | 131 LOG(ERROR) << "Failed to get checkin response. Fetcher failed. Retrying."; |
129 RecordCheckinStatusToUMA(URL_FETCHING_FAILED); | 132 RecordCheckinStatusToUMA(URL_FETCHING_FAILED); |
130 RetryWithBackoff(true); | 133 RetryWithBackoff(true); |
131 return; | 134 return; |
132 } | 135 } |
133 | 136 |
134 net::HttpStatusCode response_status = static_cast<net::HttpStatusCode>( | 137 net::HttpStatusCode response_status = static_cast<net::HttpStatusCode>( |
135 source->GetResponseCode()); | 138 source->GetResponseCode()); |
136 if (response_status == net::HTTP_BAD_REQUEST || | 139 if (response_status == net::HTTP_BAD_REQUEST || |
137 response_status == net::HTTP_UNAUTHORIZED) { | 140 response_status == net::HTTP_UNAUTHORIZED) { |
138 // BAD_REQUEST indicates that the request was malformed. | 141 // BAD_REQUEST indicates that the request was malformed. |
139 // UNAUTHORIZED indicates that security token didn't match the android id. | 142 // UNAUTHORIZED indicates that security token didn't match the android id. |
140 LOG(ERROR) << "No point retrying the checkin with status: " | 143 LOG(ERROR) << "No point retrying the checkin with status: " |
141 << response_status << ". Checkin failed."; | 144 << response_status << ". Checkin failed."; |
142 RecordCheckinStatusToUMA(response_status == net::HTTP_BAD_REQUEST ? | 145 RecordCheckinStatusToUMA(response_status == net::HTTP_BAD_REQUEST ? |
143 HTTP_BAD_REQUEST : HTTP_UNAUTHORIZED); | 146 HTTP_BAD_REQUEST : HTTP_UNAUTHORIZED); |
| 147 recorder_->RecordCheckin(android_id_, GCMStatsRecorder::Failure); |
144 callback_.Run(0,0); | 148 callback_.Run(0,0); |
145 return; | 149 return; |
146 } | 150 } |
147 | 151 |
148 if (response_status != net::HTTP_OK || | 152 if (response_status != net::HTTP_OK || |
149 !source->GetResponseAsString(&response_string) || | 153 !source->GetResponseAsString(&response_string) || |
150 !response_proto.ParseFromString(response_string)) { | 154 !response_proto.ParseFromString(response_string)) { |
151 LOG(ERROR) << "Failed to get checkin response. HTTP Status: " | 155 LOG(ERROR) << "Failed to get checkin response. HTTP Status: " |
152 << response_status << ". Retrying."; | 156 << response_status << ". Retrying."; |
153 RecordCheckinStatusToUMA(response_status != net::HTTP_OK ? | 157 RecordCheckinStatusToUMA(response_status != net::HTTP_OK ? |
(...skipping 10 matching lines...) Expand all Loading... |
164 RecordCheckinStatusToUMA(ZERO_ID_OR_TOKEN); | 168 RecordCheckinStatusToUMA(ZERO_ID_OR_TOKEN); |
165 RetryWithBackoff(true); | 169 RetryWithBackoff(true); |
166 return; | 170 return; |
167 } | 171 } |
168 | 172 |
169 RecordCheckinStatusToUMA(SUCCESS); | 173 RecordCheckinStatusToUMA(SUCCESS); |
170 callback_.Run(response_proto.android_id(), response_proto.security_token()); | 174 callback_.Run(response_proto.android_id(), response_proto.security_token()); |
171 } | 175 } |
172 | 176 |
173 } // namespace gcm | 177 } // namespace gcm |
OLD | NEW |