OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_session.h" | 5 #include "remoting/protocol/fake_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "net/base/address_list.h" | 9 #include "net/base/address_list.h" |
10 #include "net/base/io_buffer.h" | 10 #include "net/base/io_buffer.h" |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 } | 277 } |
278 bool FakeUdpSocket::SetSendBufferSize(int32 size) { | 278 bool FakeUdpSocket::SetSendBufferSize(int32 size) { |
279 NOTIMPLEMENTED(); | 279 NOTIMPLEMENTED(); |
280 return false; | 280 return false; |
281 } | 281 } |
282 | 282 |
283 FakeSession::FakeSession() | 283 FakeSession::FakeSession() |
284 : event_handler_(NULL), | 284 : event_handler_(NULL), |
285 candidate_config_(CandidateSessionConfig::CreateDefault()), | 285 candidate_config_(CandidateSessionConfig::CreateDefault()), |
286 config_(SessionConfig::GetDefault()), | 286 config_(SessionConfig::GetDefault()), |
287 message_loop_(NULL), | 287 message_loop_(MessageLoop::current()), |
| 288 async_creation_(false), |
288 jid_(kTestJid), | 289 jid_(kTestJid), |
289 error_(OK), | 290 error_(OK), |
290 closed_(false) { | 291 closed_(false), |
| 292 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
291 } | 293 } |
292 | 294 |
293 FakeSession::~FakeSession() { } | 295 FakeSession::~FakeSession() { } |
294 | 296 |
295 FakeSocket* FakeSession::GetStreamChannel(const std::string& name) { | 297 FakeSocket* FakeSession::GetStreamChannel(const std::string& name) { |
296 return stream_channels_[name]; | 298 return stream_channels_[name]; |
297 } | 299 } |
298 | 300 |
299 FakeUdpSocket* FakeSession::GetDatagramChannel(const std::string& name) { | 301 FakeUdpSocket* FakeSession::GetDatagramChannel(const std::string& name) { |
300 return datagram_channels_[name]; | 302 return datagram_channels_[name]; |
(...skipping 29 matching lines...) Expand all Loading... |
330 | 332 |
331 ChannelFactory* FakeSession::GetMultiplexedChannelFactory() { | 333 ChannelFactory* FakeSession::GetMultiplexedChannelFactory() { |
332 return this; | 334 return this; |
333 } | 335 } |
334 | 336 |
335 void FakeSession::Close() { | 337 void FakeSession::Close() { |
336 closed_ = true; | 338 closed_ = true; |
337 } | 339 } |
338 | 340 |
339 void FakeSession::CreateStreamChannel( | 341 void FakeSession::CreateStreamChannel( |
340 const std::string& name, const StreamChannelCallback& callback) { | 342 const std::string& name, |
341 scoped_ptr<FakeSocket> channel(new FakeSocket()); | 343 const StreamChannelCallback& callback) { |
342 stream_channels_[name] = channel.get(); | 344 scoped_ptr<FakeSocket> channel; |
343 callback.Run(channel.PassAs<net::StreamSocket>()); | 345 // If we are in the error state then we put NULL in the channels list, so that |
| 346 // NotifyStreamChannelCallback() still calls the callback. |
| 347 if (error_ == OK) |
| 348 channel.reset(new FakeSocket()); |
| 349 stream_channels_[name] = channel.release(); |
| 350 |
| 351 if (async_creation_) { |
| 352 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 353 &FakeSession::NotifyStreamChannelCallback, weak_factory_.GetWeakPtr(), |
| 354 name, callback)); |
| 355 } else { |
| 356 NotifyStreamChannelCallback(name, callback); |
| 357 } |
| 358 } |
| 359 |
| 360 void FakeSession::NotifyStreamChannelCallback( |
| 361 const std::string& name, |
| 362 const StreamChannelCallback& callback) { |
| 363 if (stream_channels_.find(name) != stream_channels_.end()) |
| 364 callback.Run(scoped_ptr<net::StreamSocket>(stream_channels_[name])); |
344 } | 365 } |
345 | 366 |
346 void FakeSession::CreateDatagramChannel( | 367 void FakeSession::CreateDatagramChannel( |
347 const std::string& name, const DatagramChannelCallback& callback) { | 368 const std::string& name, |
348 scoped_ptr<FakeUdpSocket> channel(new FakeUdpSocket()); | 369 const DatagramChannelCallback& callback) { |
349 datagram_channels_[name] = channel.get(); | 370 scoped_ptr<FakeUdpSocket> channel; |
350 callback.Run(channel.PassAs<net::Socket>()); | 371 // If we are in the error state then we put NULL in the channels list, so that |
| 372 // NotifyStreamChannelCallback() still calls the callback. |
| 373 if (error_ == OK) |
| 374 channel.reset(new FakeUdpSocket()); |
| 375 datagram_channels_[name] = channel.release(); |
| 376 |
| 377 if (async_creation_) { |
| 378 message_loop_->PostTask(FROM_HERE, base::Bind( |
| 379 &FakeSession::NotifyDatagramChannelCallback, weak_factory_.GetWeakPtr(), |
| 380 name, callback)); |
| 381 } else { |
| 382 NotifyDatagramChannelCallback(name, callback); |
| 383 } |
| 384 } |
| 385 |
| 386 void FakeSession::NotifyDatagramChannelCallback( |
| 387 const std::string& name, |
| 388 const DatagramChannelCallback& callback) { |
| 389 if (datagram_channels_.find(name) != datagram_channels_.end()) |
| 390 callback.Run(scoped_ptr<net::Socket>(datagram_channels_[name])); |
351 } | 391 } |
352 | 392 |
353 void FakeSession::CancelChannelCreation(const std::string& name) { | 393 void FakeSession::CancelChannelCreation(const std::string& name) { |
| 394 stream_channels_.erase(name); |
| 395 datagram_channels_.erase(name); |
354 } | 396 } |
355 | 397 |
356 } // namespace protocol | 398 } // namespace protocol |
357 } // namespace remoting | 399 } // namespace remoting |
OLD | NEW |