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

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
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 (GCMCheckinRequestStatus
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 RESPONSE_PARSING_FAILED, // Check in response parsing failed.
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
42 void RecordCheckinStatusToUMA(CheckinRequestStatus status) {
43 UMA_HISTOGRAM_ENUMERATION("GCM.CheckinRequestStatus", status, STATUS_COUNT);
44 }
45
21 } // namespace 46 } // namespace
22 47
23 CheckinRequest::CheckinRequest( 48 CheckinRequest::CheckinRequest(
24 const CheckinRequestCallback& callback, 49 const CheckinRequestCallback& callback,
25 const net::BackoffEntry::Policy& backoff_policy, 50 const net::BackoffEntry::Policy& backoff_policy,
26 const checkin_proto::ChromeBuildProto& chrome_build_proto, 51 const checkin_proto::ChromeBuildProto& chrome_build_proto,
27 int64 user_serial_number, 52 int64 user_serial_number,
28 uint64 android_id, 53 uint64 android_id,
29 uint64 security_token, 54 uint64 security_token,
30 net::URLRequestContextGetter* request_context_getter) 55 net::URLRequestContextGetter* request_context_getter)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 } 112 }
88 113
89 Start(); 114 Start();
90 } 115 }
91 116
92 void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) { 117 void CheckinRequest::OnURLFetchComplete(const net::URLFetcher* source) {
93 std::string response_string; 118 std::string response_string;
94 checkin_proto::AndroidCheckinResponse response_proto; 119 checkin_proto::AndroidCheckinResponse response_proto;
95 if (!source->GetStatus().is_success()) { 120 if (!source->GetStatus().is_success()) {
96 LOG(ERROR) << "Failed to get checkin response. Fetcher failed. Retrying."; 121 LOG(ERROR) << "Failed to get checkin response. Fetcher failed. Retrying.";
122 RecordCheckinStatusToUMA(URL_FETCHING_FAILED);
97 RetryWithBackoff(true); 123 RetryWithBackoff(true);
98 return; 124 return;
99 } 125 }
100 126
101 net::HttpStatusCode response_status = static_cast<net::HttpStatusCode>( 127 net::HttpStatusCode response_status = static_cast<net::HttpStatusCode>(
102 source->GetResponseCode()); 128 source->GetResponseCode());
103 if (response_status == net::HTTP_BAD_REQUEST || 129 if (response_status == net::HTTP_BAD_REQUEST ||
104 response_status == net::HTTP_UNAUTHORIZED) { 130 response_status == net::HTTP_UNAUTHORIZED) {
105 // BAD_REQUEST indicates that the request was malformed. 131 // BAD_REQUEST indicates that the request was malformed.
106 // UNAUTHORIZED indicates that security token didn't match the android id. 132 // UNAUTHORIZED indicates that security token didn't match the android id.
107 LOG(ERROR) << "No point retrying the checkin with status: " 133 LOG(ERROR) << "No point retrying the checkin with status: "
108 << response_status << ". Checkin failed."; 134 << response_status << ". Checkin failed.";
135 if (response_status == net::HTTP_BAD_REQUEST) {
136 RecordCheckinStatusToUMA(HTTP_BAD_REQUEST);
137 } else {
jianli 2014/02/12 18:41:05 nit: bracket is not needed for single line if/else
juyik 2014/02/12 18:55:20 Done.
138 RecordCheckinStatusToUMA(HTTP_UNAUTHORIZED);
139 }
109 callback_.Run(0,0); 140 callback_.Run(0,0);
110 return; 141 return;
111 } 142 }
112 143
113 if (response_status != net::HTTP_OK || 144 if (response_status != net::HTTP_OK ||
114 !source->GetResponseAsString(&response_string) || 145 !source->GetResponseAsString(&response_string) ||
115 !response_proto.ParseFromString(response_string)) { 146 !response_proto.ParseFromString(response_string)) {
116 LOG(ERROR) << "Failed to get checkin response. HTTP Status: " 147 LOG(ERROR) << "Failed to get checkin response. HTTP Status: "
117 << response_status << ". Retrying."; 148 << response_status << ". Retrying.";
149 if (response_status != net::HTTP_OK) {
150 RecordCheckinStatusToUMA(HTTP_NOT_OK);
151 } else {
jianli 2014/02/12 18:41:05 ditto
juyik 2014/02/12 18:55:20 Done.
152 RecordCheckinStatusToUMA(RESPONSE_PARSING_FAILED);
153 }
118 RetryWithBackoff(true); 154 RetryWithBackoff(true);
119 return; 155 return;
120 } 156 }
121 157
122 if (!response_proto.has_android_id() || 158 if (!response_proto.has_android_id() ||
123 !response_proto.has_security_token() || 159 !response_proto.has_security_token() ||
124 response_proto.android_id() == 0 || 160 response_proto.android_id() == 0 ||
125 response_proto.security_token() == 0) { 161 response_proto.security_token() == 0) {
126 LOG(ERROR) << "Android ID or security token is 0. Retrying."; 162 LOG(ERROR) << "Android ID or security token is 0. Retrying.";
163 RecordCheckinStatusToUMA(ZERO_ID_OR_TOKEN);
127 RetryWithBackoff(true); 164 RetryWithBackoff(true);
128 return; 165 return;
129 } 166 }
130 167
168 RecordCheckinStatusToUMA(SUCCESS);
131 callback_.Run(response_proto.android_id(), response_proto.security_token()); 169 callback_.Run(response_proto.android_id(), response_proto.security_token());
132 } 170 }
133 171
134 } // namespace gcm 172 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/registration_request.cc » ('j') | google_apis/gcm/engine/registration_request.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698