| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 FakeDatagramSocket* FakeDatagramChannelFactory::GetFakeChannel( | 150 FakeDatagramSocket* FakeDatagramChannelFactory::GetFakeChannel( |
| 151 const std::string& name) { | 151 const std::string& name) { |
| 152 return channels_[name].get(); | 152 return channels_[name].get(); |
| 153 } | 153 } |
| 154 | 154 |
| 155 void FakeDatagramChannelFactory::CreateChannel( | 155 void FakeDatagramChannelFactory::CreateChannel( |
| 156 const std::string& name, | 156 const std::string& name, |
| 157 const ChannelCreatedCallback& callback) { | 157 const ChannelCreatedCallback& callback) { |
| 158 EXPECT_TRUE(channels_[name] == nullptr); | 158 EXPECT_TRUE(channels_[name] == nullptr); |
| 159 | 159 |
| 160 scoped_ptr<FakeDatagramSocket> channel(new FakeDatagramSocket()); | 160 std::unique_ptr<FakeDatagramSocket> channel(new FakeDatagramSocket()); |
| 161 channels_[name] = channel->GetWeakPtr(); | 161 channels_[name] = channel->GetWeakPtr(); |
| 162 | 162 |
| 163 if (peer_factory_) { | 163 if (peer_factory_) { |
| 164 FakeDatagramSocket* peer_socket = peer_factory_->GetFakeChannel(name); | 164 FakeDatagramSocket* peer_socket = peer_factory_->GetFakeChannel(name); |
| 165 if (peer_socket) | 165 if (peer_socket) |
| 166 channel->PairWith(peer_socket); | 166 channel->PairWith(peer_socket); |
| 167 } | 167 } |
| 168 | 168 |
| 169 if (fail_create_) | 169 if (fail_create_) |
| 170 channel.reset(); | 170 channel.reset(); |
| 171 | 171 |
| 172 if (asynchronous_create_) { | 172 if (asynchronous_create_) { |
| 173 task_runner_->PostTask( | 173 task_runner_->PostTask( |
| 174 FROM_HERE, | 174 FROM_HERE, |
| 175 base::Bind(&FakeDatagramChannelFactory::NotifyChannelCreated, | 175 base::Bind(&FakeDatagramChannelFactory::NotifyChannelCreated, |
| 176 weak_factory_.GetWeakPtr(), base::Passed(&channel), | 176 weak_factory_.GetWeakPtr(), base::Passed(&channel), |
| 177 name, callback)); | 177 name, callback)); |
| 178 } else { | 178 } else { |
| 179 NotifyChannelCreated(std::move(channel), name, callback); | 179 NotifyChannelCreated(std::move(channel), name, callback); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 void FakeDatagramChannelFactory::NotifyChannelCreated( | 183 void FakeDatagramChannelFactory::NotifyChannelCreated( |
| 184 scoped_ptr<FakeDatagramSocket> owned_socket, | 184 std::unique_ptr<FakeDatagramSocket> owned_socket, |
| 185 const std::string& name, | 185 const std::string& name, |
| 186 const ChannelCreatedCallback& callback) { | 186 const ChannelCreatedCallback& callback) { |
| 187 if (channels_.find(name) != channels_.end()) | 187 if (channels_.find(name) != channels_.end()) |
| 188 callback.Run(std::move(owned_socket)); | 188 callback.Run(std::move(owned_socket)); |
| 189 } | 189 } |
| 190 | 190 |
| 191 void FakeDatagramChannelFactory::CancelChannelCreation( | 191 void FakeDatagramChannelFactory::CancelChannelCreation( |
| 192 const std::string& name) { | 192 const std::string& name) { |
| 193 channels_.erase(name); | 193 channels_.erase(name); |
| 194 } | 194 } |
| 195 | 195 |
| 196 } // namespace protocol | 196 } // namespace protocol |
| 197 } // namespace remoting | 197 } // namespace remoting |
| OLD | NEW |