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