| 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/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
| 10 #include "net/base/address_list.h" | 10 #include "net/base/address_list.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 } | 27 } |
| 28 | 28 |
| 29 void FakeDatagramSocket::AppendInputPacket(const std::string& data) { | 29 void FakeDatagramSocket::AppendInputPacket(const std::string& data) { |
| 30 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); | 30 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
| 31 input_packets_.push_back(data); | 31 input_packets_.push_back(data); |
| 32 | 32 |
| 33 // Complete pending read if any. | 33 // Complete pending read if any. |
| 34 if (!read_callback_.is_null()) { | 34 if (!read_callback_.is_null()) { |
| 35 DCHECK_EQ(input_pos_, static_cast<int>(input_packets_.size()) - 1); | 35 DCHECK_EQ(input_pos_, static_cast<int>(input_packets_.size()) - 1); |
| 36 int result = CopyReadData(read_buffer_.get(), read_buffer_size_); | 36 int result = CopyReadData(read_buffer_.get(), read_buffer_size_); |
| 37 read_buffer_ = NULL; | 37 read_buffer_ = nullptr; |
| 38 | 38 |
| 39 net::CompletionCallback callback = read_callback_; | 39 net::CompletionCallback callback = read_callback_; |
| 40 read_callback_.Reset(); | 40 read_callback_.Reset(); |
| 41 callback.Run(result); | 41 callback.Run(result); |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 void FakeDatagramSocket::PairWith(FakeDatagramSocket* peer_socket) { | 45 void FakeDatagramSocket::PairWith(FakeDatagramSocket* peer_socket) { |
| 46 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); | 46 EXPECT_TRUE(task_runner_->BelongsToCurrentThread()); |
| 47 peer_socket_ = peer_socket->GetWeakPtr(); | 47 peer_socket_ = peer_socket->GetWeakPtr(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 FakeDatagramChannelFactory::FakeDatagramChannelFactory() | 103 FakeDatagramChannelFactory::FakeDatagramChannelFactory() |
| 104 : task_runner_(base::ThreadTaskRunnerHandle::Get()), | 104 : task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 105 asynchronous_create_(false), | 105 asynchronous_create_(false), |
| 106 fail_create_(false), | 106 fail_create_(false), |
| 107 weak_factory_(this) { | 107 weak_factory_(this) { |
| 108 } | 108 } |
| 109 | 109 |
| 110 FakeDatagramChannelFactory::~FakeDatagramChannelFactory() { | 110 FakeDatagramChannelFactory::~FakeDatagramChannelFactory() { |
| 111 for (ChannelsMap::iterator it = channels_.begin(); it != channels_.end(); | 111 for (ChannelsMap::iterator it = channels_.begin(); it != channels_.end(); |
| 112 ++it) { | 112 ++it) { |
| 113 EXPECT_TRUE(it->second == NULL); | 113 EXPECT_TRUE(it->second == nullptr); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 | 116 |
| 117 void FakeDatagramChannelFactory::PairWith( | 117 void FakeDatagramChannelFactory::PairWith( |
| 118 FakeDatagramChannelFactory* peer_factory) { | 118 FakeDatagramChannelFactory* peer_factory) { |
| 119 peer_factory_ = peer_factory->weak_factory_.GetWeakPtr(); | 119 peer_factory_ = peer_factory->weak_factory_.GetWeakPtr(); |
| 120 peer_factory_->peer_factory_ = weak_factory_.GetWeakPtr(); | 120 peer_factory_->peer_factory_ = weak_factory_.GetWeakPtr(); |
| 121 } | 121 } |
| 122 | 122 |
| 123 FakeDatagramSocket* FakeDatagramChannelFactory::GetFakeChannel( | 123 FakeDatagramSocket* FakeDatagramChannelFactory::GetFakeChannel( |
| 124 const std::string& name) { | 124 const std::string& name) { |
| 125 return channels_[name].get(); | 125 return channels_[name].get(); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void FakeDatagramChannelFactory::CreateChannel( | 128 void FakeDatagramChannelFactory::CreateChannel( |
| 129 const std::string& name, | 129 const std::string& name, |
| 130 const ChannelCreatedCallback& callback) { | 130 const ChannelCreatedCallback& callback) { |
| 131 EXPECT_TRUE(channels_[name] == NULL); | 131 EXPECT_TRUE(channels_[name] == nullptr); |
| 132 | 132 |
| 133 scoped_ptr<FakeDatagramSocket> channel(new FakeDatagramSocket()); | 133 scoped_ptr<FakeDatagramSocket> channel(new FakeDatagramSocket()); |
| 134 channels_[name] = channel->GetWeakPtr(); | 134 channels_[name] = channel->GetWeakPtr(); |
| 135 | 135 |
| 136 if (peer_factory_) { | 136 if (peer_factory_) { |
| 137 FakeDatagramSocket* peer_socket = peer_factory_->GetFakeChannel(name); | 137 FakeDatagramSocket* peer_socket = peer_factory_->GetFakeChannel(name); |
| 138 if (peer_socket) | 138 if (peer_socket) |
| 139 channel->PairWith(peer_socket); | 139 channel->PairWith(peer_socket); |
| 140 } | 140 } |
| 141 | 141 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 161 callback.Run(owned_socket.Pass()); | 161 callback.Run(owned_socket.Pass()); |
| 162 } | 162 } |
| 163 | 163 |
| 164 void FakeDatagramChannelFactory::CancelChannelCreation( | 164 void FakeDatagramChannelFactory::CancelChannelCreation( |
| 165 const std::string& name) { | 165 const std::string& name) { |
| 166 channels_.erase(name); | 166 channels_.erase(name); |
| 167 } | 167 } |
| 168 | 168 |
| 169 } // namespace protocol | 169 } // namespace protocol |
| 170 } // namespace remoting | 170 } // namespace remoting |
| OLD | NEW |