summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 09:35:30 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 09:35:30 +0000
commit3d6ddbadc0c670fa3db69f7173a67da09f9f1a12 (patch)
treeaa1cc86f6426f6607360670e21023969f697f16d
parent387a6ceae16e24b7ed19dc143f97c3378ca343df (diff)
downloadchromium_src-3d6ddbadc0c670fa3db69f7173a67da09f9f1a12.zip
chromium_src-3d6ddbadc0c670fa3db69f7173a67da09f9f1a12.tar.gz
chromium_src-3d6ddbadc0c670fa3db69f7173a67da09f9f1a12.tar.bz2
Moved ChromeAsyncSocket to jingle/notifier/base.
Fixed some signed/unsigned warnings. BUG=45612 TEST=existing unittests Review URL: http://codereview.chromium.org/2857039 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52638 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/sync/tools/sync_listen_notifications.cc4
-rw-r--r--chrome/browser/sync/tools/sync_tools.gyp46
-rw-r--r--jingle/jingle.gyp5
-rw-r--r--jingle/notifier/base/chrome_async_socket.cc (renamed from chrome/browser/sync/tools/chrome_async_socket.cc)85
-rw-r--r--jingle/notifier/base/chrome_async_socket.h (renamed from chrome/browser/sync/tools/chrome_async_socket.h)10
-rw-r--r--jingle/notifier/base/chrome_async_socket_unittest.cc (renamed from chrome/browser/sync/tools/chrome_async_socket_unittest.cc)18
6 files changed, 64 insertions, 104 deletions
diff --git a/chrome/browser/sync/tools/sync_listen_notifications.cc b/chrome/browser/sync/tools/sync_listen_notifications.cc
index d2c972a..69431e1 100644
--- a/chrome/browser/sync/tools/sync_listen_notifications.cc
+++ b/chrome/browser/sync/tools/sync_listen_notifications.cc
@@ -17,8 +17,8 @@
#include "chrome/browser/sync/notifier/chrome_invalidation_client.h"
#include "chrome/browser/sync/notifier/chrome_system_resources.h"
#include "chrome/browser/sync/sync_constants.h"
-#include "chrome/browser/sync/tools/chrome_async_socket.h"
#include "chrome/common/chrome_switches.h"
+#include "jingle/notifier/base/chrome_async_socket.h"
#include "jingle/notifier/base/task_pump.h"
#include "jingle/notifier/communicator/xmpp_socket_adapter.h"
#include "jingle/notifier/listener/listen_task.h"
@@ -100,7 +100,7 @@ class XmppNotificationClient : public sigslot::has_slots<> {
buzz::AsyncSocket* buzz_async_socket =
use_chrome_async_socket ?
static_cast<buzz::AsyncSocket*>(
- new sync_tools::ChromeAsyncSocket(
+ new notifier::ChromeAsyncSocket(
net::ClientSocketFactory::GetDefaultFactory(),
ssl_config, 4096, 64 * 1024, NULL)) :
static_cast<buzz::AsyncSocket*>(
diff --git a/chrome/browser/sync/tools/sync_tools.gyp b/chrome/browser/sync/tools/sync_tools.gyp
index 0205024..18d163c 100644
--- a/chrome/browser/sync/tools/sync_tools.gyp
+++ b/chrome/browser/sync/tools/sync_tools.gyp
@@ -5,22 +5,6 @@
{
'targets': [
{
- 'target_name': 'chrome_async_socket',
- 'type': '<(library)',
- 'sources': [
- 'chrome_async_socket.cc',
- 'chrome_async_socket.h',
- ],
- 'dependencies': [
- '<(DEPTH)/base/base.gyp:base',
- '<(DEPTH)/net/net.gyp:net',
- '<(DEPTH)/third_party/libjingle/libjingle.gyp:libjingle',
- ],
- 'export_dependent_settings': [
- '<(DEPTH)/third_party/libjingle/libjingle.gyp:libjingle',
- ],
- },
- {
'target_name': 'sync_listen_notifications',
'type': 'executable',
'sources': [
@@ -32,7 +16,6 @@
'<(DEPTH)/chrome/browser/sync/sync_constants.h',
],
'dependencies': [
- 'chrome_async_socket',
'<(DEPTH)/base/base.gyp:base',
'<(DEPTH)/chrome/chrome.gyp:common_constants',
'<(DEPTH)/chrome/chrome.gyp:sync_notifier',
@@ -40,35 +23,6 @@
'<(DEPTH)/third_party/libjingle/libjingle.gyp:libjingle',
],
},
- {
- 'target_name': 'chrome_async_socket_unit_tests',
- 'type': 'executable',
- 'sources': [
- # TODO(akalin): Write our own test suite and runner.
- '<(DEPTH)/base/test/run_all_unittests.cc',
- '<(DEPTH)/base/test/test_suite.h',
- 'chrome_async_socket_unittest.cc',
- ],
- 'dependencies': [
- 'chrome_async_socket',
- '<(DEPTH)/base/base.gyp:base',
- '<(DEPTH)/net/net.gyp:net',
- '<(DEPTH)/net/net.gyp:net_test_support',
- '<(DEPTH)/testing/gtest.gyp:gtest',
- ],
- # TODO(akalin): Remove this once we have our own test suite and
- # runner.
- 'conditions': [
- ['OS == "linux" or OS == "freebsd" or OS == "openbsd" or OS == "solaris"', {
- 'dependencies': [
- # Needed to handle the #include chain:
- # base/test/test_suite.h
- # gtk/gtk.h
- '<(DEPTH)/build/linux/system.gyp:gtk',
- ],
- }],
- ],
- },
],
}
diff --git a/jingle/jingle.gyp b/jingle/jingle.gyp
index 99f74f3..e950c46 100644
--- a/jingle/jingle.gyp
+++ b/jingle/jingle.gyp
@@ -15,6 +15,8 @@
'target_name': 'notifier',
'type': '<(library)',
'sources': [
+ 'notifier/base/chrome_async_socket.cc',
+ 'notifier/base/chrome_async_socket.h',
'notifier/base/signal_thread_task.h',
'notifier/base/ssl_adapter.h',
'notifier/base/ssl_adapter.cc',
@@ -96,6 +98,7 @@
# TODO(akalin): Write our own test suite and runner.
'../base/test/run_all_unittests.cc',
'../base/test/test_suite.h',
+ 'notifier/base/chrome_async_socket_unittest.cc',
'notifier/listener/talk_mediator_unittest.cc',
'notifier/listener/send_update_task_unittest.cc',
'notifier/listener/subscribe_task_unittest.cc',
@@ -107,6 +110,8 @@
'dependencies': [
'notifier',
'../base/base.gyp:base',
+ '../net/net.gyp:net',
+ '../net/net.gyp:net_test_support',
'../testing/gmock.gyp:gmock',
'../testing/gtest.gyp:gtest',
'../third_party/libjingle/libjingle.gyp:libjingle',
diff --git a/chrome/browser/sync/tools/chrome_async_socket.cc b/jingle/notifier/base/chrome_async_socket.cc
index e5d662f..85929c1 100644
--- a/chrome/browser/sync/tools/chrome_async_socket.cc
+++ b/jingle/notifier/base/chrome_async_socket.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/sync/tools/chrome_async_socket.h"
+#include "jingle/notifier/base/chrome_async_socket.h"
#if defined(OS_WIN)
#include <winsock2.h>
@@ -25,7 +25,7 @@
#include "net/socket/tcp_client_socket.h"
#include "talk/base/socketaddress.h"
-namespace sync_tools {
+namespace notifier {
ChromeAsyncSocket::ChromeAsyncSocket(
net::ClientSocketFactory* client_socket_factory,
@@ -52,14 +52,14 @@ ChromeAsyncSocket::ChromeAsyncSocket(
ALLOW_THIS_IN_INITIALIZER_LIST(this)),
read_state_(IDLE),
read_buf_(new net::IOBufferWithSize(read_buf_size)),
- read_start_(0),
- read_end_(0),
+ read_start_(0U),
+ read_end_(0U),
write_state_(IDLE),
write_buf_(new net::IOBufferWithSize(write_buf_size)),
- write_end_(0) {
+ write_end_(0U) {
DCHECK(client_socket_factory_);
- DCHECK_GT(read_buf_size, 0);
- DCHECK_GT(write_buf_size, 0);
+ DCHECK_GT(read_buf_size, 0U);
+ DCHECK_GT(write_buf_size, 0U);
}
ChromeAsyncSocket::~ChromeAsyncSocket() {}
@@ -101,7 +101,7 @@ namespace {
net::AddressList SocketAddressToAddressList(
const talk_base::SocketAddress& address) {
- DCHECK_NE(address.ip(), 0);
+ DCHECK_NE(address.ip(), 0U);
// Use malloc() as net::AddressList uses free().
addrinfo* ai = static_cast<addrinfo*>(std::malloc(sizeof *ai));
memset(ai, 0, sizeof *ai);
@@ -181,7 +181,7 @@ void ChromeAsyncSocket::ProcessConnectDone(int status) {
state_ = STATE_OPEN;
PostDoRead();
// Write buffer should be empty.
- DCHECK_EQ(write_end_, 0);
+ DCHECK_EQ(write_end_, 0U);
SignalConnected();
}
@@ -190,8 +190,8 @@ void ChromeAsyncSocket::ProcessConnectDone(int status) {
void ChromeAsyncSocket::PostDoRead() {
DCHECK(IsOpen());
DCHECK_EQ(read_state_, IDLE);
- DCHECK_EQ(read_start_, 0);
- DCHECK_EQ(read_end_, 0);
+ DCHECK_EQ(read_start_, 0U);
+ DCHECK_EQ(read_end_, 0U);
MessageLoop* message_loop = MessageLoop::current();
CHECK(message_loop);
message_loop->PostTask(
@@ -206,8 +206,8 @@ void ChromeAsyncSocket::PostDoRead() {
void ChromeAsyncSocket::DoRead() {
DCHECK(IsOpen());
DCHECK_EQ(read_state_, POSTED);
- DCHECK_EQ(read_start_, 0);
- DCHECK_EQ(read_end_, 0);
+ DCHECK_EQ(read_start_, 0U);
+ DCHECK_EQ(read_end_, 0U);
// Once we call Read(), we cannot call StartTls() until the read
// finishes. This is okay, as StartTls() is called only from a read
// handler (i.e., after a read finishes and before another read is
@@ -227,11 +227,11 @@ void ChromeAsyncSocket::ProcessReadDone(int status) {
DCHECK_NE(status, net::ERR_IO_PENDING);
DCHECK(IsOpen());
DCHECK_EQ(read_state_, PENDING);
- DCHECK_EQ(read_start_, 0);
- DCHECK_EQ(read_end_, 0);
+ DCHECK_EQ(read_start_, 0U);
+ DCHECK_EQ(read_end_, 0U);
read_state_ = IDLE;
if (status > 0) {
- read_end_ = status;
+ read_end_ = static_cast<size_t>(status);
SignalRead();
} else if (status == 0) {
// Other side closed the connection.
@@ -261,10 +261,10 @@ bool ChromeAsyncSocket::Read(char* data, size_t len, size_t* len_read) {
return false;
}
DCHECK_LE(read_start_, read_end_);
- if ((state_ == STATE_TLS_CONNECTING) || read_end_ == 0) {
+ if ((state_ == STATE_TLS_CONNECTING) || read_end_ == 0U) {
if (state_ == STATE_TLS_CONNECTING) {
DCHECK_EQ(read_state_, IDLE);
- DCHECK_EQ(read_end_, 0);
+ DCHECK_EQ(read_end_, 0U);
} else {
DCHECK_NE(read_state_, IDLE);
}
@@ -273,12 +273,12 @@ bool ChromeAsyncSocket::Read(char* data, size_t len, size_t* len_read) {
}
DCHECK_EQ(read_state_, IDLE);
*len_read = std::min(len, read_end_ - read_start_);
- DCHECK_GT(*len_read, 0);
+ DCHECK_GT(*len_read, 0U);
std::memcpy(data, read_buf_->data() + read_start_, *len_read);
read_start_ += *len_read;
if (read_start_ == read_end_) {
- read_start_ = 0;
- read_end_ = 0;
+ read_start_ = 0U;
+ read_end_ = 0U;
// We defer execution of DoRead() here for similar reasons as
// ProcessConnectDone().
PostDoRead();
@@ -297,7 +297,7 @@ bool ChromeAsyncSocket::Write(const char* data, size_t len) {
}
// TODO(akalin): Avoid this check by modifying the interface to have
// a "ready for writing" signal.
- if ((write_buf_->size() - write_end_) < len) {
+ if ((static_cast<size_t>(write_buf_->size()) - write_end_) < len) {
LOG(DFATAL) << "queueing " << len << " bytes would exceed the "
<< "max write buffer size = " << write_buf_->size()
<< " by " << (len - write_buf_->size()) << " bytes";
@@ -310,7 +310,7 @@ bool ChromeAsyncSocket::Write(const char* data, size_t len) {
// the TLS-connect finishes. Otherwise, start writing if we're not
// already writing and we have something to write.
if ((state_ != STATE_TLS_CONNECTING) &&
- (write_state_ == IDLE) && (write_end_ > 0)) {
+ (write_state_ == IDLE) && (write_end_ > 0U)) {
// We defer execution of DoWrite() here for similar reasons as
// ProcessConnectDone().
PostDoWrite();
@@ -323,7 +323,7 @@ bool ChromeAsyncSocket::Write(const char* data, size_t len) {
void ChromeAsyncSocket::PostDoWrite() {
DCHECK(IsOpen());
DCHECK_EQ(write_state_, IDLE);
- DCHECK_GT(write_end_, 0);
+ DCHECK_GT(write_end_, 0U);
MessageLoop* message_loop = MessageLoop::current();
CHECK(message_loop);
message_loop->PostTask(
@@ -338,7 +338,7 @@ void ChromeAsyncSocket::PostDoWrite() {
void ChromeAsyncSocket::DoWrite() {
DCHECK(IsOpen());
DCHECK_EQ(write_state_, POSTED);
- DCHECK_GT(write_end_, 0);
+ DCHECK_GT(write_end_, 0U);
// Once we call Write(), we cannot call StartTls() until the write
// finishes. This is okay, as StartTls() is called only after we
// have received a reply to a message we sent to the server and
@@ -359,15 +359,16 @@ void ChromeAsyncSocket::ProcessWriteDone(int status) {
DCHECK_NE(status, net::ERR_IO_PENDING);
DCHECK(IsOpen());
DCHECK_EQ(write_state_, PENDING);
- DCHECK_GT(write_end_, 0);
+ DCHECK_GT(write_end_, 0U);
write_state_ = IDLE;
if (status < net::OK) {
DoNetErrorFromStatus(status);
DoClose();
return;
}
- if (status > write_end_) {
- LOG(DFATAL) << "bytes read = " << status
+ size_t written = static_cast<size_t>(status);
+ if (written > write_end_) {
+ LOG(DFATAL) << "bytes written = " << written
<< " exceeds bytes requested = " << write_end_;
DoNetError(net::ERR_UNEXPECTED);
DoClose();
@@ -377,10 +378,10 @@ void ChromeAsyncSocket::ProcessWriteDone(int status) {
// of DrainableIOBuffers. This'll also allow us to not have an
// artificial buffer size limit.
std::memmove(write_buf_->data(),
- write_buf_->data() + status,
- write_end_ - status);
- write_end_ -= status;
- if (write_end_ > 0) {
+ write_buf_->data() + written,
+ write_end_ - written);
+ write_end_ -= written;
+ if (write_end_ > 0U) {
PostDoWrite();
}
}
@@ -401,10 +402,10 @@ void ChromeAsyncSocket::DoClose() {
}
transport_socket_.reset();
read_state_ = IDLE;
- read_start_ = 0;
- read_end_ = 0;
+ read_start_ = 0U;
+ read_end_ = 0U;
write_state_ = IDLE;
- write_end_ = 0;
+ write_end_ = 0U;
if (state_ != STATE_CLOSED) {
state_ = STATE_CLOSED;
SignalClosed();
@@ -427,9 +428,9 @@ bool ChromeAsyncSocket::StartTls(const std::string& domain_name) {
state_ = STATE_TLS_CONNECTING;
read_state_ = IDLE;
- read_start_ = 0;
- read_end_ = 0;
- DCHECK_EQ(write_end_, 0);
+ read_start_ = 0U;
+ read_end_ = 0U;
+ DCHECK_EQ(write_end_, 0U);
// Clear out any posted DoRead() tasks.
scoped_runnable_method_factory_.RevokeAll();
@@ -459,8 +460,8 @@ void ChromeAsyncSocket::ProcessSSLConnectDone(int status) {
DCHECK_NE(status, net::ERR_IO_PENDING);
DCHECK_EQ(state_, STATE_TLS_CONNECTING);
DCHECK_EQ(read_state_, IDLE);
- DCHECK_EQ(read_start_, 0);
- DCHECK_EQ(read_end_, 0);
+ DCHECK_EQ(read_start_, 0U);
+ DCHECK_EQ(read_end_, 0U);
DCHECK_EQ(write_state_, IDLE);
if (status != net::OK) {
DoNetErrorFromStatus(status);
@@ -469,10 +470,10 @@ void ChromeAsyncSocket::ProcessSSLConnectDone(int status) {
}
state_ = STATE_TLS_OPEN;
PostDoRead();
- if (write_end_ > 0) {
+ if (write_end_ > 0U) {
PostDoWrite();
}
SignalSSLConnected();
}
-} // namespace sync_tools
+} // namespace notifier
diff --git a/chrome/browser/sync/tools/chrome_async_socket.h b/jingle/notifier/base/chrome_async_socket.h
index 63e1c3b..ebf8b38 100644
--- a/chrome/browser/sync/tools/chrome_async_socket.h
+++ b/jingle/notifier/base/chrome_async_socket.h
@@ -4,8 +4,8 @@
//
// An implementation of buzz::AsyncSocket that uses Chrome sockets.
-#ifndef CHROME_BROWSER_SYNC_TOOLS_CHROME_ASYNC_SOCKET_H_
-#define CHROME_BROWSER_SYNC_TOOLS_CHROME_ASYNC_SOCKET_H_
+#ifndef JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_
+#define JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_
#if !defined(FEATURE_ENABLE_SSL)
#error ChromeAsyncSocket expects FEATURE_ENABLE_SSL to be defined
@@ -30,7 +30,7 @@ class ClientSocketFactory;
class IOBufferWithSize;
} // namespace net
-namespace sync_tools {
+namespace notifier {
class ChromeAsyncSocket : public buzz::AsyncSocket {
public:
@@ -221,6 +221,6 @@ class ChromeAsyncSocket : public buzz::AsyncSocket {
DISALLOW_COPY_AND_ASSIGN(ChromeAsyncSocket);
};
-} // namespace sync_tools
+} // namespace notifier
-#endif // CHROME_BROWSER_SYNC_TOOLS_CHROME_ASYNC_SOCKET_H_
+#endif // JINGLE_NOTIFIER_BASE_CHROME_ASYNC_SOCKET_H_
diff --git a/chrome/browser/sync/tools/chrome_async_socket_unittest.cc b/jingle/notifier/base/chrome_async_socket_unittest.cc
index bf33ea5..a975d6f 100644
--- a/chrome/browser/sync/tools/chrome_async_socket_unittest.cc
+++ b/jingle/notifier/base/chrome_async_socket_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/sync/tools/chrome_async_socket.h"
+#include "jingle/notifier/base/chrome_async_socket.h"
#include <deque>
#include <string>
@@ -18,7 +18,7 @@
#include "talk/base/socketaddress.h"
#include "testing/gtest/include/gtest/gtest.h"
-namespace sync_tools {
+namespace notifier {
namespace {
@@ -353,7 +353,7 @@ class ChromeAsyncSocketTest
ADD_FAILURE();
break;
}
- if (len_read == 0) {
+ if (len_read == 0U) {
break;
}
read.append(buf.get(), len_read);
@@ -519,9 +519,9 @@ TEST_F(ChromeAsyncSocketTest, EmptyRead) {
DoOpenClosed();
char buf[4096];
- size_t len_read = 10000;
+ size_t len_read = 10000U;
EXPECT_TRUE(chrome_async_socket_.Read(buf, sizeof(buf), &len_read));
- EXPECT_EQ(0, len_read);
+ EXPECT_EQ(0U, len_read);
DoCloseOpenedNoError();
}
@@ -870,9 +870,9 @@ TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) {
async_socket_data_provider_.AddRead(net::MockRead(kReadData));
char buf[4096];
- size_t len_read = 10000;
+ size_t len_read = 10000U;
EXPECT_TRUE(chrome_async_socket_.Read(buf, sizeof(buf), &len_read));
- EXPECT_EQ(0, len_read);
+ EXPECT_EQ(0U, len_read);
message_loop_.RunAllPending();
ExpectSSLConnectSignal();
@@ -880,7 +880,7 @@ TEST_F(ChromeAsyncSocketTest, ReadDuringSSLConnecting) {
ExpectNoSignal();
ExpectNonErrorState(ChromeAsyncSocket::STATE_TLS_OPEN);
- len_read = 10000;
+ len_read = 10000U;
EXPECT_TRUE(chrome_async_socket_.Read(buf, sizeof(buf), &len_read));
EXPECT_EQ(kReadData, std::string(buf, len_read));
@@ -1012,4 +1012,4 @@ TEST_F(ChromeAsyncSocketTest, SSLAsyncWrite) {
} // namespace
-} // namespace sync_tools
+} // namespace notifier