Chromium Code Reviews| 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.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 InstanceIDGetTokenRequest::ExtraRequestInfo::ExtraRequestInfo( | |
| 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 } | |
| 37 | |
| 38 InstanceIDGetTokenRequest::ExtraRequestInfo::~ExtraRequestInfo() {} | |
| 39 | |
| 40 InstanceIDGetTokenRequest::InstanceIDGetTokenRequest( | |
| 41 const GURL& registration_url, | |
| 42 const RequestInfo& request_info, | |
| 43 const ExtraRequestInfo& extra_request_info, | |
| 44 const net::BackoffEntry::Policy& backoff_policy, | |
| 45 const RegistrationCallback& callback, | |
| 46 int max_retry_count, | |
| 47 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | |
| 48 GCMStatsRecorder* recorder) | |
| 49 : RegistrationRequest(registration_url, | |
| 50 request_info, | |
| 51 backoff_policy, | |
| 52 callback, | |
| 53 max_retry_count, | |
| 54 request_context_getter, | |
| 55 recorder), | |
| 56 extra_request_info_(extra_request_info) { | |
| 57 } | |
| 58 | |
| 59 InstanceIDGetTokenRequest::~InstanceIDGetTokenRequest() {} | |
| 60 | |
| 61 void InstanceIDGetTokenRequest::BuildRequestBody(std::string* body){ | |
| 62 DCHECK(!extra_request_info_.instance_id.empty() && | |
|
Nicolas Zea
2015/05/21 21:07:51
These should probably be in ExtraRequestInfo const
jianli
2015/05/21 23:11:24
Done.
| |
| 63 !extra_request_info_.authorized_entity.empty() && | |
| 64 !extra_request_info_.scope.empty()); | |
| 65 | |
| 66 RegistrationRequest::BuildRequestBody(body); | |
| 67 | |
| 68 BuildFormEncoding(kScopeKey, extra_request_info_.scope, body); | |
| 69 for (auto iter = extra_request_info_.options.begin(); | |
| 70 iter != extra_request_info_.options.end(); | |
| 71 ++iter) { | |
| 72 BuildFormEncoding(kOptionKeyPrefix + iter->first, iter->second, body); | |
| 73 } | |
| 74 BuildFormEncoding(kGMSVersionKey, | |
| 75 base::IntToString(extra_request_info_.gcm_version), | |
| 76 body); | |
| 77 BuildFormEncoding(kInstanceIDKey, extra_request_info_.instance_id, body); | |
| 78 BuildFormEncoding(kAuthorizedEntityKey, | |
| 79 extra_request_info_.authorized_entity, | |
| 80 body); | |
| 81 } | |
| 82 | |
| 83 std::string InstanceIDGetTokenRequest::GetSourceForRecorder() const { | |
| 84 return extra_request_info_.authorized_entity; | |
| 85 } | |
| 86 | |
| 87 } // namespace gcm | |
| OLD | NEW |