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

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

Issue 202083005: Add activity recording capability to gcm internals page. User can refresh, start/stop recording, an… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 9 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 <string>
8
7 #include "base/bind.h" 9 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
10 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
11 #include "base/values.h" 13 #include "base/values.h"
12 #include "net/base/escape.h" 14 #include "net/base/escape.h"
13 #include "net/http/http_request_headers.h" 15 #include "net/http/http_request_headers.h"
14 #include "net/http/http_status_code.h" 16 #include "net/http/http_status_code.h"
15 #include "net/url_request/url_fetcher.h" 17 #include "net/url_request/url_fetcher.h"
16 #include "net/url_request/url_request_context_getter.h" 18 #include "net/url_request/url_request_context_getter.h"
(...skipping 27 matching lines...) Expand all
44 const char kInvalidParameters[] = "INVALID_PARAMETERS"; 46 const char kInvalidParameters[] = "INVALID_PARAMETERS";
45 47
46 void BuildFormEncoding(const std::string& key, 48 void BuildFormEncoding(const std::string& key,
47 const std::string& value, 49 const std::string& value,
48 std::string* out) { 50 std::string* out) {
49 if (!out->empty()) 51 if (!out->empty())
50 out->append("&"); 52 out->append("&");
51 out->append(key + "=" + net::EscapeUrlEncodedData(value, true)); 53 out->append(key + "=" + net::EscapeUrlEncodedData(value, true));
52 } 54 }
53 55
56 // Helper for getting string representation of the Status enum.
57 std::string GetStatusString(RegistrationRequest::Status status) {
fgorski 2014/03/18 21:28:37 Same here, I think it is better to pass the Regist
juyik 2014/03/20 01:09:53 Removed changes for now. Will do this in a future
58 switch (status) {
59 case RegistrationRequest::SUCCESS:
60 return "SUCCESS";
61 case RegistrationRequest::INVALID_PARAMETERS:
62 return "INVALID_PARAMETERS";
63 case RegistrationRequest::INVALID_SENDER:
64 return "INVALID_SENDER";
65 case RegistrationRequest::AUTHENTICATION_FAILED:
66 return "AUTHENTICATION_FAILED";
67 case RegistrationRequest::DEVICE_REGISTRATION_ERROR:
68 return "DEVICE_REGISTRATION_ERROR";
69 case RegistrationRequest::UNKNOWN_ERROR:
70 return "UNKNOWN_ERROR";
71 case RegistrationRequest::URL_FETCHING_FAILED:
72 return "URL_FETCHING_FAILED";
73 case RegistrationRequest::HTTP_NOT_OK:
74 return "HTTP_NOT_OK";
75 case RegistrationRequest::RESPONSE_PARSING_FAILED:
76 return "RESPONSE_PARSING_FAILED";
77 case RegistrationRequest::REACHED_MAX_RETRIES:
78 return "REACHED_MAX_RETRIES";
79 default:
80 NOTREACHED();
81 return "UNKNOWN";
82 }
83 }
84
54 // Gets correct status from the error message. 85 // Gets correct status from the error message.
55 RegistrationRequest::Status GetStatusFromError(const std::string& error) { 86 RegistrationRequest::Status GetStatusFromError(const std::string& error) {
56 // TODO(fgorski): Improve error parsing in case there is nore then just an 87 // TODO(fgorski): Improve error parsing in case there is nore then just an
57 // Error=ERROR_STRING in response. 88 // Error=ERROR_STRING in response.
58 if (error.find(kDeviceRegistrationError) != std::string::npos) 89 if (error.find(kDeviceRegistrationError) != std::string::npos)
59 return RegistrationRequest::DEVICE_REGISTRATION_ERROR; 90 return RegistrationRequest::DEVICE_REGISTRATION_ERROR;
60 if (error.find(kAuthenticationFailed) != std::string::npos) 91 if (error.find(kAuthenticationFailed) != std::string::npos)
61 return RegistrationRequest::AUTHENTICATION_FAILED; 92 return RegistrationRequest::AUTHENTICATION_FAILED;
62 if (error.find(kInvalidSender) != std::string::npos) 93 if (error.find(kInvalidSender) != std::string::npos)
63 return RegistrationRequest::INVALID_SENDER; 94 return RegistrationRequest::INVALID_SENDER;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 sender_ids(sender_ids) { 126 sender_ids(sender_ids) {
96 } 127 }
97 128
98 RegistrationRequest::RequestInfo::~RequestInfo() {} 129 RegistrationRequest::RequestInfo::~RequestInfo() {}
99 130
100 RegistrationRequest::RegistrationRequest( 131 RegistrationRequest::RegistrationRequest(
101 const RequestInfo& request_info, 132 const RequestInfo& request_info,
102 const net::BackoffEntry::Policy& backoff_policy, 133 const net::BackoffEntry::Policy& backoff_policy,
103 const RegistrationCallback& callback, 134 const RegistrationCallback& callback,
104 int max_retry_count, 135 int max_retry_count,
105 scoped_refptr<net::URLRequestContextGetter> request_context_getter) 136 scoped_refptr<net::URLRequestContextGetter> request_context_getter,
137 GCMStatsRecorder* recorder)
106 : callback_(callback), 138 : callback_(callback),
107 request_info_(request_info), 139 request_info_(request_info),
108 backoff_entry_(&backoff_policy), 140 backoff_entry_(&backoff_policy),
109 request_context_getter_(request_context_getter), 141 request_context_getter_(request_context_getter),
110 retries_left_(max_retry_count), 142 retries_left_(max_retry_count),
143 recorder_(recorder),
111 weak_ptr_factory_(this) { 144 weak_ptr_factory_(this) {
112 DCHECK_GE(max_retry_count, 0); 145 DCHECK_GE(max_retry_count, 0);
113 } 146 }
114 147
115 RegistrationRequest::~RegistrationRequest() {} 148 RegistrationRequest::~RegistrationRequest() {}
116 149
117 void RegistrationRequest::Start() { 150 void RegistrationRequest::Start() {
118 DCHECK(!callback_.is_null()); 151 DCHECK(!callback_.is_null());
119 DCHECK(request_info_.android_id != 0UL); 152 DCHECK(request_info_.android_id != 0UL);
120 DCHECK(request_info_.security_token != 0UL); 153 DCHECK(request_info_.security_token != 0UL);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 << " milliseconds."; 203 << " milliseconds.";
171 base::MessageLoop::current()->PostDelayedTask( 204 base::MessageLoop::current()->PostDelayedTask(
172 FROM_HERE, 205 FROM_HERE,
173 base::Bind(&RegistrationRequest::RetryWithBackoff, 206 base::Bind(&RegistrationRequest::RetryWithBackoff,
174 weak_ptr_factory_.GetWeakPtr(), 207 weak_ptr_factory_.GetWeakPtr(),
175 false), 208 false),
176 backoff_entry_.GetTimeUntilRelease()); 209 backoff_entry_.GetTimeUntilRelease());
177 return; 210 return;
178 } 211 }
179 212
213 recorder_->RecordRegister(request_info_.app_id, GCMStatsRecorder::Retry,
214 request_info_.sender_ids);
180 Start(); 215 Start();
181 } 216 }
182 217
183 RegistrationRequest::Status RegistrationRequest::ParseResponse( 218 RegistrationRequest::Status RegistrationRequest::ParseResponse(
184 const net::URLFetcher* source, std::string* token) { 219 const net::URLFetcher* source, std::string* token) {
185 if (!source->GetStatus().is_success()) { 220 if (!source->GetStatus().is_success()) {
186 LOG(ERROR) << "URL fetching failed."; 221 LOG(ERROR) << "URL fetching failed.";
187 return URL_FETCHING_FAILED; 222 return URL_FETCHING_FAILED;
188 } 223 }
189 224
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 return UNKNOWN_ERROR; 256 return UNKNOWN_ERROR;
222 } 257 }
223 258
224 void RegistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { 259 void RegistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) {
225 std::string token; 260 std::string token;
226 Status status = ParseResponse(source, &token); 261 Status status = ParseResponse(source, &token);
227 RecordRegistrationStatusToUMA(status); 262 RecordRegistrationStatusToUMA(status);
228 263
229 if (ShouldRetryWithStatus(status)) { 264 if (ShouldRetryWithStatus(status)) {
230 if (retries_left_ > 0) { 265 if (retries_left_ > 0) {
266 recorder_->RecordRegisterWithStatus(request_info_.app_id,
267 GCMStatsRecorder::RetryRequested,
268 request_info_.sender_ids,
269 GetStatusString(status));
231 RetryWithBackoff(true); 270 RetryWithBackoff(true);
232 return; 271 return;
233 } 272 }
234 273
235 status = REACHED_MAX_RETRIES; 274 status = REACHED_MAX_RETRIES;
236 RecordRegistrationStatusToUMA(status); 275 RecordRegistrationStatusToUMA(status);
276 recorder_->RecordRegisterWithStatus(request_info_.app_id,
277 GCMStatsRecorder::Failure,
278 request_info_.sender_ids,
279 GetStatusString(status));
280 } else {
281 recorder_->RecordRegister(request_info_.app_id,
282 GCMStatsRecorder::Success,
283 request_info_.sender_ids);
284
237 } 285 }
238 286
239 callback_.Run(status, token); 287 callback_.Run(status, token);
240 } 288 }
241 289
242 } // namespace gcm 290 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698