| 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" | |
| 16 #include "remoting/base/compound_buffer.h" | 15 #include "remoting/base/compound_buffer.h" |
| 17 #include "remoting/proto/internal.pb.h" | 16 #include "remoting/proto/internal.pb.h" |
| 17 #include "remoting/protocol/p2p_stream_socket.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_(nullptr), | 25 : socket_(nullptr), |
| 26 read_pending_(false), | 26 read_pending_(false), |
| 27 pending_messages_(0), | 27 pending_messages_(0), |
| 28 closed_(false), | 28 closed_(false), |
| 29 weak_factory_(this) { | 29 weak_factory_(this) { |
| 30 } | 30 } |
| 31 | 31 |
| 32 MessageReader::~MessageReader() { | 32 MessageReader::~MessageReader() { |
| 33 } | 33 } |
| 34 | 34 |
| 35 void MessageReader::SetMessageReceivedCallback( | 35 void MessageReader::SetMessageReceivedCallback( |
| 36 const MessageReceivedCallback& callback) { | 36 const MessageReceivedCallback& callback) { |
| 37 DCHECK(CalledOnValidThread()); | 37 DCHECK(CalledOnValidThread()); |
| 38 message_received_callback_ = callback; | 38 message_received_callback_ = callback; |
| 39 } | 39 } |
| 40 | 40 |
| 41 void MessageReader::StartReading( | 41 void MessageReader::StartReading( |
| 42 net::Socket* socket, | 42 P2PStreamSocket* socket, |
| 43 const ReadFailedCallback& read_failed_callback) { | 43 const ReadFailedCallback& read_failed_callback) { |
| 44 DCHECK(CalledOnValidThread()); | 44 DCHECK(CalledOnValidThread()); |
| 45 DCHECK(socket); | 45 DCHECK(socket); |
| 46 DCHECK(!read_failed_callback.is_null()); | 46 DCHECK(!read_failed_callback.is_null()); |
| 47 | 47 |
| 48 socket_ = socket; | 48 socket_ = socket; |
| 49 read_failed_callback_ = read_failed_callback; | 49 read_failed_callback_ = read_failed_callback; |
| 50 DoRead(); | 50 DoRead(); |
| 51 } | 51 } |
| 52 | 52 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
| 136 pending_messages_--; | 136 pending_messages_--; |
| 137 DCHECK_GE(pending_messages_, 0); | 137 DCHECK_GE(pending_messages_, 0); |
| 138 | 138 |
| 139 // Start next read if necessary. | 139 // Start next read if necessary. |
| 140 DoRead(); | 140 DoRead(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 } // namespace protocol | 143 } // namespace protocol |
| 144 } // namespace remoting | 144 } // namespace remoting |
| OLD | NEW |