Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(626)

Side by Side Diff: google_apis/gcm/engine/mcs_client.cc

Issue 160703002: [GCM] Track connection failures properly (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix comment Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 DCHECK_EQ(CONNECTING, state_); 529 DCHECK_EQ(CONNECTING, state_);
530 mcs_proto::LoginResponse* login_response = 530 mcs_proto::LoginResponse* login_response =
531 reinterpret_cast<mcs_proto::LoginResponse*>(protobuf.get()); 531 reinterpret_cast<mcs_proto::LoginResponse*>(protobuf.get());
532 DVLOG(1) << "Received login response:"; 532 DVLOG(1) << "Received login response:";
533 DVLOG(1) << " Id: " << login_response->id(); 533 DVLOG(1) << " Id: " << login_response->id();
534 DVLOG(1) << " Timestamp: " << login_response->server_timestamp(); 534 DVLOG(1) << " Timestamp: " << login_response->server_timestamp();
535 if (login_response->has_error() && login_response->error().code() != 0) { 535 if (login_response->has_error() && login_response->error().code() != 0) {
536 state_ = UNINITIALIZED; 536 state_ = UNINITIALIZED;
537 DVLOG(1) << " Error code: " << login_response->error().code(); 537 DVLOG(1) << " Error code: " << login_response->error().code();
538 DVLOG(1) << " Error message: " << login_response->error().message(); 538 DVLOG(1) << " Error message: " << login_response->error().message();
539 LOG(ERROR) << "Failed to log in to GCM, resetting connection.";
540 connection_factory_->SignalConnectionReset(
541 ConnectionFactory::LOGIN_FAILURE);
539 mcs_error_callback_.Run(); 542 mcs_error_callback_.Run();
540 return; 543 return;
541 } 544 }
542 545
543 if (login_response->has_heartbeat_config()) { 546 if (login_response->has_heartbeat_config()) {
544 heartbeat_manager_.UpdateHeartbeatConfig( 547 heartbeat_manager_.UpdateHeartbeatConfig(
545 login_response->heartbeat_config()); 548 login_response->heartbeat_config());
546 } 549 }
547 550
548 state_ = CONNECTED; 551 state_ = CONNECTED;
(...skipping 30 matching lines...) Expand all
579 MCSMessage(kHeartbeatAckTag, mcs_proto::HeartbeatAck())); 582 MCSMessage(kHeartbeatAckTag, mcs_proto::HeartbeatAck()));
580 return; 583 return;
581 case kHeartbeatAckTag: 584 case kHeartbeatAckTag:
582 DCHECK_GE(stream_id_in_, 1U); 585 DCHECK_GE(stream_id_in_, 1U);
583 DVLOG(1) << "Received heartbeat ack."; 586 DVLOG(1) << "Received heartbeat ack.";
584 // Do nothing else, all messages act as heartbeat acks. 587 // Do nothing else, all messages act as heartbeat acks.
585 return; 588 return;
586 case kCloseTag: 589 case kCloseTag:
587 LOG(ERROR) << "Received close command, resetting connection."; 590 LOG(ERROR) << "Received close command, resetting connection.";
588 state_ = LOADED; 591 state_ = LOADED;
589 connection_factory_->SignalConnectionReset(); 592 connection_factory_->SignalConnectionReset(
593 ConnectionFactory::CLOSE_COMMAND);
590 return; 594 return;
591 case kIqStanzaTag: { 595 case kIqStanzaTag: {
592 DCHECK_GE(stream_id_in_, 1U); 596 DCHECK_GE(stream_id_in_, 1U);
593 mcs_proto::IqStanza* iq_stanza = 597 mcs_proto::IqStanza* iq_stanza =
594 reinterpret_cast<mcs_proto::IqStanza*>(protobuf.get()); 598 reinterpret_cast<mcs_proto::IqStanza*>(protobuf.get());
595 const mcs_proto::Extension& iq_extension = iq_stanza->extension(); 599 const mcs_proto::Extension& iq_extension = iq_stanza->extension();
596 switch (iq_extension.id()) { 600 switch (iq_extension.id()) {
597 case kSelectiveAck: { 601 case kSelectiveAck: {
598 PersistentIdList acked_ids; 602 PersistentIdList acked_ids;
599 if (BuildPersistentIdListFromProto(iq_extension.data(), 603 if (BuildPersistentIdListFromProto(iq_extension.data(),
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 acked_incoming_ids, 734 acked_incoming_ids,
731 base::Bind(&MCSClient::OnGCMUpdateFinished, 735 base::Bind(&MCSClient::OnGCMUpdateFinished,
732 weak_ptr_factory_.GetWeakPtr())); 736 weak_ptr_factory_.GetWeakPtr()));
733 } 737 }
734 738
735 MCSClient::PersistentId MCSClient::GetNextPersistentId() { 739 MCSClient::PersistentId MCSClient::GetNextPersistentId() {
736 return base::Uint64ToString(base::TimeTicks::Now().ToInternalValue()); 740 return base::Uint64ToString(base::TimeTicks::Now().ToInternalValue());
737 } 741 }
738 742
739 void MCSClient::OnConnectionResetByHeartbeat() { 743 void MCSClient::OnConnectionResetByHeartbeat() {
740 connection_factory_->SignalConnectionReset(); 744 connection_factory_->SignalConnectionReset(
745 ConnectionFactory::HEARTBEAT_FAILURE);
741 } 746 }
742 747
743 void MCSClient::NotifyMessageSendStatus( 748 void MCSClient::NotifyMessageSendStatus(
744 const google::protobuf::MessageLite& protobuf, 749 const google::protobuf::MessageLite& protobuf,
745 MessageSendStatus status) { 750 MessageSendStatus status) {
746 if (GetMCSProtoTag(protobuf) != kDataMessageStanzaTag) 751 if (GetMCSProtoTag(protobuf) != kDataMessageStanzaTag)
747 return; 752 return;
748 753
749 const mcs_proto::DataMessageStanza* data_message_stanza = 754 const mcs_proto::DataMessageStanza* data_message_stanza =
750 reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf); 755 reinterpret_cast<const mcs_proto::DataMessageStanza*>(&protobuf);
751 message_sent_callback_.Run( 756 message_sent_callback_.Run(
752 data_message_stanza->device_user_id(), 757 data_message_stanza->device_user_id(),
753 data_message_stanza->category(), 758 data_message_stanza->category(),
754 data_message_stanza->id(), 759 data_message_stanza->id(),
755 status); 760 status);
756 } 761 }
757 762
758 void MCSClient::SetGCMStoreForTesting(GCMStore* gcm_store) { 763 void MCSClient::SetGCMStoreForTesting(GCMStore* gcm_store) {
759 gcm_store_ = gcm_store; 764 gcm_store_ = gcm_store;
760 } 765 }
761 766
762 } // namespace gcm 767 } // namespace gcm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698