OLD | NEW |
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" | |
15 #include "base/time/default_clock.h" | 14 #include "base/time/default_clock.h" |
16 #include "google_apis/gcm/base/mcs_message.h" | 15 #include "google_apis/gcm/base/mcs_message.h" |
17 #include "google_apis/gcm/base/mcs_util.h" | 16 #include "google_apis/gcm/base/mcs_util.h" |
18 #include "google_apis/gcm/engine/checkin_request.h" | 17 #include "google_apis/gcm/engine/checkin_request.h" |
19 #include "google_apis/gcm/engine/connection_factory_impl.h" | 18 #include "google_apis/gcm/engine/connection_factory_impl.h" |
20 #include "google_apis/gcm/engine/gcm_store_impl.h" | 19 #include "google_apis/gcm/engine/gcm_store_impl.h" |
21 #include "google_apis/gcm/engine/mcs_client.h" | 20 #include "google_apis/gcm/engine/mcs_client.h" |
22 #include "google_apis/gcm/protocol/mcs.pb.h" | 21 #include "google_apis/gcm/protocol/mcs.pb.h" |
23 #include "net/http/http_network_session.h" | 22 #include "net/http/http_network_session.h" |
24 #include "net/url_request/url_request_context.h" | 23 #include "net/url_request/url_request_context.h" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 mcs_client_->Login(device_checkin_info_.android_id, | 286 mcs_client_->Login(device_checkin_info_.android_id, |
288 device_checkin_info_.secret); | 287 device_checkin_info_.secret); |
289 } | 288 } |
290 | 289 |
291 void GCMClientImpl::ResetState() { | 290 void GCMClientImpl::ResetState() { |
292 state_ = UNINITIALIZED; | 291 state_ = UNINITIALIZED; |
293 // TODO(fgorski): reset all of the necessart objects and start over. | 292 // TODO(fgorski): reset all of the necessart objects and start over. |
294 } | 293 } |
295 | 294 |
296 void GCMClientImpl::StartCheckin() { | 295 void GCMClientImpl::StartCheckin() { |
297 CheckinRequest::RequestInfo request_info( | |
298 device_checkin_info_.android_id, | |
299 device_checkin_info_.secret, | |
300 std::string(), | |
301 account_ids_, | |
302 chrome_build_proto_); | |
303 checkin_request_.reset( | 296 checkin_request_.reset( |
304 new CheckinRequest(request_info, | 297 new CheckinRequest(base::Bind(&GCMClientImpl::OnCheckinCompleted, |
| 298 weak_ptr_factory_.GetWeakPtr()), |
305 kDefaultBackoffPolicy, | 299 kDefaultBackoffPolicy, |
306 base::Bind(&GCMClientImpl::OnCheckinCompleted, | 300 chrome_build_proto_, |
307 weak_ptr_factory_.GetWeakPtr()), | 301 device_checkin_info_.android_id, |
| 302 device_checkin_info_.secret, |
| 303 account_ids_, |
308 url_request_context_getter_)); | 304 url_request_context_getter_)); |
309 checkin_request_->Start(); | 305 checkin_request_->Start(); |
310 } | 306 } |
311 | 307 |
312 void GCMClientImpl::OnCheckinCompleted( | 308 void GCMClientImpl::OnCheckinCompleted(uint64 android_id, |
313 const checkin_proto::AndroidCheckinResponse& checkin_response) { | 309 uint64 security_token) { |
314 checkin_request_.reset(); | 310 checkin_request_.reset(); |
315 | 311 |
316 if (!checkin_response.has_android_id() || | 312 CheckinInfo checkin_info; |
317 !checkin_response.has_security_token()) { | 313 checkin_info.android_id = android_id; |
318 // TODO(fgorski): I don't think a retry here will help, we should probably | 314 checkin_info.secret = security_token; |
| 315 |
| 316 if (!checkin_info.IsValid()) { |
| 317 // TODO(fgorski): I don't think a retry here will help, we should probalby |
319 // start over. By checking in with (0, 0). | 318 // start over. By checking in with (0, 0). |
320 return; | 319 return; |
321 } | 320 } |
322 | 321 |
323 CheckinInfo checkin_info; | |
324 checkin_info.android_id = checkin_response.android_id(); | |
325 checkin_info.secret = checkin_response.security_token(); | |
326 | |
327 if (state_ == INITIAL_DEVICE_CHECKIN) { | 322 if (state_ == INITIAL_DEVICE_CHECKIN) { |
328 OnFirstTimeDeviceCheckinCompleted(checkin_info); | 323 OnFirstTimeDeviceCheckinCompleted(checkin_info); |
329 } else { | 324 } else { |
330 // checkin_info is not expected to change after a periodic checkin as it | 325 // checkin_info is not expected to change after a periodic checkin as it |
331 // would invalidate the registratoin IDs. | 326 // would invalidate the registratoin IDs. |
332 DCHECK_EQ(READY, state_); | 327 DCHECK_EQ(READY, state_); |
333 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id); | 328 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id); |
334 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret); | 329 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret); |
335 } | 330 } |
336 | 331 |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 if (iter != send_error_details.additional_data.end()) { | 696 if (iter != send_error_details.additional_data.end()) { |
702 send_error_details.message_id = iter->second; | 697 send_error_details.message_id = iter->second; |
703 send_error_details.additional_data.erase(iter); | 698 send_error_details.additional_data.erase(iter); |
704 } | 699 } |
705 | 700 |
706 delegate_->OnMessageSendError(data_message_stanza.category(), | 701 delegate_->OnMessageSendError(data_message_stanza.category(), |
707 send_error_details); | 702 send_error_details); |
708 } | 703 } |
709 | 704 |
710 } // namespace gcm | 705 } // namespace gcm |
OLD | NEW |