summaryrefslogtreecommitdiffstats
path: root/jingle
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-23 02:02:46 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-23 02:02:46 +0000
commit16e4597aacc86dedb212835ccc5de13baab8bc23 (patch)
tree99a80b5ef22e59dc90136ff5856bd3e0dc98ab1c /jingle
parent06cb23886ba8f1eec7e6ad3217a76051b9079579 (diff)
downloadchromium_src-16e4597aacc86dedb212835ccc5de13baab8bc23.zip
chromium_src-16e4597aacc86dedb212835ccc5de13baab8bc23.tar.gz
chromium_src-16e4597aacc86dedb212835ccc5de13baab8bc23.tar.bz2
Remove StreamSocketAdapter.
PseudoTcpChannel is no longer used, so we don't need StreamSocketAdapter anymore. BUG=None TEST=compiles Review URL: http://codereview.chromium.org/6898032 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82769 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
-rw-r--r--jingle/glue/stream_socket_adapter.cc260
-rw-r--r--jingle/glue/stream_socket_adapter.h90
-rw-r--r--jingle/glue/stream_socket_adapter_unittest.cc151
-rw-r--r--jingle/jingle.gyp3
4 files changed, 0 insertions, 504 deletions
diff --git a/jingle/glue/stream_socket_adapter.cc b/jingle/glue/stream_socket_adapter.cc
deleted file mode 100644
index 315dc53..0000000
--- a/jingle/glue/stream_socket_adapter.cc
+++ /dev/null
@@ -1,260 +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 "jingle/glue/stream_socket_adapter.h"
-
-#include "base/logging.h"
-#include "base/message_loop.h"
-#include "net/base/address_list.h"
-#include "net/base/io_buffer.h"
-#include "net/base/net_errors.h"
-#include "third_party/libjingle/source/talk/base/stream.h"
-
-namespace jingle_glue {
-
-StreamSocketAdapter::StreamSocketAdapter(talk_base::StreamInterface* stream)
- : message_loop_(MessageLoop::current()),
- stream_(stream),
- read_pending_(false),
- write_pending_(false),
- closed_error_code_(net::OK) {
- DCHECK(stream);
- stream_->SignalEvent.connect(this, &StreamSocketAdapter::OnStreamEvent);
-}
-
-StreamSocketAdapter::~StreamSocketAdapter() {
-}
-
-int StreamSocketAdapter::Connect(net::CompletionCallback* callback) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
- return net::OK;
-}
-
-void StreamSocketAdapter::Disconnect() {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-}
-
-bool StreamSocketAdapter::IsConnected() const {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
- return true;
-}
-
-bool StreamSocketAdapter::IsConnectedAndIdle() const {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
- return true;
-}
-
-int StreamSocketAdapter::GetPeerAddress(net::AddressList* address) const {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-
- // We actually don't know the peer address. Returning so the upper layers
- // won't complain.
- net::IPAddressNumber ip_address(4);
- *address = net::AddressList(ip_address, 0, false);
- return net::OK;
-}
-
-int StreamSocketAdapter::GetLocalAddress(net::IPEndPoint* address) const {
- return net::ERR_UNEXPECTED;
-}
-
-const net::BoundNetLog& StreamSocketAdapter::NetLog() const {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
- return net_log_;
-}
-
-void StreamSocketAdapter::SetSubresourceSpeculation() {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-}
-
-void StreamSocketAdapter::SetOmniboxSpeculation() {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-}
-
-bool StreamSocketAdapter::WasEverUsed() const {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
- return true;
-}
-
-bool StreamSocketAdapter::UsingTCPFastOpen() const {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
- return false;
-}
-
-int StreamSocketAdapter::Read(
- net::IOBuffer* buffer, int buffer_size, net::CompletionCallback* callback) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
- DCHECK(buffer);
- CHECK(!read_pending_);
-
- if (!stream_.get()) {
- DCHECK(closed_error_code_ != net::OK);
- return closed_error_code_;
- }
-
- int result = ReadStream(buffer, buffer_size);
- if (result == net::ERR_SOCKET_NOT_CONNECTED &&
- stream_->GetState() == talk_base::SS_OPENING)
- result = net::ERR_IO_PENDING;
- if (result == net::ERR_IO_PENDING) {
- read_pending_ = true;
- read_callback_ = callback;
- read_buffer_ = buffer;
- read_buffer_size_ = buffer_size;
- }
- return result;
-}
-
-int StreamSocketAdapter::Write(
- net::IOBuffer* buffer, int buffer_size, net::CompletionCallback* callback) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
- DCHECK(buffer);
- CHECK(!write_pending_);
-
- if (!stream_.get()) {
- DCHECK(closed_error_code_ != net::OK);
- return closed_error_code_;
- }
-
- int result = WriteStream(buffer, buffer_size);
- if (result == net::ERR_SOCKET_NOT_CONNECTED &&
- stream_->GetState() == talk_base::SS_OPENING)
- result = net::ERR_IO_PENDING;
-
- if (result == net::ERR_IO_PENDING) {
- write_pending_ = true;
- write_callback_ = callback;
- write_buffer_ = buffer;
- write_buffer_size_ = buffer_size;
- }
- return result;
-}
-
-bool StreamSocketAdapter::SetReceiveBufferSize(int32 size) {
- NOTIMPLEMENTED();
- return false;
-}
-
-bool StreamSocketAdapter::SetSendBufferSize(int32 size) {
- NOTIMPLEMENTED();
- return false;
-}
-
-void StreamSocketAdapter::Close(int error_code) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-
- if (!stream_.get()) // Already closed.
- return;
-
- DCHECK(error_code != net::OK);
- closed_error_code_ = error_code;
- stream_->SignalEvent.disconnect(this);
- stream_->Close();
- stream_.reset(NULL);
-
- if (read_pending_) {
- net::CompletionCallback* callback = read_callback_;
- read_pending_ = false;
- read_buffer_ = NULL;
- callback->Run(error_code);
- }
-
- if (write_pending_) {
- net::CompletionCallback* callback = write_callback_;
- write_pending_ = false;
- write_buffer_ = NULL;
- callback->Run(error_code);
- }
-}
-
-void StreamSocketAdapter::OnStreamEvent(
- talk_base::StreamInterface* stream, int events, int error) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-
- if (events & talk_base::SE_WRITE)
- DoWrite();
-
- if (events & talk_base::SE_READ)
- DoRead();
-}
-
-void StreamSocketAdapter::DoWrite() {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-
- // Write if there is a pending read.
- if (write_buffer_) {
- int result = WriteStream(write_buffer_, write_buffer_size_);
- if (result != net::ERR_IO_PENDING) {
- net::CompletionCallback* callback = write_callback_;
- write_pending_ = false;
- write_buffer_ = NULL;
- callback->Run(result);
- }
- }
-}
-
-void StreamSocketAdapter::DoRead() {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-
- // Read if there is a pending read.
- if (read_pending_) {
- int result = ReadStream(read_buffer_, read_buffer_size_);
- if (result != net::ERR_IO_PENDING) {
- net::CompletionCallback* callback = read_callback_;\
- read_pending_ = false;
- read_buffer_ = NULL;
- callback->Run(result);
- }
- }
-}
-
-int StreamSocketAdapter::ReadStream(net::IOBuffer* buffer, int buffer_size) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-
- size_t bytes_read;
- int error;
- talk_base::StreamResult result = stream_->Read(
- buffer->data(), buffer_size, &bytes_read, &error);
- switch (result) {
- case talk_base::SR_SUCCESS:
- return bytes_read;
-
- case talk_base::SR_BLOCK:
- return net::ERR_IO_PENDING;
-
- case talk_base::SR_EOS:
- return net::ERR_CONNECTION_CLOSED;
-
- case talk_base::SR_ERROR:
- return net::MapSystemError(error);
- }
- NOTREACHED();
- return net::ERR_FAILED;
-}
-
-int StreamSocketAdapter::WriteStream(net::IOBuffer* buffer, int buffer_size) {
- DCHECK_EQ(MessageLoop::current(), message_loop_);
-
- size_t bytes_written;
- int error;
- talk_base::StreamResult result = stream_->Write(
- buffer->data(), buffer_size, &bytes_written, &error);
- switch (result) {
- case talk_base::SR_SUCCESS:
- return bytes_written;
-
- case talk_base::SR_BLOCK:
- return net::ERR_IO_PENDING;
-
- case talk_base::SR_EOS:
- return net::ERR_CONNECTION_CLOSED;
-
- case talk_base::SR_ERROR:
- return net::MapSystemError(error);
- }
- NOTREACHED();
- return net::ERR_FAILED;
-}
-
-} // namespace jingle_glue
diff --git a/jingle/glue/stream_socket_adapter.h b/jingle/glue/stream_socket_adapter.h
deleted file mode 100644
index 14a6bfc..0000000
--- a/jingle/glue/stream_socket_adapter.h
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright (c) 2011 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 JINGLE_GLUE_STREAM_SOCKET_ADAPTER_H_
-#define JINGLE_GLUE_STREAM_SOCKET_ADAPTER_H_
-
-#include "base/memory/scoped_ptr.h"
-#include "net/base/net_log.h"
-#include "net/socket/client_socket.h"
-#include "third_party/libjingle/source/talk/base/sigslot.h"
-
-class MessageLoop;
-
-namespace talk_base {
-class StreamInterface;
-} // namespace talk_base
-
-namespace jingle_glue {
-
-// StreamSocketAdapter implements net::Socket interface on top of
-// libjingle's StreamInterface. It is used by JingleChromotocolConnection
-// to provide net::Socket interface for channels.
-class StreamSocketAdapter : public net::ClientSocket,
- public sigslot::has_slots<> {
- public:
- // Ownership of the stream is passed to the adapter.
- explicit StreamSocketAdapter(talk_base::StreamInterface* stream);
- virtual ~StreamSocketAdapter();
-
- // ClientSocket interface.
- virtual int Connect(net::CompletionCallback* callback);
- virtual void Disconnect();
- virtual bool IsConnected() const;
- virtual bool IsConnectedAndIdle() const;
- virtual int GetPeerAddress(net::AddressList* address) const;
- virtual int GetLocalAddress(net::IPEndPoint* address) const;
- virtual const net::BoundNetLog& NetLog() const;
- virtual void SetSubresourceSpeculation();
- virtual void SetOmniboxSpeculation();
- virtual bool WasEverUsed() const;
- virtual bool UsingTCPFastOpen() const;
-
- // Closes the stream. |error_code| specifies error code that will
- // be returned by Read() and Write() after the stream is closed.
- void Close(int error_code);
-
- // Socket interface.
- virtual int Read(net::IOBuffer* buffer, int buffer_size,
- net::CompletionCallback* callback);
- virtual int Write(net::IOBuffer* buffer, int buffer_size,
- net::CompletionCallback* callback);
-
- virtual bool SetReceiveBufferSize(int32 size);
- virtual bool SetSendBufferSize(int32 size);
-
- private:
- void OnStreamEvent(talk_base::StreamInterface* stream,
- int events, int error);
-
- void DoWrite();
- void DoRead();
-
- int ReadStream(net::IOBuffer* buffer, int buffer_size);
- int WriteStream(net::IOBuffer* buffer, int buffer_size);
-
- MessageLoop* message_loop_;
-
- scoped_ptr<talk_base::StreamInterface> stream_;
-
- bool read_pending_;
- net::CompletionCallback* read_callback_;
- scoped_refptr<net::IOBuffer> read_buffer_;
- int read_buffer_size_;
-
- bool write_pending_;
- net::CompletionCallback* write_callback_;
- scoped_refptr<net::IOBuffer> write_buffer_;
- int write_buffer_size_;
-
- int closed_error_code_;
-
- net::BoundNetLog net_log_;
-
- DISALLOW_COPY_AND_ASSIGN(StreamSocketAdapter);
-};
-
-} // namespace jingle_glue
-
-#endif // JINGLE_GLUE_STREAM_SOCKET_ADAPTER_H_
diff --git a/jingle/glue/stream_socket_adapter_unittest.cc b/jingle/glue/stream_socket_adapter_unittest.cc
deleted file mode 100644
index bac43e5..0000000
--- a/jingle/glue/stream_socket_adapter_unittest.cc
+++ /dev/null
@@ -1,151 +0,0 @@
-// Copyright (c) 2011 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/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop.h"
-#include "jingle/glue/stream_socket_adapter.h"
-#include "jingle/glue/jingle_glue_mock_objects.h"
-#include "net/base/io_buffer.h"
-#include "net/base/net_errors.h"
-#include "net/socket/socket.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "third_party/libjingle/source/talk/p2p/base/transportchannel.h"
-
-using net::IOBuffer;
-
-using testing::_;
-using testing::Return;
-using testing::SetArgumentPointee;
-
-namespace jingle_glue {
-
-namespace {
-const int kBufferSize = 4096;
-const int kTestDataSize = 4;
-const int kTestError = -32123;
-} // namespace
-
-class StreamSocketAdapterTest : public testing::Test {
- public:
- StreamSocketAdapterTest()
- : ALLOW_THIS_IN_INITIALIZER_LIST(
- callback_(this, &StreamSocketAdapterTest::Callback)),
- callback_result_(0) {
- stream_ = new MockStream();
- target_.reset(new StreamSocketAdapter(stream_));
- }
-
- protected:
- void Callback(int result) {
- callback_result_ = result;
- }
-
- // |stream_| must be allocated on the heap, because StreamSocketAdapter
- // owns the object and it will free it in the end.
- MockStream* stream_;
- scoped_ptr<StreamSocketAdapter> target_;
- net::CompletionCallbackImpl<StreamSocketAdapterTest> callback_;
- int callback_result_;
- MessageLoopForIO message_loop_;
-};
-
-// Verify that Read() calls Read() in stream.
-TEST_F(StreamSocketAdapterTest, Read) {
- scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize));
-
- EXPECT_CALL(*stream_, Read(buffer->data(), kBufferSize, _, _))
- .WillOnce(DoAll(SetArgumentPointee<2>(kTestDataSize),
- Return(talk_base::SR_SUCCESS)));
-
- int result = target_->Read(buffer, kBufferSize, &callback_);
- EXPECT_EQ(kTestDataSize, result);
- EXPECT_EQ(0, callback_result_);
-}
-
-// Verify that read callback is called for pending reads.
-TEST_F(StreamSocketAdapterTest, ReadPending) {
- scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize));
-
- EXPECT_CALL(*stream_, Read(buffer->data(), kBufferSize, _, _))
- .Times(2)
- .WillOnce(Return(talk_base::SR_BLOCK))
- .WillOnce(DoAll(SetArgumentPointee<2>(kTestDataSize),
- Return(talk_base::SR_SUCCESS)));
-
- int result = target_->Read(buffer, kBufferSize, &callback_);
- ASSERT_EQ(net::ERR_IO_PENDING, result);
-
- stream_->SignalEvent(stream_, talk_base::SE_READ, 0);
- EXPECT_EQ(kTestDataSize, callback_result_);
-}
-
-// Verify that Read() returns error after Close().
-TEST_F(StreamSocketAdapterTest, ReadClose) {
- scoped_refptr<IOBuffer> buffer(new IOBuffer(kBufferSize));
-
- EXPECT_CALL(*stream_, Read(buffer->data(), kBufferSize, _, _))
- .WillOnce(Return(talk_base::SR_BLOCK));
-
- int result = target_->Read(buffer, kBufferSize, &callback_);
- ASSERT_EQ(net::ERR_IO_PENDING, result);
-
- EXPECT_CALL(*stream_, Close());
- target_->Close(kTestError);
- EXPECT_EQ(kTestError, callback_result_);
-
- // All Read() calls after Close() should return the error.
- EXPECT_EQ(kTestError, target_->Read(buffer, kBufferSize, &callback_));
-}
-
-// Verify that Write() calls stream's Write() and returns result.
-TEST_F(StreamSocketAdapterTest, Write) {
- scoped_refptr<IOBuffer> buffer(new IOBuffer(kTestDataSize));
-
- EXPECT_CALL(*stream_, Write(buffer->data(), kTestDataSize, _, _))
- .WillOnce(DoAll(SetArgumentPointee<2>(kTestDataSize),
- Return(talk_base::SR_SUCCESS)));
-
- int result = target_->Write(buffer, kTestDataSize, &callback_);
- EXPECT_EQ(kTestDataSize, result);
- EXPECT_EQ(0, callback_result_);
-}
-
-// Verify that write callback is called for pending writes.
-TEST_F(StreamSocketAdapterTest, WritePending) {
- scoped_refptr<IOBuffer> buffer(new IOBuffer(kTestDataSize));
-
- EXPECT_CALL(*stream_, Write(buffer->data(), kTestDataSize, _, _))
- .Times(2)
- .WillOnce(Return(talk_base::SR_BLOCK))
- .WillOnce(DoAll(SetArgumentPointee<2>(kTestDataSize),
- Return(talk_base::SR_SUCCESS)));
-
- int result = target_->Write(buffer, kTestDataSize, &callback_);
- ASSERT_EQ(net::ERR_IO_PENDING, result);
-
- stream_->SignalEvent(stream_, talk_base::SE_WRITE, 0);
- EXPECT_EQ(kTestDataSize, callback_result_);
-}
-
-// Verify that Write() returns error after Close().
-TEST_F(StreamSocketAdapterTest, WriteClose) {
- scoped_refptr<IOBuffer> buffer(new IOBuffer(kTestDataSize));
-
- EXPECT_CALL(*stream_, Write(buffer->data(), kTestDataSize, _, _))
- .WillOnce(Return(talk_base::SR_BLOCK));
-
- int result = target_->Write(buffer, kTestDataSize, &callback_);
- ASSERT_EQ(net::ERR_IO_PENDING, result);
-
- EXPECT_CALL(*stream_, Close());
- target_->Close(kTestError);
- EXPECT_EQ(kTestError, callback_result_);
-
- // All Write() calls after Close() should return the error.
- EXPECT_EQ(kTestError, target_->Write(buffer, kTestError, &callback_));
-}
-
-} // namespace jingle_glue
diff --git a/jingle/jingle.gyp b/jingle/jingle.gyp
index 09cbc51..c796210 100644
--- a/jingle/jingle.gyp
+++ b/jingle/jingle.gyp
@@ -16,8 +16,6 @@
'glue/channel_socket_adapter.h',
'glue/pseudotcp_adapter.cc',
'glue/pseudotcp_adapter.h',
- 'glue/stream_socket_adapter.cc',
- 'glue/stream_socket_adapter.h',
'glue/thread_wrapper.cc',
'glue/thread_wrapper.h',
'glue/utils.cc',
@@ -154,7 +152,6 @@
'glue/jingle_glue_mock_objects.cc',
'glue/jingle_glue_mock_objects.h',
'glue/pseudotcp_adapter_unittest.cc',
- 'glue/stream_socket_adapter_unittest.cc',
'glue/thread_wrapper_unittest.cc',
'notifier/base/chrome_async_socket_unittest.cc',
'notifier/base/fake_ssl_client_socket_unittest.cc',