diff options
author | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 03:01:54 +0000 |
---|---|---|
committer | akalin@chromium.org <akalin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-16 03:01:54 +0000 |
commit | 39e8c48020b4b985e9314838ca1270410e328b61 (patch) | |
tree | 4560bfd3643832e90e8173f46ee3624df428c441 | |
parent | c56428f24b67efa6a2eff77a709b7b6489403617 (diff) | |
download | chromium_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
5 files changed, 62 insertions, 55 deletions
diff --git a/chrome/browser/sync/engine/syncapi.cc b/chrome/browser/sync/engine/syncapi.cc index 452e584..7414332 100644 --- a/chrome/browser/sync/engine/syncapi.cc +++ b/chrome/browser/sync/engine/syncapi.cc @@ -52,6 +52,7 @@ #include "chrome/common/deprecated/event_sys.h" #include "chrome/common/net/gaia/gaia_authenticator.h" #include "chrome/common/net/network_change_notifier_proxy.h" +#include "chrome/common/net/notifier/listener/mediator_thread_impl.h" #include "chrome/common/net/notifier/listener/notification_constants.h" #include "chrome/common/net/notifier/listener/talk_mediator.h" #include "chrome/common/net/notifier/listener/talk_mediator_impl.h" @@ -1250,8 +1251,11 @@ bool SyncManager::SyncInternal::Init( // jank if we try to shut down sync. Fix this. connection_manager()->CheckServerReachable(); + const bool kInitializeSsl = true; + const bool kConnectImmediately = false; talk_mediator_.reset(new TalkMediatorImpl( - network_change_notifier_thread, invalidate_xmpp_auth_token)); + new notifier::MediatorThreadImpl(network_change_notifier_thread), + kInitializeSsl, kConnectImmediately, invalidate_xmpp_auth_token)); if (notification_method != browser_sync::NOTIFICATION_LEGACY) { if (notification_method == browser_sync::NOTIFICATION_TRANSITIONAL) { talk_mediator_->AddSubscribedServiceUrl( 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)); diff --git a/chrome/service/cloud_print/cloud_print_proxy_backend.cc b/chrome/service/cloud_print/cloud_print_proxy_backend.cc index 719ecb5..f910a87 100644 --- a/chrome/service/cloud_print/cloud_print_proxy_backend.cc +++ b/chrome/service/cloud_print/cloud_print_proxy_backend.cc @@ -12,6 +12,7 @@ #include "chrome/service/cloud_print/cloud_print_consts.h" #include "chrome/service/cloud_print/cloud_print_helpers.h" #include "chrome/service/cloud_print/printer_job_handler.h" +#include "chrome/common/net/notifier/listener/mediator_thread_impl.h" #include "chrome/common/net/notifier/listener/talk_mediator_impl.h" #include "chrome/service/gaia/service_gaia_authenticator.h" #include "chrome/service/net/service_network_change_notifier_thread.h" @@ -286,8 +287,14 @@ void CloudPrintProxyBackend::Core::DoInitializeWithToken( // TODO(sanjeevr): Validate the tokens. auth_token_ = cloud_print_token; + + const bool kInitializeSsl = true; + const bool kConnectImmediately = false; + const bool kInvalidateXmppAuthToken = false; talk_mediator_.reset(new notifier::TalkMediatorImpl( - g_service_process->network_change_notifier_thread(), false)); + new notifier::MediatorThreadImpl( + g_service_process->network_change_notifier_thread()), + kInitializeSsl, kConnectImmediately, kInvalidateXmppAuthToken)); talk_mediator_->AddSubscribedServiceUrl(kCloudPrintTalkServiceUrl); talk_mediator_->SetDelegate(this); talk_mediator_->SetAuthToken(email, cloud_print_xmpp_token, |