Chromium Code Reviews| 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 (error_ == OK) |
| 346 channel.reset(new FakeSocket()); | |
| 347 stream_channels_[name] = channel.release(); | |
|
Wez
2012/09/25 17:43:58
Doesn't this mean we end up with a NULL channel in
Sergey Ulanov
2012/09/25 18:59:08
We want that. Presence of the null in that contain
| |
| 348 | |
| 349 if (async_creation_) { | |
| 350 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 351 &FakeSession::CallStreamChannelCallback, weak_factory_.GetWeakPtr(), | |
| 352 name, callback)); | |
| 353 } else { | |
| 354 CallStreamChannelCallback(name, callback); | |
| 355 } | |
| 356 } | |
| 357 | |
| 358 void FakeSession::CallStreamChannelCallback( | |
| 359 const std::string& name, | |
| 360 const StreamChannelCallback& callback) { | |
| 361 if (stream_channels_.find(name) != stream_channels_.end()) | |
| 362 callback.Run(scoped_ptr<net::StreamSocket>(stream_channels_[name])); | |
| 344 } | 363 } |
| 345 | 364 |
| 346 void FakeSession::CreateDatagramChannel( | 365 void FakeSession::CreateDatagramChannel( |
| 347 const std::string& name, const DatagramChannelCallback& callback) { | 366 const std::string& name, |
| 348 scoped_ptr<FakeUdpSocket> channel(new FakeUdpSocket()); | 367 const DatagramChannelCallback& callback) { |
| 349 datagram_channels_[name] = channel.get(); | 368 scoped_ptr<FakeUdpSocket> channel; |
| 350 callback.Run(channel.PassAs<net::Socket>()); | 369 if (error_ == OK) |
| 370 channel.reset(new FakeUdpSocket()); | |
| 371 datagram_channels_[name] = channel.release(); | |
| 372 | |
| 373 if (async_creation_) { | |
| 374 message_loop_->PostTask(FROM_HERE, base::Bind( | |
| 375 &FakeSession::CallDatagramChannelCallback, weak_factory_.GetWeakPtr(), | |
| 376 name, callback)); | |
| 377 } else { | |
| 378 CallDatagramChannelCallback(name, callback); | |
| 379 } | |
| 380 } | |
| 381 | |
| 382 void FakeSession::CallDatagramChannelCallback( | |
| 383 const std::string& name, | |
| 384 const DatagramChannelCallback& callback) { | |
| 385 if (datagram_channels_.find(name) != datagram_channels_.end()) | |
| 386 callback.Run(scoped_ptr<net::Socket>(datagram_channels_[name])); | |
| 351 } | 387 } |
| 352 | 388 |
| 353 void FakeSession::CancelChannelCreation(const std::string& name) { | 389 void FakeSession::CancelChannelCreation(const std::string& name) { |
| 390 stream_channels_.erase(name); | |
| 391 datagram_channels_.erase(name); | |
| 354 } | 392 } |
| 355 | 393 |
| 356 } // namespace protocol | 394 } // namespace protocol |
| 357 } // namespace remoting | 395 } // namespace remoting |
| OLD | NEW |