OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 REMOTING_PROTOCOL_MESSAGE_READER_H_ | 5 #ifndef REMOTING_PROTOCOL_MESSAGE_READER_H_ |
6 #define REMOTING_PROTOCOL_MESSAGE_READER_H_ | 6 #define REMOTING_PROTOCOL_MESSAGE_READER_H_ |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 // processed by the receiver (|done_task| is called for each message). | 34 // processed by the receiver (|done_task| is called for each message). |
35 // It is still possible that the MessageReceivedCallback is called | 35 // It is still possible that the MessageReceivedCallback is called |
36 // twice (so that there is more than one outstanding message), | 36 // twice (so that there is more than one outstanding message), |
37 // e.g. when we the sender sends multiple messages in one TCP packet. | 37 // e.g. when we the sender sends multiple messages in one TCP packet. |
38 class MessageReader : public base::RefCountedThreadSafe<MessageReader> { | 38 class MessageReader : public base::RefCountedThreadSafe<MessageReader> { |
39 public: | 39 public: |
40 typedef base::Callback<void(scoped_ptr<CompoundBuffer>, const base::Closure&)> | 40 typedef base::Callback<void(scoped_ptr<CompoundBuffer>, const base::Closure&)> |
41 MessageReceivedCallback; | 41 MessageReceivedCallback; |
42 | 42 |
43 MessageReader(); | 43 MessageReader(); |
44 virtual ~MessageReader(); | |
45 | 44 |
46 // Initialize the MessageReader with a socket. If a message is received | 45 // Initialize the MessageReader with a socket. If a message is received |
47 // |callback| is called. | 46 // |callback| is called. |
48 void Init(net::Socket* socket, const MessageReceivedCallback& callback); | 47 void Init(net::Socket* socket, const MessageReceivedCallback& callback); |
49 | 48 |
50 private: | 49 private: |
| 50 friend class base::RefCountedThreadSafe<MessageReader>; |
| 51 virtual ~MessageReader(); |
| 52 |
51 void DoRead(); | 53 void DoRead(); |
52 void OnRead(int result); | 54 void OnRead(int result); |
53 void HandleReadResult(int result); | 55 void HandleReadResult(int result); |
54 void OnDataReceived(net::IOBuffer* data, int data_size); | 56 void OnDataReceived(net::IOBuffer* data, int data_size); |
55 void OnMessageDone(scoped_refptr<base::MessageLoopProxy> message_loop); | 57 void OnMessageDone(scoped_refptr<base::MessageLoopProxy> message_loop); |
56 void ProcessDoneEvent(); | 58 void ProcessDoneEvent(); |
57 | 59 |
58 net::Socket* socket_; | 60 net::Socket* socket_; |
59 | 61 |
60 // Set to true, when we have a socket read pending, and expecting | 62 // Set to true, when we have a socket read pending, and expecting |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 112 } |
111 | 113 |
112 scoped_refptr<MessageReader> message_reader_; | 114 scoped_refptr<MessageReader> message_reader_; |
113 MessageReceivedCallback message_received_callback_; | 115 MessageReceivedCallback message_received_callback_; |
114 }; | 116 }; |
115 | 117 |
116 } // namespace protocol | 118 } // namespace protocol |
117 } // namespace remoting | 119 } // namespace remoting |
118 | 120 |
119 #endif // REMOTING_PROTOCOL_MESSAGE_READER_H_ | 121 #endif // REMOTING_PROTOCOL_MESSAGE_READER_H_ |
OLD | NEW |