OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/fake_datagram_socket.h" | 5 #include "remoting/protocol/fake_datagram_socket.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback_helpers.h" |
8 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
9 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
10 #include "net/base/address_list.h" | 11 #include "net/base/address_list.h" |
11 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
12 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
13 #include "net/base/net_util.h" | 14 #include "net/base/net_util.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace remoting { | 17 namespace remoting { |
17 namespace protocol { | 18 namespace protocol { |
(...skipping 11 matching lines...) Expand all Loading... |
29 void FakeDatagramSocket::AppendInputPacket(const std::string& data) { | 30 void FakeDatagramSocket::AppendInputPacket(const std::string& data) { |
30 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); | 31 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
31 input_packets_.push_back(data); | 32 input_packets_.push_back(data); |
32 | 33 |
33 // Complete pending read if any. | 34 // Complete pending read if any. |
34 if (!read_callback_.is_null()) { | 35 if (!read_callback_.is_null()) { |
35 DCHECK_EQ(input_pos_, static_cast<int>(input_packets_.size()) - 1); | 36 DCHECK_EQ(input_pos_, static_cast<int>(input_packets_.size()) - 1); |
36 int result = CopyReadData(read_buffer_.get(), read_buffer_size_); | 37 int result = CopyReadData(read_buffer_.get(), read_buffer_size_); |
37 read_buffer_ = nullptr; | 38 read_buffer_ = nullptr; |
38 | 39 |
39 net::CompletionCallback callback = read_callback_; | 40 base::ResetAndReturn(&read_callback_).Run(result); |
40 read_callback_.Reset(); | |
41 callback.Run(result); | |
42 } | 41 } |
43 } | 42 } |
44 | 43 |
45 void FakeDatagramSocket::PairWith(FakeDatagramSocket* peer_socket) { | 44 void FakeDatagramSocket::PairWith(FakeDatagramSocket* peer_socket) { |
46 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); | 45 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
47 peer_socket_ = peer_socket->GetWeakPtr(); | 46 peer_socket_ = peer_socket->GetWeakPtr(); |
48 peer_socket->peer_socket_ = GetWeakPtr(); | 47 peer_socket->peer_socket_ = GetWeakPtr(); |
49 } | 48 } |
50 | 49 |
51 base::WeakPtr<FakeDatagramSocket> FakeDatagramSocket::GetWeakPtr() { | 50 base::WeakPtr<FakeDatagramSocket> FakeDatagramSocket::GetWeakPtr() { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 callback.Run(owned_socket.Pass()); | 160 callback.Run(owned_socket.Pass()); |
162 } | 161 } |
163 | 162 |
164 void FakeDatagramChannelFactory::CancelChannelCreation( | 163 void FakeDatagramChannelFactory::CancelChannelCreation( |
165 const std::string& name) { | 164 const std::string& name) { |
166 channels_.erase(name); | 165 channels_.erase(name); |
167 } | 166 } |
168 | 167 |
169 } // namespace protocol | 168 } // namespace protocol |
170 } // namespace remoting | 169 } // namespace remoting |
OLD | NEW |