OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "google_apis/gcm/engine/instance_id_get_token_request_handler.h" |
| 6 |
| 7 #include "base/strings/string_number_conversions.h" |
| 8 #include "google_apis/gcm/base/gcm_util.h" |
| 9 #include "net/url_request/url_request_context_getter.h" |
| 10 |
| 11 namespace gcm { |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Request constants. |
| 16 const char kAuthorizedEntityKey[] = "sender"; |
| 17 const char kGMSVersionKey[] = "gmsv"; |
| 18 const char kInstanceIDKey[] = "appid"; |
| 19 const char kScopeKey[] = "scope"; |
| 20 // Prefix that needs to be added for each option key. |
| 21 const char kOptionKeyPrefix[] = "X-"; |
| 22 |
| 23 } // namespace |
| 24 |
| 25 InstanceIDGetTokenRequestHandler::InstanceIDGetTokenRequestHandler( |
| 26 const std::string& instance_id, |
| 27 const std::string& authorized_entity, |
| 28 const std::string& scope, |
| 29 int gcm_version, |
| 30 const std::map<std::string, std::string>& options) |
| 31 : instance_id_(instance_id), |
| 32 authorized_entity_(authorized_entity), |
| 33 scope_(scope), |
| 34 gcm_version_(gcm_version), |
| 35 options_(options) { |
| 36 DCHECK(!instance_id.empty()); |
| 37 DCHECK(!authorized_entity.empty()); |
| 38 DCHECK(!scope.empty()); |
| 39 } |
| 40 |
| 41 InstanceIDGetTokenRequestHandler::~InstanceIDGetTokenRequestHandler() {} |
| 42 |
| 43 void InstanceIDGetTokenRequestHandler::BuildRequestBody(std::string* body){ |
| 44 BuildFormEncoding(kScopeKey, scope_, body); |
| 45 for (auto iter = options_.begin(); iter != options_.end(); ++iter) |
| 46 BuildFormEncoding(kOptionKeyPrefix + iter->first, iter->second, body); |
| 47 BuildFormEncoding(kGMSVersionKey, base::IntToString(gcm_version_), body); |
| 48 BuildFormEncoding(kInstanceIDKey, instance_id_, body); |
| 49 BuildFormEncoding(kAuthorizedEntityKey, authorized_entity_, body); |
| 50 } |
| 51 |
| 52 } // namespace gcm |
OLD | NEW |