Chromium Code Reviews| 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). |
|
Kevin M
2016/05/24 21:49:00
Document |statistics| and the lifetime requirement
shaktisahu
2016/05/24 22:42:14
Done.
| |
| 33 explicit StreamPacketReader(net::StreamSocket* socket); | 34 explicit StreamPacketReader(net::StreamSocket* socket, |
| 35 BlimpConnectionStatistics* statistics); | |
| 34 | 36 |
| 35 ~StreamPacketReader() override; | 37 ~StreamPacketReader() override; |
| 36 | 38 |
| 37 // PacketReader implementation. | 39 // PacketReader implementation. |
| 38 void ReadPacket(const scoped_refptr<net::GrowableIOBuffer>& buf, | 40 void ReadPacket(const scoped_refptr<net::GrowableIOBuffer>& buf, |
| 39 const net::CompletionCallback& cb) override; | 41 const net::CompletionCallback& cb) override; |
| 40 | 42 |
| 41 private: | 43 private: |
| 42 enum class ReadState { | 44 enum class ReadState { |
| 43 IDLE, | 45 IDLE, |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 65 ReadState read_state_; | 67 ReadState read_state_; |
| 66 | 68 |
| 67 net::StreamSocket* socket_; | 69 net::StreamSocket* socket_; |
| 68 | 70 |
| 69 // The size of the payload, in bytes. | 71 // The size of the payload, in bytes. |
| 70 size_t payload_size_; | 72 size_t payload_size_; |
| 71 | 73 |
| 72 scoped_refptr<net::GrowableIOBuffer> header_buffer_; | 74 scoped_refptr<net::GrowableIOBuffer> header_buffer_; |
| 73 scoped_refptr<net::GrowableIOBuffer> payload_buffer_; | 75 scoped_refptr<net::GrowableIOBuffer> payload_buffer_; |
| 74 net::CompletionCallback callback_; | 76 net::CompletionCallback callback_; |
| 77 BlimpConnectionStatistics* statistics_; | |
| 75 | 78 |
| 76 base::WeakPtrFactory<StreamPacketReader> weak_factory_; | 79 base::WeakPtrFactory<StreamPacketReader> weak_factory_; |
| 77 | 80 |
| 78 DISALLOW_COPY_AND_ASSIGN(StreamPacketReader); | 81 DISALLOW_COPY_AND_ASSIGN(StreamPacketReader); |
| 79 }; | 82 }; |
| 80 | 83 |
| 81 } // namespace blimp | 84 } // namespace blimp |
| 82 | 85 |
| 83 #endif // BLIMP_NET_STREAM_PACKET_READER_H_ | 86 #endif // BLIMP_NET_STREAM_PACKET_READER_H_ |
| OLD | NEW |