Index: google_apis/gcm/engine/instance_id_get_token_request.cc |
diff --git a/google_apis/gcm/engine/instance_id_get_token_request.cc b/google_apis/gcm/engine/instance_id_get_token_request.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4ccc42ecf5ff81e3824030cd481ebca3c87fbf81 |
--- /dev/null |
+++ b/google_apis/gcm/engine/instance_id_get_token_request.cc |
@@ -0,0 +1,87 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "google_apis/gcm/engine/instance_id_get_token_request.h" |
+ |
+#include "base/strings/string_number_conversions.h" |
+#include "google_apis/gcm/base/gcm_util.h" |
+#include "net/url_request/url_request_context_getter.h" |
+ |
+namespace gcm { |
+ |
+namespace { |
+ |
+// Request constants. |
+const char kAuthorizedEntityKey[] = "sender"; |
+const char kGMSVersionKey[] = "gmsv"; |
+const char kInstanceIDKey[] = "appid"; |
+const char kScopeKey[] = "scope"; |
+// Prefix that needs to be added for each option key. |
+const char kOptionKeyPrefix[] = "X-"; |
+ |
+} // namespace |
+ |
+InstanceIDGetTokenRequest::ExtraRequestInfo::ExtraRequestInfo( |
+ const std::string& instance_id, |
+ const std::string& authorized_entity, |
+ const std::string& scope, |
+ int gcm_version, |
+ const std::map<std::string, std::string>& options) |
+ : instance_id(instance_id), |
+ authorized_entity(authorized_entity), |
+ scope(scope), |
+ gcm_version(gcm_version), |
+ options(options) { |
+} |
+ |
+InstanceIDGetTokenRequest::ExtraRequestInfo::~ExtraRequestInfo() {} |
+ |
+InstanceIDGetTokenRequest::InstanceIDGetTokenRequest( |
+ const GURL& registration_url, |
+ const RequestInfo& request_info, |
+ const ExtraRequestInfo& extra_request_info, |
+ const net::BackoffEntry::Policy& backoff_policy, |
+ const RegistrationCallback& callback, |
+ int max_retry_count, |
+ scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
+ GCMStatsRecorder* recorder) |
+ : RegistrationRequest(registration_url, |
+ request_info, |
+ backoff_policy, |
+ callback, |
+ max_retry_count, |
+ request_context_getter, |
+ recorder), |
+ extra_request_info_(extra_request_info) { |
+} |
+ |
+InstanceIDGetTokenRequest::~InstanceIDGetTokenRequest() {} |
+ |
+void InstanceIDGetTokenRequest::BuildRequestBody(std::string* body){ |
+ 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.
|
+ !extra_request_info_.authorized_entity.empty() && |
+ !extra_request_info_.scope.empty()); |
+ |
+ RegistrationRequest::BuildRequestBody(body); |
+ |
+ BuildFormEncoding(kScopeKey, extra_request_info_.scope, body); |
+ for (auto iter = extra_request_info_.options.begin(); |
+ iter != extra_request_info_.options.end(); |
+ ++iter) { |
+ BuildFormEncoding(kOptionKeyPrefix + iter->first, iter->second, body); |
+ } |
+ BuildFormEncoding(kGMSVersionKey, |
+ base::IntToString(extra_request_info_.gcm_version), |
+ body); |
+ BuildFormEncoding(kInstanceIDKey, extra_request_info_.instance_id, body); |
+ BuildFormEncoding(kAuthorizedEntityKey, |
+ extra_request_info_.authorized_entity, |
+ body); |
+} |
+ |
+std::string InstanceIDGetTokenRequest::GetSourceForRecorder() const { |
+ return extra_request_info_.authorized_entity; |
+} |
+ |
+} // namespace gcm |