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" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 } | 261 } |
262 | 262 |
263 state_ = INITIAL_DEVICE_CHECKIN; | 263 state_ = INITIAL_DEVICE_CHECKIN; |
264 device_checkin_info_.Reset(); | 264 device_checkin_info_.Reset(); |
265 StartCheckin(); | 265 StartCheckin(); |
266 } | 266 } |
267 | 267 |
268 void GCMClientImpl::InitializeMCSClient( | 268 void GCMClientImpl::InitializeMCSClient( |
269 scoped_ptr<GCMStore::LoadResult> result) { | 269 scoped_ptr<GCMStore::LoadResult> result) { |
270 std::vector<GURL> endpoints; | 270 std::vector<GURL> endpoints; |
271 endpoints.push_back(gservices_settings_.mcs_main_endpoint()); | 271 endpoints.push_back(gservices_settings_.GetMCSMainEndpoint()); |
272 endpoints.push_back(gservices_settings_.mcs_fallback_endpoint()); | 272 endpoints.push_back(gservices_settings_.GetMCSFallbackEndpoint()); |
273 connection_factory_ = internals_builder_->BuildConnectionFactory( | 273 connection_factory_ = internals_builder_->BuildConnectionFactory( |
274 endpoints, | 274 endpoints, |
275 kDefaultBackoffPolicy, | 275 kDefaultBackoffPolicy, |
276 network_session_, | 276 network_session_, |
277 net_log_.net_log(), | 277 net_log_.net_log(), |
278 &recorder_); | 278 &recorder_); |
279 mcs_client_ = internals_builder_->BuildMCSClient( | 279 mcs_client_ = internals_builder_->BuildMCSClient( |
280 chrome_build_proto_.chrome_version(), | 280 chrome_build_proto_.chrome_version(), |
281 clock_.get(), | 281 clock_.get(), |
282 connection_factory_.get(), | 282 connection_factory_.get(), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // Make sure no checkin is in progress. | 329 // Make sure no checkin is in progress. |
330 if (checkin_request_.get()) | 330 if (checkin_request_.get()) |
331 return; | 331 return; |
332 | 332 |
333 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, | 333 CheckinRequest::RequestInfo request_info(device_checkin_info_.android_id, |
334 device_checkin_info_.secret, | 334 device_checkin_info_.secret, |
335 gservices_settings_.digest(), | 335 gservices_settings_.digest(), |
336 account_ids_, | 336 account_ids_, |
337 chrome_build_proto_); | 337 chrome_build_proto_); |
338 checkin_request_.reset( | 338 checkin_request_.reset( |
339 new CheckinRequest(gservices_settings_.checkin_url(), | 339 new CheckinRequest(gservices_settings_.GetCheckinURL(), |
340 request_info, | 340 request_info, |
341 kDefaultBackoffPolicy, | 341 kDefaultBackoffPolicy, |
342 base::Bind(&GCMClientImpl::OnCheckinCompleted, | 342 base::Bind(&GCMClientImpl::OnCheckinCompleted, |
343 weak_ptr_factory_.GetWeakPtr()), | 343 weak_ptr_factory_.GetWeakPtr()), |
344 url_request_context_getter_, | 344 url_request_context_getter_, |
345 &recorder_)); | 345 &recorder_)); |
346 checkin_request_->Start(); | 346 checkin_request_->Start(); |
347 } | 347 } |
348 | 348 |
349 void GCMClientImpl::OnCheckinCompleted( | 349 void GCMClientImpl::OnCheckinCompleted( |
(...skipping 18 matching lines...) Expand all Loading... |
368 // would invalidate the registratoin IDs. | 368 // would invalidate the registratoin IDs. |
369 DCHECK_EQ(READY, state_); | 369 DCHECK_EQ(READY, state_); |
370 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id); | 370 DCHECK_EQ(device_checkin_info_.android_id, checkin_info.android_id); |
371 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret); | 371 DCHECK_EQ(device_checkin_info_.secret, checkin_info.secret); |
372 } | 372 } |
373 | 373 |
374 if (device_checkin_info_.IsValid()) { | 374 if (device_checkin_info_.IsValid()) { |
375 // First update G-services settings, as something might have changed. | 375 // First update G-services settings, as something might have changed. |
376 if (gservices_settings_.UpdateFromCheckinResponse(checkin_response)) { | 376 if (gservices_settings_.UpdateFromCheckinResponse(checkin_response)) { |
377 gcm_store_->SetGServicesSettings( | 377 gcm_store_->SetGServicesSettings( |
378 gservices_settings_.GetSettingsMap(), | 378 gservices_settings_.get_settings_map(), |
379 gservices_settings_.digest(), | 379 gservices_settings_.digest(), |
380 base::Bind(&GCMClientImpl::SetGServicesSettingsCallback, | 380 base::Bind(&GCMClientImpl::SetGServicesSettingsCallback, |
381 weak_ptr_factory_.GetWeakPtr())); | 381 weak_ptr_factory_.GetWeakPtr())); |
382 } | 382 } |
383 | 383 |
384 last_checkin_time_ = clock_->Now(); | 384 last_checkin_time_ = clock_->Now(); |
385 gcm_store_->SetLastCheckinTime( | 385 gcm_store_->SetLastCheckinTime( |
386 last_checkin_time_, | 386 last_checkin_time_, |
387 base::Bind(&GCMClientImpl::SetLastCheckinTimeCallback, | 387 base::Bind(&GCMClientImpl::SetLastCheckinTimeCallback, |
388 weak_ptr_factory_.GetWeakPtr())); | 388 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 19 matching lines...) Expand all Loading... |
408 time_to_next_checkin = base::TimeDelta(); | 408 time_to_next_checkin = base::TimeDelta(); |
409 | 409 |
410 base::MessageLoop::current()->PostDelayedTask( | 410 base::MessageLoop::current()->PostDelayedTask( |
411 FROM_HERE, | 411 FROM_HERE, |
412 base::Bind(&GCMClientImpl::StartCheckin, | 412 base::Bind(&GCMClientImpl::StartCheckin, |
413 periodic_checkin_ptr_factory_.GetWeakPtr()), | 413 periodic_checkin_ptr_factory_.GetWeakPtr()), |
414 time_to_next_checkin); | 414 time_to_next_checkin); |
415 } | 415 } |
416 | 416 |
417 base::TimeDelta GCMClientImpl::GetTimeToNextCheckin() const { | 417 base::TimeDelta GCMClientImpl::GetTimeToNextCheckin() const { |
418 return last_checkin_time_ + gservices_settings_.checkin_interval() - | 418 return last_checkin_time_ + gservices_settings_.GetCheckinInterval() - |
419 clock_->Now(); | 419 clock_->Now(); |
420 } | 420 } |
421 | 421 |
422 void GCMClientImpl::SetLastCheckinTimeCallback(bool success) { | 422 void GCMClientImpl::SetLastCheckinTimeCallback(bool success) { |
423 // TODO(fgorski): This is one of the signals that store needs a rebuild. | 423 // TODO(fgorski): This is one of the signals that store needs a rebuild. |
424 DCHECK(success); | 424 DCHECK(success); |
425 } | 425 } |
426 | 426 |
427 void GCMClientImpl::SetDeviceCredentialsCallback(bool success) { | 427 void GCMClientImpl::SetDeviceCredentialsCallback(bool success) { |
428 // TODO(fgorski): This is one of the signals that store needs a rebuild. | 428 // TODO(fgorski): This is one of the signals that store needs a rebuild. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 } | 466 } |
467 | 467 |
468 RegistrationRequest::RequestInfo request_info( | 468 RegistrationRequest::RequestInfo request_info( |
469 device_checkin_info_.android_id, | 469 device_checkin_info_.android_id, |
470 device_checkin_info_.secret, | 470 device_checkin_info_.secret, |
471 app_id, | 471 app_id, |
472 sender_ids); | 472 sender_ids); |
473 DCHECK_EQ(0u, pending_registration_requests_.count(app_id)); | 473 DCHECK_EQ(0u, pending_registration_requests_.count(app_id)); |
474 | 474 |
475 RegistrationRequest* registration_request = | 475 RegistrationRequest* registration_request = |
476 new RegistrationRequest(gservices_settings_.registration_url(), | 476 new RegistrationRequest(gservices_settings_.GetRegistrationURL(), |
477 request_info, | 477 request_info, |
478 kDefaultBackoffPolicy, | 478 kDefaultBackoffPolicy, |
479 base::Bind(&GCMClientImpl::OnRegisterCompleted, | 479 base::Bind(&GCMClientImpl::OnRegisterCompleted, |
480 weak_ptr_factory_.GetWeakPtr(), | 480 weak_ptr_factory_.GetWeakPtr(), |
481 app_id, | 481 app_id, |
482 sender_ids), | 482 sender_ids), |
483 kMaxRegistrationRetries, | 483 kMaxRegistrationRetries, |
484 url_request_context_getter_, | 484 url_request_context_getter_, |
485 &recorder_); | 485 &recorder_); |
486 pending_registration_requests_[app_id] = registration_request; | 486 pending_registration_requests_[app_id] = registration_request; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 gcm_store_->RemoveRegistration( | 540 gcm_store_->RemoveRegistration( |
541 app_id, | 541 app_id, |
542 base::Bind(&GCMClientImpl::UpdateRegistrationCallback, | 542 base::Bind(&GCMClientImpl::UpdateRegistrationCallback, |
543 weak_ptr_factory_.GetWeakPtr())); | 543 weak_ptr_factory_.GetWeakPtr())); |
544 | 544 |
545 UnregistrationRequest::RequestInfo request_info( | 545 UnregistrationRequest::RequestInfo request_info( |
546 device_checkin_info_.android_id, | 546 device_checkin_info_.android_id, |
547 device_checkin_info_.secret, | 547 device_checkin_info_.secret, |
548 app_id); | 548 app_id); |
549 | 549 |
550 UnregistrationRequest* unregistration_request = | 550 UnregistrationRequest* unregistration_request = new UnregistrationRequest( |
551 new UnregistrationRequest( | 551 gservices_settings_.GetRegistrationURL(), |
552 gservices_settings_.registration_url(), | 552 request_info, |
553 request_info, | 553 kDefaultBackoffPolicy, |
554 kDefaultBackoffPolicy, | 554 base::Bind(&GCMClientImpl::OnUnregisterCompleted, |
555 base::Bind(&GCMClientImpl::OnUnregisterCompleted, | 555 weak_ptr_factory_.GetWeakPtr(), |
556 weak_ptr_factory_.GetWeakPtr(), | 556 app_id), |
557 app_id), | 557 url_request_context_getter_, |
558 url_request_context_getter_, | 558 &recorder_); |
559 &recorder_); | |
560 pending_unregistration_requests_[app_id] = unregistration_request; | 559 pending_unregistration_requests_[app_id] = unregistration_request; |
561 unregistration_request->Start(); | 560 unregistration_request->Start(); |
562 } | 561 } |
563 | 562 |
564 void GCMClientImpl::OnUnregisterCompleted( | 563 void GCMClientImpl::OnUnregisterCompleted( |
565 const std::string& app_id, | 564 const std::string& app_id, |
566 UnregistrationRequest::Status status) { | 565 UnregistrationRequest::Status status) { |
567 DVLOG(1) << "Unregister completed for app: " << app_id | 566 DVLOG(1) << "Unregister completed for app: " << app_id |
568 << " with " << (status ? "success." : "failure."); | 567 << " with " << (status ? "success." : "failure."); |
569 delegate_->OnUnregisterFinished( | 568 delegate_->OnUnregisterFinished( |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 | 801 |
803 recorder_.RecordIncomingSendError( | 802 recorder_.RecordIncomingSendError( |
804 data_message_stanza.category(), | 803 data_message_stanza.category(), |
805 data_message_stanza.to(), | 804 data_message_stanza.to(), |
806 data_message_stanza.id()); | 805 data_message_stanza.id()); |
807 delegate_->OnMessageSendError(data_message_stanza.category(), | 806 delegate_->OnMessageSendError(data_message_stanza.category(), |
808 send_error_details); | 807 send_error_details); |
809 } | 808 } |
810 | 809 |
811 } // namespace gcm | 810 } // namespace gcm |
OLD | NEW |