OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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/gcm_registration_request.h" |
| 6 |
| 7 #include "base/metrics/histogram.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 kSenderKey[] = "sender"; |
| 17 |
| 18 // Request validation constants. |
| 19 const size_t kMaxSenders = 100; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 GCMRegistrationRequest::ExtraRequestInfo::ExtraRequestInfo( |
| 24 const std::vector<std::string>& sender_ids) |
| 25 : sender_ids(sender_ids) { |
| 26 } |
| 27 |
| 28 GCMRegistrationRequest::ExtraRequestInfo::~ExtraRequestInfo() {} |
| 29 |
| 30 GCMRegistrationRequest::GCMRegistrationRequest( |
| 31 const GURL& registration_url, |
| 32 const RequestInfo& request_info, |
| 33 const ExtraRequestInfo& extra_request_info, |
| 34 const net::BackoffEntry::Policy& backoff_policy, |
| 35 const RegistrationCallback& callback, |
| 36 int max_retry_count, |
| 37 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
| 38 GCMStatsRecorder* recorder) |
| 39 : RegistrationRequest(registration_url, |
| 40 request_info, |
| 41 backoff_policy, |
| 42 callback, |
| 43 max_retry_count, |
| 44 request_context_getter, |
| 45 recorder), |
| 46 extra_request_info_(extra_request_info) { |
| 47 } |
| 48 |
| 49 GCMRegistrationRequest::~GCMRegistrationRequest() {} |
| 50 |
| 51 |
| 52 void GCMRegistrationRequest::BuildRequestBody(std::string* body){ |
| 53 DCHECK(0 < extra_request_info_.sender_ids.size() && |
| 54 extra_request_info_.sender_ids.size() <= kMaxSenders); |
| 55 |
| 56 RegistrationRequest::BuildRequestBody(body); |
| 57 |
| 58 std::string senders; |
| 59 for (auto iter = extra_request_info_.sender_ids.begin(); |
| 60 iter != extra_request_info_.sender_ids.end(); |
| 61 ++iter) { |
| 62 if (!senders.empty()) |
| 63 senders.append(","); |
| 64 senders.append(*iter); |
| 65 } |
| 66 BuildFormEncoding(kSenderKey, senders, body); |
| 67 UMA_HISTOGRAM_COUNTS("GCM.RegistrationSenderIdCount", |
| 68 extra_request_info_.sender_ids.size()); |
| 69 } |
| 70 |
| 71 std::string GCMRegistrationRequest::GetSourceForRecorder() const { |
| 72 std::string senders; |
| 73 for (auto iter = extra_request_info_.sender_ids.begin(); |
| 74 iter != extra_request_info_.sender_ids.end(); |
| 75 ++iter) { |
| 76 if (!senders.empty()) |
| 77 senders.append(","); |
| 78 senders.append(*iter); |
| 79 } |
| 80 return senders; |
| 81 } |
| 82 |
| 83 } // namespace gcm |
OLD | NEW |