summaryrefslogtreecommitdiffstats
path: root/jingle
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 20:40:07 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-16 20:40:07 +0000
commitce8ecfa68eb910eb86873c564fc83bd6d4d210be (patch)
treee2a5c6a7cd324976a370da85eeffbee4de150bac /jingle
parent77f037650c26466d95ed6b138adff38873f0f7d9 (diff)
downloadchromium_src-ce8ecfa68eb910eb86873c564fc83bd6d4d210be.zip
chromium_src-ce8ecfa68eb910eb86873c564fc83bd6d4d210be.tar.gz
chromium_src-ce8ecfa68eb910eb86873c564fc83bd6d4d210be.tar.bz2
Added switch to use ChromeAsyncSocket for sync.
BUG=45612 TEST=manual Review URL: http://codereview.chromium.org/2819049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52737 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'jingle')
-rw-r--r--jingle/notifier/communicator/login.cc48
-rw-r--r--jingle/notifier/communicator/login.h4
-rw-r--r--jingle/notifier/communicator/single_login_attempt.cc28
-rw-r--r--jingle/notifier/communicator/single_login_attempt.h2
-rw-r--r--jingle/notifier/listener/mediator_thread_impl.cc23
-rw-r--r--jingle/notifier/listener/mediator_thread_impl.h4
-rw-r--r--jingle/notifier/listener/talk_mediator_unittest.cc7
7 files changed, 84 insertions, 32 deletions
diff --git a/jingle/notifier/communicator/login.cc b/jingle/notifier/communicator/login.cc
index 74af528..7cf4952 100644
--- a/jingle/notifier/communicator/login.cc
+++ b/jingle/notifier/communicator/login.cc
@@ -35,6 +35,7 @@ static const int kRedirectTimeoutMinutes = 5;
static const int kDisconnectionDelaySecs = 10;
Login::Login(talk_base::TaskParent* parent,
+ bool use_chrome_async_socket,
const buzz::XmppClientSettings& user_settings,
const ConnectionOptions& options,
std::string lang,
@@ -45,6 +46,7 @@ Login::Login(talk_base::TaskParent* parent,
bool proxy_only,
bool previous_login_successful)
: parent_(parent),
+ use_chrome_async_socket_(use_chrome_async_socket),
login_settings_(new LoginSettings(user_settings,
options,
lang,
@@ -107,6 +109,7 @@ void Login::StartConnection() {
}
single_attempt_ = new SingleLoginAttempt(parent_,
login_settings_.get(),
+ use_chrome_async_socket_,
successful_connection_);
// Do the signaling hook-ups.
@@ -304,28 +307,33 @@ void Login::OnIPAddressChanged() {
}
void Login::CheckConnection() {
- LOG(INFO) << "Checking connection";
- talk_base::PhysicalSocketServer physical;
- scoped_ptr<talk_base::Socket> socket(physical.CreateSocket(SOCK_STREAM));
- bool alive =
- !socket->Connect(talk_base::SocketAddress("talk.google.com", 5222));
- LOG(INFO) << "Network is " << (alive ? "alive" : "not alive");
- if (alive) {
- // Our connection is up. If we have a disconnect timer going,
- // stop it so we don't disconnect.
- disconnect_timer_.Stop();
- } else {
- // Our network connection is down. Start the disconnect timer if
- // it's not already going. Don't disconnect immediately to avoid
- // constant connection/disconnection due to flaky network
- // interfaces.
- if (!disconnect_timer_.IsRunning()) {
- disconnect_timer_.Start(
- base::TimeDelta::FromSeconds(kDisconnectionDelaySecs),
- this, &Login::OnDisconnectTimeout);
+ // We don't check the connection if we're using ChromeAsyncSocket,
+ // as this code requires a libjingle thread to be running. This
+ // code will go away in a future cleanup CL, anyway.
+ if (!use_chrome_async_socket_) {
+ LOG(INFO) << "Checking connection";
+ talk_base::PhysicalSocketServer physical;
+ scoped_ptr<talk_base::Socket> socket(physical.CreateSocket(SOCK_STREAM));
+ bool alive =
+ !socket->Connect(talk_base::SocketAddress("talk.google.com", 5222));
+ LOG(INFO) << "Network is " << (alive ? "alive" : "not alive");
+ if (alive) {
+ // Our connection is up. If we have a disconnect timer going,
+ // stop it so we don't disconnect.
+ disconnect_timer_.Stop();
+ } else {
+ // Our network connection is down. Start the disconnect timer if
+ // it's not already going. Don't disconnect immediately to avoid
+ // constant connection/disconnection due to flaky network
+ // interfaces.
+ if (!disconnect_timer_.IsRunning()) {
+ disconnect_timer_.Start(
+ base::TimeDelta::FromSeconds(kDisconnectionDelaySecs),
+ this, &Login::OnDisconnectTimeout);
+ }
}
+ auto_reconnect_.NetworkStateChanged(alive);
}
- auto_reconnect_.NetworkStateChanged(alive);
}
void Login::OnDisconnectTimeout() {
diff --git a/jingle/notifier/communicator/login.h b/jingle/notifier/communicator/login.h
index bd41cb5..29dc9e3 100644
--- a/jingle/notifier/communicator/login.h
+++ b/jingle/notifier/communicator/login.h
@@ -48,8 +48,9 @@ class SingleLoginAttempt;
class Login : public net::NetworkChangeNotifier::Observer,
public sigslot::has_slots<> {
public:
- // network_status and firewall may be NULL.
+ // firewall may be NULL.
Login(talk_base::TaskParent* parent,
+ bool use_chrome_async_socket,
const buzz::XmppClientSettings& user_settings,
const ConnectionOptions& options,
std::string lang,
@@ -124,6 +125,7 @@ class Login : public net::NetworkChangeNotifier::Observer,
void OnDisconnectTimeout();
talk_base::TaskParent* parent_;
+ bool use_chrome_async_socket_;
scoped_ptr<LoginSettings> login_settings_;
AutoReconnect auto_reconnect_;
SingleLoginAttempt* single_attempt_;
diff --git a/jingle/notifier/communicator/single_login_attempt.cc b/jingle/notifier/communicator/single_login_attempt.cc
index 00163c09..8f1e26f 100644
--- a/jingle/notifier/communicator/single_login_attempt.cc
+++ b/jingle/notifier/communicator/single_login_attempt.cc
@@ -3,12 +3,14 @@
// found in the LICENSE file.
#include <algorithm>
+#include <cstddef>
#include <string>
#include <vector>
#include "jingle/notifier/communicator/single_login_attempt.h"
#include "base/logging.h"
+#include "jingle/notifier/base/chrome_async_socket.h"
#include "jingle/notifier/communicator/connection_options.h"
#include "jingle/notifier/communicator/connection_settings.h"
#include "jingle/notifier/communicator/const_communicator.h"
@@ -18,6 +20,8 @@
#include "jingle/notifier/communicator/product_info.h"
#include "jingle/notifier/communicator/xmpp_connection_generator.h"
#include "jingle/notifier/communicator/xmpp_socket_adapter.h"
+#include "net/base/ssl_config_service.h"
+#include "net/socket/client_socket_factory.h"
#include "talk/base/asynchttprequest.h"
#include "talk/base/firewallsocketserver.h"
#include "talk/base/signalthread.h"
@@ -28,6 +32,10 @@
#include "talk/xmpp/xmppclientsettings.h"
#include "talk/xmpp/constants.h"
+namespace net {
+class NetLog;
+} // namespace net
+
namespace notifier {
static void GetClientErrorInformation(
@@ -53,8 +61,10 @@ static void GetClientErrorInformation(
SingleLoginAttempt::SingleLoginAttempt(talk_base::TaskParent* parent,
LoginSettings* login_settings,
+ bool use_chrome_async_socket,
bool successful_connection)
: talk_base::Task(parent),
+ use_chrome_async_socket_(use_chrome_async_socket),
state_(buzz::XmppEngine::STATE_NONE),
code_(buzz::XmppEngine::ERROR_NONE),
subcode_(0),
@@ -210,6 +220,24 @@ void SingleLoginAttempt::OnCertificateExpired() {
buzz::AsyncSocket* SingleLoginAttempt::CreateSocket(
const buzz::XmppClientSettings& xcs) {
+ if (use_chrome_async_socket_) {
+ net::ClientSocketFactory* const client_socket_factory =
+ net::ClientSocketFactory::GetDefaultFactory();
+ // The default SSLConfig is good enough for us for now.
+ const net::SSLConfig ssl_config;
+ // A read buffer of 64k ought to be sufficient.
+ const size_t kReadBufSize = 64U * 1024U;
+ // This number was taken from a similar number in
+ // XmppSocketAdapter.
+ const size_t kWriteBufSize = 64U * 1024U;
+ // TODO(akalin): Use a real NetLog.
+ net::NetLog* const net_log = NULL;
+ return new ChromeAsyncSocket(
+ client_socket_factory, ssl_config,
+ kReadBufSize, kWriteBufSize, net_log);
+ }
+ // TODO(akalin): Always use ChromeAsyncSocket and get rid of this
+ // code.
bool allow_unverified_certs =
login_settings_->connection_options().allow_unverified_certs();
XmppSocketAdapter* adapter = new XmppSocketAdapter(xcs,
diff --git a/jingle/notifier/communicator/single_login_attempt.h b/jingle/notifier/communicator/single_login_attempt.h
index 3595c0fb..582615d 100644
--- a/jingle/notifier/communicator/single_login_attempt.h
+++ b/jingle/notifier/communicator/single_login_attempt.h
@@ -48,6 +48,7 @@ class SingleLoginAttempt : public talk_base::Task, public sigslot::has_slots<> {
public:
SingleLoginAttempt(talk_base::TaskParent* parent,
LoginSettings* login_settings,
+ bool use_chrome_async_socket,
bool successful_connection);
~SingleLoginAttempt();
virtual int ProcessStart();
@@ -119,6 +120,7 @@ class SingleLoginAttempt : public talk_base::Task, public sigslot::has_slots<> {
bool auto_reconnect() const;
+ bool use_chrome_async_socket_;
buzz::XmppEngine::State state_;
buzz::XmppEngine::Error code_;
int subcode_;
diff --git a/jingle/notifier/listener/mediator_thread_impl.cc b/jingle/notifier/listener/mediator_thread_impl.cc
index 9f740dd..0cf2423 100644
--- a/jingle/notifier/listener/mediator_thread_impl.cc
+++ b/jingle/notifier/listener/mediator_thread_impl.cc
@@ -26,9 +26,10 @@ DISABLE_RUNNABLE_METHOD_REFCOUNT(notifier::MediatorThreadImpl);
namespace notifier {
-MediatorThreadImpl::MediatorThreadImpl()
+MediatorThreadImpl::MediatorThreadImpl(bool use_chrome_async_socket)
: delegate_(NULL),
parent_message_loop_(MessageLoop::current()),
+ use_chrome_async_socket_(use_chrome_async_socket),
worker_thread_("MediatorThread worker thread") {
DCHECK(parent_message_loop_);
}
@@ -50,13 +51,16 @@ void MediatorThreadImpl::Start() {
// TODO(akalin): Make this function return a bool and remove this
// CHECK().
CHECK(worker_thread_.StartWithOptions(options));
- worker_message_loop()->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &MediatorThreadImpl::StartLibjingleThread));
+ if (!use_chrome_async_socket_) {
+ worker_message_loop()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &MediatorThreadImpl::StartLibjingleThread));
+ }
}
void MediatorThreadImpl::StartLibjingleThread() {
DCHECK_EQ(MessageLoop::current(), worker_message_loop());
+ DCHECK(!use_chrome_async_socket_);
socket_server_.reset(new talk_base::PhysicalSocketServer());
libjingle_thread_.reset(new talk_base::Thread());
talk_base::ThreadManager::SetCurrent(libjingle_thread_.get());
@@ -67,6 +71,7 @@ void MediatorThreadImpl::StartLibjingleThread() {
void MediatorThreadImpl::StopLibjingleThread() {
DCHECK_EQ(MessageLoop::current(), worker_message_loop());
+ DCHECK(!use_chrome_async_socket_);
talk_base::ThreadManager::SetCurrent(NULL);
libjingle_thread_.reset();
socket_server_.reset();
@@ -74,6 +79,7 @@ void MediatorThreadImpl::StopLibjingleThread() {
void MediatorThreadImpl::PumpLibjingleLoop() {
DCHECK_EQ(MessageLoop::current(), worker_message_loop());
+ DCHECK(!use_chrome_async_socket_);
// Pump the libjingle message loop 100ms at a time.
if (!libjingle_thread_.get()) {
// StopLibjingleThread() was called.
@@ -97,9 +103,11 @@ void MediatorThreadImpl::Logout() {
worker_message_loop()->PostTask(
FROM_HERE,
NewRunnableMethod(this, &MediatorThreadImpl::DoDisconnect));
- worker_message_loop()->PostTask(
- FROM_HERE,
- NewRunnableMethod(this, &MediatorThreadImpl::StopLibjingleThread));
+ if (!use_chrome_async_socket_) {
+ worker_message_loop()->PostTask(
+ FROM_HERE,
+ NewRunnableMethod(this, &MediatorThreadImpl::StopLibjingleThread));
+ }
// TODO(akalin): Decomp this into a separate stop method.
worker_thread_.Stop();
// Process any messages the worker thread may be posted on our
@@ -186,6 +194,7 @@ void MediatorThreadImpl::DoLogin(
// Language is not used in the stanza so we default to |en|.
std::string lang = "en";
login_.reset(new notifier::Login(pump_.get(),
+ use_chrome_async_socket_,
settings,
options,
lang,
diff --git a/jingle/notifier/listener/mediator_thread_impl.h b/jingle/notifier/listener/mediator_thread_impl.h
index 0e2e22f..6d4f997 100644
--- a/jingle/notifier/listener/mediator_thread_impl.h
+++ b/jingle/notifier/listener/mediator_thread_impl.h
@@ -59,7 +59,7 @@ class MediatorThreadImpl
: public MediatorThread,
public sigslot::has_slots<> {
public:
- MediatorThreadImpl();
+ explicit MediatorThreadImpl(bool use_chrome_async_socket);
virtual ~MediatorThreadImpl();
virtual void SetDelegate(Delegate* delegate);
@@ -121,6 +121,7 @@ class MediatorThreadImpl
void OnSubscriptionStateChangeOnParentThread(
bool success);
+ const bool use_chrome_async_socket_;
base::Thread worker_thread_;
scoped_refptr<net::HostResolver> host_resolver_;
@@ -131,6 +132,7 @@ class MediatorThreadImpl
scoped_ptr<notifier::TaskPump> pump_;
scoped_ptr<notifier::Login> login_;
+ // Used only when |use_chrome_async_socket_| is false.
scoped_ptr<talk_base::SocketServer> socket_server_;
scoped_ptr<talk_base::Thread> libjingle_thread_;
diff --git a/jingle/notifier/listener/talk_mediator_unittest.cc b/jingle/notifier/listener/talk_mediator_unittest.cc
index 88af342..fc08a63 100644
--- a/jingle/notifier/listener/talk_mediator_unittest.cc
+++ b/jingle/notifier/listener/talk_mediator_unittest.cc
@@ -39,11 +39,13 @@ class TalkMediatorImplTest : public testing::Test {
virtual ~TalkMediatorImplTest() {}
TalkMediatorImpl* NewTalkMediator() {
+ const bool kUseChromeAsyncSocket = false;
const bool kInitializeSsl = true;
const bool kConnectImmediately = false;
const bool kInvalidateXmppAuthToken = false;
- return new TalkMediatorImpl(new MediatorThreadImpl(), kInitializeSsl,
- kConnectImmediately, kInvalidateXmppAuthToken);
+ return new TalkMediatorImpl(
+ new MediatorThreadImpl(kUseChromeAsyncSocket),
+ kInitializeSsl, kConnectImmediately, kInvalidateXmppAuthToken);
}
TalkMediatorImpl* NewMockedTalkMediator(
@@ -201,7 +203,6 @@ TEST_F(TalkMediatorImplTest, MediatorThreadCallbacks) {
// Shouldn't trigger a call to the delegate since we disconnect
// it before we logout.
talk1.reset();
- EXPECT_EQ(1, mock->logout_calls);
}
} // namespace notifier