| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef BLIMP_NET_STREAM_PACKET_READER_H_ | 5 #ifndef BLIMP_NET_STREAM_PACKET_READER_H_ |
| 6 #define BLIMP_NET_STREAM_PACKET_READER_H_ | 6 #define BLIMP_NET_STREAM_PACKET_READER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "blimp/net/blimp_net_export.h" | 13 #include "blimp/net/blimp_net_export.h" |
| 14 #include "blimp/net/packet_reader.h" | 14 #include "blimp/net/packet_reader.h" |
| 15 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 16 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
| 17 | 17 |
| 18 namespace net { | 18 namespace net { |
| 19 class GrowableIOBuffer; | 19 class GrowableIOBuffer; |
| 20 class StreamSocket; | 20 class StreamSocket; |
| 21 } // namespace net | 21 } // namespace net |
| 22 | 22 |
| 23 namespace blimp { | 23 namespace blimp { |
| 24 class BlimpConnectionStatistics; |
| 24 | 25 |
| 25 // Reads opaque length-prefixed packets of bytes from a StreamSocket. | 26 // Reads opaque length-prefixed packets of bytes from a StreamSocket. |
| 26 // The header segment is 32-bit, encoded in network byte order. | 27 // The header segment is 32-bit, encoded in network byte order. |
| 27 // The body segment length is specified in the header (capped at | 28 // The body segment length is specified in the header (capped at |
| 28 // kMaxPacketPayloadSizeBytes). | 29 // kMaxPacketPayloadSizeBytes). |
| 29 class BLIMP_NET_EXPORT StreamPacketReader : public PacketReader { | 30 class BLIMP_NET_EXPORT StreamPacketReader : public PacketReader { |
| 30 public: | 31 public: |
| 31 // |socket|: The socket to read packets from. The caller must ensure |socket| | 32 // |socket|: The socket to read packets from. The caller must ensure |socket| |
| 32 // is valid while the reader is in-use (see ReadPacket below). | 33 // is valid while the reader is in-use (see ReadPacket below). |
| 33 explicit StreamPacketReader(net::StreamSocket* socket); | 34 // |statistics|: Statistics collector to keep track of number of bytes read. |
| 35 // |statistics| is expected to outlive |this|. |
| 36 StreamPacketReader(net::StreamSocket* socket, |
| 37 BlimpConnectionStatistics* statistics); |
| 34 | 38 |
| 35 ~StreamPacketReader() override; | 39 ~StreamPacketReader() override; |
| 36 | 40 |
| 37 // PacketReader implementation. | 41 // PacketReader implementation. |
| 38 void ReadPacket(const scoped_refptr<net::GrowableIOBuffer>& buf, | 42 void ReadPacket(const scoped_refptr<net::GrowableIOBuffer>& buf, |
| 39 const net::CompletionCallback& cb) override; | 43 const net::CompletionCallback& cb) override; |
| 40 | 44 |
| 41 private: | 45 private: |
| 42 enum class ReadState { | 46 enum class ReadState { |
| 43 IDLE, | 47 IDLE, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 ReadState read_state_; | 69 ReadState read_state_; |
| 66 | 70 |
| 67 net::StreamSocket* socket_; | 71 net::StreamSocket* socket_; |
| 68 | 72 |
| 69 // The size of the payload, in bytes. | 73 // The size of the payload, in bytes. |
| 70 size_t payload_size_; | 74 size_t payload_size_; |
| 71 | 75 |
| 72 scoped_refptr<net::GrowableIOBuffer> header_buffer_; | 76 scoped_refptr<net::GrowableIOBuffer> header_buffer_; |
| 73 scoped_refptr<net::GrowableIOBuffer> payload_buffer_; | 77 scoped_refptr<net::GrowableIOBuffer> payload_buffer_; |
| 74 net::CompletionCallback callback_; | 78 net::CompletionCallback callback_; |
| 79 BlimpConnectionStatistics* statistics_; |
| 75 | 80 |
| 76 base::WeakPtrFactory<StreamPacketReader> weak_factory_; | 81 base::WeakPtrFactory<StreamPacketReader> weak_factory_; |
| 77 | 82 |
| 78 DISALLOW_COPY_AND_ASSIGN(StreamPacketReader); | 83 DISALLOW_COPY_AND_ASSIGN(StreamPacketReader); |
| 79 }; | 84 }; |
| 80 | 85 |
| 81 } // namespace blimp | 86 } // namespace blimp |
| 82 | 87 |
| 83 #endif // BLIMP_NET_STREAM_PACKET_READER_H_ | 88 #endif // BLIMP_NET_STREAM_PACKET_READER_H_ |
| OLD | NEW |