Commit a29e1639 authored by sergeyu's avatar sergeyu Committed by Commit bot

Cleanup ChannelFactory interface

Removed CreateDatagramChannel() (it was never used) and renamed
CreateStreamChannel() to CreateChannel()

BUG=402993

Review URL: https://codereview.chromium.org/550383002

Cr-Commit-Position: refs/heads/master@{#293863}
parent 63f76cae
......@@ -44,7 +44,7 @@ void ChannelDispatcherBase::Init(Session* session,
initialized_callback_ = callback;
channel_factory_->CreateStreamChannel(channel_name_, base::Bind(
channel_factory_->CreateChannel(channel_name_, base::Bind(
&ChannelDispatcherBase::OnChannelReady, base::Unretained(this)));
}
......
......@@ -22,9 +22,7 @@ class ChannelFactory : public base::NonThreadSafe {
// TODO(sergeyu): Specify connection error code when channel
// connection fails.
typedef base::Callback<void(scoped_ptr<net::StreamSocket>)>
StreamChannelCallback;
typedef base::Callback<void(scoped_ptr<net::Socket>)>
DatagramChannelCallback;
ChannelCreatedCallback;
ChannelFactory() {}
......@@ -35,15 +33,12 @@ class ChannelFactory : public base::NonThreadSafe {
// before the factory is destroyed and CancelChannelCreation() must be called
// to cancel creation of channels for which the |callback| hasn't been called
// yet.
virtual void CreateStreamChannel(
const std::string& name, const StreamChannelCallback& callback) = 0;
virtual void CreateDatagramChannel(
const std::string& name, const DatagramChannelCallback& callback) = 0;
// Cancels a pending CreateStreamChannel() or CreateDatagramChannel()
// operation for the named channel. If the channel creation already
// completed then canceling it has no effect. When shutting down
// this method must be called for each channel pending creation.
virtual void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) = 0;
// Cancels a pending CreateChannel() operation for the named channel. If the
// channel creation already completed then canceling it has no effect. When
// shutting down this method must be called for each channel pending creation.
virtual void CancelChannelCreation(const std::string& name) = 0;
protected:
......
......@@ -58,11 +58,11 @@ const char ChannelMultiplexer::kMuxChannelName[] = "mux";
struct ChannelMultiplexer::PendingChannel {
PendingChannel(const std::string& name,
const StreamChannelCallback& callback)
const ChannelCreatedCallback& callback)
: name(name), callback(callback) {
}
std::string name;
StreamChannelCallback callback;
ChannelCreatedCallback callback;
};
class ChannelMultiplexer::MuxChannel {
......@@ -370,9 +370,8 @@ ChannelMultiplexer::~ChannelMultiplexer() {
base_channel_factory_->CancelChannelCreation(base_channel_name_);
}
void ChannelMultiplexer::CreateStreamChannel(
const std::string& name,
const StreamChannelCallback& callback) {
void ChannelMultiplexer::CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) {
if (base_channel_.get()) {
// Already have |base_channel_|. Create new multiplexed channel
// synchronously.
......@@ -386,7 +385,7 @@ void ChannelMultiplexer::CreateStreamChannel(
// If this is the first multiplexed channel then create the base channel.
if (pending_channels_.size() == 1U) {
base_channel_factory_->CreateStreamChannel(
base_channel_factory_->CreateChannel(
base_channel_name_,
base::Bind(&ChannelMultiplexer::OnBaseChannelReady,
base::Unretained(this)));
......@@ -394,13 +393,6 @@ void ChannelMultiplexer::CreateStreamChannel(
}
}
void ChannelMultiplexer::CreateDatagramChannel(
const std::string& name,
const DatagramChannelCallback& callback) {
NOTIMPLEMENTED();
callback.Run(scoped_ptr<net::Socket>());
}
void ChannelMultiplexer::CancelChannelCreation(const std::string& name) {
for (std::list<PendingChannel>::iterator it = pending_channels_.begin();
it != pending_channels_.end(); ++it) {
......
......@@ -24,12 +24,8 @@ class ChannelMultiplexer : public ChannelFactory {
virtual ~ChannelMultiplexer();
// ChannelFactory interface.
virtual void CreateStreamChannel(
const std::string& name,
const StreamChannelCallback& callback) OVERRIDE;
virtual void CreateDatagramChannel(
const std::string& name,
const DatagramChannelCallback& callback) OVERRIDE;
virtual void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) OVERRIDE;
virtual void CancelChannelCreation(const std::string& name) OVERRIDE;
private:
......
......@@ -94,10 +94,10 @@ class ChannelMultiplexerTest : public testing::Test {
scoped_ptr<net::StreamSocket>* host_socket,
scoped_ptr<net::StreamSocket>* client_socket) {
int counter = 2;
host_mux_->CreateStreamChannel(name, base::Bind(
host_mux_->CreateChannel(name, base::Bind(
&ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this),
host_socket, &counter));
client_mux_->CreateStreamChannel(name, base::Bind(
client_mux_->CreateChannel(name, base::Bind(
&ChannelMultiplexerTest::OnChannelConnected, base::Unretained(this),
client_socket, &counter));
......@@ -355,9 +355,9 @@ TEST_F(ChannelMultiplexerTest, SessionFail) {
MockConnectCallback cb1;
MockConnectCallback cb2;
host_mux_->CreateStreamChannel(kTestChannelName, base::Bind(
host_mux_->CreateChannel(kTestChannelName, base::Bind(
&MockConnectCallback::OnConnected, base::Unretained(&cb1)));
host_mux_->CreateStreamChannel(kTestChannelName2, base::Bind(
host_mux_->CreateChannel(kTestChannelName2, base::Bind(
&MockConnectCallback::OnConnected, base::Unretained(&cb2)));
EXPECT_CALL(cb1, OnConnectedPtr(NULL))
......
......@@ -332,58 +332,31 @@ void FakeSession::Close() {
closed_ = true;
}
void FakeSession::CreateStreamChannel(
const std::string& name,
const StreamChannelCallback& callback) {
void FakeSession::CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) {
scoped_ptr<FakeSocket> channel;
// If we are in the error state then we put NULL in the channels list, so that
// NotifyStreamChannelCallback() still calls the callback.
// NotifyChannelCreated() still calls the callback.
if (error_ == OK)
channel.reset(new FakeSocket());
stream_channels_[name] = channel.release();
if (async_creation_) {
message_loop_->PostTask(FROM_HERE, base::Bind(
&FakeSession::NotifyStreamChannelCallback, weak_factory_.GetWeakPtr(),
&FakeSession::NotifyChannelCreated, weak_factory_.GetWeakPtr(),
name, callback));
} else {
NotifyStreamChannelCallback(name, callback);
NotifyChannelCreated(name, callback);
}
}
void FakeSession::NotifyStreamChannelCallback(
void FakeSession::NotifyChannelCreated(
const std::string& name,
const StreamChannelCallback& callback) {
const ChannelCreatedCallback& 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;
// If we are in the error state then we put NULL in the channels list, so that
// NotifyStreamChannelCallback() still calls the callback.
if (error_ == OK)
channel.reset(new FakeUdpSocket());
datagram_channels_[name] = channel.release();
if (async_creation_) {
message_loop_->PostTask(FROM_HERE, base::Bind(
&FakeSession::NotifyDatagramChannelCallback, weak_factory_.GetWeakPtr(),
name, callback));
} else {
NotifyDatagramChannelCallback(name, callback);
}
}
void FakeSession::NotifyDatagramChannelCallback(
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);
......
......@@ -178,21 +178,13 @@ class FakeSession : public Session,
virtual void Close() OVERRIDE;
// ChannelFactory interface.
virtual void CreateStreamChannel(
const std::string& name,
const StreamChannelCallback& callback) OVERRIDE;
virtual void CreateDatagramChannel(
const std::string& name,
const DatagramChannelCallback& callback) OVERRIDE;
virtual void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) OVERRIDE;
virtual void CancelChannelCreation(const std::string& name) OVERRIDE;
public:
void NotifyStreamChannelCallback(
const std::string& name,
const StreamChannelCallback& callback);
void NotifyDatagramChannelCallback(
const std::string& name,
const DatagramChannelCallback& callback);
void NotifyChannelCreated(const std::string& name,
const ChannelCreatedCallback& callback);
EventHandler* event_handler_;
scoped_ptr<const CandidateSessionConfig> candidate_config_;
......
......@@ -250,9 +250,8 @@ void JingleSession::AddPendingRemoteCandidates(Transport* channel,
}
}
void JingleSession::CreateStreamChannel(
const std::string& name,
const StreamChannelCallback& callback) {
void JingleSession::CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) {
DCHECK(!channels_[name]);
scoped_ptr<ChannelAuthenticator> channel_authenticator =
......@@ -265,21 +264,6 @@ void JingleSession::CreateStreamChannel(
channels_[name] = channel.release();
}
void JingleSession::CreateDatagramChannel(
const std::string& name,
const DatagramChannelCallback& callback) {
DCHECK(!channels_[name]);
scoped_ptr<ChannelAuthenticator> channel_authenticator =
authenticator_->CreateChannelAuthenticator();
scoped_ptr<DatagramTransport> channel =
session_manager_->transport_factory_->CreateDatagramTransport();
channel->Initialize(name, this, channel_authenticator.Pass());
channel->Connect(callback);
AddPendingRemoteCandidates(channel.get(), name);
channels_[name] = channel.release();
}
void JingleSession::CancelChannelCreation(const std::string& name) {
ChannelsMap::iterator it = channels_.find(name);
if (it != channels_.end() && !it->second->is_connected()) {
......
......@@ -54,12 +54,8 @@ class JingleSession : public Session,
virtual void Close() OVERRIDE;
// ChannelFactory interface.
virtual void CreateStreamChannel(
const std::string& name,
const StreamChannelCallback& callback) OVERRIDE;
virtual void CreateDatagramChannel(
const std::string& name,
const DatagramChannelCallback& callback) OVERRIDE;
virtual void CreateChannel(const std::string& name,
const ChannelCreatedCallback& callback) OVERRIDE;
virtual void CancelChannelCreation(const std::string& name) OVERRIDE;
// Transport::EventHandler interface.
......
......@@ -84,7 +84,7 @@ class MockSessionEventHandler : public Session::EventHandler {
const TransportRoute& route));
};
class MockStreamChannelCallback {
class MockChannelCreatedCallback {
public:
MOCK_METHOD1(OnDone, void(net::StreamSocket* socket));
};
......@@ -262,10 +262,10 @@ class JingleSessionTest : public testing::Test {
}
void CreateChannel() {
client_session_->GetTransportChannelFactory()->CreateStreamChannel(
client_session_->GetTransportChannelFactory()->CreateChannel(
kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated,
base::Unretained(this)));
host_session_->GetTransportChannelFactory()->CreateStreamChannel(
host_session_->GetTransportChannelFactory()->CreateChannel(
kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated,
base::Unretained(this)));
......@@ -305,8 +305,8 @@ class JingleSessionTest : public testing::Test {
scoped_ptr<Session> client_session_;
MockSessionEventHandler client_session_event_handler_;
MockStreamChannelCallback client_channel_callback_;
MockStreamChannelCallback host_channel_callback_;
MockChannelCreatedCallback client_channel_callback_;
MockChannelCreatedCallback host_channel_callback_;
scoped_ptr<net::StreamSocket> client_socket_;
scoped_ptr<net::StreamSocket> host_socket_;
......@@ -453,10 +453,10 @@ TEST_F(JingleSessionTest, TestMuxStreamChannel) {
ASSERT_NO_FATAL_FAILURE(
InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
client_session_->GetMultiplexedChannelFactory()->CreateStreamChannel(
client_session_->GetMultiplexedChannelFactory()->CreateChannel(
kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated,
base::Unretained(this)));
host_session_->GetMultiplexedChannelFactory()->CreateStreamChannel(
host_session_->GetMultiplexedChannelFactory()->CreateChannel(
kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated,
base::Unretained(this)));
......@@ -499,10 +499,10 @@ TEST_F(JingleSessionTest, TestFailedChannelAuth) {
ASSERT_NO_FATAL_FAILURE(
InitiateConnection(1, FakeAuthenticator::ACCEPT, false));
client_session_->GetTransportChannelFactory()->CreateStreamChannel(
client_session_->GetTransportChannelFactory()->CreateChannel(
kChannelName, base::Bind(&JingleSessionTest::OnClientChannelCreated,
base::Unretained(this)));
host_session_->GetTransportChannelFactory()->CreateStreamChannel(
host_session_->GetTransportChannelFactory()->CreateChannel(
kChannelName, base::Bind(&JingleSessionTest::OnHostChannelCreated,
base::Unretained(this)));
......
......@@ -32,7 +32,7 @@ void ProtobufVideoReader::Init(protocol::Session* session,
initialized_callback_ = callback;
video_stub_ = video_stub;
channel_factory_->CreateStreamChannel(
channel_factory_->CreateChannel(
kVideoChannelName,
base::Bind(&ProtobufVideoReader::OnChannelReady, base::Unretained(this)));
}
......
......@@ -28,7 +28,7 @@ void ProtobufVideoWriter::Init(protocol::Session* session,
channel_factory_ = session->GetTransportChannelFactory();
initialized_callback_ = callback;
channel_factory_->CreateStreamChannel(
channel_factory_->CreateChannel(
kVideoChannelName,
base::Bind(&ProtobufVideoWriter::OnChannelReady, base::Unretained(this)));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment