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

Side by Side Diff: google_apis/gcm/gcm_client_impl.cc

Issue 233103003: [GCM] Adding basic G-services handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « google_apis/gcm/gcm_client_impl.h ('k') | google_apis/gcm/tools/mcs_probe.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/gcm_client_impl.h" 5 #include "google_apis/gcm/gcm_client_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/sequenced_task_runner.h" 13 #include "base/sequenced_task_runner.h"
14 #include "base/strings/string_number_conversions.h"
14 #include "base/time/default_clock.h" 15 #include "base/time/default_clock.h"
15 #include "google_apis/gcm/base/mcs_message.h" 16 #include "google_apis/gcm/base/mcs_message.h"
16 #include "google_apis/gcm/base/mcs_util.h" 17 #include "google_apis/gcm/base/mcs_util.h"
17 #include "google_apis/gcm/engine/checkin_request.h" 18 #include "google_apis/gcm/engine/checkin_request.h"
18 #include "google_apis/gcm/engine/connection_factory_impl.h" 19 #include "google_apis/gcm/engine/connection_factory_impl.h"
19 #include "google_apis/gcm/engine/gcm_store_impl.h" 20 #include "google_apis/gcm/engine/gcm_store_impl.h"
20 #include "google_apis/gcm/engine/mcs_client.h" 21 #include "google_apis/gcm/engine/mcs_client.h"
21 #include "google_apis/gcm/protocol/mcs.pb.h" 22 #include "google_apis/gcm/protocol/mcs.pb.h"
22 #include "net/http/http_network_session.h" 23 #include "net/http/http_network_session.h"
23 #include "net/url_request/url_request_context.h" 24 #include "net/url_request/url_request_context.h"
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 mcs_client_->Login(device_checkin_info_.android_id, 279 mcs_client_->Login(device_checkin_info_.android_id,
279 device_checkin_info_.secret); 280 device_checkin_info_.secret);
280 } 281 }
281 282
282 void GCMClientImpl::ResetState() { 283 void GCMClientImpl::ResetState() {
283 state_ = UNINITIALIZED; 284 state_ = UNINITIALIZED;
284 // TODO(fgorski): reset all of the necessart objects and start over. 285 // TODO(fgorski): reset all of the necessart objects and start over.
285 } 286 }
286 287
287 void GCMClientImpl::StartCheckin() { 288 void GCMClientImpl::StartCheckin() {
289 CheckinRequest::RequestInfo request_info(
290 device_checkin_info_.android_id,
291 device_checkin_info_.secret,
292 std::string(),
293 account_ids_,
294 chrome_build_proto_);
288 checkin_request_.reset( 295 checkin_request_.reset(
289 new CheckinRequest(base::Bind(&GCMClientImpl::OnCheckinCompleted, 296 new CheckinRequest(request_info,
297 kDefaultBackoffPolicy,
298 base::Bind(&GCMClientImpl::OnCheckinCompleted,
290 weak_ptr_factory_.GetWeakPtr()), 299 weak_ptr_factory_.GetWeakPtr()),
291 kDefaultBackoffPolicy,
292 chrome_build_proto_,
293 device_checkin_info_.android_id,
294 device_checkin_info_.secret,
295 account_ids_,
296 url_request_context_getter_)); 300 url_request_context_getter_));
297 checkin_request_->Start(); 301 checkin_request_->Start();
298 } 302 }
299 303
300 void GCMClientImpl::OnCheckinCompleted(uint64 android_id, 304 void GCMClientImpl::OnCheckinCompleted(
301 uint64 security_token) { 305 const checkin_proto::AndroidCheckinResponse& checkin_response) {
302 checkin_request_.reset(); 306 checkin_request_.reset();
303 307
304 CheckinInfo checkin_info; 308 if (!checkin_response.has_android_id() ||
305 checkin_info.android_id = android_id; 309 !checkin_response.has_security_token()) {
306 checkin_info.secret = security_token; 310 // TODO(fgorski): I don't think a retry here will help, we should probably
307
308 if (!checkin_info.IsValid()) {
309 // TODO(fgorski): I don't think a retry here will help, we should probalby
310 // start over. By checking in with (0, 0). 311 // start over. By checking in with (0, 0).
311 return; 312 return;
312 } 313 }
313 314
315 CheckinInfo checkin_info;
316 checkin_info.android_id = checkin_response.android_id();
317 checkin_info.secret = checkin_response.security_token();
318
314 if (state_ == INITIAL_DEVICE_CHECKIN) { 319 if (state_ == INITIAL_DEVICE_CHECKIN) {
315 OnFirstTimeDeviceCheckinCompleted(checkin_info); 320 OnFirstTimeDeviceCheckinCompleted(checkin_info);
316 } else { 321 } else {
317 // checkin_info is not expected to change after a periodic checkin as it 322 // checkin_info is not expected to change after a periodic checkin as it
318 // would invalidate the registratoin IDs. 323 // would invalidate the registratoin IDs.
319 DCHECK_EQ(READY, state_); 324 DCHECK_EQ(READY, state_);
320 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id); 325 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id);
321 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret); 326 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret);
322 } 327 }
323 328
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 if (iter != send_error_details.additional_data.end()) { 693 if (iter != send_error_details.additional_data.end()) {
689 send_error_details.message_id = iter->second; 694 send_error_details.message_id = iter->second;
690 send_error_details.additional_data.erase(iter); 695 send_error_details.additional_data.erase(iter);
691 } 696 }
692 697
693 delegate_->OnMessageSendError(data_message_stanza.category(), 698 delegate_->OnMessageSendError(data_message_stanza.category(),
694 send_error_details); 699 send_error_details);
695 } 700 }
696 701
697 } // namespace gcm 702 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/gcm_client_impl.h ('k') | google_apis/gcm/tools/mcs_probe.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698