| 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/connection_handler.h" | 5 #include "google_apis/gcm/engine/connection_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 // ---- Helpers for building messages. ---- | 45 // ---- Helpers for building messages. ---- |
| 46 | 46 |
| 47 // Encode a protobuf packet with protobuf type |tag| and serialized protobuf | 47 // Encode a protobuf packet with protobuf type |tag| and serialized protobuf |
| 48 // bytes |proto| into the MCS message form (tag + varint size + bytes). | 48 // bytes |proto| into the MCS message form (tag + varint size + bytes). |
| 49 std::string EncodePacket(uint8 tag, const std::string& proto) { | 49 std::string EncodePacket(uint8 tag, const std::string& proto) { |
| 50 std::string result; | 50 std::string result; |
| 51 google::protobuf::io::StringOutputStream string_output_stream(&result); | 51 google::protobuf::io::StringOutputStream string_output_stream(&result); |
| 52 google::protobuf::io::CodedOutputStream coded_output_stream( | 52 google::protobuf::io::CodedOutputStream coded_output_stream( |
| 53 &string_output_stream); | 53 &string_output_stream); |
| 54 const char tag_byte[1] = {tag}; | 54 const unsigned char tag_byte[1] = {tag}; |
| 55 coded_output_stream.WriteRaw(tag_byte, 1); | 55 coded_output_stream.WriteRaw(tag_byte, 1); |
| 56 coded_output_stream.WriteVarint32(proto.size()); | 56 coded_output_stream.WriteVarint32(proto.size()); |
| 57 coded_output_stream.WriteRaw(proto.c_str(), proto.size()); | 57 coded_output_stream.WriteRaw(proto.c_str(), proto.size()); |
| 58 return result; | 58 return result; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Encode a handshake request into the MCS message form. | 61 // Encode a handshake request into the MCS message form. |
| 62 std::string EncodeHandshakeRequest() { | 62 std::string EncodeHandshakeRequest() { |
| 63 std::string result; | 63 std::string result; |
| 64 const char version_byte[1] = {kMCSVersion}; | 64 const char version_byte[1] = {kMCSVersion}; |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 data_message.set_category(kDataMsgCategory); | 617 data_message.set_category(kDataMsgCategory); |
| 618 connection_handler()->SendMessage(data_message); | 618 connection_handler()->SendMessage(data_message); |
| 619 EXPECT_FALSE(connection_handler()->CanSendMessage()); | 619 EXPECT_FALSE(connection_handler()->CanSendMessage()); |
| 620 WaitForMessage(); // The message send. Should result in an error | 620 WaitForMessage(); // The message send. Should result in an error |
| 621 EXPECT_FALSE(connection_handler()->CanSendMessage()); | 621 EXPECT_FALSE(connection_handler()->CanSendMessage()); |
| 622 EXPECT_EQ(net::ERR_CONNECTION_CLOSED, last_error()); | 622 EXPECT_EQ(net::ERR_CONNECTION_CLOSED, last_error()); |
| 623 } | 623 } |
| 624 | 624 |
| 625 } // namespace | 625 } // namespace |
| 626 } // namespace gcm | 626 } // namespace gcm |
| OLD | NEW |