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

Side by Side Diff: google_apis/gcm/engine/registration_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 most of peter's concerns Created 4 years, 5 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 <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 15 matching lines...) Expand all
26 #include "url/gurl.h" 26 #include "url/gurl.h"
27 27
28 namespace gcm { 28 namespace gcm {
29 29
30 namespace { 30 namespace {
31 31
32 const char kRegistrationRequestContentType[] = 32 const char kRegistrationRequestContentType[] =
33 "application/x-www-form-urlencoded"; 33 "application/x-www-form-urlencoded";
34 34
35 // Request constants. 35 // Request constants.
36 const char kAppIdKey[] = "app"; 36 const char kCategoryKey[] = "app";
37 const char kSubtypeKey[] = "X-subtype";
37 const char kDeviceIdKey[] = "device"; 38 const char kDeviceIdKey[] = "device";
38 const char kLoginHeader[] = "AidLogin"; 39 const char kLoginHeader[] = "AidLogin";
39 40
40 // Response constants. 41 // Response constants.
41 const char kErrorPrefix[] = "Error="; 42 const char kErrorPrefix[] = "Error=";
42 const char kTokenPrefix[] = "token="; 43 const char kTokenPrefix[] = "token=";
43 const char kDeviceRegistrationError[] = "PHONE_REGISTRATION_ERROR"; 44 const char kDeviceRegistrationError[] = "PHONE_REGISTRATION_ERROR";
44 const char kAuthenticationFailed[] = "AUTHENTICATION_FAILED"; 45 const char kAuthenticationFailed[] = "AUTHENTICATION_FAILED";
45 const char kInvalidSender[] = "INVALID_SENDER"; 46 const char kInvalidSender[] = "INVALID_SENDER";
46 const char kInvalidParameters[] = "INVALID_PARAMETERS"; 47 const char kInvalidParameters[] = "INVALID_PARAMETERS";
(...skipping 19 matching lines...) Expand all
66 return status == RegistrationRequest::UNKNOWN_ERROR || 67 return status == RegistrationRequest::UNKNOWN_ERROR ||
67 status == RegistrationRequest::AUTHENTICATION_FAILED || 68 status == RegistrationRequest::AUTHENTICATION_FAILED ||
68 status == RegistrationRequest::DEVICE_REGISTRATION_ERROR || 69 status == RegistrationRequest::DEVICE_REGISTRATION_ERROR ||
69 status == RegistrationRequest::HTTP_NOT_OK || 70 status == RegistrationRequest::HTTP_NOT_OK ||
70 status == RegistrationRequest::URL_FETCHING_FAILED || 71 status == RegistrationRequest::URL_FETCHING_FAILED ||
71 status == RegistrationRequest::RESPONSE_PARSING_FAILED; 72 status == RegistrationRequest::RESPONSE_PARSING_FAILED;
72 } 73 }
73 74
74 } // namespace 75 } // namespace
75 76
76 RegistrationRequest::RequestInfo::RequestInfo(uint64_t android_id, 77 RegistrationRequest::RequestInfo::RequestInfo(
77 uint64_t security_token, 78 uint64_t android_id,
78 const std::string& app_id) 79 uint64_t security_token,
79 : android_id(android_id), security_token(security_token), app_id(app_id) { 80 const std::string& app_id,
81 bool use_subtype,
82 const std::string& category_for_subtypes)
83 : android_id(android_id),
84 security_token(security_token),
85 app_id(app_id),
86 use_subtype(use_subtype),
87 category_for_subtypes(category_for_subtypes) {
80 DCHECK(android_id != 0UL); 88 DCHECK(android_id != 0UL);
81 DCHECK(security_token != 0UL); 89 DCHECK(security_token != 0UL);
82 } 90 }
83 91
84 RegistrationRequest::RequestInfo::~RequestInfo() {} 92 RegistrationRequest::RequestInfo::~RequestInfo() {}
85 93
86 RegistrationRequest::CustomRequestHandler::CustomRequestHandler() {} 94 RegistrationRequest::CustomRequestHandler::CustomRequestHandler() {}
87 95
88 RegistrationRequest::CustomRequestHandler::~CustomRequestHandler() {} 96 RegistrationRequest::CustomRequestHandler::~CustomRequestHandler() {}
89 97
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 net::HttpRequestHeaders headers; 149 net::HttpRequestHeaders headers;
142 headers.SetHeader( 150 headers.SetHeader(
143 net::HttpRequestHeaders::kAuthorization, 151 net::HttpRequestHeaders::kAuthorization,
144 std::string(kLoginHeader) + " " + 152 std::string(kLoginHeader) + " " +
145 base::Uint64ToString(request_info_.android_id) + ":" + 153 base::Uint64ToString(request_info_.android_id) + ":" +
146 base::Uint64ToString(request_info_.security_token)); 154 base::Uint64ToString(request_info_.security_token));
147 *extra_headers = headers.ToString(); 155 *extra_headers = headers.ToString();
148 } 156 }
149 157
150 void RegistrationRequest::BuildRequestBody(std::string* body) { 158 void RegistrationRequest::BuildRequestBody(std::string* body) {
151 BuildFormEncoding(kAppIdKey, request_info_.app_id, body); 159 if (request_info_.use_subtype) {
160 BuildFormEncoding(kCategoryKey, request_info_.category_for_subtypes, body);
161 BuildFormEncoding(kSubtypeKey, request_info_.app_id, body);
162 } else {
163 BuildFormEncoding(kCategoryKey, request_info_.app_id, body);
164 }
165
152 BuildFormEncoding(kDeviceIdKey, 166 BuildFormEncoding(kDeviceIdKey,
153 base::Uint64ToString(request_info_.android_id), 167 base::Uint64ToString(request_info_.android_id),
154 body); 168 body);
155 169
156 DCHECK(custom_request_handler_.get()); 170 DCHECK(custom_request_handler_.get());
157 custom_request_handler_->BuildRequestBody(body); 171 custom_request_handler_->BuildRequestBody(body);
158 } 172 }
159 173
160 void RegistrationRequest::RetryWithBackoff() { 174 void RegistrationRequest::RetryWithBackoff() {
161 DCHECK_GT(retries_left_, 0); 175 DCHECK_GT(retries_left_, 0);
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // Only REACHED_MAX_RETRIES is reported because the function will skip 263 // Only REACHED_MAX_RETRIES is reported because the function will skip
250 // reporting count and time when status is not SUCCESS. 264 // reporting count and time when status is not SUCCESS.
251 DCHECK(custom_request_handler_.get()); 265 DCHECK(custom_request_handler_.get());
252 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta()); 266 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta());
253 } 267 }
254 268
255 callback_.Run(status, token); 269 callback_.Run(status, token);
256 } 270 }
257 271
258 } // namespace gcm 272 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698