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 #include "remoting/protocol/message_reader.h" | 5 #include "remoting/protocol/message_reader.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
15 #include "net/socket/socket.h" | 15 #include "net/socket/socket.h" |
16 #include "remoting/base/compound_buffer.h" | 16 #include "remoting/base/compound_buffer.h" |
17 #include "remoting/proto/internal.pb.h" | 17 #include "remoting/proto/internal.pb.h" |
18 | 18 |
19 namespace remoting { | 19 namespace remoting { |
20 namespace protocol { | 20 namespace protocol { |
21 | 21 |
22 static const int kReadBufferSize = 4096; | 22 static const int kReadBufferSize = 4096; |
23 | 23 |
24 MessageReader::MessageReader() | 24 MessageReader::MessageReader() |
25 : socket_(NULL), | 25 : socket_(NULL), |
26 read_pending_(false), | 26 read_pending_(false), |
27 pending_messages_(0), | 27 pending_messages_(0), |
28 closed_(false), | 28 closed_(false), |
29 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | 29 weak_factory_(this) { |
30 } | 30 } |
31 | 31 |
32 void MessageReader::Init(net::Socket* socket, | 32 void MessageReader::Init(net::Socket* socket, |
33 const MessageReceivedCallback& callback) { | 33 const MessageReceivedCallback& callback) { |
34 DCHECK(CalledOnValidThread()); | 34 DCHECK(CalledOnValidThread()); |
35 message_received_callback_ = callback; | 35 message_received_callback_ = callback; |
36 DCHECK(socket); | 36 DCHECK(socket); |
37 socket_ = socket; | 37 socket_ = socket; |
38 DoRead(); | 38 DoRead(); |
39 } | 39 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 DCHECK(CalledOnValidThread()); | 112 DCHECK(CalledOnValidThread()); |
113 pending_messages_--; | 113 pending_messages_--; |
114 DCHECK_GE(pending_messages_, 0); | 114 DCHECK_GE(pending_messages_, 0); |
115 | 115 |
116 // Start next read if necessary. | 116 // Start next read if necessary. |
117 DoRead(); | 117 DoRead(); |
118 } | 118 } |
119 | 119 |
120 } // namespace protocol | 120 } // namespace protocol |
121 } // namespace remoting | 121 } // namespace remoting |
OLD | NEW |