summaryrefslogtreecommitdiffstats
path: root/chrome/common
diff options
context:
space:
mode:
authorakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-16 03:01:54 +0000
committerakalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-16 03:01:54 +0000
commit39e8c48020b4b985e9314838ca1270410e328b61 (patch)
tree4560bfd3643832e90e8173f46ee3624df428c441 /chrome/common
parentc56428f24b67efa6a2eff77a709b7b6489403617 (diff)
downloadchromium_src-39e8c48020b4b985e9314838ca1270410e328b61.zip
chromium_src-39e8c48020b4b985e9314838ca1270410e328b61.tar.gz
chromium_src-39e8c48020b4b985e9314838ca1270410e328b61.tar.bz2
Combined both constructors of TalkMediatorImpl into one.
BUG=none TEST=manual, trybots Review URL: http://codereview.chromium.org/2835003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49891 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common')
-rw-r--r--chrome/common/net/notifier/listener/talk_mediator_impl.cc33
-rw-r--r--chrome/common/net/notifier/listener/talk_mediator_impl.h16
-rw-r--r--chrome/common/net/notifier/listener/talk_mediator_unittest.cc53
3 files changed, 49 insertions, 53 deletions
diff --git a/chrome/common/net/notifier/listener/talk_mediator_impl.cc b/chrome/common/net/notifier/listener/talk_mediator_impl.cc
index 2e977fc..6d5acf5 100644
--- a/chrome/common/net/notifier/listener/talk_mediator_impl.cc
+++ b/chrome/common/net/notifier/listener/talk_mediator_impl.cc
@@ -39,33 +39,18 @@ class SslInitializationSingleton {
};
TalkMediatorImpl::TalkMediatorImpl(
- chrome_common_net::NetworkChangeNotifierThread*
- network_change_notifier_thread,
- bool invalidate_xmpp_auth_token)
+ MediatorThread* mediator_thread,
+ bool initialize_ssl,
+ bool connect_immediately,
+ bool invalidate_xmpp_auth_token)
: delegate_(NULL),
- mediator_thread_(
- new MediatorThreadImpl(network_change_notifier_thread)),
+ mediator_thread_(mediator_thread),
invalidate_xmpp_auth_token_(invalidate_xmpp_auth_token) {
DCHECK(non_thread_safe_.CalledOnValidThread());
- // Ensure the SSL library is initialized.
- SslInitializationSingleton::GetInstance()->RegisterClient();
-
- // Construct the callback channel with the shutdown event.
- TalkMediatorInitialization(false);
-}
-
-TalkMediatorImpl::TalkMediatorImpl(MediatorThread *thread)
- : delegate_(NULL),
- mediator_thread_(thread),
- invalidate_xmpp_auth_token_(false) {
- DCHECK(non_thread_safe_.CalledOnValidThread());
- // When testing we do not initialize the SSL library.
- TalkMediatorInitialization(true);
-}
-
-void TalkMediatorImpl::TalkMediatorInitialization(bool should_connect) {
- DCHECK(non_thread_safe_.CalledOnValidThread());
- if (should_connect) {
+ if (initialize_ssl) {
+ SslInitializationSingleton::GetInstance()->RegisterClient();
+ }
+ if (connect_immediately) {
mediator_thread_->SetDelegate(this);
state_.connected = 1;
}
diff --git a/chrome/common/net/notifier/listener/talk_mediator_impl.h b/chrome/common/net/notifier/listener/talk_mediator_impl.h
index 8625fa4..e14840f 100644
--- a/chrome/common/net/notifier/listener/talk_mediator_impl.h
+++ b/chrome/common/net/notifier/listener/talk_mediator_impl.h
@@ -20,20 +20,17 @@
#include "talk/xmpp/xmppclientsettings.h"
#include "testing/gtest/include/gtest/gtest_prod.h" // For FRIEND_TEST
-namespace chrome_common_net {
-class NetworkChangeNotifierThread;
-} // namespace chrome_common_net
-
namespace notifier {
class TalkMediatorImpl
: public TalkMediator, public MediatorThread::Delegate {
public:
+ // Takes ownership of |mediator_thread|.
TalkMediatorImpl(
- chrome_common_net::NetworkChangeNotifierThread*
- network_change_notifier_thread,
+ MediatorThread* mediator_thread,
+ bool initialize_ssl,
+ bool connect_immediately,
bool invalidate_xmpp_auth_token);
- explicit TalkMediatorImpl(MediatorThread* thread);
virtual ~TalkMediatorImpl();
// TalkMediator implementation.
@@ -77,11 +74,6 @@ class TalkMediatorImpl
unsigned int subscribed : 1; // Subscribed to the xmpp receiving channel.
};
- // Completes common initialization between the constructors. Set should
- // connect to true if the talk mediator should connect to the controlled
- // mediator thread's SignalStateChange object.
- void TalkMediatorInitialization(bool should_connect);
-
NonThreadSafe non_thread_safe_;
// Delegate, which we don't own. May be NULL.
diff --git a/chrome/common/net/notifier/listener/talk_mediator_unittest.cc b/chrome/common/net/notifier/listener/talk_mediator_unittest.cc
index ea9d222..dd144b2 100644
--- a/chrome/common/net/notifier/listener/talk_mediator_unittest.cc
+++ b/chrome/common/net/notifier/listener/talk_mediator_unittest.cc
@@ -9,6 +9,7 @@
#include "base/message_loop.h"
#include "chrome/common/net/fake_network_change_notifier_thread.h"
#include "chrome/common/net/notifier/listener/mediator_thread_mock.h"
+#include "chrome/common/net/notifier/listener/mediator_thread_impl.h"
#include "chrome/common/net/notifier/listener/talk_mediator_impl.h"
#include "talk/xmpp/xmppengine.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -38,6 +39,25 @@ class TalkMediatorImplTest : public testing::Test {
TalkMediatorImplTest() {}
virtual ~TalkMediatorImplTest() {}
+ TalkMediatorImpl* NewTalkMediator() {
+ const bool kInitializeSsl = true;
+ const bool kConnectImmediately = false;
+ const bool kInvalidateXmppAuthToken = false;
+ return new TalkMediatorImpl(
+ new MediatorThreadImpl(&fake_network_change_notifier_thread_),
+ kInitializeSsl, kConnectImmediately, kInvalidateXmppAuthToken);
+ }
+
+ TalkMediatorImpl* NewMockedTalkMediator(
+ MockMediatorThread* mock_mediator_thread) {
+ const bool kInitializeSsl = false;
+ const bool kConnectImmediately = true;
+ const bool kInvalidateXmppAuthToken = false;
+ return new TalkMediatorImpl(mock_mediator_thread,
+ kInitializeSsl, kConnectImmediately,
+ kInvalidateXmppAuthToken);
+ }
+
chrome_common_net::FakeNetworkChangeNotifierThread
fake_network_change_notifier_thread_;
int last_message_;
@@ -51,42 +71,41 @@ class TalkMediatorImplTest : public testing::Test {
TEST_F(TalkMediatorImplTest, ConstructionOfTheClass) {
// Constructing a single talk mediator enables SSL through the singleton.
- scoped_ptr<TalkMediatorImpl> talk1(
- new TalkMediatorImpl(&fake_network_change_notifier_thread_, false));
+ scoped_ptr<TalkMediatorImpl> talk1(NewTalkMediator());
}
TEST_F(TalkMediatorImplTest, SetAuthTokenWithBadInput) {
- scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(
- new MockMediatorThread()));
+ scoped_ptr<TalkMediatorImpl> talk1(
+ NewMockedTalkMediator(new MockMediatorThread()));
EXPECT_FALSE(talk1->SetAuthToken("@missinguser.com", "", "fake_service"));
EXPECT_FALSE(talk1->state_.initialized);
- scoped_ptr<TalkMediatorImpl> talk2(new TalkMediatorImpl(
- new MockMediatorThread()));
+ scoped_ptr<TalkMediatorImpl> talk2(
+ NewMockedTalkMediator(new MockMediatorThread()));
EXPECT_FALSE(talk2->SetAuthToken("", "1234567890", "fake_service"));
EXPECT_FALSE(talk2->state_.initialized);
- scoped_ptr<TalkMediatorImpl> talk3(new TalkMediatorImpl(
- new MockMediatorThread()));
+ scoped_ptr<TalkMediatorImpl> talk3(
+ NewMockedTalkMediator(new MockMediatorThread()));
EXPECT_FALSE(talk3->SetAuthToken("missingdomain", "abcde", "fake_service"));
EXPECT_FALSE(talk3->state_.initialized);
}
TEST_F(TalkMediatorImplTest, SetAuthTokenWithGoodInput) {
- scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(
- new MockMediatorThread()));
+ scoped_ptr<TalkMediatorImpl> talk1(
+ NewMockedTalkMediator(new MockMediatorThread()));
EXPECT_TRUE(talk1->SetAuthToken("chromium@gmail.com", "token",
"fake_service"));
EXPECT_TRUE(talk1->state_.initialized);
- scoped_ptr<TalkMediatorImpl> talk2(new TalkMediatorImpl(
- new MockMediatorThread()));
+ scoped_ptr<TalkMediatorImpl> talk2(
+ NewMockedTalkMediator(new MockMediatorThread()));
EXPECT_TRUE(talk2->SetAuthToken("chromium@mail.google.com", "token",
"fake_service"));
EXPECT_TRUE(talk2->state_.initialized);
- scoped_ptr<TalkMediatorImpl> talk3(new TalkMediatorImpl(
- new MockMediatorThread()));
+ scoped_ptr<TalkMediatorImpl> talk3(
+ NewMockedTalkMediator(new MockMediatorThread()));
EXPECT_TRUE(talk3->SetAuthToken("chromium@chromium.org", "token",
"fake_service"));
EXPECT_TRUE(talk3->state_.initialized);
@@ -95,7 +114,7 @@ TEST_F(TalkMediatorImplTest, SetAuthTokenWithGoodInput) {
TEST_F(TalkMediatorImplTest, LoginWiring) {
// The TalkMediatorImpl owns the mock.
MockMediatorThread* mock = new MockMediatorThread();
- scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(mock));
+ scoped_ptr<TalkMediatorImpl> talk1(NewMockedTalkMediator(mock));
// Login checks states for initialization.
EXPECT_FALSE(talk1->Login());
@@ -122,7 +141,7 @@ TEST_F(TalkMediatorImplTest, LoginWiring) {
TEST_F(TalkMediatorImplTest, SendNotification) {
// The TalkMediatorImpl owns the mock.
MockMediatorThread* mock = new MockMediatorThread();
- scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(mock));
+ scoped_ptr<TalkMediatorImpl> talk1(NewMockedTalkMediator(mock));
// Failure due to not being logged in.
OutgoingNotificationData data;
@@ -153,7 +172,7 @@ TEST_F(TalkMediatorImplTest, SendNotification) {
TEST_F(TalkMediatorImplTest, MediatorThreadCallbacks) {
// The TalkMediatorImpl owns the mock.
MockMediatorThread* mock = new MockMediatorThread();
- scoped_ptr<TalkMediatorImpl> talk1(new TalkMediatorImpl(mock));
+ scoped_ptr<TalkMediatorImpl> talk1(NewMockedTalkMediator(mock));
MockTalkMediatorDelegate mock_delegate;
EXPECT_CALL(mock_delegate, OnNotificationStateChange(true));