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

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

Issue 383993006: [GCM] Add a SelectiveAck test for midstream acks (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 <set> 7 #include <set>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 acked_outgoing_persistent_ids, 763 acked_outgoing_persistent_ids,
764 base::Bind(&MCSClient::OnGCMUpdateFinished, 764 base::Bind(&MCSClient::OnGCMUpdateFinished,
765 weak_ptr_factory_.GetWeakPtr())); 765 weak_ptr_factory_.GetWeakPtr()));
766 766
767 HandleServerConfirmedReceipt(last_stream_id_received); 767 HandleServerConfirmedReceipt(last_stream_id_received);
768 } 768 }
769 769
770 void MCSClient::HandleSelectiveAck(const PersistentIdList& id_list) { 770 void MCSClient::HandleSelectiveAck(const PersistentIdList& id_list) {
771 std::set<PersistentId> remaining_ids(id_list.begin(), id_list.end()); 771 std::set<PersistentId> remaining_ids(id_list.begin(), id_list.end());
772 772
773 StreamId last_stream_id_received = -1; 773 StreamId last_stream_id_received = 0;
774 774
775 // First check the to_resend_ queue. Acknowledgments are always contiguous, 775 // First check the to_resend_ queue. Acknowledgments are always contiguous,
776 // so if there's a pending message that hasn't been acked, all newer messages 776 // so if there's a pending message that hasn't been acked, all newer messages
777 // must also be unacked. 777 // must also be unacked.
778 while(!to_resend_.empty() && !remaining_ids.empty()) { 778 while(!to_resend_.empty() && !remaining_ids.empty()) {
779 const MCSPacketInternal& outgoing_packet = to_resend_.front(); 779 const MCSPacketInternal& outgoing_packet = to_resend_.front();
780 if (remaining_ids.count(outgoing_packet->persistent_id) == 0) 780 if (remaining_ids.count(outgoing_packet->persistent_id) == 0)
781 break; // Newer message must be unacked too. 781 break; // Newer message must be unacked too.
782 remaining_ids.erase(outgoing_packet->persistent_id); 782 remaining_ids.erase(outgoing_packet->persistent_id);
783 NotifyMessageSendStatus(*outgoing_packet->protobuf, SENT); 783 NotifyMessageSendStatus(*outgoing_packet->protobuf, SENT);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 base::Bind(&MCSClient::OnGCMUpdateFinished, 832 base::Bind(&MCSClient::OnGCMUpdateFinished,
833 weak_ptr_factory_.GetWeakPtr())); 833 weak_ptr_factory_.GetWeakPtr()));
834 834
835 // Resend any remaining outgoing messages, as they were not received by the 835 // Resend any remaining outgoing messages, as they were not received by the
836 // server. 836 // server.
837 DVLOG(1) << "Resending " << to_resend_.size() << " messages."; 837 DVLOG(1) << "Resending " << to_resend_.size() << " messages.";
838 while (!to_resend_.empty()) { 838 while (!to_resend_.empty()) {
839 to_send_.push_front(to_resend_.back()); 839 to_send_.push_front(to_resend_.back());
840 to_resend_.pop_back(); 840 to_resend_.pop_back();
841 } 841 }
842 base::MessageLoop::current()->PostTask(
fgorski 2014/07/14 20:59:35 Add comment why this is added.
Nicolas Zea 2014/07/14 21:16:17 The above comment applies to this. We're resending
fgorski 2014/07/15 04:07:58 Fair enough, comment was cut by the diff view I wa
843 FROM_HERE,
844 base::Bind(&MCSClient::MaybeSendMessage,
845 weak_ptr_factory_.GetWeakPtr()));
842 } 846 }
843 847
844 void MCSClient::HandleServerConfirmedReceipt(StreamId device_stream_id) { 848 void MCSClient::HandleServerConfirmedReceipt(StreamId device_stream_id) {
845 PersistentIdList acked_incoming_ids; 849 PersistentIdList acked_incoming_ids;
846 for (std::map<StreamId, PersistentIdList>::iterator iter = 850 for (std::map<StreamId, PersistentIdList>::iterator iter =
847 acked_server_ids_.begin(); 851 acked_server_ids_.begin();
848 iter != acked_server_ids_.end() && 852 iter != acked_server_ids_.end() &&
849 iter->first <= device_stream_id;) { 853 iter->first <= device_stream_id;) {
850 acked_incoming_ids.insert(acked_incoming_ids.end(), 854 acked_incoming_ids.insert(acked_incoming_ids.end(),
851 iter->second.begin(), 855 iter->second.begin(),
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 reinterpret_cast<mcs_proto::DataMessageStanza*>(packet->protobuf.get()); 905 reinterpret_cast<mcs_proto::DataMessageStanza*>(packet->protobuf.get());
902 CollapseKey collapse_key(*data_message); 906 CollapseKey collapse_key(*data_message);
903 if (collapse_key.IsValid()) 907 if (collapse_key.IsValid())
904 collapse_key_map_.erase(collapse_key); 908 collapse_key_map_.erase(collapse_key);
905 } 909 }
906 910
907 return packet; 911 return packet;
908 } 912 }
909 913
910 } // namespace gcm 914 } // namespace gcm
OLDNEW
« no previous file with comments | « no previous file | google_apis/gcm/engine/mcs_client_unittest.cc » ('j') | google_apis/gcm/engine/mcs_client_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698