| 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/engine/mcs_client.h" | 5 #include "google_apis/gcm/engine/mcs_client.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 DCHECK_EQ(CONNECTING, state_); | 525 DCHECK_EQ(CONNECTING, state_); |
| 526 mcs_proto::LoginResponse* login_response = | 526 mcs_proto::LoginResponse* login_response = |
| 527 reinterpret_cast<mcs_proto::LoginResponse*>(protobuf.get()); | 527 reinterpret_cast<mcs_proto::LoginResponse*>(protobuf.get()); |
| 528 DVLOG(1) << "Received login response:"; | 528 DVLOG(1) << "Received login response:"; |
| 529 DVLOG(1) << " Id: " << login_response->id(); | 529 DVLOG(1) << " Id: " << login_response->id(); |
| 530 DVLOG(1) << " Timestamp: " << login_response->server_timestamp(); | 530 DVLOG(1) << " Timestamp: " << login_response->server_timestamp(); |
| 531 if (login_response->has_error() && login_response->error().code() != 0) { | 531 if (login_response->has_error() && login_response->error().code() != 0) { |
| 532 state_ = UNINITIALIZED; | 532 state_ = UNINITIALIZED; |
| 533 DVLOG(1) << " Error code: " << login_response->error().code(); | 533 DVLOG(1) << " Error code: " << login_response->error().code(); |
| 534 DVLOG(1) << " Error message: " << login_response->error().message(); | 534 DVLOG(1) << " Error message: " << login_response->error().message(); |
| 535 LOG(ERROR) << "Failed to log in to GCM, resetting connection."; |
| 536 connection_factory_->SignalConnectionReset( |
| 537 ConnectionFactory::LOGIN_FAILURE); |
| 535 mcs_error_callback_.Run(); | 538 mcs_error_callback_.Run(); |
| 536 return; | 539 return; |
| 537 } | 540 } |
| 538 | 541 |
| 539 if (login_response->has_heartbeat_config()) { | 542 if (login_response->has_heartbeat_config()) { |
| 540 heartbeat_manager_.UpdateHeartbeatConfig( | 543 heartbeat_manager_.UpdateHeartbeatConfig( |
| 541 login_response->heartbeat_config()); | 544 login_response->heartbeat_config()); |
| 542 } | 545 } |
| 543 | 546 |
| 544 state_ = CONNECTED; | 547 state_ = CONNECTED; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 575 MCSMessage(kHeartbeatAckTag, mcs_proto::HeartbeatAck())); | 578 MCSMessage(kHeartbeatAckTag, mcs_proto::HeartbeatAck())); |
| 576 return; | 579 return; |
| 577 case kHeartbeatAckTag: | 580 case kHeartbeatAckTag: |
| 578 DCHECK_GE(stream_id_in_, 1U); | 581 DCHECK_GE(stream_id_in_, 1U); |
| 579 DVLOG(1) << "Received heartbeat ack."; | 582 DVLOG(1) << "Received heartbeat ack."; |
| 580 // Do nothing else, all messages act as heartbeat acks. | 583 // Do nothing else, all messages act as heartbeat acks. |
| 581 return; | 584 return; |
| 582 case kCloseTag: | 585 case kCloseTag: |
| 583 LOG(ERROR) << "Received close command, resetting connection."; | 586 LOG(ERROR) << "Received close command, resetting connection."; |
| 584 state_ = LOADED; | 587 state_ = LOADED; |
| 585 connection_factory_->SignalConnectionReset(); | 588 connection_factory_->SignalConnectionReset( |
| 589 ConnectionFactory::CLOSE_COMMAND); |
| 586 return; | 590 return; |
| 587 case kIqStanzaTag: { | 591 case kIqStanzaTag: { |
| 588 DCHECK_GE(stream_id_in_, 1U); | 592 DCHECK_GE(stream_id_in_, 1U); |
| 589 mcs_proto::IqStanza* iq_stanza = | 593 mcs_proto::IqStanza* iq_stanza = |
| 590 reinterpret_cast<mcs_proto::IqStanza*>(protobuf.get()); | 594 reinterpret_cast<mcs_proto::IqStanza*>(protobuf.get()); |
| 591 const mcs_proto::Extension& iq_extension = iq_stanza->extension(); | 595 const mcs_proto::Extension& iq_extension = iq_stanza->extension(); |
| 592 switch (iq_extension.id()) { | 596 switch (iq_extension.id()) { |
| 593 case kSelectiveAck: { | 597 case kSelectiveAck: { |
| 594 PersistentIdList acked_ids; | 598 PersistentIdList acked_ids; |
| 595 if (BuildPersistentIdListFromProto(iq_extension.data(), | 599 if (BuildPersistentIdListFromProto(iq_extension.data(), |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 acked_incoming_ids, | 730 acked_incoming_ids, |
| 727 base::Bind(&MCSClient::OnGCMUpdateFinished, | 731 base::Bind(&MCSClient::OnGCMUpdateFinished, |
| 728 weak_ptr_factory_.GetWeakPtr())); | 732 weak_ptr_factory_.GetWeakPtr())); |
| 729 } | 733 } |
| 730 | 734 |
| 731 MCSClient::PersistentId MCSClient::GetNextPersistentId() { | 735 MCSClient::PersistentId MCSClient::GetNextPersistentId() { |
| 732 return base::Uint64ToString(base::TimeTicks::Now().ToInternalValue()); | 736 return base::Uint64ToString(base::TimeTicks::Now().ToInternalValue()); |
| 733 } | 737 } |
| 734 | 738 |
| 735 void MCSClient::OnConnectionResetByHeartbeat() { | 739 void MCSClient::OnConnectionResetByHeartbeat() { |
| 736 connection_factory_->SignalConnectionReset(); | 740 connection_factory_->SignalConnectionReset( |
| 741 ConnectionFactory::HEARTBEAT_FAILURE); |
| 737 } | 742 } |
| 738 | 743 |
| 739 void MCSClient::NotifyMessageSendStatus( | 744 void MCSClient::NotifyMessageSendStatus( |
| 740 const google::protobuf::MessageLite& protobuf, | 745 const google::protobuf::MessageLite& protobuf, |
| 741 MessageSendStatus status) { | 746 MessageSendStatus status) { |
| 742 if (GetMCSProtoTag(protobuf) != kDataMessageStanzaTag) | 747 if (GetMCSProtoTag(protobuf) != kDataMessageStanzaTag) |
| 743 return; | 748 return; |
| 744 | 749 |
| 745 const mcs_proto::DataMessageStanza* data_message_stanza = | 750 const mcs_proto::DataMessageStanza* data_message_stanza = |
| 746 reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf); | 751 reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf); |
| 747 message_sent_callback_.Run( | 752 message_sent_callback_.Run( |
| 748 data_message_stanza->device_user_id(), | 753 data_message_stanza->device_user_id(), |
| 749 data_message_stanza->category(), | 754 data_message_stanza->category(), |
| 750 data_message_stanza->id(), | 755 data_message_stanza->id(), |
| 751 status); | 756 status); |
| 752 } | 757 } |
| 753 | 758 |
| 754 void MCSClient::SetGCMStoreForTesting(GCMStore* gcm_store) { | 759 void MCSClient::SetGCMStoreForTesting(GCMStore* gcm_store) { |
| 755 gcm_store_ = gcm_store; | 760 gcm_store_ = gcm_store; |
| 756 } | 761 } |
| 757 | 762 |
| 758 } // namespace gcm | 763 } // namespace gcm |
| OLD | NEW |