| 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" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
| 12 #include "net/base/escape.h" | 13 #include "net/base/escape.h" |
| 13 #include "net/http/http_request_headers.h" | 14 #include "net/http/http_request_headers.h" |
| 14 #include "net/http/http_status_code.h" | 15 #include "net/http/http_status_code.h" |
| 15 #include "net/url_request/url_fetcher.h" | 16 #include "net/url_request/url_fetcher.h" |
| 16 #include "net/url_request/url_request_context_getter.h" | 17 #include "net/url_request/url_request_context_getter.h" |
| 17 #include "net/url_request/url_request_status.h" | 18 #include "net/url_request/url_request_status.h" |
| 18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 19 | 20 |
| 20 namespace gcm { | 21 namespace gcm { |
| 21 | 22 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 sender_ids(sender_ids) { | 96 sender_ids(sender_ids) { |
| 96 } | 97 } |
| 97 | 98 |
| 98 RegistrationRequest::RequestInfo::~RequestInfo() {} | 99 RegistrationRequest::RequestInfo::~RequestInfo() {} |
| 99 | 100 |
| 100 RegistrationRequest::RegistrationRequest( | 101 RegistrationRequest::RegistrationRequest( |
| 101 const RequestInfo& request_info, | 102 const RequestInfo& request_info, |
| 102 const net::BackoffEntry::Policy& backoff_policy, | 103 const net::BackoffEntry::Policy& backoff_policy, |
| 103 const RegistrationCallback& callback, | 104 const RegistrationCallback& callback, |
| 104 int max_retry_count, | 105 int max_retry_count, |
| 105 scoped_refptr<net::URLRequestContextGetter> request_context_getter) | 106 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 107 GCMStatsRecorder* recorder) |
| 106 : callback_(callback), | 108 : callback_(callback), |
| 107 request_info_(request_info), | 109 request_info_(request_info), |
| 108 backoff_entry_(&backoff_policy), | 110 backoff_entry_(&backoff_policy), |
| 109 request_context_getter_(request_context_getter), | 111 request_context_getter_(request_context_getter), |
| 110 retries_left_(max_retry_count), | 112 retries_left_(max_retry_count), |
| 113 recorder_(recorder), |
| 111 weak_ptr_factory_(this) { | 114 weak_ptr_factory_(this) { |
| 112 DCHECK_GE(max_retry_count, 0); | 115 DCHECK_GE(max_retry_count, 0); |
| 113 } | 116 } |
| 114 | 117 |
| 115 RegistrationRequest::~RegistrationRequest() {} | 118 RegistrationRequest::~RegistrationRequest() {} |
| 116 | 119 |
| 117 void RegistrationRequest::Start() { | 120 void RegistrationRequest::Start() { |
| 118 DCHECK(!callback_.is_null()); | 121 DCHECK(!callback_.is_null()); |
| 119 DCHECK(request_info_.android_id != 0UL); | 122 DCHECK(request_info_.android_id != 0UL); |
| 120 DCHECK(request_info_.security_token != 0UL); | 123 DCHECK(request_info_.security_token != 0UL); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 145 DCHECK(!iter->empty()); | 148 DCHECK(!iter->empty()); |
| 146 if (!senders.empty()) | 149 if (!senders.empty()) |
| 147 senders.append(","); | 150 senders.append(","); |
| 148 senders.append(*iter); | 151 senders.append(*iter); |
| 149 } | 152 } |
| 150 BuildFormEncoding(kSenderKey, senders, &body); | 153 BuildFormEncoding(kSenderKey, senders, &body); |
| 151 | 154 |
| 152 DVLOG(1) << "Performing registration for: " << request_info_.app_id; | 155 DVLOG(1) << "Performing registration for: " << request_info_.app_id; |
| 153 DVLOG(1) << "Registration request: " << body; | 156 DVLOG(1) << "Registration request: " << body; |
| 154 url_fetcher_->SetUploadData(kRegistrationRequestContentType, body); | 157 url_fetcher_->SetUploadData(kRegistrationRequestContentType, body); |
| 158 recorder_->RecordRegistrationSent(android_id, request_info_.app_id, senders); |
| 155 url_fetcher_->Start(); | 159 url_fetcher_->Start(); |
| 156 } | 160 } |
| 157 | 161 |
| 158 void RegistrationRequest::RetryWithBackoff(bool update_backoff) { | 162 void RegistrationRequest::RetryWithBackoff(bool update_backoff) { |
| 159 if (update_backoff) { | 163 if (update_backoff) { |
| 160 DCHECK_GT(retries_left_, 0); | 164 DCHECK_GT(retries_left_, 0); |
| 161 --retries_left_; | 165 --retries_left_; |
| 162 url_fetcher_.reset(); | 166 url_fetcher_.reset(); |
| 163 backoff_entry_.InformOfRequest(false); | 167 backoff_entry_.InformOfRequest(false); |
| 164 } | 168 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 return HTTP_NOT_OK; | 222 return HTTP_NOT_OK; |
| 219 } | 223 } |
| 220 | 224 |
| 221 return UNKNOWN_ERROR; | 225 return UNKNOWN_ERROR; |
| 222 } | 226 } |
| 223 | 227 |
| 224 void RegistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { | 228 void RegistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { |
| 225 std::string token; | 229 std::string token; |
| 226 Status status = ParseResponse(source, &token); | 230 Status status = ParseResponse(source, &token); |
| 227 RecordRegistrationStatusToUMA(status); | 231 RecordRegistrationStatusToUMA(status); |
| 232 recorder_->RecordRegistrationResponse( |
| 233 base::Uint64ToString(request_info_.android_id), |
| 234 request_info_.app_id, |
| 235 request_info_.sender_ids, |
| 236 status); |
| 228 | 237 |
| 229 if (ShouldRetryWithStatus(status)) { | 238 if (ShouldRetryWithStatus(status)) { |
| 230 if (retries_left_ > 0) { | 239 if (retries_left_ > 0) { |
| 240 recorder_->RecordRegistrationRetryRequested( |
| 241 base::Uint64ToString(request_info_.android_id), |
| 242 request_info_.app_id, |
| 243 request_info_.sender_ids, |
| 244 retries_left_); |
| 231 RetryWithBackoff(true); | 245 RetryWithBackoff(true); |
| 232 return; | 246 return; |
| 233 } | 247 } |
| 234 | 248 |
| 235 status = REACHED_MAX_RETRIES; | 249 status = REACHED_MAX_RETRIES; |
| 250 recorder_->RecordRegistrationResponse( |
| 251 base::Uint64ToString(request_info_.android_id), |
| 252 request_info_.app_id, |
| 253 request_info_.sender_ids, |
| 254 status); |
| 236 RecordRegistrationStatusToUMA(status); | 255 RecordRegistrationStatusToUMA(status); |
| 237 } | 256 } |
| 238 | 257 |
| 239 callback_.Run(status, token); | 258 callback_.Run(status, token); |
| 240 } | 259 } |
| 241 | 260 |
| 242 } // namespace gcm | 261 } // namespace gcm |
| OLD | NEW |