diff options
23 files changed, 297 insertions, 70 deletions
diff --git a/chrome/browser/invalidation/ticl_invalidation_service.cc b/chrome/browser/invalidation/ticl_invalidation_service.cc index 0935f7e..c32714d 100644 --- a/chrome/browser/invalidation/ticl_invalidation_service.cc +++ b/chrome/browser/invalidation/ticl_invalidation_service.cc @@ -81,7 +81,7 @@ void TiclInvalidationService::Init() { } if (IsReadyToStart()) { - StartInvalidator(); + StartInvalidator(PUSH_CLIENT_CHANNEL); } notification_registrar_.Add(this, @@ -190,7 +190,7 @@ void TiclInvalidationService::OnGetTokenSuccess( request_access_token_backoff_.Reset(); access_token_ = access_token; if (!IsStarted() && IsReadyToStart()) { - StartInvalidator(); + StartInvalidator(PUSH_CLIENT_CHANNEL); } else { UpdateInvalidatorCredentials(); } @@ -230,7 +230,7 @@ void TiclInvalidationService::OnRefreshTokenAvailable( const std::string& account_id) { if (oauth2_token_service_->GetPrimaryAccountId() == account_id) { if (!IsStarted() && IsReadyToStart()) { - StartInvalidator(); + StartInvalidator(PUSH_CLIENT_CHANNEL); } } } @@ -313,7 +313,8 @@ bool TiclInvalidationService::IsStarted() { return invalidator_.get() != NULL; } -void TiclInvalidationService::StartInvalidator() { +void TiclInvalidationService::StartInvalidator( + InvalidationNetworkChannel network_channel) { DCHECK(CalledOnValidThread()); DCHECK(!invalidator_); DCHECK(invalidator_storage_); @@ -327,18 +328,38 @@ void TiclInvalidationService::StartInvalidator() { return; } - notifier::NotifierOptions options = - ParseNotifierOptions(*CommandLine::ForCurrentProcess()); - options.request_context_getter = profile_->GetRequestContext(); - options.auth_mechanism = "X-OAUTH2"; + syncer::NetworkChannelCreator network_channel_creator; + + switch (network_channel) { + case PUSH_CLIENT_CHANNEL: { + notifier::NotifierOptions options = + ParseNotifierOptions(*CommandLine::ForCurrentProcess()); + options.request_context_getter = profile_->GetRequestContext(); + options.auth_mechanism = "X-OAUTH2"; + DCHECK_EQ(notifier::NOTIFICATION_SERVER, options.notification_method); + network_channel_creator = + syncer::NonBlockingInvalidator::MakePushClientChannelCreator(options); + break; + } + case GCM_NETWORK_CHANNEL: { + network_channel_creator = + syncer::NonBlockingInvalidator::MakeGCMNetworkChannelCreator(); + break; + } + default: { + NOTREACHED(); + return; + } + } invalidator_.reset(new syncer::NonBlockingInvalidator( - options, + network_channel_creator, invalidator_storage_->GetInvalidatorClientId(), invalidator_storage_->GetSavedInvalidations(), invalidator_storage_->GetBootstrapData(), syncer::WeakHandle<syncer::InvalidationStateTracker>( invalidator_storage_->AsWeakPtr()), - content::GetUserAgent(GURL()))); + content::GetUserAgent(GURL()), + profile_->GetRequestContext())); UpdateInvalidatorCredentials(); diff --git a/chrome/browser/invalidation/ticl_invalidation_service.h b/chrome/browser/invalidation/ticl_invalidation_service.h index 6231d71..d5323af 100644 --- a/chrome/browser/invalidation/ticl_invalidation_service.h +++ b/chrome/browser/invalidation/ticl_invalidation_service.h @@ -93,10 +93,15 @@ class TiclInvalidationService friend class TiclInvalidationServiceTestDelegate; private: + enum InvalidationNetworkChannel { + PUSH_CLIENT_CHANNEL = 0, + GCM_NETWORK_CHANNEL = 1 + }; + bool IsReadyToStart(); bool IsStarted(); - void StartInvalidator(); + void StartInvalidator(InvalidationNetworkChannel network_channel); void UpdateInvalidatorCredentials(); void StopInvalidator(); void Logout(); diff --git a/sync/notifier/gcm_network_channel.cc b/sync/notifier/gcm_network_channel.cc new file mode 100644 index 0000000..41f288c --- /dev/null +++ b/sync/notifier/gcm_network_channel.cc @@ -0,0 +1,22 @@ +// Copyright 2014 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 "sync/notifier/gcm_network_channel.h" + +namespace syncer { + +GCMNetworkChannel::GCMNetworkChannel() { +} + +GCMNetworkChannel::~GCMNetworkChannel() { +} + +void GCMNetworkChannel::SendEncodedMessage(const std::string& encoded_message) { +} + +void GCMNetworkChannel::UpdateCredentials(const std::string& email, + const std::string& token) { +} + +} // namespace syncer diff --git a/sync/notifier/gcm_network_channel.h b/sync/notifier/gcm_network_channel.h new file mode 100644 index 0000000..b7d97fb --- /dev/null +++ b/sync/notifier/gcm_network_channel.h @@ -0,0 +1,38 @@ +// Copyright 2014 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 SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ +#define SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "sync/base/sync_export.h" +#include "sync/notifier/sync_system_resources.h" + +namespace syncer { + +// GCMNetworkChannel is an implementation of SyncNetworkChannel that routes +// messages through GCMProfileService. +class SYNC_EXPORT_PRIVATE GCMNetworkChannel + : public SyncNetworkChannel { + public: + explicit GCMNetworkChannel(); + + virtual ~GCMNetworkChannel(); + + // SyncNetworkChannel implementation. + virtual void SendEncodedMessage(const std::string& encoded_message) OVERRIDE; + virtual void UpdateCredentials(const std::string& email, + const std::string& token) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(GCMNetworkChannel); +}; + +} // namespace syncer + +#endif // SYNC_NOTIFIER_GCM_NETWORK_CHANNEL_H_ diff --git a/sync/notifier/gcm_network_channel_unittest.cc b/sync/notifier/gcm_network_channel_unittest.cc new file mode 100644 index 0000000..8656385 --- /dev/null +++ b/sync/notifier/gcm_network_channel_unittest.cc @@ -0,0 +1,40 @@ +// Copyright 2014 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 "sync/notifier/gcm_network_channel.h" + +#include "base/compiler_specific.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace syncer { +namespace { + +class GCMNetworkChannelTest + : public ::testing::Test, + public SyncNetworkChannel::Observer { + protected: + GCMNetworkChannelTest() + : gcm_network_channel_() { + gcm_network_channel_.AddObserver(this); + gcm_network_channel_.SetMessageReceiver( + invalidation::NewPermanentCallback( + this, &GCMNetworkChannelTest::OnIncomingMessage)); + } + + virtual ~GCMNetworkChannelTest() { + gcm_network_channel_.RemoveObserver(this); + } + + virtual void OnNetworkChannelStateChanged( + InvalidatorState invalidator_state) OVERRIDE { + } + + void OnIncomingMessage(std::string incoming_message) { + } + + GCMNetworkChannel gcm_network_channel_; +}; + +} // namespace +} // namespace syncer diff --git a/sync/notifier/invalidation_notifier.cc b/sync/notifier/invalidation_notifier.cc index a509409..b67165f 100644 --- a/sync/notifier/invalidation_notifier.cc +++ b/sync/notifier/invalidation_notifier.cc @@ -18,7 +18,7 @@ namespace syncer { InvalidationNotifier::InvalidationNotifier( - scoped_ptr<notifier::PushClient> push_client, + scoped_ptr<SyncNetworkChannel> network_channel, const std::string& invalidator_client_id, const UnackedInvalidationsMap& saved_invalidations, const std::string& invalidation_bootstrap_data, @@ -30,7 +30,7 @@ InvalidationNotifier::InvalidationNotifier( client_info_(client_info), invalidator_client_id_(invalidator_client_id), invalidation_bootstrap_data_(invalidation_bootstrap_data), - invalidation_listener_(push_client.Pass()) { + invalidation_listener_(network_channel.Pass()) { } InvalidationNotifier::~InvalidationNotifier() { diff --git a/sync/notifier/invalidation_notifier.h b/sync/notifier/invalidation_notifier.h index a11608c..1314007 100644 --- a/sync/notifier/invalidation_notifier.h +++ b/sync/notifier/invalidation_notifier.h @@ -40,7 +40,7 @@ class SYNC_EXPORT_PRIVATE InvalidationNotifier public: // |invalidation_state_tracker| must be initialized. InvalidationNotifier( - scoped_ptr<notifier::PushClient> push_client, + scoped_ptr<SyncNetworkChannel> network_channel, const std::string& invalidator_client_id, const UnackedInvalidationsMap& saved_invalidations, const std::string& invalidation_bootstrap_data, diff --git a/sync/notifier/invalidation_notifier_unittest.cc b/sync/notifier/invalidation_notifier_unittest.cc index bc92e23..223fb28 100644 --- a/sync/notifier/invalidation_notifier_unittest.cc +++ b/sync/notifier/invalidation_notifier_unittest.cc @@ -16,6 +16,7 @@ #include "sync/notifier/fake_invalidation_state_tracker.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/invalidator_test_template.h" +#include "sync/notifier/push_client_channel.h" #include "testing/gtest/include/gtest/gtest.h" namespace syncer { @@ -36,9 +37,13 @@ class InvalidationNotifierTestDelegate { const base::WeakPtr<InvalidationStateTracker>& invalidation_state_tracker) { DCHECK(!invalidator_.get()); + scoped_ptr<notifier::PushClient> push_client( + new notifier::FakePushClient()); + scoped_ptr<SyncNetworkChannel> network_channel( + new PushClientChannel(push_client.Pass())); invalidator_.reset( new InvalidationNotifier( - scoped_ptr<notifier::PushClient>(new notifier::FakePushClient()), + network_channel.Pass(), invalidator_client_id, UnackedInvalidationsMap(), initial_state, diff --git a/sync/notifier/non_blocking_invalidator.cc b/sync/notifier/non_blocking_invalidator.cc index bd05967..5ec1758 100644 --- a/sync/notifier/non_blocking_invalidator.cc +++ b/sync/notifier/non_blocking_invalidator.cc @@ -15,9 +15,39 @@ #include "jingle/notifier/listener/push_client.h" #include "sync/notifier/invalidation_notifier.h" #include "sync/notifier/object_id_invalidation_map.h" +#include "sync/notifier/sync_system_resources.h" namespace syncer { +struct NonBlockingInvalidator::InitializeOptions { + InitializeOptions( + NetworkChannelCreator network_channel_creator, + const std::string& invalidator_client_id, + const UnackedInvalidationsMap& saved_invalidations, + const std::string& invalidation_bootstrap_data, + const WeakHandle<InvalidationStateTracker>& + invalidation_state_tracker, + const std::string& client_info, + scoped_refptr<net::URLRequestContextGetter> request_context_getter) + : network_channel_creator(network_channel_creator), + invalidator_client_id(invalidator_client_id), + saved_invalidations(saved_invalidations), + invalidation_bootstrap_data(invalidation_bootstrap_data), + invalidation_state_tracker(invalidation_state_tracker), + client_info(client_info), + request_context_getter(request_context_getter) { + } + + NetworkChannelCreator network_channel_creator; + std::string invalidator_client_id; + UnackedInvalidationsMap saved_invalidations; + std::string invalidation_bootstrap_data; + WeakHandle<InvalidationStateTracker> invalidation_state_tracker; + std::string client_info; + scoped_refptr<net::URLRequestContextGetter> request_context_getter; +}; + + class NonBlockingInvalidator::Core : public base::RefCountedThreadSafe<NonBlockingInvalidator::Core>, // InvalidationHandler to observe the InvalidationNotifier we create. @@ -30,12 +60,7 @@ class NonBlockingInvalidator::Core // Helpers called on I/O thread. void Initialize( - const notifier::NotifierOptions& notifier_options, - const std::string& invalidator_client_id, - const UnackedInvalidationsMap& saved_invalidations, - const std::string& invalidation_bootstrap_data, - const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, - const std::string& client_info); + const NonBlockingInvalidator::InitializeOptions& initialize_options); void Teardown(); void UpdateRegisteredIds(const ObjectIdSet& ids); void UpdateCredentials(const std::string& email, const std::string& token); @@ -70,26 +95,21 @@ NonBlockingInvalidator::Core::~Core() { } void NonBlockingInvalidator::Core::Initialize( - const notifier::NotifierOptions& notifier_options, - const std::string& invalidator_client_id, - const UnackedInvalidationsMap& saved_invalidations, - const std::string& invalidation_bootstrap_data, - const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, - const std::string& client_info) { - DCHECK(notifier_options.request_context_getter.get()); - DCHECK_EQ(notifier::NOTIFICATION_SERVER, - notifier_options.notification_method); - network_task_runner_ = notifier_options.request_context_getter-> - GetNetworkTaskRunner(); + const NonBlockingInvalidator::InitializeOptions& initialize_options) { + DCHECK(initialize_options.request_context_getter.get()); + network_task_runner_ = + initialize_options.request_context_getter->GetNetworkTaskRunner(); DCHECK(network_task_runner_->BelongsToCurrentThread()); + scoped_ptr<SyncNetworkChannel> network_channel = + initialize_options.network_channel_creator.Run(); invalidation_notifier_.reset( new InvalidationNotifier( - notifier::PushClient::CreateDefaultOnIOThread(notifier_options), - invalidator_client_id, - saved_invalidations, - invalidation_bootstrap_data, - invalidation_state_tracker, - client_info)); + network_channel.Pass(), + initialize_options.invalidator_client_id, + initialize_options.saved_invalidations, + initialize_options.invalidation_bootstrap_data, + initialize_options.invalidation_state_tracker, + initialize_options.client_info)); invalidation_notifier_->RegisterHandler(this); } @@ -127,30 +147,34 @@ void NonBlockingInvalidator::Core::OnIncomingInvalidation( } NonBlockingInvalidator::NonBlockingInvalidator( - const notifier::NotifierOptions& notifier_options, + NetworkChannelCreator network_channel_creator, const std::string& invalidator_client_id, const UnackedInvalidationsMap& saved_invalidations, const std::string& invalidation_bootstrap_data, const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, - const std::string& client_info) + const std::string& client_info, + const scoped_refptr<net::URLRequestContextGetter>& request_context_getter) : parent_task_runner_(base::ThreadTaskRunnerHandle::Get()), - network_task_runner_( - notifier_options.request_context_getter->GetNetworkTaskRunner()), + network_task_runner_(request_context_getter->GetNetworkTaskRunner()), weak_ptr_factory_(this) { core_ = new Core(MakeWeakHandle(weak_ptr_factory_.GetWeakPtr())); + InitializeOptions initialize_options( + network_channel_creator, + invalidator_client_id, + saved_invalidations, + invalidation_bootstrap_data, + invalidation_state_tracker, + client_info, + request_context_getter); + if (!network_task_runner_->PostTask( FROM_HERE, base::Bind( &NonBlockingInvalidator::Core::Initialize, core_.get(), - notifier_options, - invalidator_client_id, - saved_invalidations, - invalidation_bootstrap_data, - invalidation_state_tracker, - client_info))) { + initialize_options))) { NOTREACHED(); } } @@ -216,4 +240,16 @@ void NonBlockingInvalidator::OnIncomingInvalidation( registrar_.DispatchInvalidationsToHandlers(invalidation_map); } +NetworkChannelCreator + NonBlockingInvalidator::MakePushClientChannelCreator( + const notifier::NotifierOptions& notifier_options) { + return base::Bind(SyncNetworkChannel::CreatePushClientChannel, + notifier_options); +} + +NetworkChannelCreator + NonBlockingInvalidator::MakeGCMNetworkChannelCreator() { + return base::Bind(SyncNetworkChannel::CreateGCMNetworkChannel); +} + } // namespace syncer diff --git a/sync/notifier/non_blocking_invalidator.h b/sync/notifier/non_blocking_invalidator.h index d40166a..7de6d95 100644 --- a/sync/notifier/non_blocking_invalidator.h +++ b/sync/notifier/non_blocking_invalidator.h @@ -11,6 +11,7 @@ #include <string> #include "base/basictypes.h" +#include "base/callback.h" #include "base/compiler_specific.h" #include "base/memory/ref_counted.h" #include "base/memory/weak_ptr.h" @@ -27,6 +28,12 @@ class SingleThreadTaskRunner; } // namespace base namespace syncer { +class SyncNetworkChannel; + +// Callback type for function that creates SyncNetworkChannel. This function +// gets passed into NonBlockingInvalidator constructor. +typedef base::Callback<scoped_ptr<SyncNetworkChannel>(void)> + NetworkChannelCreator; class SYNC_EXPORT_PRIVATE NonBlockingInvalidator : public Invalidator, @@ -35,13 +42,15 @@ class SYNC_EXPORT_PRIVATE NonBlockingInvalidator public: // |invalidation_state_tracker| must be initialized. NonBlockingInvalidator( - const notifier::NotifierOptions& notifier_options, + NetworkChannelCreator network_channel_creator, const std::string& invalidator_client_id, const UnackedInvalidationsMap& saved_invalidations, const std::string& invalidation_bootstrap_data, const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, - const std::string& client_info); + const std::string& client_info, + const scoped_refptr<net::URLRequestContextGetter>& + request_context_getter); virtual ~NonBlockingInvalidator(); @@ -59,7 +68,15 @@ class SYNC_EXPORT_PRIVATE NonBlockingInvalidator virtual void OnIncomingInvalidation( const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; + // Static functions to construct callback that creates network channel for + // SyncSystemResources. The goal is to pass network channel to invalidator at + // the same time not exposing channel specific parameters to invalidator and + // channel implementation to client of invalidator. + static NetworkChannelCreator MakePushClientChannelCreator( + const notifier::NotifierOptions& notifier_options); + static NetworkChannelCreator MakeGCMNetworkChannelCreator(); private: + struct InitializeOptions; class Core; InvalidatorRegistrar registrar_; diff --git a/sync/notifier/non_blocking_invalidator_unittest.cc b/sync/notifier/non_blocking_invalidator_unittest.cc index 0c439c5..3dd2dbb 100644 --- a/sync/notifier/non_blocking_invalidator_unittest.cc +++ b/sync/notifier/non_blocking_invalidator_unittest.cc @@ -42,16 +42,19 @@ class NonBlockingInvalidatorTestDelegate { io_thread_.StartWithOptions(options); request_context_getter_ = new net::TestURLRequestContextGetter(io_thread_.message_loop_proxy()); - notifier::NotifierOptions invalidator_options; - invalidator_options.request_context_getter = request_context_getter_; + notifier::NotifierOptions notifier_options; + notifier_options.request_context_getter = request_context_getter_; + NetworkChannelCreator network_channel_creator = + NonBlockingInvalidator::MakePushClientChannelCreator(notifier_options); invalidator_.reset( new NonBlockingInvalidator( - invalidator_options, + network_channel_creator, invalidator_client_id, UnackedInvalidationsMap(), initial_state, MakeWeakHandle(invalidation_state_tracker), - "fake_client_info")); + "fake_client_info", + request_context_getter_)); } Invalidator* GetInvalidator() { diff --git a/sync/notifier/push_client_channel.cc b/sync/notifier/push_client_channel.cc index a067a21..c54b1ba 100644 --- a/sync/notifier/push_client_channel.cc +++ b/sync/notifier/push_client_channel.cc @@ -5,7 +5,6 @@ #include "sync/notifier/push_client_channel.h" #include "base/stl_util.h" -#include "google/cacheinvalidation/client_gateway.pb.h" #include "jingle/notifier/listener/push_client.h" namespace syncer { diff --git a/sync/notifier/push_client_channel.h b/sync/notifier/push_client_channel.h index fa029ab..5e4f92b 100644 --- a/sync/notifier/push_client_channel.h +++ b/sync/notifier/push_client_channel.h @@ -35,7 +35,8 @@ class SYNC_EXPORT_PRIVATE PushClientChannel // If not connected, connects with the given credentials. If // already connected, the next connection attempt will use the given // credentials. - void UpdateCredentials(const std::string& email, const std::string& token); + virtual void UpdateCredentials(const std::string& email, + const std::string& token) OVERRIDE; // SyncNetworkChannel implementation. virtual void SendEncodedMessage(const std::string& encoded_message) OVERRIDE; diff --git a/sync/notifier/sync_invalidation_listener.cc b/sync/notifier/sync_invalidation_listener.cc index 9adb897..fce7d5c 100644 --- a/sync/notifier/sync_invalidation_listener.cc +++ b/sync/notifier/sync_invalidation_listener.cc @@ -30,20 +30,20 @@ namespace syncer { SyncInvalidationListener::Delegate::~Delegate() {} SyncInvalidationListener::SyncInvalidationListener( - scoped_ptr<notifier::PushClient> push_client) - : push_client_channel_(push_client.Pass()), - sync_system_resources_(&push_client_channel_, this), + scoped_ptr<SyncNetworkChannel> network_channel) + : sync_network_channel_(network_channel.Pass()), + sync_system_resources_(sync_network_channel_.get(), this), delegate_(NULL), ticl_state_(DEFAULT_INVALIDATION_ERROR), push_client_state_(DEFAULT_INVALIDATION_ERROR), weak_ptr_factory_(this) { DCHECK(CalledOnValidThread()); - push_client_channel_.AddObserver(this); + sync_network_channel_->AddObserver(this); } SyncInvalidationListener::~SyncInvalidationListener() { DCHECK(CalledOnValidThread()); - push_client_channel_.RemoveObserver(this); + sync_network_channel_->RemoveObserver(this); Stop(); DCHECK(!delegate_); } @@ -94,7 +94,7 @@ void SyncInvalidationListener::Start( void SyncInvalidationListener::UpdateCredentials( const std::string& email, const std::string& token) { DCHECK(CalledOnValidThread()); - push_client_channel_.UpdateCredentials(email, token); + sync_network_channel_->UpdateCredentials(email, token); } void SyncInvalidationListener::UpdateRegisteredIds(const ObjectIdSet& ids) { diff --git a/sync/notifier/sync_invalidation_listener.h b/sync/notifier/sync_invalidation_listener.h index 2b4632d..18a05d7 100644 --- a/sync/notifier/sync_invalidation_listener.h +++ b/sync/notifier/sync_invalidation_listener.h @@ -22,7 +22,6 @@ #include "sync/notifier/ack_handler.h" #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/invalidator_state.h" -#include "sync/notifier/push_client_channel.h" #include "sync/notifier/state_writer.h" #include "sync/notifier/sync_system_resources.h" #include "sync/notifier/unacked_invalidation_set.h" @@ -67,7 +66,7 @@ class SYNC_EXPORT_PRIVATE SyncInvalidationListener }; explicit SyncInvalidationListener( - scoped_ptr<notifier::PushClient> push_client); + scoped_ptr<SyncNetworkChannel> network_channel); // Calls Stop(). virtual ~SyncInvalidationListener(); @@ -167,7 +166,7 @@ class SYNC_EXPORT_PRIVATE SyncInvalidationListener WeakHandle<AckHandler> GetThisAsAckHandler(); - PushClientChannel push_client_channel_; + scoped_ptr<SyncNetworkChannel> sync_network_channel_; SyncSystemResources sync_system_resources_; UnackedInvalidationsMap unacked_invalidations_map_; WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; diff --git a/sync/notifier/sync_invalidation_listener_unittest.cc b/sync/notifier/sync_invalidation_listener_unittest.cc index 2808b97..5fd9442 100644 --- a/sync/notifier/sync_invalidation_listener_unittest.cc +++ b/sync/notifier/sync_invalidation_listener_unittest.cc @@ -19,6 +19,7 @@ #include "sync/notifier/fake_invalidation_state_tracker.h" #include "sync/notifier/invalidation_util.h" #include "sync/notifier/object_id_invalidation_map.h" +#include "sync/notifier/push_client_channel.h" #include "sync/notifier/sync_invalidation_listener.h" #include "sync/notifier/unacked_invalidation_set_test_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -279,7 +280,8 @@ class SyncInvalidationListenerTest : public testing::Test { kAppsId_(kChromeSyncSourceId, "APP"), fake_push_client_(new notifier::FakePushClient()), fake_invalidation_client_(NULL), - listener_(scoped_ptr<notifier::PushClient>(fake_push_client_)), + listener_(scoped_ptr<SyncNetworkChannel>(new PushClientChannel( + scoped_ptr<notifier::PushClient>(fake_push_client_)))), fake_delegate_(&listener_) {} virtual void SetUp() { diff --git a/sync/notifier/sync_system_resources.cc b/sync/notifier/sync_system_resources.cc index 99e3ee5..c9ca212 100644 --- a/sync/notifier/sync_system_resources.cc +++ b/sync/notifier/sync_system_resources.cc @@ -17,7 +17,10 @@ #include "google/cacheinvalidation/client_gateway.pb.h" #include "google/cacheinvalidation/deps/callback.h" #include "google/cacheinvalidation/include/types.h" +#include "jingle/notifier/listener/push_client.h" +#include "sync/notifier/gcm_network_channel.h" #include "sync/notifier/invalidation_util.h" +#include "sync/notifier/push_client_channel.h" namespace syncer { @@ -168,6 +171,18 @@ void SyncNetworkChannel::RemoveObserver(Observer* observer) { observers_.RemoveObserver(observer); } +scoped_ptr<SyncNetworkChannel> SyncNetworkChannel::CreatePushClientChannel( + const notifier::NotifierOptions& notifier_options) { + scoped_ptr<notifier::PushClient> push_client( + notifier::PushClient::CreateDefaultOnIOThread(notifier_options)); + return scoped_ptr<SyncNetworkChannel>( + new PushClientChannel(push_client.Pass())); +} + +scoped_ptr<SyncNetworkChannel> SyncNetworkChannel::CreateGCMNetworkChannel() { + return scoped_ptr<SyncNetworkChannel>(new GCMNetworkChannel()); +} + const std::string& SyncNetworkChannel::GetServiceContextForTest() const { return service_context_; } diff --git a/sync/notifier/sync_system_resources.h b/sync/notifier/sync_system_resources.h index 3ddc708..22fcb96 100644 --- a/sync/notifier/sync_system_resources.h +++ b/sync/notifier/sync_system_resources.h @@ -19,6 +19,7 @@ #include "base/message_loop/message_loop.h" #include "base/threading/non_thread_safe.h" #include "google/cacheinvalidation/include/system-resources.h" +#include "jingle/notifier/base/notifier_options.h" #include "sync/base/sync_export.h" #include "sync/notifier/invalidator_state.h" #include "sync/notifier/state_writer.h" @@ -110,12 +111,20 @@ class SYNC_EXPORT_PRIVATE SyncNetworkChannel // Subclass should implement SendEncodedMessage to send encoded message to // Tango over network. virtual void SendEncodedMessage(const std::string& encoded_message) = 0; + virtual void UpdateCredentials(const std::string& email, + const std::string& token) = 0; // Classes interested in network channel state changes should implement // SyncNetworkChannel::Observer and register here. void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); + // Helper functions that know how to construct network channels from channel + // specific parameters. + static scoped_ptr<SyncNetworkChannel> CreatePushClientChannel( + const notifier::NotifierOptions& notifier_options); + static scoped_ptr<SyncNetworkChannel> CreateGCMNetworkChannel(); + const std::string& GetServiceContextForTest() const; int64 GetSchedulingHashForTest() const; diff --git a/sync/notifier/sync_system_resources_unittest.cc b/sync/notifier/sync_system_resources_unittest.cc index f63e906..632b11d0 100644 --- a/sync/notifier/sync_system_resources_unittest.cc +++ b/sync/notifier/sync_system_resources_unittest.cc @@ -188,6 +188,10 @@ class TestSyncNetworkChannel : public SyncNetworkChannel { last_encoded_message_ = encoded_message; } + virtual void UpdateCredentials(const std::string& email, + const std::string& token) OVERRIDE { + } + std::string last_encoded_message_; }; diff --git a/sync/sync_notifier.gypi b/sync/sync_notifier.gypi index 7986bd7..930bb09 100644 --- a/sync/sync_notifier.gypi +++ b/sync/sync_notifier.gypi @@ -48,6 +48,8 @@ 'conditions': [ ['OS != "android"', { 'sources': [ + 'notifier/gcm_network_channel.cc', + 'notifier/gcm_network_channel.h', 'notifier/invalidation_notifier.cc', 'notifier/invalidation_notifier.h', 'notifier/non_blocking_invalidator.cc', diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi index 761cb29..57e2b47 100644 --- a/sync/sync_tests.gypi +++ b/sync/sync_tests.gypi @@ -317,6 +317,7 @@ ['OS != "android"', { 'sources': [ 'notifier/fake_invalidator_unittest.cc', + 'notifier/gcm_network_channel_unittest.cc', 'notifier/invalidation_notifier_unittest.cc', 'notifier/invalidator_registrar_unittest.cc', 'notifier/non_blocking_invalidator_unittest.cc', diff --git a/sync/tools/sync_client.cc b/sync/tools/sync_client.cc index c0a1ef1..b0c9b55 100644 --- a/sync/tools/sync_client.cc +++ b/sync/tools/sync_client.cc @@ -269,17 +269,21 @@ int SyncClientMain(int argc, char* argv[]) { new MyTestURLRequestContextGetter(io_thread.message_loop_proxy()); const notifier::NotifierOptions& notifier_options = ParseNotifierOptions(command_line, context_getter); + syncer::NetworkChannelCreator network_channel_creator = + syncer::NonBlockingInvalidator::MakePushClientChannelCreator( + notifier_options); const char kClientInfo[] = "standalone_sync_client"; std::string invalidator_id = base::RandBytesAsString(8); NullInvalidationStateTracker null_invalidation_state_tracker; scoped_ptr<Invalidator> invalidator(new NonBlockingInvalidator( - notifier_options, + network_channel_creator, invalidator_id, null_invalidation_state_tracker.GetSavedInvalidations(), null_invalidation_state_tracker.GetBootstrapData(), WeakHandle<InvalidationStateTracker>( null_invalidation_state_tracker.AsWeakPtr()), - kClientInfo)); + kClientInfo, + notifier_options.request_context_getter)); // Set up database directory for the syncer. base::ScopedTempDir database_dir; diff --git a/sync/tools/sync_listen_notifications.cc b/sync/tools/sync_listen_notifications.cc index 5d212f3..12d089b 100644 --- a/sync/tools/sync_listen_notifications.cc +++ b/sync/tools/sync_listen_notifications.cc @@ -177,17 +177,21 @@ int SyncListenNotificationsMain(int argc, char* argv[]) { ParseNotifierOptions( command_line, new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); + syncer::NetworkChannelCreator network_channel_creator = + syncer::NonBlockingInvalidator::MakePushClientChannelCreator( + notifier_options); const char kClientInfo[] = "sync_listen_notifications"; NullInvalidationStateTracker null_invalidation_state_tracker; scoped_ptr<Invalidator> invalidator( new NonBlockingInvalidator( - notifier_options, + network_channel_creator, base::RandBytesAsString(8), null_invalidation_state_tracker.GetSavedInvalidations(), null_invalidation_state_tracker.GetBootstrapData(), WeakHandle<InvalidationStateTracker>( null_invalidation_state_tracker.AsWeakPtr()), - kClientInfo)); + kClientInfo, + notifier_options.request_context_getter)); NotificationPrinter notification_printer; |