| 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/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 Loading... |
| 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 Loading... |
| 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& product_category_for_subtypes) |
| 83 : android_id(android_id), |
| 84 security_token(security_token), |
| 85 app_id(app_id), |
| 86 use_subtype(use_subtype), |
| 87 product_category_for_subtypes(product_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 Loading... |
| 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_.product_category_for_subtypes, |
| 161 body); |
| 162 BuildFormEncoding(kSubtypeKey, request_info_.app_id, body); |
| 163 } else { |
| 164 BuildFormEncoding(kCategoryKey, request_info_.app_id, body); |
| 165 } |
| 166 |
| 152 BuildFormEncoding(kDeviceIdKey, | 167 BuildFormEncoding(kDeviceIdKey, |
| 153 base::Uint64ToString(request_info_.android_id), | 168 base::Uint64ToString(request_info_.android_id), |
| 154 body); | 169 body); |
| 155 | 170 |
| 156 DCHECK(custom_request_handler_.get()); | 171 DCHECK(custom_request_handler_.get()); |
| 157 custom_request_handler_->BuildRequestBody(body); | 172 custom_request_handler_->BuildRequestBody(body); |
| 158 } | 173 } |
| 159 | 174 |
| 160 void RegistrationRequest::RetryWithBackoff() { | 175 void RegistrationRequest::RetryWithBackoff() { |
| 161 DCHECK_GT(retries_left_, 0); | 176 DCHECK_GT(retries_left_, 0); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // Only REACHED_MAX_RETRIES is reported because the function will skip | 264 // Only REACHED_MAX_RETRIES is reported because the function will skip |
| 250 // reporting count and time when status is not SUCCESS. | 265 // reporting count and time when status is not SUCCESS. |
| 251 DCHECK(custom_request_handler_.get()); | 266 DCHECK(custom_request_handler_.get()); |
| 252 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta()); | 267 custom_request_handler_->ReportUMAs(status, 0, base::TimeDelta()); |
| 253 } | 268 } |
| 254 | 269 |
| 255 callback_.Run(status, token); | 270 callback_.Run(status, token); |
| 256 } | 271 } |
| 257 | 272 |
| 258 } // namespace gcm | 273 } // namespace gcm |
| OLD | NEW |