Index: google_apis/gcm/engine/gcm_registration_request.cc |
diff --git a/google_apis/gcm/engine/gcm_registration_request.cc b/google_apis/gcm/engine/gcm_registration_request.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..024d47cc230b80ef8dd062e9d3755e8c889d2598 |
--- /dev/null |
+++ b/google_apis/gcm/engine/gcm_registration_request.cc |
@@ -0,0 +1,83 @@ |
+// Copyright 2015 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/gcm_registration_request.h" |
+ |
+#include "base/metrics/histogram.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 kSenderKey[] = "sender"; |
+ |
+// Request validation constants. |
+const size_t kMaxSenders = 100; |
+ |
+} // namespace |
+ |
+GCMRegistrationRequest::ExtraRequestInfo::ExtraRequestInfo( |
+ const std::vector<std::string>& sender_ids) |
+ : sender_ids(sender_ids) { |
+} |
+ |
+GCMRegistrationRequest::ExtraRequestInfo::~ExtraRequestInfo() {} |
+ |
+GCMRegistrationRequest::GCMRegistrationRequest( |
+ 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) { |
+} |
+ |
+GCMRegistrationRequest::~GCMRegistrationRequest() {} |
+ |
+ |
+void GCMRegistrationRequest::BuildRequestBody(std::string* body){ |
+ DCHECK(0 < extra_request_info_.sender_ids.size() && |
+ extra_request_info_.sender_ids.size() <= kMaxSenders); |
+ |
+ RegistrationRequest::BuildRequestBody(body); |
+ |
+ std::string senders; |
+ for (auto iter = extra_request_info_.sender_ids.begin(); |
+ iter != extra_request_info_.sender_ids.end(); |
+ ++iter) { |
+ if (!senders.empty()) |
+ senders.append(","); |
+ senders.append(*iter); |
+ } |
+ BuildFormEncoding(kSenderKey, senders, body); |
+ UMA_HISTOGRAM_COUNTS("GCM.RegistrationSenderIdCount", |
+ extra_request_info_.sender_ids.size()); |
+} |
+ |
+std::string GCMRegistrationRequest::GetSourceForRecorder() const { |
+ std::string senders; |
+ for (auto iter = extra_request_info_.sender_ids.begin(); |
+ iter != extra_request_info_.sender_ids.end(); |
+ ++iter) { |
+ if (!senders.empty()) |
+ senders.append(","); |
+ senders.append(*iter); |
+ } |
+ return senders; |
+} |
+ |
+} // namespace gcm |