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

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

Issue 158023007: Add GCM check in status code metric collection. We also decided to collect registration success sig… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | google_apis/gcm/engine/registration_request.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 "google_apis/gcm/protocol/checkin.pb.h" 10 #include "google_apis/gcm/protocol/checkin.pb.h"
10 #include "net/http/http_status_code.h" 11 #include "net/http/http_status_code.h"
11 #include "net/url_request/url_fetcher.h" 12 #include "net/url_request/url_fetcher.h"
12 #include "net/url_request/url_request_status.h" 13 #include "net/url_request/url_request_status.h"
13 #include "url/gurl.h" 14 #include "url/gurl.h"
14 15
15 namespace gcm { 16 namespace gcm {
16 17
17 namespace { 18 namespace {
18 const char kCheckinURL[] = "https://android.clients.google.com/checkin"; 19 const char kCheckinURL[] = "https://android.clients.google.com/checkin";
19 const char kRequestContentType[] = "application/x-protobuf"; 20 const char kRequestContentType[] = "application/x-protobuf";
20 const int kRequestVersionValue = 2; 21 const int kRequestVersionValue = 2;
22
23 // This enum is also used in an UMA histogram (GCMRegistrationRequestStatus
24 // enum defined in tools/metrics/histograms/histogram.xml). Hence the entries
25 // here shouldn't be deleted or re-ordered and new ones should be added to
26 // the end.
27 enum CheckinRequestStatus {
28 SUCCESS, // Checkin completed successfully.
29 URL_FETCHING_FAILED, // URL fetching failed.
30 HTTP_BAD_REQUEST, // The request was malformed.
31 HTTP_UNAUTHORIZED, // The security token didn't match the android id.
32 HTTP_NOT_OK, // HTTP status was not OK.
33 FAILED_PARSING_RESPONSE, // Failed to parse the checkin response.
34 ZERO_ID_OR_TOKEN, // Either returned android id or security token
35 // was zero.
36 // NOTE: always keep this entry at the end. Add new status types only
37 // immediately above this line. Make sure to update the corresponding
38 // histogram enum accordingly.
39 STATUS_COUNT
40 };
41
21 } // namespace 42 } // namespace
22 43
23 CheckinRequest::CheckinRequest( 44 CheckinRequest::CheckinRequest(
24 const CheckinRequestCallback& callback, 45 const CheckinRequestCallback& callback,
25 const net::BackoffEntry::Policy& backoff_policy, 46 const net::BackoffEntry::Policy& backoff_policy,
26 const checkin_proto::ChromeBuildProto& chrome_build_proto, 47 const checkin_proto::ChromeBuildProto& chrome_build_proto,
27 int64 user_serial_number, 48 int64 user_serial_number,
28 uint64 android_id, 49 uint64 android_id,
29 uint64 security_token, 50 uint64 security_token,
30 net::URLRequestContextGetter* request_context_getter) 51 net::URLRequestContextGetter* request_context_getter)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 108 }
88 109
89 Start(); 110 Start();
90 } 111 }
91 112
92 void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) { 113 void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) {
93 std::string response_string; 114 std::string response_string;
94 checkin_proto::AndroidCheckinResponse response_proto; 115 checkin_proto::AndroidCheckinResponse response_proto;
95 if (!source->GetStatus().is_success()) { 116 if (!source->GetStatus().is_success()) {
96 LOG(ERROR) << "Failed to get checkin response. Fetcher failed. Retrying."; 117 LOG(ERROR) << "Failed to get checkin response. Fetcher failed. Retrying.";
118 UMA_HISTOGRAM_ENUMERATION("GCM.CheckinRequestStatus",
Alexei Svitkine (slow) 2014/02/12 17:49:05 Nit: Instead of repeating this histogram macro in
juyik 2014/02/12 18:15:41 Done.
119 URL_FETCHING_FAILED,
120 STATUS_COUNT);
97 RetryWithBackoff(true); 121 RetryWithBackoff(true);
98 return; 122 return;
99 } 123 }
100 124
101 net::HttpStatusCode response_status = static_cast<net::HttpStatusCode>( 125 net::HttpStatusCode response_status = static_cast<net::HttpStatusCode>(
102 source->GetResponseCode()); 126 source->GetResponseCode());
103 if (response_status == net::HTTP_BAD_REQUEST || 127 if (response_status == net::HTTP_BAD_REQUEST ||
104 response_status == net::HTTP_UNAUTHORIZED) { 128 response_status == net::HTTP_UNAUTHORIZED) {
105 // BAD_REQUEST indicates that the request was malformed. 129 // BAD_REQUEST indicates that the request was malformed.
106 // UNAUTHORIZED indicates that security token didn't match the android id. 130 // UNAUTHORIZED indicates that security token didn't match the android id.
107 LOG(ERROR) << "No point retrying the checkin with status: " 131 LOG(ERROR) << "No point retrying the checkin with status: "
108 << response_status << ". Checkin failed."; 132 << response_status << ". Checkin failed.";
133 if (response_status == net::HTTP_BAD_REQUEST) {
134 UMA_HISTOGRAM_ENUMERATION("GCM.CheckinRequestStatus",
135 HTTP_BAD_REQUEST,
136 STATUS_COUNT);
137 } else {
138 UMA_HISTOGRAM_ENUMERATION("GCM.CheckinRequestStatus",
139 HTTP_UNAUTHORIZED,
140 STATUS_COUNT);
141 }
109 callback_.Run(0,0); 142 callback_.Run(0,0);
110 return; 143 return;
111 } 144 }
112 145
113 if (response_status != net::HTTP_OK || 146 if (response_status != net::HTTP_OK ||
114 !source->GetResponseAsString(&response_string) || 147 !source->GetResponseAsString(&response_string) ||
115 !response_proto.ParseFromString(response_string)) { 148 !response_proto.ParseFromString(response_string)) {
116 LOG(ERROR) << "Failed to get checkin response. HTTP Status: " 149 LOG(ERROR) << "Failed to get checkin response. HTTP Status: "
117 << response_status << ". Retrying."; 150 << response_status << ". Retrying.";
151 if (response_status != net::HTTP_OK) {
152 UMA_HISTOGRAM_ENUMERATION("GCM.CheckinRequestStatus",
153 HTTP_NOT_OK,
154 STATUS_COUNT);
155 } else {
156 UMA_HISTOGRAM_ENUMERATION("GCM.CheckinRequestStatus",
157 FAILED_PARSING_RESPONSE,
158 STATUS_COUNT);
159 }
118 RetryWithBackoff(true); 160 RetryWithBackoff(true);
119 return; 161 return;
120 } 162 }
121 163
122 if (!response_proto.has_android_id() || 164 if (!response_proto.has_android_id() ||
123 !response_proto.has_security_token() || 165 !response_proto.has_security_token() ||
124 response_proto.android_id() == 0 || 166 response_proto.android_id() == 0 ||
125 response_proto.security_token() == 0) { 167 response_proto.security_token() == 0) {
126 LOG(ERROR) << "Android ID or security token is 0. Retrying."; 168 LOG(ERROR) << "Android ID or security token is 0. Retrying.";
169 UMA_HISTOGRAM_ENUMERATION("GCM.CheckinRequestStatus",
170 ZERO_ID_OR_TOKEN,
171 STATUS_COUNT);
127 RetryWithBackoff(true); 172 RetryWithBackoff(true);
128 return; 173 return;
129 } 174 }
130 175
176 UMA_HISTOGRAM_ENUMERATION("GCM.CheckinRequestStatus", SUCCESS, STATUS_COUNT);
131 callback_.Run(response_proto.android_id(), response_proto.security_token()); 177 callback_.Run(response_proto.android_id(), response_proto.security_token());
132 } 178 }
133 179
134 } // namespace gcm 180 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/registration_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698