| 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_BLIMP_MESSAGE_PUMP_H_ | 5 #ifndef BLIMP_NET_BLIMP_MESSAGE_PUMP_H_ |
| 6 #define BLIMP_NET_BLIMP_MESSAGE_PUMP_H_ | 6 #define BLIMP_NET_BLIMP_MESSAGE_PUMP_H_ |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "blimp/net/blimp_net_export.h" | 11 #include "blimp/net/blimp_net_export.h" |
| 12 #include "net/base/completion_callback.h" | 12 #include "net/base/completion_callback.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 class GrowableIOBuffer; | 15 class GrowableIOBuffer; |
| 16 } | 16 } |
| 17 | 17 |
| 18 namespace blimp { | 18 namespace blimp { |
| 19 | 19 |
| 20 class BlimpMessageProcessor; | 20 class BlimpMessageProcessor; |
| 21 class ConnectionErrorObserver; | 21 class ConnectionErrorObserver; |
| 22 class PacketReader; | 22 class PacketReader; |
| 23 | 23 |
| 24 // Reads and deserializes incoming packets from |reader_|, and forwards parsed | 24 // Reads and deserializes incoming packets from |reader_|, and forwards parsed |
| 25 // BlimpMessages to |processor_|. When |processor_| is ready to take the next | 25 // BlimpMessages to |processor_|. When |processor_| is ready to take the next |
| 26 // message, the BlimpMessagePump reads the next packet. | 26 // message, the BlimpMessagePump reads the next packet. |
| 27 class BLIMP_NET_EXPORT BlimpMessagePump { | 27 class BLIMP_NET_EXPORT BlimpMessagePump { |
| 28 public: | 28 public: |
| 29 // Caller ensures |reader| outlive this object. | 29 // Caller ensures that |reader| outlives this object. |
| 30 explicit BlimpMessagePump(PacketReader* reader); | 30 explicit BlimpMessagePump(PacketReader* reader); |
| 31 | 31 |
| 32 ~BlimpMessagePump(); | 32 ~BlimpMessagePump(); |
| 33 | 33 |
| 34 // Sets the processor which will take blimp messages. | 34 // Sets the processor which will take BlimpMessages. Can only be set once. |
| 35 // Can be set multiple times, but previously set processors are discarded. | |
| 36 // Caller retains the ownership of |processor|. | 35 // Caller retains the ownership of |processor|. |
| 37 void SetMessageProcessor(BlimpMessageProcessor* processor); | 36 void SetMessageProcessor(BlimpMessageProcessor* processor); |
| 38 | 37 |
| 39 void set_error_observer(ConnectionErrorObserver* observer) { | 38 void set_error_observer(ConnectionErrorObserver* observer) { |
| 40 error_observer_ = observer; | 39 error_observer_ = observer; |
| 41 } | 40 } |
| 42 | 41 |
| 43 private: | 42 private: |
| 44 // Read next packet from |reader_|. | 43 // Read next packet from |reader_|. |
| 45 void ReadNextPacket(); | 44 void ReadNextPacket(); |
| 46 | 45 |
| 47 // Callback when next packet is ready in |buffer_|. | 46 // Callback when next packet is ready in |buffer_|. |
| 48 void OnReadPacketComplete(int result); | 47 void OnReadPacketComplete(int result); |
| 49 | 48 |
| 50 // Callback when |processor_| finishes processing a blimp message. | 49 // Callback when |processor_| finishes processing a BlimpMessage. |
| 51 void OnProcessMessageComplete(int result); | 50 void OnProcessMessageComplete(int result); |
| 52 | 51 |
| 53 PacketReader* reader_; | 52 PacketReader* reader_; |
| 54 ConnectionErrorObserver* error_observer_; | 53 ConnectionErrorObserver* error_observer_; |
| 55 BlimpMessageProcessor* processor_; | 54 BlimpMessageProcessor* processor_; |
| 56 scoped_refptr<net::GrowableIOBuffer> buffer_; | 55 scoped_refptr<net::GrowableIOBuffer> buffer_; |
| 57 net::CancelableCompletionCallback read_packet_callback_; | 56 |
| 57 // Cancelled in the event that the connection is destroyed (along with |
| 58 // |this|) while a inflight callback is held by |processor_|. |
| 58 net::CancelableCompletionCallback process_msg_callback_; | 59 net::CancelableCompletionCallback process_msg_callback_; |
| 59 | 60 |
| 61 // Cancelled to guard against |this| being called back from a completed read |
| 62 // operation. |
| 63 net::CancelableCompletionCallback read_callback_; |
| 64 |
| 60 DISALLOW_COPY_AND_ASSIGN(BlimpMessagePump); | 65 DISALLOW_COPY_AND_ASSIGN(BlimpMessagePump); |
| 61 }; | 66 }; |
| 62 | 67 |
| 63 } // namespace blimp | 68 } // namespace blimp |
| 64 | 69 |
| 65 #endif // BLIMP_NET_BLIMP_MESSAGE_PUMP_H_ | 70 #endif // BLIMP_NET_BLIMP_MESSAGE_PUMP_H_ |
| OLD | NEW |