OLD | NEW |
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 "components/gcm_driver/gcm_client_impl.h" | 5 #include "components/gcm_driver/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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 scoped_ptr<GCMStore::LoadResult> result) { | 334 scoped_ptr<GCMStore::LoadResult> result) { |
335 std::vector<GURL> endpoints; | 335 std::vector<GURL> endpoints; |
336 endpoints.push_back(gservices_settings_.GetMCSMainEndpoint()); | 336 endpoints.push_back(gservices_settings_.GetMCSMainEndpoint()); |
337 endpoints.push_back(gservices_settings_.GetMCSFallbackEndpoint()); | 337 endpoints.push_back(gservices_settings_.GetMCSFallbackEndpoint()); |
338 connection_factory_ = internals_builder_->BuildConnectionFactory( | 338 connection_factory_ = internals_builder_->BuildConnectionFactory( |
339 endpoints, | 339 endpoints, |
340 kDefaultBackoffPolicy, | 340 kDefaultBackoffPolicy, |
341 network_session_, | 341 network_session_, |
342 net_log_.net_log(), | 342 net_log_.net_log(), |
343 &recorder_); | 343 &recorder_); |
| 344 connection_factory_->SetConnectionListener(this); |
344 mcs_client_ = internals_builder_->BuildMCSClient( | 345 mcs_client_ = internals_builder_->BuildMCSClient( |
345 chrome_build_info_.version, | 346 chrome_build_info_.version, |
346 clock_.get(), | 347 clock_.get(), |
347 connection_factory_.get(), | 348 connection_factory_.get(), |
348 gcm_store_.get(), | 349 gcm_store_.get(), |
349 &recorder_).Pass(); | 350 &recorder_).Pass(); |
350 | 351 |
351 mcs_client_->Initialize( | 352 mcs_client_->Initialize( |
352 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()), | 353 base::Bind(&GCMClientImpl::OnMCSError, weak_ptr_factory_.GetWeakPtr()), |
353 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS, | 354 base::Bind(&GCMClientImpl::OnMessageReceivedFromMCS, |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 void GCMClientImpl::ClearActivityLogs() { | 705 void GCMClientImpl::ClearActivityLogs() { |
705 recorder_.Clear(); | 706 recorder_.Clear(); |
706 } | 707 } |
707 | 708 |
708 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { | 709 GCMClient::GCMStatistics GCMClientImpl::GetStatistics() const { |
709 GCMClient::GCMStatistics stats; | 710 GCMClient::GCMStatistics stats; |
710 stats.gcm_client_created = true; | 711 stats.gcm_client_created = true; |
711 stats.is_recording = recorder_.is_recording(); | 712 stats.is_recording = recorder_.is_recording(); |
712 stats.gcm_client_state = GetStateString(); | 713 stats.gcm_client_state = GetStateString(); |
713 stats.connection_client_created = mcs_client_.get() != NULL; | 714 stats.connection_client_created = mcs_client_.get() != NULL; |
| 715 if (connection_factory_.get()) |
| 716 stats.connection_state = connection_factory_->GetConnectionStateString(); |
714 if (mcs_client_.get()) { | 717 if (mcs_client_.get()) { |
715 stats.connection_state = mcs_client_->GetStateString(); | |
716 stats.send_queue_size = mcs_client_->GetSendQueueSize(); | 718 stats.send_queue_size = mcs_client_->GetSendQueueSize(); |
717 stats.resend_queue_size = mcs_client_->GetResendQueueSize(); | 719 stats.resend_queue_size = mcs_client_->GetResendQueueSize(); |
718 } | 720 } |
719 if (device_checkin_info_.android_id > 0) | 721 if (device_checkin_info_.android_id > 0) |
720 stats.android_id = device_checkin_info_.android_id; | 722 stats.android_id = device_checkin_info_.android_id; |
721 recorder_.CollectActivities(&stats.recorded_activities); | 723 recorder_.CollectActivities(&stats.recorded_activities); |
722 | 724 |
723 for (RegistrationInfoMap::const_iterator it = registrations_.begin(); | 725 for (RegistrationInfoMap::const_iterator it = registrations_.begin(); |
724 it != registrations_.end(); ++it) { | 726 it != registrations_.end(); ++it) { |
725 stats.registered_app_ids.push_back(it->first); | 727 stats.registered_app_ids.push_back(it->first); |
726 } | 728 } |
727 return stats; | 729 return stats; |
728 } | 730 } |
729 | 731 |
730 void GCMClientImpl::OnActivityRecorded() { | 732 void GCMClientImpl::OnActivityRecorded() { |
731 delegate_->OnActivityRecorded(); | 733 delegate_->OnActivityRecorded(); |
732 } | 734 } |
733 | 735 |
| 736 void GCMClientImpl::OnConnected(const GURL& current_server, |
| 737 const net::IPEndPoint& ip_endpoint) { |
| 738 // TODO(zea): inform GCMClient::Delegate and app handlers as well. |
| 739 delegate_->OnActivityRecorded(); |
| 740 } |
| 741 |
| 742 void GCMClientImpl::OnDisconnected() { |
| 743 // TODO(zea): inform GCMClient::Delegate and app handlers as well. |
| 744 delegate_->OnActivityRecorded(); |
| 745 } |
| 746 |
734 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { | 747 void GCMClientImpl::OnMessageReceivedFromMCS(const gcm::MCSMessage& message) { |
735 switch (message.tag()) { | 748 switch (message.tag()) { |
736 case kLoginResponseTag: | 749 case kLoginResponseTag: |
737 DVLOG(1) << "Login response received by GCM Client. Ignoring."; | 750 DVLOG(1) << "Login response received by GCM Client. Ignoring."; |
738 return; | 751 return; |
739 case kDataMessageStanzaTag: | 752 case kDataMessageStanzaTag: |
740 DVLOG(1) << "A downstream message received. Processing..."; | 753 DVLOG(1) << "A downstream message received. Processing..."; |
741 HandleIncomingMessage(message); | 754 HandleIncomingMessage(message); |
742 return; | 755 return; |
743 default: | 756 default: |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 | 881 |
869 recorder_.RecordIncomingSendError( | 882 recorder_.RecordIncomingSendError( |
870 data_message_stanza.category(), | 883 data_message_stanza.category(), |
871 data_message_stanza.to(), | 884 data_message_stanza.to(), |
872 data_message_stanza.id()); | 885 data_message_stanza.id()); |
873 delegate_->OnMessageSendError(data_message_stanza.category(), | 886 delegate_->OnMessageSendError(data_message_stanza.category(), |
874 send_error_details); | 887 send_error_details); |
875 } | 888 } |
876 | 889 |
877 } // namespace gcm | 890 } // namespace gcm |
OLD | NEW |