Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: google_apis/gcm/engine/registration_request.cc

Issue 183923006: [GCM] API update to allow only a single sender in registration (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updates based on CR. Changing how the senders/reg_ids are stored to avoid upgrade to multiple sedne… Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "google_apis/gcm/engine/registration_request.h" 5 #include "google_apis/gcm/engine/registration_request.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/strings/string_number_conversions.h" 10 #include "base/strings/string_number_conversions.h"
(...skipping 15 matching lines...) Expand all
26 const char kRegistrationRequestContentType[] = 26 const char kRegistrationRequestContentType[] =
27 "application/x-www-form-urlencoded"; 27 "application/x-www-form-urlencoded";
28 28
29 // Request constants. 29 // Request constants.
30 const char kAppIdKey[] = "app"; 30 const char kAppIdKey[] = "app";
31 const char kCertKey[] = "cert"; 31 const char kCertKey[] = "cert";
32 const char kDeviceIdKey[] = "device"; 32 const char kDeviceIdKey[] = "device";
33 const char kLoginHeader[] = "AidLogin"; 33 const char kLoginHeader[] = "AidLogin";
34 const char kSenderKey[] = "sender"; 34 const char kSenderKey[] = "sender";
35 35
36 // Request validation constants.
37 const size_t kMaxSenders = 100;
38
39 // Response constants. 36 // Response constants.
40 const char kErrorPrefix[] = "Error="; 37 const char kErrorPrefix[] = "Error=";
41 const char kTokenPrefix[] = "token="; 38 const char kTokenPrefix[] = "token=";
42 const char kDeviceRegistrationError[] = "PHONE_REGISTRATION_ERROR"; 39 const char kDeviceRegistrationError[] = "PHONE_REGISTRATION_ERROR";
43 const char kAuthenticationFailed[] = "AUTHENTICATION_FAILED"; 40 const char kAuthenticationFailed[] = "AUTHENTICATION_FAILED";
44 const char kInvalidSender[] = "INVALID_SENDER"; 41 const char kInvalidSender[] = "INVALID_SENDER";
45 const char kInvalidParameters[] = "INVALID_PARAMETERS"; 42 const char kInvalidParameters[] = "INVALID_PARAMETERS";
46 43
47 void BuildFormEncoding(const std::string& key, 44 void BuildFormEncoding(const std::string& key,
48 const std::string& value, 45 const std::string& value,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 RegistrationRequest::STATUS_COUNT); 80 RegistrationRequest::STATUS_COUNT);
84 } 81 }
85 82
86 } // namespace 83 } // namespace
87 84
88 RegistrationRequest::RequestInfo::RequestInfo( 85 RegistrationRequest::RequestInfo::RequestInfo(
89 uint64 android_id, 86 uint64 android_id,
90 uint64 security_token, 87 uint64 security_token,
91 const std::string& app_id, 88 const std::string& app_id,
92 const std::string& cert, 89 const std::string& cert,
93 const std::vector<std::string>& sender_ids) 90 const std::string& sender_id)
94 : android_id(android_id), 91 : android_id(android_id),
95 security_token(security_token), 92 security_token(security_token),
96 app_id(app_id), 93 app_id(app_id),
97 cert(cert), 94 cert(cert),
98 sender_ids(sender_ids) { 95 sender_id(sender_id) {
99 } 96 }
100 97
101 RegistrationRequest::RequestInfo::~RequestInfo() {} 98 RegistrationRequest::RequestInfo::~RequestInfo() {}
102 99
103 RegistrationRequest::RegistrationRequest( 100 RegistrationRequest::RegistrationRequest(
104 const RequestInfo& request_info, 101 const RequestInfo& request_info,
105 const net::BackoffEntry::Policy& backoff_policy, 102 const net::BackoffEntry::Policy& backoff_policy,
106 const RegistrationCallback& callback, 103 const RegistrationCallback& callback,
107 int max_retry_count, 104 int max_retry_count,
108 scoped_refptr<net::URLRequestContextGetter> request_context_getter) 105 scoped_refptr<net::URLRequestContextGetter> request_context_getter)
109 : callback_(callback), 106 : callback_(callback),
110 request_info_(request_info), 107 request_info_(request_info),
111 backoff_entry_(&backoff_policy), 108 backoff_entry_(&backoff_policy),
112 request_context_getter_(request_context_getter), 109 request_context_getter_(request_context_getter),
113 retries_left_(max_retry_count), 110 retries_left_(max_retry_count),
114 weak_ptr_factory_(this) { 111 weak_ptr_factory_(this) {
115 DCHECK_GE(max_retry_count, 0); 112 DCHECK_GE(max_retry_count, 0);
116 } 113 }
117 114
118 RegistrationRequest::~RegistrationRequest() {} 115 RegistrationRequest::~RegistrationRequest() {}
119 116
120 void RegistrationRequest::Start() { 117 void RegistrationRequest::Start() {
121 DCHECK(!callback_.is_null()); 118 DCHECK(!callback_.is_null());
122 DCHECK(request_info_.android_id != 0UL); 119 DCHECK(request_info_.android_id != 0UL);
123 DCHECK(request_info_.security_token != 0UL); 120 DCHECK(request_info_.security_token != 0UL);
124 DCHECK(!request_info_.cert.empty()); 121 DCHECK(!request_info_.cert.empty());
125 DCHECK(0 < request_info_.sender_ids.size() && 122 DCHECK(!request_info_.sender_id.empty());
126 request_info_.sender_ids.size() <= kMaxSenders);
127 123
128 DCHECK(!url_fetcher_.get()); 124 DCHECK(!url_fetcher_.get());
129 url_fetcher_.reset(net::URLFetcher::Create( 125 url_fetcher_.reset(net::URLFetcher::Create(
130 GURL(kRegistrationURL), net::URLFetcher::POST, this)); 126 GURL(kRegistrationURL), net::URLFetcher::POST, this));
131 url_fetcher_->SetRequestContext(request_context_getter_); 127 url_fetcher_->SetRequestContext(request_context_getter_);
132 128
133 std::string android_id = base::Uint64ToString(request_info_.android_id); 129 std::string android_id = base::Uint64ToString(request_info_.android_id);
134 std::string auth_header = 130 std::string auth_header =
135 std::string(net::HttpRequestHeaders::kAuthorization) + ": " + 131 std::string(net::HttpRequestHeaders::kAuthorization) + ": " +
136 kLoginHeader + " " + android_id + ":" + 132 kLoginHeader + " " + android_id + ":" +
137 base::Uint64ToString(request_info_.security_token); 133 base::Uint64ToString(request_info_.security_token);
138 url_fetcher_->SetExtraRequestHeaders(auth_header); 134 url_fetcher_->SetExtraRequestHeaders(auth_header);
139 135
140 std::string body; 136 std::string body;
141 BuildFormEncoding(kAppIdKey, request_info_.app_id, &body); 137 BuildFormEncoding(kAppIdKey, request_info_.app_id, &body);
142 BuildFormEncoding(kCertKey, request_info_.cert, &body); 138 BuildFormEncoding(kCertKey, request_info_.cert, &body);
143 BuildFormEncoding(kDeviceIdKey, android_id, &body); 139 BuildFormEncoding(kDeviceIdKey, android_id, &body);
144 140 BuildFormEncoding(kSenderKey, request_info_.sender_id, &body);
145 std::string senders;
146 for (std::vector<std::string>::const_iterator iter =
147 request_info_.sender_ids.begin();
148 iter != request_info_.sender_ids.end();
149 ++iter) {
150 DCHECK(!iter->empty());
151 if (!senders.empty())
152 senders.append(",");
153 senders.append(*iter);
154 }
155 BuildFormEncoding(kSenderKey, senders, &body);
156 141
157 DVLOG(1) << "Performing registration for: " << request_info_.app_id; 142 DVLOG(1) << "Performing registration for: " << request_info_.app_id;
158 DVLOG(1) << "Registration request: " << body; 143 DVLOG(1) << "Registration request: " << body;
159 url_fetcher_->SetUploadData(kRegistrationRequestContentType, body); 144 url_fetcher_->SetUploadData(kRegistrationRequestContentType, body);
160 url_fetcher_->Start(); 145 url_fetcher_->Start();
161 } 146 }
162 147
163 void RegistrationRequest::RetryWithBackoff(bool update_backoff) { 148 void RegistrationRequest::RetryWithBackoff(bool update_backoff) {
164 if (update_backoff) { 149 if (update_backoff) {
165 DCHECK_GT(retries_left_, 0); 150 DCHECK_GT(retries_left_, 0);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 } 223 }
239 224
240 status = REACHED_MAX_RETRIES; 225 status = REACHED_MAX_RETRIES;
241 RecordRegistrationStatusToUMA(status); 226 RecordRegistrationStatusToUMA(status);
242 } 227 }
243 228
244 callback_.Run(status, token); 229 callback_.Run(status, token);
245 } 230 }
246 231
247 } // namespace gcm 232 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698