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/callback_helpers.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 weak_factory_(this) { | 162 weak_factory_(this) { |
163 } | 163 } |
164 | 164 |
165 FakeStreamChannelFactory::~FakeStreamChannelFactory() {} | 165 FakeStreamChannelFactory::~FakeStreamChannelFactory() {} |
166 | 166 |
167 FakeStreamSocket* FakeStreamChannelFactory::GetFakeChannel( | 167 FakeStreamSocket* FakeStreamChannelFactory::GetFakeChannel( |
168 const std::string& name) { | 168 const std::string& name) { |
169 return channels_[name].get(); | 169 return channels_[name].get(); |
170 } | 170 } |
171 | 171 |
| 172 void FakeStreamChannelFactory::PairWith( |
| 173 FakeStreamChannelFactory* peer_factory) { |
| 174 peer_factory_ = peer_factory->weak_factory_.GetWeakPtr(); |
| 175 peer_factory->peer_factory_ = weak_factory_.GetWeakPtr(); |
| 176 } |
| 177 |
172 void FakeStreamChannelFactory::CreateChannel( | 178 void FakeStreamChannelFactory::CreateChannel( |
173 const std::string& name, | 179 const std::string& name, |
174 const ChannelCreatedCallback& callback) { | 180 const ChannelCreatedCallback& callback) { |
175 scoped_ptr<FakeStreamSocket> channel(new FakeStreamSocket()); | 181 scoped_ptr<FakeStreamSocket> channel(new FakeStreamSocket()); |
176 channels_[name] = channel->GetWeakPtr(); | 182 channels_[name] = channel->GetWeakPtr(); |
177 | 183 |
| 184 if (peer_factory_) { |
| 185 FakeStreamSocket* peer_channel = peer_factory_->GetFakeChannel(name); |
| 186 if (peer_channel) |
| 187 channel->PairWith(peer_channel); |
| 188 } |
| 189 |
178 if (fail_create_) | 190 if (fail_create_) |
179 channel.reset(); | 191 channel.reset(); |
180 | 192 |
181 if (asynchronous_create_) { | 193 if (asynchronous_create_) { |
182 task_runner_->PostTask(FROM_HERE, base::Bind( | 194 task_runner_->PostTask(FROM_HERE, base::Bind( |
183 &FakeStreamChannelFactory::NotifyChannelCreated, | 195 &FakeStreamChannelFactory::NotifyChannelCreated, |
184 weak_factory_.GetWeakPtr(), base::Passed(&channel), name, callback)); | 196 weak_factory_.GetWeakPtr(), base::Passed(&channel), name, callback)); |
185 } else { | 197 } else { |
186 NotifyChannelCreated(channel.Pass(), name, callback); | 198 NotifyChannelCreated(channel.Pass(), name, callback); |
187 } | 199 } |
188 } | 200 } |
189 | 201 |
190 void FakeStreamChannelFactory::NotifyChannelCreated( | 202 void FakeStreamChannelFactory::NotifyChannelCreated( |
191 scoped_ptr<FakeStreamSocket> owned_channel, | 203 scoped_ptr<FakeStreamSocket> owned_channel, |
192 const std::string& name, | 204 const std::string& name, |
193 const ChannelCreatedCallback& callback) { | 205 const ChannelCreatedCallback& callback) { |
194 if (channels_.find(name) != channels_.end()) | 206 if (channels_.find(name) != channels_.end()) |
195 callback.Run(owned_channel.Pass()); | 207 callback.Run(owned_channel.Pass()); |
196 } | 208 } |
197 | 209 |
198 void FakeStreamChannelFactory::CancelChannelCreation(const std::string& name) { | 210 void FakeStreamChannelFactory::CancelChannelCreation(const std::string& name) { |
199 channels_.erase(name); | 211 channels_.erase(name); |
200 } | 212 } |
201 | 213 |
202 } // namespace protocol | 214 } // namespace protocol |
203 } // namespace remoting | 215 } // namespace remoting |
OLD | NEW |