Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(15)

Side by Side Diff: google_apis/gcm/engine/registration_request.cc

Issue 248213004: Record connection, registration, and receiving activities. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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(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
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 request_info_.app_id,
234 request_info_.sender_ids,
235 status);
228 236
229 if (ShouldRetryWithStatus(status)) { 237 if (ShouldRetryWithStatus(status)) {
230 if (retries_left_ > 0) { 238 if (retries_left_ > 0) {
239 recorder_->RecordRegistrationRetryRequested(
240 request_info_.app_id,
241 request_info_.sender_ids,
242 retries_left_);
231 RetryWithBackoff(true); 243 RetryWithBackoff(true);
232 return; 244 return;
233 } 245 }
234 246
235 status = REACHED_MAX_RETRIES; 247 status = REACHED_MAX_RETRIES;
248 recorder_->RecordRegistrationResponse(
249 request_info_.app_id,
250 request_info_.sender_ids,
251 status);
236 RecordRegistrationStatusToUMA(status); 252 RecordRegistrationStatusToUMA(status);
237 } 253 }
238 254
239 callback_.Run(status, token); 255 callback_.Run(status, token);
240 } 256 }
241 257
242 } // namespace gcm 258 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/registration_request.h ('k') | google_apis/gcm/engine/registration_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698