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/unregistration_request.h" | 5 #include "google_apis/gcm/engine/unregistration_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/strings/string_piece.h" | 11 #include "base/strings/string_piece.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "google_apis/gcm/monitoring/gcm_stats_recorder.h" |
13 #include "net/base/escape.h" | 14 #include "net/base/escape.h" |
14 #include "net/http/http_request_headers.h" | 15 #include "net/http/http_request_headers.h" |
15 #include "net/http/http_status_code.h" | 16 #include "net/http/http_status_code.h" |
16 #include "net/url_request/url_fetcher.h" | 17 #include "net/url_request/url_fetcher.h" |
17 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
18 #include "net/url_request/url_request_status.h" | 19 #include "net/url_request/url_request_status.h" |
19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
20 | 21 |
21 namespace gcm { | 22 namespace gcm { |
22 | 23 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 security_token(security_token), | 109 security_token(security_token), |
109 app_id(app_id) { | 110 app_id(app_id) { |
110 } | 111 } |
111 | 112 |
112 UnregistrationRequest::RequestInfo::~RequestInfo() {} | 113 UnregistrationRequest::RequestInfo::~RequestInfo() {} |
113 | 114 |
114 UnregistrationRequest::UnregistrationRequest( | 115 UnregistrationRequest::UnregistrationRequest( |
115 const RequestInfo& request_info, | 116 const RequestInfo& request_info, |
116 const net::BackoffEntry::Policy& backoff_policy, | 117 const net::BackoffEntry::Policy& backoff_policy, |
117 const UnregistrationCallback& callback, | 118 const UnregistrationCallback& callback, |
118 scoped_refptr<net::URLRequestContextGetter> request_context_getter) | 119 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 120 GCMStatsRecorder* recorder) |
119 : callback_(callback), | 121 : callback_(callback), |
120 request_info_(request_info), | 122 request_info_(request_info), |
121 backoff_entry_(&backoff_policy), | 123 backoff_entry_(&backoff_policy), |
122 request_context_getter_(request_context_getter), | 124 request_context_getter_(request_context_getter), |
| 125 recorder_(recorder), |
123 weak_ptr_factory_(this) { | 126 weak_ptr_factory_(this) { |
124 } | 127 } |
125 | 128 |
126 UnregistrationRequest::~UnregistrationRequest() {} | 129 UnregistrationRequest::~UnregistrationRequest() {} |
127 | 130 |
128 void UnregistrationRequest::Start() { | 131 void UnregistrationRequest::Start() { |
129 DCHECK(!callback_.is_null()); | 132 DCHECK(!callback_.is_null()); |
130 DCHECK(request_info_.android_id != 0UL); | 133 DCHECK(request_info_.android_id != 0UL); |
131 DCHECK(request_info_.security_token != 0UL); | 134 DCHECK(request_info_.security_token != 0UL); |
132 DCHECK(!url_fetcher_.get()); | 135 DCHECK(!url_fetcher_.get()); |
(...skipping 16 matching lines...) Expand all Loading... |
149 BuildFormEncoding(kDeviceIdKey, android_id, &body); | 152 BuildFormEncoding(kDeviceIdKey, android_id, &body); |
150 BuildFormEncoding(kDeleteKey, kDeleteValue, &body); | 153 BuildFormEncoding(kDeleteKey, kDeleteValue, &body); |
151 BuildFormEncoding(kUnregistrationCallerKey, | 154 BuildFormEncoding(kUnregistrationCallerKey, |
152 kUnregistrationCallerValue, | 155 kUnregistrationCallerValue, |
153 &body); | 156 &body); |
154 | 157 |
155 DVLOG(1) << "Unregistration request: " << body; | 158 DVLOG(1) << "Unregistration request: " << body; |
156 url_fetcher_->SetUploadData(kRequestContentType, body); | 159 url_fetcher_->SetUploadData(kRequestContentType, body); |
157 | 160 |
158 DVLOG(1) << "Performing unregistration for: " << request_info_.app_id; | 161 DVLOG(1) << "Performing unregistration for: " << request_info_.app_id; |
| 162 recorder_->RecordUnregistrationSent(request_info_.app_id); |
159 url_fetcher_->Start(); | 163 url_fetcher_->Start(); |
160 } | 164 } |
161 | 165 |
162 void UnregistrationRequest::RetryWithBackoff(bool update_backoff) { | 166 void UnregistrationRequest::RetryWithBackoff(bool update_backoff) { |
163 if (update_backoff) { | 167 if (update_backoff) { |
164 url_fetcher_.reset(); | 168 url_fetcher_.reset(); |
165 backoff_entry_.InformOfRequest(false); | 169 backoff_entry_.InformOfRequest(false); |
166 } | 170 } |
167 | 171 |
168 if (backoff_entry_.ShouldRejectRequest()) { | 172 if (backoff_entry_.ShouldRejectRequest()) { |
169 DVLOG(1) << "Delaying GCM unregistration of app: " | 173 DVLOG(1) << "Delaying GCM unregistration of app: " |
170 << request_info_.app_id << ", for " | 174 << request_info_.app_id << ", for " |
171 << backoff_entry_.GetTimeUntilRelease().InMilliseconds() | 175 << backoff_entry_.GetTimeUntilRelease().InMilliseconds() |
172 << " milliseconds."; | 176 << " milliseconds."; |
| 177 recorder_->RecordUnregistrationRetryDelayed( |
| 178 request_info_.app_id, |
| 179 backoff_entry_.GetTimeUntilRelease().InMilliseconds()); |
173 base::MessageLoop::current()->PostDelayedTask( | 180 base::MessageLoop::current()->PostDelayedTask( |
174 FROM_HERE, | 181 FROM_HERE, |
175 base::Bind(&UnregistrationRequest::RetryWithBackoff, | 182 base::Bind(&UnregistrationRequest::RetryWithBackoff, |
176 weak_ptr_factory_.GetWeakPtr(), | 183 weak_ptr_factory_.GetWeakPtr(), |
177 false), | 184 false), |
178 backoff_entry_.GetTimeUntilRelease()); | 185 backoff_entry_.GetTimeUntilRelease()); |
179 return; | 186 return; |
180 } | 187 } |
181 | 188 |
182 Start(); | 189 Start(); |
183 } | 190 } |
184 | 191 |
185 void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { | 192 void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { |
186 UnregistrationRequest::Status status = | 193 UnregistrationRequest::Status status = |
187 ParseFetcherResponse(source, request_info_.app_id); | 194 ParseFetcherResponse(source, request_info_.app_id); |
188 | 195 |
189 DVLOG(1) << "UnregistrationRequestStauts: " << status; | 196 DVLOG(1) << "UnregistrationRequestStauts: " << status; |
190 UMA_HISTOGRAM_ENUMERATION("GCM.UnregistrationRequestStatus", | 197 UMA_HISTOGRAM_ENUMERATION("GCM.UnregistrationRequestStatus", |
191 status, | 198 status, |
192 UNREGISTRATION_STATUS_COUNT); | 199 UNREGISTRATION_STATUS_COUNT); |
| 200 recorder_->RecordUnregistrationResponse(request_info_.app_id, status); |
193 | 201 |
194 if (status == URL_FETCHING_FAILED || | 202 if (status == URL_FETCHING_FAILED || |
195 status == SERVICE_UNAVAILABLE || | 203 status == SERVICE_UNAVAILABLE || |
196 status == INTERNAL_SERVER_ERROR || | 204 status == INTERNAL_SERVER_ERROR || |
197 status == INCORRECT_APP_ID || | 205 status == INCORRECT_APP_ID || |
198 status == RESPONSE_PARSING_FAILED) { | 206 status == RESPONSE_PARSING_FAILED) { |
199 RetryWithBackoff(true); | 207 RetryWithBackoff(true); |
200 } else { | 208 } else { |
201 // status == SUCCESS || HTTP_NOT_OK || NO_RESPONSE_BODY || | 209 // status == SUCCESS || HTTP_NOT_OK || NO_RESPONSE_BODY || |
202 // INVALID_PARAMETERS || UNKNOWN_ERROR | 210 // INVALID_PARAMETERS || UNKNOWN_ERROR |
203 callback_.Run(status); | 211 callback_.Run(status); |
204 } | 212 } |
205 } | 213 } |
206 | 214 |
207 } // namespace gcm | 215 } // namespace gcm |
OLD | NEW |