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

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

Issue 2111973002: Add support for GCM subtypes to desktop Instance ID implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid9push
Patch Set: Address jianli's review comments Created 4 years, 4 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/unregistration_request.h" 5 #include "google_apis/gcm/engine/unregistration_request.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 11 matching lines...) Expand all
22 #include "net/url_request/url_request_context_getter.h" 22 #include "net/url_request/url_request_context_getter.h"
23 #include "net/url_request/url_request_status.h" 23 #include "net/url_request/url_request_status.h"
24 24
25 namespace gcm { 25 namespace gcm {
26 26
27 namespace { 27 namespace {
28 28
29 const char kRequestContentType[] = "application/x-www-form-urlencoded"; 29 const char kRequestContentType[] = "application/x-www-form-urlencoded";
30 30
31 // Request constants. 31 // Request constants.
32 const char kAppIdKey[] = "app"; 32 const char kCategoryKey[] = "app";
33 const char kSubtypeKey[] = "X-subtype";
33 const char kDeleteKey[] = "delete"; 34 const char kDeleteKey[] = "delete";
34 const char kDeleteValue[] = "true"; 35 const char kDeleteValue[] = "true";
35 const char kDeviceIdKey[] = "device"; 36 const char kDeviceIdKey[] = "device";
36 const char kLoginHeader[] = "AidLogin"; 37 const char kLoginHeader[] = "AidLogin";
37 38
38 } // namespace 39 } // namespace
39 40
40 UnregistrationRequest::RequestInfo::RequestInfo(uint64_t android_id, 41 UnregistrationRequest::RequestInfo::RequestInfo(uint64_t android_id,
41 uint64_t security_token, 42 uint64_t security_token,
42 const std::string& app_id) 43 const std::string& category,
43 : android_id(android_id), security_token(security_token), app_id(app_id) { 44 const std::string& subtype)
45 : android_id(android_id),
46 security_token(security_token),
47 category(category),
48 subtype(subtype) {
44 DCHECK(android_id != 0UL); 49 DCHECK(android_id != 0UL);
45 DCHECK(security_token != 0UL); 50 DCHECK(security_token != 0UL);
51 DCHECK(!category.empty());
46 } 52 }
47 53
48 UnregistrationRequest::RequestInfo::~RequestInfo() {} 54 UnregistrationRequest::RequestInfo::~RequestInfo() {}
49 55
50 UnregistrationRequest::CustomRequestHandler::CustomRequestHandler() {} 56 UnregistrationRequest::CustomRequestHandler::CustomRequestHandler() {}
51 57
52 UnregistrationRequest::CustomRequestHandler::~CustomRequestHandler() {} 58 UnregistrationRequest::CustomRequestHandler::~CustomRequestHandler() {}
53 59
54 UnregistrationRequest::UnregistrationRequest( 60 UnregistrationRequest::UnregistrationRequest(
55 const GURL& registration_url, 61 const GURL& registration_url,
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 std::string extra_headers; 95 std::string extra_headers;
90 BuildRequestHeaders(&extra_headers); 96 BuildRequestHeaders(&extra_headers);
91 url_fetcher_->SetExtraRequestHeaders(extra_headers); 97 url_fetcher_->SetExtraRequestHeaders(extra_headers);
92 98
93 std::string body; 99 std::string body;
94 BuildRequestBody(&body); 100 BuildRequestBody(&body);
95 101
96 DVLOG(1) << "Unregistration request: " << body; 102 DVLOG(1) << "Unregistration request: " << body;
97 url_fetcher_->SetUploadData(kRequestContentType, body); 103 url_fetcher_->SetUploadData(kRequestContentType, body);
98 104
99 DVLOG(1) << "Performing unregistration for: " << request_info_.app_id; 105 DVLOG(1) << "Performing unregistration for: " << request_info_.app_id();
100 recorder_->RecordUnregistrationSent(request_info_.app_id, source_to_record_); 106 recorder_->RecordUnregistrationSent(request_info_.app_id(),
107 source_to_record_);
101 request_start_time_ = base::TimeTicks::Now(); 108 request_start_time_ = base::TimeTicks::Now();
102 url_fetcher_->Start(); 109 url_fetcher_->Start();
103 } 110 }
104 111
105 void UnregistrationRequest::BuildRequestHeaders(std::string* extra_headers) { 112 void UnregistrationRequest::BuildRequestHeaders(std::string* extra_headers) {
106 net::HttpRequestHeaders headers; 113 net::HttpRequestHeaders headers;
107 headers.SetHeader( 114 headers.SetHeader(
108 net::HttpRequestHeaders::kAuthorization, 115 net::HttpRequestHeaders::kAuthorization,
109 std::string(kLoginHeader) + " " + 116 std::string(kLoginHeader) + " " +
110 base::Uint64ToString(request_info_.android_id) + ":" + 117 base::Uint64ToString(request_info_.android_id) + ":" +
111 base::Uint64ToString(request_info_.security_token)); 118 base::Uint64ToString(request_info_.security_token));
112 headers.SetHeader(kAppIdKey, request_info_.app_id);
113 *extra_headers = headers.ToString(); 119 *extra_headers = headers.ToString();
114 } 120 }
115 121
116 void UnregistrationRequest::BuildRequestBody(std::string* body) { 122 void UnregistrationRequest::BuildRequestBody(std::string* body) {
117 BuildFormEncoding(kAppIdKey, request_info_.app_id, body); 123 BuildFormEncoding(kCategoryKey, request_info_.category, body);
Nicolas Zea 2016/08/17 20:54:09 if/else here too?
johnme 2016/08/18 17:43:22 As above, |subtype| is an additional field that is
124 if (!request_info_.subtype.empty())
125 BuildFormEncoding(kSubtypeKey, request_info_.subtype, body);
126
118 BuildFormEncoding(kDeviceIdKey, 127 BuildFormEncoding(kDeviceIdKey,
119 base::Uint64ToString(request_info_.android_id), 128 base::Uint64ToString(request_info_.android_id),
120 body); 129 body);
121 BuildFormEncoding(kDeleteKey, kDeleteValue, body); 130 BuildFormEncoding(kDeleteKey, kDeleteValue, body);
122 131
123 DCHECK(custom_request_handler_.get()); 132 DCHECK(custom_request_handler_.get());
124 custom_request_handler_->BuildRequestBody(body); 133 custom_request_handler_->BuildRequestBody(body);
125 } 134 }
126 135
127 UnregistrationRequest::Status UnregistrationRequest::ParseResponse( 136 UnregistrationRequest::Status UnregistrationRequest::ParseResponse(
(...skipping 17 matching lines...) Expand all
145 DCHECK(custom_request_handler_.get()); 154 DCHECK(custom_request_handler_.get());
146 return custom_request_handler_->ParseResponse(source); 155 return custom_request_handler_->ParseResponse(source);
147 } 156 }
148 157
149 void UnregistrationRequest::RetryWithBackoff() { 158 void UnregistrationRequest::RetryWithBackoff() {
150 DCHECK_GT(retries_left_, 0); 159 DCHECK_GT(retries_left_, 0);
151 --retries_left_; 160 --retries_left_;
152 url_fetcher_.reset(); 161 url_fetcher_.reset();
153 backoff_entry_.InformOfRequest(false); 162 backoff_entry_.InformOfRequest(false);
154 163
155 DVLOG(1) << "Delaying GCM unregistration of app: " 164 DVLOG(1) << "Delaying GCM unregistration of app: " << request_info_.app_id()
156 << request_info_.app_id << ", for " 165 << ", for " << backoff_entry_.GetTimeUntilRelease().InMilliseconds()
157 << backoff_entry_.GetTimeUntilRelease().InMilliseconds()
158 << " milliseconds."; 166 << " milliseconds.";
159 recorder_->RecordUnregistrationRetryDelayed( 167 recorder_->RecordUnregistrationRetryDelayed(
160 request_info_.app_id, 168 request_info_.app_id(), source_to_record_,
161 source_to_record_, 169 backoff_entry_.GetTimeUntilRelease().InMilliseconds(), retries_left_ + 1);
162 backoff_entry_.GetTimeUntilRelease().InMilliseconds(),
163 retries_left_ + 1);
164 DCHECK(!weak_ptr_factory_.HasWeakPtrs()); 170 DCHECK(!weak_ptr_factory_.HasWeakPtrs());
165 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 171 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
166 FROM_HERE, 172 FROM_HERE,
167 base::Bind(&UnregistrationRequest::Start, weak_ptr_factory_.GetWeakPtr()), 173 base::Bind(&UnregistrationRequest::Start, weak_ptr_factory_.GetWeakPtr()),
168 backoff_entry_.GetTimeUntilRelease()); 174 backoff_entry_.GetTimeUntilRelease());
169 } 175 }
170 176
171 void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) { 177 void UnregistrationRequest::OnURLFetchComplete(const net::URLFetcher* source) {
172 UnregistrationRequest::Status status = ParseResponse(source); 178 UnregistrationRequest::Status status = ParseResponse(source);
173 179
174 DVLOG(1) << "UnregistrationRequestStauts: " << status; 180 DVLOG(1) << "UnregistrationRequestStauts: " << status;
175 181
176 DCHECK(custom_request_handler_.get()); 182 DCHECK(custom_request_handler_.get());
177 custom_request_handler_->ReportUMAs( 183 custom_request_handler_->ReportUMAs(
178 status, 184 status,
179 backoff_entry_.failure_count(), 185 backoff_entry_.failure_count(),
180 base::TimeTicks::Now() - request_start_time_); 186 base::TimeTicks::Now() - request_start_time_);
181 187
182 recorder_->RecordUnregistrationResponse( 188 recorder_->RecordUnregistrationResponse(request_info_.app_id(),
183 request_info_.app_id, source_to_record_, status); 189 source_to_record_, status);
184 190
185 if (status == URL_FETCHING_FAILED || 191 if (status == URL_FETCHING_FAILED ||
186 status == HTTP_NOT_OK || 192 status == HTTP_NOT_OK ||
187 status == NO_RESPONSE_BODY || 193 status == NO_RESPONSE_BODY ||
188 status == SERVICE_UNAVAILABLE || 194 status == SERVICE_UNAVAILABLE ||
189 status == INTERNAL_SERVER_ERROR || 195 status == INTERNAL_SERVER_ERROR ||
190 status == INCORRECT_APP_ID || 196 status == INCORRECT_APP_ID ||
191 status == RESPONSE_PARSING_FAILED) { 197 status == RESPONSE_PARSING_FAILED) {
192 if (retries_left_ > 0) { 198 if (retries_left_ > 0) {
193 RetryWithBackoff(); 199 RetryWithBackoff();
194 return; 200 return;
195 } 201 }
196 202
197 status = REACHED_MAX_RETRIES; 203 status = REACHED_MAX_RETRIES;
198 recorder_->RecordUnregistrationResponse( 204 recorder_->RecordUnregistrationResponse(request_info_.app_id(),
199 request_info_.app_id, source_to_record_, status); 205 source_to_record_, status);
200 206
201 // Only REACHED_MAX_RETRIES is reported because the function will skip 207 // Only REACHED_MAX_RETRIES is reported because the function will skip
202 // reporting count and time when status is not SUCCESS. 208 // reporting count and time when status is not SUCCESS.
203 DCHECK(custom_request_handler_.get()); 209 DCHECK(custom_request_handler_.get());
204 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta()); 210 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta());
205 } 211 }
206 212
207 // status == SUCCESS || INVALID_PARAMETERS || UNKNOWN_ERROR || 213 // status == SUCCESS || INVALID_PARAMETERS || UNKNOWN_ERROR ||
208 // REACHED_MAX_RETRIES 214 // REACHED_MAX_RETRIES
209 215
210 callback_.Run(status); 216 callback_.Run(status);
211 } 217 }
212 218
213 } // namespace gcm 219 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698