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_stream_socket.h" | 5 #include "remoting/protocol/fake_stream_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 20 matching lines...) Expand all Loading... |
38 // Complete pending read if any. | 39 // Complete pending read if any. |
39 if (!read_callback_.is_null()) { | 40 if (!read_callback_.is_null()) { |
40 int result = std::min(read_buffer_size_, | 41 int result = std::min(read_buffer_size_, |
41 static_cast<int>(input_data_.size() - input_pos_)); | 42 static_cast<int>(input_data_.size() - input_pos_)); |
42 EXPECT_GT(result, 0); | 43 EXPECT_GT(result, 0); |
43 memcpy(read_buffer_->data(), | 44 memcpy(read_buffer_->data(), |
44 &(*input_data_.begin()) + input_pos_, result); | 45 &(*input_data_.begin()) + input_pos_, result); |
45 input_pos_ += result; | 46 input_pos_ += result; |
46 read_buffer_ = nullptr; | 47 read_buffer_ = nullptr; |
47 | 48 |
48 net::CompletionCallback callback = read_callback_; | 49 base::ResetAndReturn(&read_callback_).Run(result); |
49 read_callback_.Reset(); | |
50 callback.Run(result); | |
51 } | 50 } |
52 } | 51 } |
53 | 52 |
54 void FakeStreamSocket::PairWith(FakeStreamSocket* peer_socket) { | 53 void FakeStreamSocket::PairWith(FakeStreamSocket* peer_socket) { |
55 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); | 54 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
56 peer_socket_ = peer_socket->GetWeakPtr(); | 55 peer_socket_ = peer_socket->GetWeakPtr(); |
57 peer_socket->peer_socket_ = GetWeakPtr(); | 56 peer_socket->peer_socket_ = GetWeakPtr(); |
58 } | 57 } |
59 | 58 |
60 base::WeakPtr<FakeStreamSocket> FakeStreamSocket::GetWeakPtr() { | 59 base::WeakPtr<FakeStreamSocket> FakeStreamSocket::GetWeakPtr() { |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 if (channels_.find(name) != channels_.end()) | 267 if (channels_.find(name) != channels_.end()) |
269 callback.Run(owned_channel.Pass()); | 268 callback.Run(owned_channel.Pass()); |
270 } | 269 } |
271 | 270 |
272 void FakeStreamChannelFactory::CancelChannelCreation(const std::string& name) { | 271 void FakeStreamChannelFactory::CancelChannelCreation(const std::string& name) { |
273 channels_.erase(name); | 272 channels_.erase(name); |
274 } | 273 } |
275 | 274 |
276 } // namespace protocol | 275 } // namespace protocol |
277 } // namespace remoting | 276 } // namespace remoting |
OLD | NEW |