Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Unified Diff: remoting/protocol/fake_session.cc

Issue 10981009: Fix ChannelMultiplexer to properly handle base channel creation failure. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« remoting/protocol/fake_session.h ('K') | « remoting/protocol/fake_session.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/protocol/fake_session.cc
diff --git a/remoting/protocol/fake_session.cc b/remoting/protocol/fake_session.cc
index 4d547430679e6ea08aac341526305a0a142b910a..d24f38e3a1848ff4c2fbce6ef1d16d9bd6d10fc8 100644
--- a/remoting/protocol/fake_session.cc
+++ b/remoting/protocol/fake_session.cc
@@ -284,10 +284,12 @@ FakeSession::FakeSession()
: event_handler_(NULL),
candidate_config_(CandidateSessionConfig::CreateDefault()),
config_(SessionConfig::GetDefault()),
- message_loop_(NULL),
+ message_loop_(MessageLoop::current()),
+ async_creation_(false),
jid_(kTestJid),
error_(OK),
- closed_(false) {
+ closed_(false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
}
FakeSession::~FakeSession() { }
@@ -337,20 +339,56 @@ void FakeSession::Close() {
}
void FakeSession::CreateStreamChannel(
- const std::string& name, const StreamChannelCallback& callback) {
- scoped_ptr<FakeSocket> channel(new FakeSocket());
- stream_channels_[name] = channel.get();
- callback.Run(channel.PassAs<net::StreamSocket>());
+ const std::string& name,
+ const StreamChannelCallback& callback) {
+ scoped_ptr<FakeSocket> channel;
+ if (error_ == OK)
+ channel.reset(new FakeSocket());
+ 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
+
+ if (async_creation_) {
+ message_loop_->PostTask(FROM_HERE, base::Bind(
+ &FakeSession::CallStreamChannelCallback, weak_factory_.GetWeakPtr(),
+ name, callback));
+ } else {
+ CallStreamChannelCallback(name, callback);
+ }
+}
+
+void FakeSession::CallStreamChannelCallback(
+ const std::string& name,
+ const StreamChannelCallback& callback) {
+ if (stream_channels_.find(name) != stream_channels_.end())
+ callback.Run(scoped_ptr<net::StreamSocket>(stream_channels_[name]));
}
void FakeSession::CreateDatagramChannel(
- const std::string& name, const DatagramChannelCallback& callback) {
- scoped_ptr<FakeUdpSocket> channel(new FakeUdpSocket());
- datagram_channels_[name] = channel.get();
- callback.Run(channel.PassAs<net::Socket>());
+ const std::string& name,
+ const DatagramChannelCallback& callback) {
+ scoped_ptr<FakeUdpSocket> channel;
+ if (error_ == OK)
+ channel.reset(new FakeUdpSocket());
+ datagram_channels_[name] = channel.release();
+
+ if (async_creation_) {
+ message_loop_->PostTask(FROM_HERE, base::Bind(
+ &FakeSession::CallDatagramChannelCallback, weak_factory_.GetWeakPtr(),
+ name, callback));
+ } else {
+ CallDatagramChannelCallback(name, callback);
+ }
+}
+
+void FakeSession::CallDatagramChannelCallback(
+ const std::string& name,
+ const DatagramChannelCallback& callback) {
+ if (datagram_channels_.find(name) != datagram_channels_.end())
+ callback.Run(scoped_ptr<net::Socket>(datagram_channels_[name]));
}
void FakeSession::CancelChannelCreation(const std::string& name) {
+ stream_channels_.erase(name);
+ datagram_channels_.erase(name);
}
} // namespace protocol
« remoting/protocol/fake_session.h ('K') | « remoting/protocol/fake_session.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698