summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 00:55:18 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-14 00:55:18 +0000
commit1635de0fadc0a867187208769d37e466a8e9914f (patch)
tree90e970ed50159a62164e51d5df28175215faf8b5 /remoting
parente321a3c8eef6418c248743fdb68aa8bbba02e98f (diff)
downloadchromium_src-1635de0fadc0a867187208769d37e466a8e9914f.zip
chromium_src-1635de0fadc0a867187208769d37e466a8e9914f.tar.gz
chromium_src-1635de0fadc0a867187208769d37e466a8e9914f.tar.bz2
Remove old tunneling code from remoting/jingle_glue.
BUG=None TEST=None Review URL: http://codereview.chromium.org/3574014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/client/jingle_host_connection.cc20
-rw-r--r--remoting/client/jingle_host_connection.h9
-rw-r--r--remoting/host/chromoting_host.cc12
-rw-r--r--remoting/host/chromoting_host.h6
-rw-r--r--remoting/jingle_glue/jingle_channel.cc241
-rw-r--r--remoting/jingle_glue/jingle_channel.h180
-rw-r--r--remoting/jingle_glue/jingle_channel_unittest.cc176
-rw-r--r--remoting/jingle_glue/jingle_client.cc75
-rw-r--r--remoting/jingle_glue/jingle_client.h34
-rw-r--r--remoting/jingle_glue/jingle_client_unittest.cc5
-rw-r--r--remoting/jingle_glue/jingle_test_client.cc157
-rw-r--r--remoting/jingle_glue/mock_objects.h12
-rw-r--r--remoting/protocol/protocol_test_client.cc15
-rw-r--r--remoting/remoting.gyp16
14 files changed, 7 insertions, 951 deletions
diff --git a/remoting/client/jingle_host_connection.cc b/remoting/client/jingle_host_connection.cc
index a4519df..044c9ee 100644
--- a/remoting/client/jingle_host_connection.cc
+++ b/remoting/client/jingle_host_connection.cc
@@ -117,26 +117,6 @@ void JingleHostConnection::OnStateChange(JingleClient* client,
}
}
-bool JingleHostConnection::OnAcceptConnection(
- JingleClient* client,
- const std::string& jid,
- JingleChannel::Callback** callback) {
- DCHECK_EQ(message_loop(), MessageLoop::current());
-
- // Client rejects all connection.
- return false;
-}
-
-void JingleHostConnection::OnNewConnection(
- JingleClient* client,
- scoped_refptr<JingleChannel> channel) {
- DCHECK_EQ(message_loop(), MessageLoop::current());
-
- // TODO(ajwong): Should we log more aggressively on this and above? We
- // shouldn't be getting any inbound connections.
- NOTREACHED() << "Clients can't accept inbound connections.";
-}
-
void JingleHostConnection::OnNewChromotocolConnection(
ChromotingConnection* connection, bool* accept) {
DCHECK_EQ(message_loop(), MessageLoop::current());
diff --git a/remoting/client/jingle_host_connection.h b/remoting/client/jingle_host_connection.h
index bbbbcab..1701b5b 100644
--- a/remoting/client/jingle_host_connection.h
+++ b/remoting/client/jingle_host_connection.h
@@ -5,8 +5,9 @@
// JingleHostConnection implements the HostConnection interface using
// libjingle as the transport protocol.
//
-// Much of this class focuses on translating JingleClient and JingleChannel
-// callbacks into HostConnection::HostEventCallback messages.
+// Much of this class focuses on translating JingleClient and
+// ChromotingConnection callbacks into HostConnection::HostEventCallback
+// messages.
//
// The public API of this class is designed to be asynchronous, and thread
// safe for invocation from other threads.
@@ -51,10 +52,6 @@ class JingleHostConnection : public HostConnection,
// JingleClient::Callback interface.
virtual void OnStateChange(JingleClient* client, JingleClient::State state);
- virtual bool OnAcceptConnection(JingleClient* client, const std::string& jid,
- JingleChannel::Callback** callback);
- void OnNewConnection(JingleClient* client,
- scoped_refptr<JingleChannel> channel);
// Callback for ChromotingServer.
void OnNewChromotocolConnection(
diff --git a/remoting/host/chromoting_host.cc b/remoting/host/chromoting_host.cc
index d0b7bb7..f944226 100644
--- a/remoting/host/chromoting_host.cc
+++ b/remoting/host/chromoting_host.cc
@@ -14,7 +14,6 @@
#include "remoting/host/event_executor.h"
#include "remoting/host/host_config.h"
#include "remoting/host/session_manager.h"
-#include "remoting/jingle_glue/jingle_channel.h"
#include "remoting/protocol/messages_decoder.h"
#include "remoting/protocol/jingle_chromoting_server.h"
@@ -263,17 +262,6 @@ void ChromotingHost::OnNewClientConnection(
client_->Init(connection);
}
-bool ChromotingHost::OnAcceptConnection(
- JingleClient* jingle_client, const std::string& jid,
- JingleChannel::Callback** channel_callback) {
- return false;
-}
-
-void ChromotingHost::OnNewConnection(JingleClient* jingle_client,
- scoped_refptr<JingleChannel> channel) {
- NOTREACHED();
-}
-
void ChromotingHost::OnServerClosed() {
// Don't need to do anything here.
}
diff --git a/remoting/host/chromoting_host.h b/remoting/host/chromoting_host.h
index c1773cb..cf74d23 100644
--- a/remoting/host/chromoting_host.h
+++ b/remoting/host/chromoting_host.h
@@ -93,12 +93,6 @@ class ChromotingHost : public base::RefCountedThreadSafe<ChromotingHost>,
////////////////////////////////////////////////////////////////////////////
// JingleClient::Callback implementations
virtual void OnStateChange(JingleClient* client, JingleClient::State state);
- virtual bool OnAcceptConnection(
- JingleClient* jingle, const std::string& jid,
- JingleChannel::Callback** channel_callback);
- virtual void OnNewConnection(
- JingleClient* jingle,
- scoped_refptr<JingleChannel> channel);
// Callback for ChromotingServer.
void OnNewClientConnection(ChromotingConnection* connection, bool* accept);
diff --git a/remoting/jingle_glue/jingle_channel.cc b/remoting/jingle_glue/jingle_channel.cc
deleted file mode 100644
index 9dc545f..0000000
--- a/remoting/jingle_glue/jingle_channel.cc
+++ /dev/null
@@ -1,241 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "remoting/jingle_glue/jingle_channel.h"
-
-#include "base/lock.h"
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "base/waitable_event.h"
-#include "media/base/data_buffer.h"
-#include "remoting/jingle_glue/jingle_thread.h"
-#include "third_party/libjingle/source/talk/base/stream.h"
-
-using media::DataBuffer;
-
-namespace remoting {
-
-// Size of a read buffer chunk in bytes.
-const size_t kReadBufferSize = 4096;
-
-JingleChannel::JingleChannel(Callback* callback)
- : state_(INITIALIZING),
- callback_(callback),
- closed_(false),
- event_handler_(this),
- write_buffer_size_(0),
- current_write_buf_pos_(0) {
- DCHECK(callback_ != NULL);
-}
-
-// This constructor is only used in unit test.
-JingleChannel::JingleChannel()
- : state_(CLOSED),
- closed_(false),
- write_buffer_size_(0),
- current_write_buf_pos_(0) {
-}
-
-JingleChannel::~JingleChannel() {
- DCHECK(closed_ || stream_ == NULL);
-}
-
-void JingleChannel::Init(JingleThread* thread,
- talk_base::StreamInterface* stream,
- const std::string& jid) {
- thread_ = thread;
- stream_.reset(stream);
- stream_->SignalEvent.connect(&event_handler_, &EventHandler::OnStreamEvent);
- jid_ = jid;
-
- // Initialize |state_|.
- switch (stream->GetState()) {
- case talk_base::SS_CLOSED:
- SetState(CLOSED);
- break;
- case talk_base::SS_OPENING:
- SetState(CONNECTING);
- break;
- case talk_base::SS_OPEN:
- SetState(OPEN);
- // Try to read in case there is something in the stream.
- thread_->message_loop()->PostTask(
- FROM_HERE, NewRunnableMethod(this, &JingleChannel::DoRead));
- break;
- default:
- NOTREACHED();
- }
-}
-
-void JingleChannel::Write(scoped_refptr<DataBuffer> data) {
- // Discard empty packets.
- if (data->GetDataSize() != 0) {
- AutoLock auto_lock(write_lock_);
- write_queue_.push_back(data);
- write_buffer_size_ += data->GetDataSize();
- // Post event so that the data gets written in the tunnel thread.
- thread_->message_loop()->PostTask(
- FROM_HERE, NewRunnableMethod(this, &JingleChannel::DoWrite));
- }
-}
-
-void JingleChannel::DoRead() {
- while (true) {
- size_t bytes_to_read;
- if (stream_->GetAvailable(&bytes_to_read)) {
- // Return immediately if we know there is nothing to read.
- if (bytes_to_read == 0)
- return;
- } else {
- // Try to read kReadBufferSize if the stream doesn't support
- // GetAvailable().
- bytes_to_read = kReadBufferSize;
- }
-
- scoped_refptr<DataBuffer> buffer(
- new DataBuffer(new uint8[bytes_to_read], kReadBufferSize));
- size_t bytes_read;
- int error;
- talk_base::StreamResult result = stream_->Read(
- buffer->GetWritableData(), bytes_to_read, &bytes_read, &error);
- switch (result) {
- case talk_base::SR_SUCCESS: {
- DCHECK_GT(bytes_read, 0U);
- buffer->SetDataSize(bytes_read);
- {
- AutoLock auto_lock(state_lock_);
- // Drop received data if the channel is already closed.
- if (!closed_)
- callback_->OnPacketReceived(this, buffer);
- }
- break;
- }
- case talk_base::SR_BLOCK: {
- return;
- }
- case talk_base::SR_EOS: {
- SetState(CLOSED);
- return;
- }
- case talk_base::SR_ERROR: {
- SetState(FAILED);
- return;
- }
- }
- }
-}
-
-void JingleChannel::DoWrite() {
- while (true) {
- if (!current_write_buf_) {
- AutoLock auto_lock(write_lock_);
- if (write_queue_.empty())
- break;
- current_write_buf_ = write_queue_.front();
- current_write_buf_pos_ = 0;
- write_queue_.pop_front();
- }
-
- size_t bytes_written;
- int error;
- talk_base::StreamResult result = stream_->Write(
- current_write_buf_->GetData() + current_write_buf_pos_,
- current_write_buf_->GetDataSize() - current_write_buf_pos_,
- &bytes_written, &error);
- switch (result) {
- case talk_base::SR_SUCCESS: {
- current_write_buf_pos_ += bytes_written;
- if (current_write_buf_pos_ >= current_write_buf_->GetDataSize())
- current_write_buf_ = NULL;
- {
- AutoLock auto_lock(write_lock_);
- write_buffer_size_ -= bytes_written;
- }
- break;
- }
- case talk_base::SR_BLOCK: {
- return;
- }
- case talk_base::SR_EOS: {
- SetState(CLOSED);
- return;
- }
- case talk_base::SR_ERROR: {
- SetState(FAILED);
- return;
- }
- }
- }
-}
-
-void JingleChannel::OnStreamEvent(talk_base::StreamInterface* stream,
- int events, int error) {
- if (events & talk_base::SE_OPEN)
- SetState(OPEN);
-
- if (state_ == OPEN && (events & talk_base::SE_WRITE))
- DoWrite();
-
- if (state_ == OPEN && (events & talk_base::SE_READ))
- DoRead();
-
- if (events & talk_base::SE_CLOSE)
- SetState(CLOSED);
-}
-
-void JingleChannel::SetState(State new_state) {
- if (new_state != state_) {
- state_ = new_state;
- {
- AutoLock auto_lock(state_lock_);
- if (!closed_)
- callback_->OnStateChange(this, new_state);
- }
- }
-}
-
-void JingleChannel::Close() {
- Close(NULL);
-}
-
-void JingleChannel::Close(Task* closed_task) {
- {
- AutoLock auto_lock(state_lock_);
- if (closed_) {
- // We are already closed.
- if (closed_task)
- thread_->message_loop()->PostTask(FROM_HERE, closed_task);
- return;
- }
- closed_ = true;
- if (closed_task)
- closed_task_.reset(closed_task);
- }
-
- thread_->message_loop()->PostTask(
- FROM_HERE, NewRunnableMethod(this, &JingleChannel::DoClose));
-}
-
-
-void JingleChannel::DoClose() {
- DCHECK(closed_);
- stream_->Close();
- stream_.reset();
-
- // TODO(sergeyu): Even though we have called Close() for the stream, it
- // doesn't mean that the p2p sessions has been closed. I.e. |closed_task_|
- // is called too early. If the client is closed right after that the other
- // side will not receive notification that the channel was closed.
- if (closed_task_.get()) {
- closed_task_->Run();
- closed_task_.reset();
- }
-}
-
-size_t JingleChannel::write_buffer_size() {
- AutoLock auto_lock(write_lock_);
- return write_buffer_size_;
-}
-
-} // namespace remoting
diff --git a/remoting/jingle_glue/jingle_channel.h b/remoting/jingle_glue/jingle_channel.h
deleted file mode 100644
index ee53760..0000000
--- a/remoting/jingle_glue/jingle_channel.h
+++ /dev/null
@@ -1,180 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef REMOTING_JINGLE_GLUE_JINGLE_CHANNEL_H_
-#define REMOTING_JINGLE_GLUE_JINGLE_CHANNEL_H_
-
-#include <deque>
-#include <string>
-
-#include "base/basictypes.h"
-#include "base/condition_variable.h"
-#include "base/gtest_prod_util.h"
-#include "base/lock.h"
-#include "base/ref_counted.h"
-#include "base/scoped_ptr.h"
-#include "base/task.h"
-#include "third_party/libjingle/source/talk/base/sigslot.h"
-
-namespace base {
-class WaitableEvent;
-} // namespace base
-
-namespace talk_base {
-class StreamInterface;
-} // namespace talk_base
-
-namespace media {
-class Buffer;
-class DataBuffer;
-} // namespace media
-
-namespace remoting {
-class JingleThread;
-
-class JingleChannel : public base::RefCountedThreadSafe<JingleChannel> {
- public:
- enum State {
- INITIALIZING,
- CONNECTING,
- OPEN,
- CLOSED,
- FAILED,
- };
-
- class Callback {
- public:
- virtual ~Callback() {}
-
- // Called when state of the connection is changed.
- virtual void OnStateChange(JingleChannel* channel, State state) = 0;
-
- // Called when a new packet is received.
- virtual void OnPacketReceived(JingleChannel* channel,
- scoped_refptr<media::DataBuffer> data) = 0;
- };
-
- virtual ~JingleChannel();
-
- // Puts data to the write buffer.
- virtual void Write(scoped_refptr<media::DataBuffer> data);
-
- // Closes the tunnel. If specified, |closed_task| is executed after the
- // connection is successfully closed.
- virtual void Close();
- virtual void Close(Task* closed_task);
-
- // Current state of the tunnel.
- State state() const { return state_; }
-
- // JID of the other end of the channel.
- const std::string& jid() const { return jid_; }
-
- // Number of bytes currently stored in the write buffer.
- size_t write_buffer_size();
-
- protected:
- // Needs access to constructor, Init().
- friend class JingleClient;
-
- // Constructor used by unit test only.
- // TODO(hclam): Have to suppress warnings in MSVC.
- JingleChannel();
-
- // Used by JingleClient to create an instance of the channel. |callback|
- // must not be NULL.
- explicit JingleChannel(Callback* callback);
-
- // Initialized the channel. Ownership of the |stream| is transfered to
- // caller. Ownership of |thread| is not.
- void Init(JingleThread* thread, talk_base::StreamInterface* stream,
- const std::string& jid);
-
- private:
- friend class JingleChannelTest;
- FRIEND_TEST_ALL_PREFIXES(JingleChannelTest, Init);
- FRIEND_TEST_ALL_PREFIXES(JingleChannelTest, Write);
- FRIEND_TEST_ALL_PREFIXES(JingleChannelTest, Read);
-
- typedef std::deque<scoped_refptr<media::DataBuffer> > DataQueue;
-
- // Event handler for the stream. It passes stream events from the stream
- // to JingleChannel.
- class EventHandler : public sigslot::has_slots<> {
- protected:
- explicit EventHandler(JingleChannel* channel) : channel_(channel) {}
-
- // Constructor used only by unit test.
- EventHandler() : channel_(NULL) {}
-
- void OnStreamEvent(talk_base::StreamInterface* stream,
- int events, int error) {
- channel_->OnStreamEvent(stream, events, error);
- }
- private:
- friend class JingleChannel;
- JingleChannel* channel_;
- };
- friend class EventHandler;
-
- // Event handler for the stream.
- void OnStreamEvent(talk_base::StreamInterface* stream,
- int events, int error);
-
- // Writes data from the buffer to the stream. Called
- // from OnStreamEvent() in the jingle thread.
- void DoWrite();
-
- // Reads data from the stream and puts it to the read buffer.
- // Called from OnStreamEvent() in the jingle thread.
- void DoRead();
-
- // Used by Close() to actually close the channel.
- void DoClose();
-
- // Updates state and calels |callback_| if neccessary.
- void SetState(State new_state);
-
- // The thread this channel runs on.
- JingleThread* thread_;
-
- // The stream of this channel.
- scoped_ptr<talk_base::StreamInterface> stream_;
-
- // Current state of the channel.
- State state_;
-
- // Callback that is called on channel events. Initialized in the constructor.
- // Must not be called if |closed_| is set to true.
- Callback* callback_;
-
- // |closed_| must be set to true after Close() is called. |state_lock_| must
- // be locked whenever closed_ is accessed.
- Lock state_lock_;
- bool closed_;
- scoped_ptr<Task> closed_task_;
-
- // Event handler for stream events.
- EventHandler event_handler_;
-
- // Jid of the other end of the channel.
- std::string jid_;
-
- // Write buffer. |write_lock_| should be locked when accessing |write_queue_|
- // and |write_buffer_size_|, but isn't necessary for |current_write_buf_|.
- // |current_write_buf_| is accessed only by the jingle thread.
- // |write_buffer_size_| stores number of bytes currently in |write_queue_|
- // and in |current_write_buf_|.
- DataQueue write_queue_;
- size_t write_buffer_size_;
- Lock write_lock_;
- scoped_refptr<media::DataBuffer> current_write_buf_;
- size_t current_write_buf_pos_;
-
- DISALLOW_COPY_AND_ASSIGN(JingleChannel);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_JINGLE_GLUE_JINGLE_CHANNEL_H_
diff --git a/remoting/jingle_glue/jingle_channel_unittest.cc b/remoting/jingle_glue/jingle_channel_unittest.cc
deleted file mode 100644
index 97b5a17..0000000
--- a/remoting/jingle_glue/jingle_channel_unittest.cc
+++ /dev/null
@@ -1,176 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/ref_counted.h"
-#include "base/waitable_event.h"
-#include "media/base/data_buffer.h"
-#include "remoting/jingle_glue/jingle_channel.h"
-#include "remoting/jingle_glue/jingle_thread.h"
-#include "remoting/jingle_glue/mock_objects.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/libjingle/source/talk/base/stream.h"
-
-using testing::_;
-using testing::Return;
-using testing::Mock;
-using testing::SetArgumentPointee;
-
-namespace remoting {
-
-namespace {
-// Size of test buffer in bytes.
-const size_t kBufferSize = 100;
-} // namespace
-
-class MockJingleChannelCallback : public JingleChannel::Callback {
- public:
- MOCK_METHOD2(OnStateChange, void(JingleChannel*, JingleChannel::State));
- MOCK_METHOD2(OnPacketReceived, void(JingleChannel*,
- scoped_refptr<media::DataBuffer>));
-};
-
-class JingleChannelTest : public testing::Test {
- public:
- virtual ~JingleChannelTest() { }
-
- // A helper that calls OnStreamEvent(). Need this because we want
- // to call it on the jingle thread.
- static void StreamEvent(JingleChannel* channel,
- talk_base::StreamInterface* stream,
- int event, int error,
- base::WaitableEvent* done_event) {
- channel->OnStreamEvent(stream, event, error);
- if (done_event)
- done_event->Signal();
- }
-
- static void OnClosed(bool* called) {
- *called = true;
- }
-
- protected:
- virtual void SetUp() {
- stream_ = new MockStream(); // Freed by the channel.
- channel_ = new JingleChannel(&callback_);
- channel_->thread_ = &thread_;
- channel_->stream_.reset(stream_);
- }
-
- JingleThread thread_;
- MockStream* stream_;
- MockJingleChannelCallback callback_;
- scoped_refptr<JingleChannel> channel_;
-};
-
-TEST_F(JingleChannelTest, Init) {
- EXPECT_CALL(*stream_, GetState())
- .Times(1)
- .WillRepeatedly(Return(talk_base::SS_OPENING));
-
- EXPECT_CALL(callback_, OnStateChange(channel_.get(),
- JingleChannel::CONNECTING))
- .Times(1);
-
- thread_.Start();
-
- EXPECT_EQ(JingleChannel::INITIALIZING, channel_->state());
- channel_->Init(&thread_, stream_, "user@domain.com");
- EXPECT_EQ(JingleChannel::CONNECTING, channel_->state());
- channel_->closed_ = true;
-
- thread_.Stop();
-}
-
-TEST_F(JingleChannelTest, Write) {
- scoped_refptr<media::DataBuffer> data = new media::DataBuffer(kBufferSize);
- data->SetDataSize(kBufferSize);
-
- EXPECT_CALL(*stream_, Write(static_cast<const void*>(data->GetData()),
- kBufferSize, _, _))
- .WillOnce(DoAll(SetArgumentPointee<2>(kBufferSize),
- Return(talk_base::SR_SUCCESS)));
-
- channel_->state_ = JingleChannel::OPEN;
- thread_.Start();
- channel_->Write(data);
- thread_.Stop();
- channel_->closed_ = true;
-}
-
-TEST_F(JingleChannelTest, Read) {
- scoped_refptr<media::DataBuffer> data = new media::DataBuffer(kBufferSize);
- data->SetDataSize(kBufferSize);
-
- EXPECT_CALL(callback_, OnPacketReceived(channel_.get(), _))
- .Times(1);
-
- EXPECT_CALL(*stream_, GetAvailable(_))
- .WillOnce(DoAll(SetArgumentPointee<0>(kBufferSize),
- Return(true)))
- .WillOnce(DoAll(SetArgumentPointee<0>(0),
- Return(true)));
-
- EXPECT_CALL(*stream_, Read(_, kBufferSize, _, _))
- .WillOnce(DoAll(SetArgumentPointee<2>(kBufferSize),
- Return(talk_base::SR_SUCCESS)));
-
- channel_->state_ = JingleChannel::OPEN;
- thread_.Start();
-
- base::WaitableEvent done_event(true, false);
- thread_.message_loop()->PostTask(FROM_HERE, NewRunnableFunction(
- &JingleChannelTest::StreamEvent, channel_.get(), stream_,
- talk_base::SE_READ, 0, &done_event));
- done_event.Wait();
-
- thread_.Stop();
-
- channel_->closed_ = true;
-}
-
-TEST_F(JingleChannelTest, Close) {
- EXPECT_CALL(*stream_, Close()).Times(1);
- // Don't expect any calls except Close().
- EXPECT_CALL(*stream_, GetAvailable(_)).Times(0);
- EXPECT_CALL(*stream_, Read(_, _, _, _)).Times(0);
- EXPECT_CALL(callback_, OnPacketReceived(_, _)).Times(0);
-
- thread_.Start();
- channel_->Close();
- // Verify that the channel doesn't call callback anymore.
- thread_.message_loop()->PostTask(FROM_HERE, NewRunnableFunction(
- &JingleChannelTest::StreamEvent, channel_.get(), stream_,
- talk_base::SE_READ, 0, static_cast<base::WaitableEvent*>(NULL)));
- thread_.Stop();
-}
-
-TEST_F(JingleChannelTest, ClosedTask) {
- EXPECT_CALL(*stream_, Close())
- .Times(1);
-
- thread_.Start();
- bool closed = false;
- channel_->Close(NewRunnableFunction(&JingleChannelTest::OnClosed,
- &closed));
- thread_.Stop();
- EXPECT_TRUE(closed);
-}
-
-TEST_F(JingleChannelTest, DoubleClose) {
- EXPECT_CALL(*stream_, Close())
- .Times(1);
-
- thread_.Start();
- bool closed1 = false;
- channel_->Close(NewRunnableFunction(&JingleChannelTest::OnClosed,
- &closed1));
- bool closed2 = false;
- channel_->Close(NewRunnableFunction(&JingleChannelTest::OnClosed,
- &closed2));
- thread_.Stop();
- EXPECT_TRUE(closed1 && closed2);
-}
-
-} // namespace remoting
diff --git a/remoting/jingle_glue/jingle_client.cc b/remoting/jingle_glue/jingle_client.cc
index e371850..6237629 100644
--- a/remoting/jingle_glue/jingle_client.cc
+++ b/remoting/jingle_glue/jingle_client.cc
@@ -22,25 +22,6 @@
namespace remoting {
-namespace {
-// A TunnelSessionClient that allows local connections.
-class LocalTunnelSessionClient : public cricket::TunnelSessionClient {
- public:
- LocalTunnelSessionClient(const buzz::Jid& jid,
- cricket::SessionManager* manager)
- : TunnelSessionClient(jid, manager) {
- }
-
- protected:
- virtual cricket::TunnelSession* MakeTunnelSession(
- cricket::Session* session, talk_base::Thread* stream_thread,
- cricket::TunnelSessionRole role) {
- session->set_allow_local_ips(true);
- return new cricket::TunnelSession(this, session, stream_thread);
- }
-};
-} // namespace
-
JingleClient::JingleClient(JingleThread* thread)
: thread_(thread),
callback_(NULL),
@@ -108,41 +89,10 @@ void JingleClient::DoInitialize(const std::string& username,
session_manager_.reset(new cricket::SessionManager(port_allocator_.get()));
- tunnel_session_client_.reset(
- new LocalTunnelSessionClient(client_->jid(),
- session_manager_.get()));
-
cricket::SessionManagerTask* receiver =
new cricket::SessionManagerTask(client_, session_manager_.get());
receiver->EnableOutgoingMessages();
receiver->Start();
-
- tunnel_session_client_->SignalIncomingTunnel.connect(
- this, &JingleClient::OnIncomingTunnel);
-}
-
-JingleChannel* JingleClient::Connect(const std::string& host_jid,
- JingleChannel::Callback* callback) {
- DCHECK(initialized_ && !closed_);
-
- // Ownership if channel is given to DoConnect.
- scoped_refptr<JingleChannel> channel = new JingleChannel(callback);
- message_loop()->PostTask(
- FROM_HERE, NewRunnableMethod(this, &JingleClient::DoConnect,
- channel, host_jid, callback));
- return channel;
-}
-
-void JingleClient::DoConnect(scoped_refptr<JingleChannel> channel,
- const std::string& host_jid,
- JingleChannel::Callback* callback) {
- DCHECK_EQ(message_loop(), MessageLoop::current());
-
- talk_base::StreamInterface* stream =
- tunnel_session_client_->CreateTunnel(buzz::Jid(host_jid), "");
- DCHECK(stream != NULL);
-
- channel->Init(thread_, stream, host_jid);
}
void JingleClient::Close() {
@@ -170,7 +120,6 @@ void JingleClient::DoClose() {
DCHECK_EQ(message_loop(), MessageLoop::current());
DCHECK(closed_);
- tunnel_session_client_.reset();
session_manager_.reset();
port_allocator_.reset();
network_manager_.reset();
@@ -226,30 +175,6 @@ void JingleClient::OnConnectionStateChanged(buzz::XmppEngine::State state) {
}
}
-void JingleClient::OnIncomingTunnel(
- cricket::TunnelSessionClient* client, buzz::Jid jid,
- std::string description, cricket::Session* session) {
- // Must always lock state and check closed_ when calling callback.
- AutoLock auto_lock(state_lock_);
-
- if (closed_) {
- // Always reject connection if we are closed.
- client->DeclineTunnel(session);
- return;
- }
-
- JingleChannel::Callback* channel_callback;
- if (callback_->OnAcceptConnection(this, jid.Str(), &channel_callback)) {
- DCHECK(channel_callback != NULL);
- talk_base::StreamInterface* stream = client->AcceptTunnel(session);
- scoped_refptr<JingleChannel> channel(new JingleChannel(channel_callback));
- channel->Init(thread_, stream, jid.Str());
- callback_->OnNewConnection(this, channel);
- } else {
- client->DeclineTunnel(session);
- }
-}
-
void JingleClient::SetFullJid(const std::string& full_jid) {
AutoLock auto_lock(full_jid_lock_);
full_jid_ = full_jid;
diff --git a/remoting/jingle_glue/jingle_client.h b/remoting/jingle_glue/jingle_client.h
index e9bf84d..1d0920a 100644
--- a/remoting/jingle_glue/jingle_client.h
+++ b/remoting/jingle_glue/jingle_client.h
@@ -7,10 +7,12 @@
#include <string>
-#include "remoting/jingle_glue/jingle_channel.h"
+#include "base/lock.h"
+#include "base/ref_counted.h"
#include "third_party/libjingle/source/talk/xmpp/xmppclient.h"
class MessageLoop;
+class Task;
namespace talk_base {
class NetworkManager;
@@ -31,6 +33,7 @@ class Session;
namespace remoting {
class IqRequest;
+class JingleThread;
class JingleClient : public base::RefCountedThreadSafe<JingleClient>,
public sigslot::has_slots<> {
@@ -48,18 +51,6 @@ class JingleClient : public base::RefCountedThreadSafe<JingleClient>,
// Called when state of the connection is changed.
virtual void OnStateChange(JingleClient* client, State state) = 0;
-
- // Called when a client attempts to connect to the machine. If the
- // connection should be accepted, must return true and must set
- // channel_callback to the callback for the new channel.
- virtual bool OnAcceptConnection(
- JingleClient* client, const std::string& jid,
- JingleChannel::Callback** channel_callback) = 0;
-
- // Called when a new client connects to the host. Ownership of the |channel|
- // is transfered to the callee.
- virtual void OnNewConnection(JingleClient* client,
- scoped_refptr<JingleChannel> channel) = 0;
};
// Creates a JingleClient object that executes on |thread|. This does not
@@ -74,14 +65,6 @@ class JingleClient : public base::RefCountedThreadSafe<JingleClient>,
void Init(const std::string& username, const std::string& auth_token,
const std::string& auth_token_service, Callback* callback);
- // Creates new JingleChannel connected to the host with the specified jid.
- // The result is returned immediately but the channel fails if the host
- // rejects connection. |host_jid| must be a full jid (includes resource ID).
- // Ownership of the result is transfered to the caller. The channel must
- // be closed/destroyed before JingleClient is destroyed.
- JingleChannel* Connect(const std::string& host_jid,
- JingleChannel::Callback* callback);
-
// Closes XMPP connection and stops the thread. Must be called before the
// object is destroyed. If specified, |closed_task| is executed after the
// connection is successfully closed.
@@ -115,18 +98,10 @@ class JingleClient : public base::RefCountedThreadSafe<JingleClient>,
void OnConnectionStateChanged(buzz::XmppEngine::State state);
- void OnIncomingTunnel(cricket::TunnelSessionClient* client, buzz::Jid jid,
- std::string description, cricket::Session* session);
-
void DoInitialize(const std::string& username,
const std::string& auth_token,
const std::string& auth_token_service);
- // Used by Connect().
- void DoConnect(scoped_refptr<JingleChannel> channel,
- const std::string& host_jid,
- JingleChannel::Callback* callback);
-
// Used by Close().
void DoClose();
@@ -160,7 +135,6 @@ class JingleClient : public base::RefCountedThreadSafe<JingleClient>,
scoped_ptr<talk_base::NetworkManager> network_manager_;
scoped_ptr<cricket::BasicPortAllocator> port_allocator_;
scoped_ptr<cricket::SessionManager> session_manager_;
- scoped_ptr<cricket::TunnelSessionClient> tunnel_session_client_;
DISALLOW_COPY_AND_ASSIGN(JingleClient);
};
diff --git a/remoting/jingle_glue/jingle_client_unittest.cc b/remoting/jingle_glue/jingle_client_unittest.cc
index 4d6d55f..38236f4 100644
--- a/remoting/jingle_glue/jingle_client_unittest.cc
+++ b/remoting/jingle_glue/jingle_client_unittest.cc
@@ -17,11 +17,6 @@ class MockJingleClientCallback : public JingleClient::Callback {
~MockJingleClientCallback() { }
MOCK_METHOD2(OnStateChange, void(JingleClient*, JingleClient::State));
- MOCK_METHOD3(OnAcceptConnection, bool(
- JingleClient*, const std::string&,
- JingleChannel::Callback**_callback));
- MOCK_METHOD2(OnNewConnection, void(
- JingleClient*, scoped_refptr<JingleChannel>));
};
class JingleClientTest : public testing::Test {
diff --git a/remoting/jingle_glue/jingle_test_client.cc b/remoting/jingle_glue/jingle_test_client.cc
deleted file mode 100644
index 4157930b..0000000
--- a/remoting/jingle_glue/jingle_test_client.cc
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "build/build_config.h"
-
-#if !defined(OS_WIN)
-extern "C" {
-#include <unistd.h>
-}
-#endif // !defined(OS_WIN)
-
-#include <iostream>
-#include <list>
-
-#include "base/at_exit.h"
-#include "base/nss_util.h"
-#include "base/time.h"
-#include "media/base/data_buffer.h"
-#include "remoting/base/constants.h"
-#include "remoting/jingle_glue/jingle_channel.h"
-#include "remoting/jingle_glue/jingle_client.h"
-#include "remoting/jingle_glue/jingle_thread.h"
-
-using remoting::JingleClient;
-using remoting::JingleChannel;
-using remoting::kChromotingTokenServiceName;
-
-class JingleTestClient : public JingleChannel::Callback,
- public JingleClient::Callback,
- public base::RefCountedThreadSafe<JingleTestClient> {
- public:
- JingleTestClient()
- : closed_event_(true, false) {
- }
-
- virtual ~JingleTestClient() {}
-
- void Run(const std::string& username, const std::string& auth_token,
- const std::string& host_jid) {
- remoting::JingleThread jingle_thread;
- jingle_thread.Start();
- client_ = new JingleClient(&jingle_thread);
- client_->Init(username, auth_token, kChromotingTokenServiceName, this);
-
- if (host_jid != "") {
- scoped_refptr<JingleChannel> channel = client_->Connect(host_jid, this);
- channels_.push_back(channel);
- }
-
- while (true) {
- std::string line;
- std::getline(std::cin, line);
-
- {
- AutoLock auto_lock(channels_lock_);
-
- // Broadcast message to all clients.
- for (ChannelsList::iterator it = channels_.begin();
- it != channels_.end(); ++it) {
- uint8* buf = new uint8[line.length()];
- memcpy(buf, line.c_str(), line.length());
- (*it)->Write(new media::DataBuffer(buf, line.length()));
- }
- }
-
- if (line == "exit")
- break;
- }
-
- while (!channels_.empty()) {
- closed_event_.Reset();
- channels_.front()->Close(
- NewRunnableMethod(this, &JingleTestClient::OnClosed));
- // Wait until channel is closed. If it is not closed within 0.1 seconds
- // continue closing everything else.
- closed_event_.TimedWait(base::TimeDelta::FromMilliseconds(100));
- channels_.pop_front();
- }
-
- client_->Close();
- jingle_thread.Stop();
- }
-
- // JingleChannel::Callback interface.
- void OnStateChange(JingleChannel* channel, JingleChannel::State state) {
- LOG(INFO) << "State of " << channel->jid() << " changed to " << state;
- }
-
- void OnPacketReceived(JingleChannel* channel,
- scoped_refptr<media::DataBuffer> buffer) {
- std::string str(reinterpret_cast<const char*>(buffer->GetData()),
- buffer->GetDataSize());
- std::cout << "(" << channel->jid() << "): " << str << std::endl;
- }
-
- // JingleClient::Callback interface.
- void OnStateChange(JingleClient* client, JingleClient::State state) {
- if (state == JingleClient::CONNECTED) {
- std::cerr << "Connected as " << client->GetFullJid() << std::endl;
- } else if (state == JingleClient::CLOSED) {
- std::cerr << "Connection closed" << std::endl;
- }
- }
-
- bool OnAcceptConnection(JingleClient* client, const std::string& jid,
- JingleChannel::Callback** callback) {
- std::cerr << "Accepting new connection from " << jid << std::endl;
- *callback = this;
- return true;
- }
-
- void OnNewConnection(JingleClient* client,
- scoped_refptr<JingleChannel> channel) {
- std::cerr << "Connected to " << channel->jid() << std::endl;
- AutoLock auto_lock(channels_lock_);
- channels_.push_back(channel);
- }
-
- void OnClosed() {
- closed_event_.Signal();
- }
-
- private:
- typedef std::list<scoped_refptr<JingleChannel> > ChannelsList;
-
- scoped_refptr<JingleClient> client_;
- ChannelsList channels_;
- Lock channels_lock_;
- base::WaitableEvent closed_event_;
-};
-
-int main(int argc, char** argv) {
- if (argc > 2)
- std::cerr << "Usage: " << argv[0] << " [<host_jid>]" << std::endl;
-
- base::AtExitManager exit_manager;
-
- base::EnsureNSPRInit();
- base::EnsureNSSInit();
-
- std::string host_jid = argc == 2 ? argv[1] : "";
-
- std::string username;
- std::cout << "JID: ";
- std::cin >> username;
-
- std::string auth_token;
- std::cout << "Auth token: ";
- std::cin >> auth_token;
-
- scoped_refptr<JingleTestClient> client = new JingleTestClient();
-
- client->Run(username, auth_token, host_jid);
-
- return 0;
-}
diff --git a/remoting/jingle_glue/mock_objects.h b/remoting/jingle_glue/mock_objects.h
index 0698ca6..5963132 100644
--- a/remoting/jingle_glue/mock_objects.h
+++ b/remoting/jingle_glue/mock_objects.h
@@ -6,23 +6,11 @@
#define REMOTING_JINGLE_GLUE_MOCK_OBJECTS_H_
#include "media/base/data_buffer.h"
-#include "remoting/jingle_glue/jingle_channel.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/libjingle/source/talk/base/stream.h"
namespace remoting {
-class MockJingleChannel : public JingleChannel {
- public:
- MockJingleChannel() {}
-
- MOCK_METHOD1(Write, void(scoped_refptr<media::DataBuffer> data));
- MOCK_METHOD0(Close, void());
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockJingleChannel);
-};
-
class MockStream : public talk_base::StreamInterface {
public:
virtual ~MockStream() { }
diff --git a/remoting/protocol/protocol_test_client.cc b/remoting/protocol/protocol_test_client.cc
index 804b008..7c15b0e 100644
--- a/remoting/protocol/protocol_test_client.cc
+++ b/remoting/protocol/protocol_test_client.cc
@@ -96,10 +96,6 @@ class ProtocolTestClient
// JingleClient::Callback interface.
virtual void OnStateChange(JingleClient* client, JingleClient::State state);
- virtual bool OnAcceptConnection(JingleClient* client, const std::string& jid,
- JingleChannel::Callback** callback);
- virtual void OnNewConnection(JingleClient* client,
- scoped_refptr<JingleChannel> channel);
// callback for JingleChromotingServer interface.
virtual void OnNewChromotocolConnection(ChromotingConnection* connection,
@@ -298,17 +294,6 @@ void ProtocolTestClient::OnStateChange(
}
}
-bool ProtocolTestClient::OnAcceptConnection(
- JingleClient* client, const std::string& jid,
- JingleChannel::Callback** callback) {
- return false;
-}
-
-void ProtocolTestClient::OnNewConnection(
- JingleClient* client, scoped_refptr<JingleChannel> channel) {
- NOTREACHED();
-}
-
void ProtocolTestClient::OnNewChromotocolConnection(
ChromotingConnection* connection, bool* accept) {
std::cerr << "Accepting connection from " << connection->jid() << std::endl;
diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp
index bcde3f5..951ddd8 100644
--- a/remoting/remoting.gyp
+++ b/remoting/remoting.gyp
@@ -313,8 +313,6 @@
'jingle_glue/channel_socket_adapter.h',
'jingle_glue/iq_request.cc',
'jingle_glue/iq_request.h',
- 'jingle_glue/jingle_channel.cc',
- 'jingle_glue/jingle_channel.h',
'jingle_glue/jingle_client.cc',
'jingle_glue/jingle_client.h',
'jingle_glue/jingle_info_task.cc',
@@ -337,19 +335,6 @@
}, # end of target 'chromoting_jingle_glue'
{
- 'target_name': 'chromoting_jingle_test_client',
- 'type': 'executable',
- 'dependencies': [
- 'chromoting_base',
- 'chromoting_jingle_glue',
- '../media/media.gyp:media',
- ],
- 'sources': [
- 'jingle_glue/jingle_test_client.cc',
- ],
- }, # end of target 'chromoting_jingle_test_client'
-
- {
'target_name': 'chromoting_protocol',
'type': '<(library)',
'dependencies': [
@@ -438,7 +423,6 @@
'host/test_key_pair.h',
'jingle_glue/channel_socket_adapter_unittest.cc',
'jingle_glue/jingle_client_unittest.cc',
- 'jingle_glue/jingle_channel_unittest.cc',
'jingle_glue/jingle_thread_unittest.cc',
'jingle_glue/iq_request_unittest.cc',
'jingle_glue/mock_objects.h',