diff options
Diffstat (limited to 'sync')
24 files changed, 594 insertions, 109 deletions
diff --git a/sync/internal_api/public/sync_manager.h b/sync/internal_api/public/sync_manager.h index bc6a137..b3f03b0 100644 --- a/sync/internal_api/public/sync_manager.h +++ b/sync/internal_api/public/sync_manager.h @@ -23,7 +23,7 @@ #include "sync/internal_api/public/sync_encryption_handler.h" #include "sync/internal_api/public/util/report_unrecoverable_error_function.h" #include "sync/internal_api/public/util/weak_handle.h" -#include "sync/notifier/invalidation_handler.h" +#include "sync/notifier/invalidation_util.h" #include "sync/protocol/sync_protocol_error.h" namespace sync_pb { @@ -39,6 +39,8 @@ struct Experiments; class ExtensionsActivityMonitor; class HttpPostProviderFactory; class InternalComponentsFactory; +class InvalidationHandler; +class Invalidator; class JsBackend; class JsEventHandler; class SyncEncryptionHandler; @@ -73,7 +75,7 @@ struct SyncCredentials { // // Unless stated otherwise, all methods of SyncManager should be called on the // same thread. -class SYNC_EXPORT SyncManager : public syncer::InvalidationHandler { +class SYNC_EXPORT SyncManager { public: // An interface the embedding application implements to be notified // on change events. Note that these methods may be called on *any* @@ -313,6 +315,7 @@ class SYNC_EXPORT SyncManager : public syncer::InvalidationHandler { ExtensionsActivityMonitor* extensions_activity_monitor, ChangeDelegate* change_delegate, const SyncCredentials& credentials, + scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -341,6 +344,27 @@ class SYNC_EXPORT SyncManager : public syncer::InvalidationHandler { // Update tokens that we're using in Sync. Email must stay the same. virtual void UpdateCredentials(const SyncCredentials& credentials) = 0; + // Called when the user disables or enables a sync type. + virtual void UpdateEnabledTypes(ModelTypeSet enabled_types) = 0; + + // Forwards to the underlying invalidator (see comments in invalidator.h). + virtual void RegisterInvalidationHandler( + InvalidationHandler* handler) = 0; + + // Forwards to the underlying notifier (see comments in invalidator.h). + virtual void UpdateRegisteredInvalidationIds( + InvalidationHandler* handler, + const ObjectIdSet& ids) = 0; + + // Forwards to the underlying notifier (see comments in invalidator.h). + virtual void UnregisterInvalidationHandler( + InvalidationHandler* handler) = 0; + + // Forwards to the underlying notifier (see comments in invalidator.h). + virtual void AcknowledgeInvalidation( + const invalidation::ObjectId& id, + const syncer::AckHandle& ack_handle) = 0; + // Put the syncer in normal mode ready to perform nudges and polls. virtual void StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) = 0; @@ -368,13 +392,6 @@ class SYNC_EXPORT SyncManager : public syncer::InvalidationHandler { const base::Closure& ready_task, const base::Closure& retry_task) = 0; - // Inform the syncer of a change in the invalidator's state. - virtual void OnInvalidatorStateChange(InvalidatorState state) = 0; - - // Inform the syncer that its cached information about a type is obsolete. - virtual void OnIncomingInvalidation( - const ObjectIdInvalidationMap& invalidation_map) = 0; - // Adds a listener to be notified of sync events. // NOTE: It is OK (in fact, it's probably a good idea) to call this before // having received OnInitializationCompleted. diff --git a/sync/internal_api/public/test/fake_sync_manager.h b/sync/internal_api/public/test/fake_sync_manager.h index ed69a52..ba38ac6 100644 --- a/sync/internal_api/public/test/fake_sync_manager.h +++ b/sync/internal_api/public/test/fake_sync_manager.h @@ -62,11 +62,10 @@ class FakeSyncManager : public SyncManager { ConfigureReason GetAndResetConfigureReason(); // Posts a method to invalidate the given IDs on the sync thread. - virtual void OnIncomingInvalidation( - const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; + void Invalidate(const ObjectIdInvalidationMap& invalidation_map); // Posts a method to update the invalidator state on the sync thread. - virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; + void UpdateInvalidatorState(InvalidatorState state); // Block until the sync thread has finished processing any pending messages. void WaitForSyncThread(); @@ -85,6 +84,7 @@ class FakeSyncManager : public SyncManager { ExtensionsActivityMonitor* extensions_activity_monitor, ChangeDelegate* change_delegate, const SyncCredentials& credentials, + scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -100,6 +100,17 @@ class FakeSyncManager : public SyncManager { ModelTypeSet types) OVERRIDE; virtual bool PurgePartiallySyncedTypes() OVERRIDE; virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; + virtual void UpdateEnabledTypes(ModelTypeSet types) OVERRIDE; + virtual void RegisterInvalidationHandler( + InvalidationHandler* handler) OVERRIDE; + virtual void UpdateRegisteredInvalidationIds( + InvalidationHandler* handler, + const ObjectIdSet& ids) OVERRIDE; + virtual void UnregisterInvalidationHandler( + InvalidationHandler* handler) OVERRIDE; + virtual void AcknowledgeInvalidation( + const invalidation::ObjectId& id, + const syncer::AckHandle& ack_handle) OVERRIDE; virtual void StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) OVERRIDE; virtual void ConfigureSyncer( @@ -125,6 +136,10 @@ class FakeSyncManager : public SyncManager { virtual void RefreshTypes(ModelTypeSet types) OVERRIDE; private: + void InvalidateOnSyncThread( + const ObjectIdInvalidationMap& invalidation_map); + void UpdateInvalidatorStateOnSyncThread(InvalidatorState state); + scoped_refptr<base::SequencedTaskRunner> sync_task_runner_; ObserverList<SyncManager::Observer> observers_; diff --git a/sync/internal_api/sync_manager_impl.cc b/sync/internal_api/sync_manager_impl.cc index 7b0e549..68f68f8 100644 --- a/sync/internal_api/sync_manager_impl.cc +++ b/sync/internal_api/sync_manager_impl.cc @@ -349,6 +349,7 @@ void SyncManagerImpl::Init( ExtensionsActivityMonitor* extensions_activity_monitor, SyncManager::ChangeDelegate* change_delegate, const SyncCredentials& credentials, + scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -368,6 +369,9 @@ void SyncManagerImpl::Init( change_delegate_ = change_delegate; + invalidator_ = invalidator.Pass(); + invalidator_->RegisterHandler(this); + AddObserver(&js_sync_manager_observer_); SetJsEventHandler(event_handler); @@ -605,11 +609,49 @@ void SyncManagerImpl::UpdateCredentials(const SyncCredentials& credentials) { if (!connection_manager_->SetAuthToken(credentials.sync_token)) return; // Auth token is known to be invalid, so exit early. + invalidator_->UpdateCredentials(credentials.email, credentials.sync_token); scheduler_->OnCredentialsUpdated(); // TODO(zea): pass the credential age to the debug info event listener. } +void SyncManagerImpl::UpdateEnabledTypes(ModelTypeSet enabled_types) { + DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK(initialized_); + invalidator_->UpdateRegisteredIds( + this, + ModelTypeSetToObjectIdSet(enabled_types)); +} + +void SyncManagerImpl::RegisterInvalidationHandler( + InvalidationHandler* handler) { + DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK(initialized_); + invalidator_->RegisterHandler(handler); +} + +void SyncManagerImpl::UpdateRegisteredInvalidationIds( + InvalidationHandler* handler, + const ObjectIdSet& ids) { + DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK(initialized_); + invalidator_->UpdateRegisteredIds(handler, ids); +} + +void SyncManagerImpl::UnregisterInvalidationHandler( + InvalidationHandler* handler) { + DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK(initialized_); + invalidator_->UnregisterHandler(handler); +} + +void SyncManagerImpl::AcknowledgeInvalidation( + const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { + DCHECK(thread_checker_.CalledOnValidThread()); + DCHECK(initialized_); + invalidator_->Acknowledge(id, ack_handle); +} + void SyncManagerImpl::AddObserver(SyncManager::Observer* observer) { DCHECK(thread_checker_.CalledOnValidThread()); observers_.AddObserver(observer); @@ -648,10 +690,15 @@ void SyncManagerImpl::ShutdownOnSyncThread() { RemoveObserver(&debug_info_event_listener_); - // |connection_manager_| may end up being NULL here in tests (in synchronous - // initialization mode). + // |invalidator_| and |connection_manager_| may end up being NULL here in + // tests (in synchronous initialization mode). // // TODO(akalin): Fix this behavior. + + if (invalidator_) + invalidator_->UnregisterHandler(this); + invalidator_.reset(); + if (connection_manager_) connection_manager_->RemoveListener(this); connection_manager_.reset(); @@ -941,6 +988,20 @@ void SyncManagerImpl::OnSyncEngineEvent(const SyncEngineEvent& event) { DVLOG(1) << "Sending OnSyncCycleCompleted"; FOR_EACH_OBSERVER(SyncManager::Observer, observers_, OnSyncCycleCompleted(event.snapshot)); + + // This is here for tests, which are still using p2p notifications. + bool is_notifiable_commit = + (event.snapshot.model_neutral_state().num_successful_commits > 0); + if (is_notifiable_commit) { + if (invalidator_) { + const ObjectIdInvalidationMap& invalidation_map = + ModelTypeInvalidationMapToObjectIdInvalidationMap( + event.snapshot.source().types); + invalidator_->SendInvalidation(invalidation_map); + } else { + DVLOG(1) << "Not sending invalidation: invalidator_ is NULL"; + } + } } if (event.what_happened == SyncEngineEvent::STOP_SYNCING_PERMANENTLY) { @@ -1163,8 +1224,6 @@ void SyncManagerImpl::UpdateNotificationInfo( } void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { - DCHECK(thread_checker_.CalledOnValidThread()); - const std::string& state_str = InvalidatorStateToString(state); invalidator_state_ = state; DVLOG(1) << "Invalidator state changed to: " << state_str; @@ -1173,6 +1232,12 @@ void SyncManagerImpl::OnInvalidatorStateChange(InvalidatorState state) { allstatus_.SetNotificationsEnabled(notifications_enabled); scheduler_->SetNotificationsEnabled(notifications_enabled); + if (invalidator_state_ == syncer::INVALIDATION_CREDENTIALS_REJECTED) { + // If the invalidator's credentials were rejected, that means that + // our sync credentials are also bad, so invalidate those. + connection_manager_->OnInvalidationCredentialsRejected(); + } + if (js_event_handler_.IsInitialized()) { base::DictionaryValue details; details.SetString("state", state_str); @@ -1187,6 +1252,15 @@ void SyncManagerImpl::OnIncomingInvalidation( const ObjectIdInvalidationMap& invalidation_map) { DCHECK(thread_checker_.CalledOnValidThread()); + // TODO(dcheng): Acknowledge immediately for now. Fix this once the + // invalidator doesn't repeatedly ping for unacknowledged invaliations, since + // it conflicts with the sync scheduler's internal backoff algorithm. + // See http://crbug.com/124149 for more information. + for (ObjectIdInvalidationMap::const_iterator it = invalidation_map.begin(); + it != invalidation_map.end(); ++it) { + invalidator_->Acknowledge(it->first, it->second.ack_handle); + } + const ModelTypeInvalidationMap& type_invalidation_map = ObjectIdInvalidationMapToModelTypeInvalidationMap(invalidation_map); if (type_invalidation_map.empty()) { diff --git a/sync/internal_api/sync_manager_impl.h b/sync/internal_api/sync_manager_impl.h index 153df81..c12eea7 100644 --- a/sync/internal_api/sync_manager_impl.h +++ b/sync/internal_api/sync_manager_impl.h @@ -51,6 +51,7 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : public SyncManager, public net::NetworkChangeNotifier::IPAddressObserver, public net::NetworkChangeNotifier::ConnectionTypeObserver, + public InvalidationHandler, public JsBackend, public SyncEngineEventListener, public ServerConnectionEventListener, @@ -73,6 +74,7 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : ExtensionsActivityMonitor* extensions_activity_monitor, SyncManager::ChangeDelegate* change_delegate, const SyncCredentials& credentials, + scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -88,6 +90,17 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : ModelTypeSet types) OVERRIDE; virtual bool PurgePartiallySyncedTypes() OVERRIDE; virtual void UpdateCredentials(const SyncCredentials& credentials) OVERRIDE; + virtual void UpdateEnabledTypes(ModelTypeSet enabled_types) OVERRIDE; + virtual void RegisterInvalidationHandler( + InvalidationHandler* handler) OVERRIDE; + virtual void UpdateRegisteredInvalidationIds( + InvalidationHandler* handler, + const ObjectIdSet& ids) OVERRIDE; + virtual void UnregisterInvalidationHandler( + InvalidationHandler* handler) OVERRIDE; + virtual void AcknowledgeInvalidation( + const invalidation::ObjectId& id, + const syncer::AckHandle& ack_handle) OVERRIDE; virtual void StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) OVERRIDE; virtual void ConfigureSyncer( @@ -99,9 +112,6 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : const ModelSafeRoutingInfo& new_routing_info, const base::Closure& ready_task, const base::Closure& retry_task) OVERRIDE; - virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; - virtual void OnIncomingInvalidation( - const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; virtual void AddObserver(SyncManager::Observer* observer) OVERRIDE; virtual void RemoveObserver(SyncManager::Observer* observer) OVERRIDE; virtual SyncStatus GetDetailedStatus() const OVERRIDE; @@ -167,6 +177,11 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : syncable::BaseTransaction* trans, std::vector<int64>* entries_changed) OVERRIDE; + // InvalidationHandler implementation. + virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; + virtual void OnIncomingInvalidation( + const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; + // Handle explicit requests to fetch updates for the given types. virtual void RefreshTypes(ModelTypeSet types) OVERRIDE; @@ -321,6 +336,9 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : // Start()ed. scoped_ptr<SyncScheduler> scheduler_; + // The Invalidator which notifies us when updates need to be downloaded. + scoped_ptr<Invalidator> invalidator_; + // A multi-purpose status watch object that aggregates stats from various // sync components. AllStatus allstatus_; diff --git a/sync/internal_api/sync_manager_impl_unittest.cc b/sync/internal_api/sync_manager_impl_unittest.cc index 2085ec3..a1ddd7f 100644 --- a/sync/internal_api/sync_manager_impl_unittest.cc +++ b/sync/internal_api/sync_manager_impl_unittest.cc @@ -46,6 +46,7 @@ #include "sync/js/js_reply_handler.h" #include "sync/js/js_test_util.h" #include "sync/notifier/fake_invalidation_handler.h" +#include "sync/notifier/fake_invalidator.h" #include "sync/notifier/invalidation_handler.h" #include "sync/notifier/invalidator.h" #include "sync/protocol/bookmark_specifics.pb.h" @@ -788,12 +789,14 @@ class SyncManagerTest : public testing::Test, }; SyncManagerTest() - : sync_manager_("Test sync manager") { + : fake_invalidator_(NULL), + sync_manager_("Test sync manager") { switches_.encryption_method = InternalComponentsFactory::ENCRYPTION_KEYSTORE; } virtual ~SyncManagerTest() { + EXPECT_FALSE(fake_invalidator_); } // Test implementation. @@ -804,6 +807,8 @@ class SyncManagerTest : public testing::Test, credentials.email = "foo@bar.com"; credentials.sync_token = "sometoken"; + fake_invalidator_ = new FakeInvalidator(); + sync_manager_.AddObserver(&manager_observer_); EXPECT_CALL(manager_observer_, OnInitializationComplete(_, _, _, _)). WillOnce(SaveArg<0>(&js_backend_)); @@ -826,6 +831,7 @@ class SyncManagerTest : public testing::Test, &extensions_activity_monitor_, this, credentials, + scoped_ptr<Invalidator>(fake_invalidator_), "fake_invalidator_client_id", std::string(), std::string(), // bootstrap tokens @@ -845,11 +851,17 @@ class SyncManagerTest : public testing::Test, sync_manager_.GetUserShare(), i->first); } PumpLoop(); + + EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&sync_manager_)); } void TearDown() { sync_manager_.RemoveObserver(&manager_observer_); sync_manager_.ShutdownOnSyncThread(); + // We can't assert that |sync_manager_| isn't registered with + // |fake_invalidator_| anymore because |fake_invalidator_| is now + // destroyed. + fake_invalidator_ = NULL; PumpLoop(); } @@ -1015,6 +1027,7 @@ class SyncManagerTest : public testing::Test, protected: FakeEncryptor encryptor_; TestUnrecoverableErrorHandler handler_; + FakeInvalidator* fake_invalidator_; SyncManagerImpl sync_manager_; WeakHandle<JsBackend> js_backend_; StrictMock<SyncManagerObserverMock> manager_observer_; @@ -1022,6 +1035,29 @@ class SyncManagerTest : public testing::Test, InternalComponentsFactory::Switches switches_; }; +TEST_F(SyncManagerTest, UpdateEnabledTypes) { + ModelSafeRoutingInfo routes; + GetModelSafeRoutingInfo(&routes); + const ModelTypeSet enabled_types = GetRoutingInfoTypes(routes); + sync_manager_.UpdateEnabledTypes(enabled_types); + EXPECT_EQ(ModelTypeSetToObjectIdSet(enabled_types), + fake_invalidator_->GetRegisteredIds(&sync_manager_)); +} + +TEST_F(SyncManagerTest, RegisterInvalidationHandler) { + FakeInvalidationHandler fake_handler; + sync_manager_.RegisterInvalidationHandler(&fake_handler); + EXPECT_TRUE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); + + const ObjectIdSet& ids = + ModelTypeSetToObjectIdSet(ModelTypeSet(BOOKMARKS, PREFERENCES)); + sync_manager_.UpdateRegisteredInvalidationIds(&fake_handler, ids); + EXPECT_EQ(ids, fake_invalidator_->GetRegisteredIds(&fake_handler)); + + sync_manager_.UnregisterInvalidationHandler(&fake_handler); + EXPECT_FALSE(fake_invalidator_->IsHandlerRegistered(&fake_handler)); +} + TEST_F(SyncManagerTest, ProcessJsMessage) { const JsArgList kNoArgs; @@ -1326,6 +1362,14 @@ TEST_F(SyncManagerTest, OnInvalidatorStateChangeJsEvents) { base::DictionaryValue auth_error_details; auth_error_details.SetString("status", "CONNECTION_AUTH_ERROR"); + EXPECT_CALL(manager_observer_, + OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); + + EXPECT_CALL( + event_handler, + HandleJsEvent("onConnectionStatusChange", + HasDetailsAsDictionary(auth_error_details))); + EXPECT_CALL(event_handler, HandleJsEvent("onNotificationStateChange", HasDetailsAsDictionary(enabled_details))); @@ -1366,6 +1410,22 @@ TEST_F(SyncManagerTest, OnInvalidatorStateChangeJsEvents) { PumpLoop(); } +// Simulate the invalidator's credentials being rejected. That should +// also clear the sync token. +TEST_F(SyncManagerTest, OnInvalidatorStateChangeCredentialsRejected) { + EXPECT_CALL(manager_observer_, + OnConnectionStatusChange(CONNECTION_AUTH_ERROR)); + + EXPECT_FALSE(sync_manager_.GetHasInvalidAuthTokenForTest()); + + SimulateInvalidatorStateChangeForTest(INVALIDATION_CREDENTIALS_REJECTED); + + EXPECT_TRUE(sync_manager_.GetHasInvalidAuthTokenForTest()); + + // Should trigger the replies. + PumpLoop(); +} + TEST_F(SyncManagerTest, OnIncomingNotification) { StrictMock<MockJsEventHandler> event_handler; diff --git a/sync/internal_api/test/fake_sync_manager.cc b/sync/internal_api/test/fake_sync_manager.cc index 7a6d6a4..3a9beca 100644 --- a/sync/internal_api/test/fake_sync_manager.cc +++ b/sync/internal_api/test/fake_sync_manager.cc @@ -61,6 +61,25 @@ ConfigureReason FakeSyncManager::GetAndResetConfigureReason() { return reason; } +void FakeSyncManager::Invalidate( + const ObjectIdInvalidationMap& invalidation_map) { + if (!sync_task_runner_->PostTask( + FROM_HERE, + base::Bind(&FakeSyncManager::InvalidateOnSyncThread, + base::Unretained(this), invalidation_map))) { + NOTREACHED(); + } +} + +void FakeSyncManager::UpdateInvalidatorState(InvalidatorState state) { + if (!sync_task_runner_->PostTask( + FROM_HERE, + base::Bind(&FakeSyncManager::UpdateInvalidatorStateOnSyncThread, + base::Unretained(this), state))) { + NOTREACHED(); + } +} + void FakeSyncManager::WaitForSyncThread() { // Post a task to |sync_task_runner_| and block until it runs. base::RunLoop run_loop; @@ -84,6 +103,7 @@ void FakeSyncManager::Init( ExtensionsActivityMonitor* extensions_activity_monitor, ChangeDelegate* change_delegate, const SyncCredentials& credentials, + scoped_ptr<Invalidator> invalidator, const std::string& invalidator_client_id, const std::string& restored_key_for_bootstrapping, const std::string& restored_keystore_key_for_bootstrapping, @@ -141,6 +161,31 @@ void FakeSyncManager::UpdateCredentials(const SyncCredentials& credentials) { NOTIMPLEMENTED(); } +void FakeSyncManager::UpdateEnabledTypes(ModelTypeSet types) { + enabled_types_ = types; +} + +void FakeSyncManager::RegisterInvalidationHandler( + InvalidationHandler* handler) { + registrar_.RegisterHandler(handler); +} + +void FakeSyncManager::UpdateRegisteredInvalidationIds( + InvalidationHandler* handler, + const ObjectIdSet& ids) { + registrar_.UpdateRegisteredIds(handler, ids); +} + +void FakeSyncManager::UnregisterInvalidationHandler( + InvalidationHandler* handler) { + registrar_.UnregisterHandler(handler); +} + +void FakeSyncManager::AcknowledgeInvalidation(const invalidation::ObjectId& id, + const AckHandle& ack_handle) { + // Do nothing. +} + void FakeSyncManager::StartSyncingNormally( const ModelSafeRoutingInfo& routing_info) { // Do nothing. @@ -156,7 +201,7 @@ void FakeSyncManager::ConfigureSyncer( const base::Closure& ready_task, const base::Closure& retry_task) { last_configure_reason_ = reason; - enabled_types_ = GetRoutingInfoTypes(new_routing_info); + ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); ModelTypeSet success_types = to_download; success_types.RemoveAll(configure_fail_types_); @@ -246,17 +291,20 @@ void FakeSyncManager::RefreshTypes(ModelTypeSet types) { last_refresh_request_types_ = types; } -void FakeSyncManager::OnIncomingInvalidation( - const ObjectIdInvalidationMap& invalidation_map) { - // Do nothing. +void FakeSyncManager::InvalidateOnSyncThread( + const ObjectIdInvalidationMap& invalidation_map) { + DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); + registrar_.DispatchInvalidationsToHandlers(invalidation_map); } -ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { - return last_refresh_request_types_; +void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( + InvalidatorState state) { + DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); + registrar_.UpdateInvalidatorState(state); } -void FakeSyncManager::OnInvalidatorStateChange(InvalidatorState state) { - // Do nothing. +ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { + return last_refresh_request_types_; } } // namespace syncer diff --git a/sync/notifier/fake_invalidator.cc b/sync/notifier/fake_invalidator.cc index 0b217f7..088d239 100644 --- a/sync/notifier/fake_invalidator.cc +++ b/sync/notifier/fake_invalidator.cc @@ -27,6 +27,11 @@ const std::string& FakeInvalidator::GetCredentialsToken() const { return token_; } +const ObjectIdInvalidationMap& +FakeInvalidator::GetLastSentInvalidationMap() const { + return last_sent_invalidation_map_; +} + void FakeInvalidator::EmitOnInvalidatorStateChange(InvalidatorState state) { registrar_.UpdateInvalidatorState(state); } @@ -64,4 +69,9 @@ void FakeInvalidator::UpdateCredentials( token_ = token; } +void FakeInvalidator::SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map) { + last_sent_invalidation_map_ = invalidation_map; +} + } // namespace syncer diff --git a/sync/notifier/fake_invalidator.h b/sync/notifier/fake_invalidator.h index 7913694..87380d0 100644 --- a/sync/notifier/fake_invalidator.h +++ b/sync/notifier/fake_invalidator.h @@ -39,12 +39,15 @@ class FakeInvalidator : public Invalidator { virtual InvalidatorState GetInvalidatorState() const OVERRIDE; virtual void UpdateCredentials( const std::string& email, const std::string& token) OVERRIDE; + virtual void SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; private: InvalidatorRegistrar registrar_; std::string state_; std::string email_; std::string token_; + ObjectIdInvalidationMap last_sent_invalidation_map_; }; } // namespace syncer diff --git a/sync/notifier/invalidation_notifier.cc b/sync/notifier/invalidation_notifier.cc index e3c79a4..d097560 100644 --- a/sync/notifier/invalidation_notifier.cc +++ b/sync/notifier/invalidation_notifier.cc @@ -79,6 +79,12 @@ void InvalidationNotifier::UpdateCredentials( invalidation_listener_.UpdateCredentials(email, token); } +void InvalidationNotifier::SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map) { + DCHECK(CalledOnValidThread()); + // Do nothing. +} + void InvalidationNotifier::OnInvalidate( const ObjectIdInvalidationMap& invalidation_map) { DCHECK(CalledOnValidThread()); diff --git a/sync/notifier/invalidation_notifier.h b/sync/notifier/invalidation_notifier.h index b7a98f8..269511f 100644 --- a/sync/notifier/invalidation_notifier.h +++ b/sync/notifier/invalidation_notifier.h @@ -62,6 +62,8 @@ class SYNC_EXPORT_PRIVATE InvalidationNotifier virtual InvalidatorState GetInvalidatorState() const OVERRIDE; virtual void UpdateCredentials( const std::string& email, const std::string& token) OVERRIDE; + virtual void SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; // SyncInvalidationListener::Delegate implementation. virtual void OnInvalidate( diff --git a/sync/notifier/invalidator.h b/sync/notifier/invalidator.h index ccb6922..a0f881e 100644 --- a/sync/notifier/invalidator.h +++ b/sync/notifier/invalidator.h @@ -83,6 +83,13 @@ class SYNC_EXPORT Invalidator { // once. virtual void UpdateCredentials( const std::string& email, const std::string& token) = 0; + + // This is here only to support the old p2p notification implementation, + // which is still used by sync integration tests. + // TODO(akalin): Remove this once we move the integration tests off p2p + // notifications. + virtual void SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map) = 0; }; } // namespace syncer diff --git a/sync/notifier/invalidator_factory.cc b/sync/notifier/invalidator_factory.cc new file mode 100644 index 0000000..f359ce8 --- /dev/null +++ b/sync/notifier/invalidator_factory.cc @@ -0,0 +1,107 @@ +// Copyright (c) 2012 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/invalidator_factory.h" + +#include <string> + +#include "base/base64.h" +#include "base/logging.h" +#include "base/rand_util.h" +#include "jingle/notifier/listener/push_client.h" +#include "sync/notifier/invalidator.h" +#include "sync/notifier/non_blocking_invalidator.h" +#include "sync/notifier/p2p_invalidator.h" + +namespace syncer { +namespace { + +Invalidator* CreateDefaultInvalidator( + const notifier::NotifierOptions& notifier_options, + const std::string& invalidator_client_id, + const InvalidationStateMap& initial_invalidation_state_map, + const std::string& invalidation_bootstrap_data, + const WeakHandle<InvalidationStateTracker>& invalidation_state_tracker, + const std::string& client_info) { + if (notifier_options.notification_method == notifier::NOTIFICATION_P2P) { + // TODO(rlarocque): Ideally, the notification target would be + // NOTIFY_OTHERS. There's no good reason to notify ourselves of our own + // commits. We self-notify for now only because the integration tests rely + // on this behaviour. See crbug.com/97780. + return new P2PInvalidator( + notifier::PushClient::CreateDefault(notifier_options), + invalidator_client_id, + NOTIFY_ALL); + } + + return new NonBlockingInvalidator( + notifier_options, invalidator_client_id, initial_invalidation_state_map, + invalidation_bootstrap_data, invalidation_state_tracker, client_info); +} + +std::string GenerateInvalidatorClientId() { + // Generate a GUID with 128 bits worth of base64-encoded randomness. + // This format is similar to that of sync's cache_guid. + const int kGuidBytes = 128 / 8; + std::string guid; + base::Base64Encode(base::RandBytesAsString(kGuidBytes), &guid); + return guid; +} + +} // namespace + +// TODO(akalin): Remove the dependency on jingle if OS_ANDROID is defined. +InvalidatorFactory::InvalidatorFactory( + const notifier::NotifierOptions& notifier_options, + const std::string& client_info, + const base::WeakPtr<InvalidationStateTracker>& + invalidation_state_tracker) + : notifier_options_(notifier_options), + client_info_(client_info) { + if (!invalidation_state_tracker.get()) { + return; + } + + // TODO(rlarocque): This is not the most obvious place for client ID + // generation code. We should try to find a better place for it when we + // refactor the invalidator into its own service. + if (invalidation_state_tracker->GetInvalidatorClientId().empty()) { + // This also clears any existing state. We can't reuse old invalidator + // state with the new ID anyway. + invalidation_state_tracker->SetInvalidatorClientId( + GenerateInvalidatorClientId()); + } + + initial_invalidation_state_map_ = + invalidation_state_tracker->GetAllInvalidationStates(); + invalidator_client_id_ = + invalidation_state_tracker->GetInvalidatorClientId(); + invalidation_bootstrap_data_ = invalidation_state_tracker->GetBootstrapData(); + invalidation_state_tracker_ = WeakHandle<InvalidationStateTracker>( + invalidation_state_tracker); +} + +InvalidatorFactory::~InvalidatorFactory() { +} + +Invalidator* InvalidatorFactory::CreateInvalidator() { +#if defined(OS_ANDROID) + // Android uses AndroidInvalidatorBridge instead. See SyncManager + // initialization code in SyncBackendHost for more information. + return NULL; +#else + return CreateDefaultInvalidator(notifier_options_, + invalidator_client_id_, + initial_invalidation_state_map_, + invalidation_bootstrap_data_, + invalidation_state_tracker_, + client_info_); +#endif +} + +std::string InvalidatorFactory::GetInvalidatorClientId() const { + return invalidator_client_id_; +} + +} // namespace syncer diff --git a/sync/notifier/invalidator_factory.h b/sync/notifier/invalidator_factory.h new file mode 100644 index 0000000..782850e --- /dev/null +++ b/sync/notifier/invalidator_factory.h @@ -0,0 +1,55 @@ +// Copyright 2012 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_INVALIDATOR_FACTORY_H_ +#define SYNC_NOTIFIER_INVALIDATOR_FACTORY_H_ + +#include <string> + +#include "base/memory/weak_ptr.h" +#include "jingle/notifier/base/notifier_options.h" +#include "sync/base/sync_export.h" +#include "sync/internal_api/public/util/weak_handle.h" +#include "sync/notifier/invalidation_state_tracker.h" + +namespace syncer { + +class Invalidator; + +// Class to instantiate various implementations of the Invalidator +// interface. +class SYNC_EXPORT InvalidatorFactory { + public: + // |client_info| is a string identifying the client, e.g. a user + // agent string. |invalidation_state_tracker| may be NULL (for + // tests). + InvalidatorFactory( + const notifier::NotifierOptions& notifier_options, + const std::string& client_info, + const base::WeakPtr<InvalidationStateTracker>& + invalidation_state_tracker); + ~InvalidatorFactory(); + + // Creates an invalidator. Caller takes ownership of the returned + // object. However, the returned object must not outlive the + // factory from which it was created. Can be called on any thread. + Invalidator* CreateInvalidator(); + + // Returns the unique ID that was (or will be) passed to the invalidator. + std::string GetInvalidatorClientId() const; + + private: + const notifier::NotifierOptions notifier_options_; + + // Some of these should be const, but can't be set up in member initializers. + InvalidationStateMap initial_invalidation_state_map_; + const std::string client_info_; + std::string invalidator_client_id_; + std::string invalidation_bootstrap_data_; + WeakHandle<InvalidationStateTracker> invalidation_state_tracker_; +}; + +} // namespace syncer + +#endif // SYNC_NOTIFIER_INVALIDATOR_FACTORY_H_ diff --git a/sync/notifier/invalidator_factory_unittest.cc b/sync/notifier/invalidator_factory_unittest.cc new file mode 100644 index 0000000..31b95fc --- /dev/null +++ b/sync/notifier/invalidator_factory_unittest.cc @@ -0,0 +1,85 @@ +// Copyright (c) 2012 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/invalidator_factory.h" + +#include "base/command_line.h" +#include "base/compiler_specific.h" +#include "base/memory/ref_counted.h" +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "base/message_loop.h" +#include "base/threading/thread.h" +#include "jingle/notifier/base/notification_method.h" +#include "jingle/notifier/base/notifier_options.h" +#include "net/url_request/url_request_test_util.h" +#include "sync/internal_api/public/base/model_type.h" +#include "sync/notifier/fake_invalidation_handler.h" +#include "sync/notifier/invalidation_state_tracker.h" +#include "sync/notifier/invalidator.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace syncer { +namespace { + +class InvalidatorFactoryTest : public testing::Test { + protected: + + virtual void SetUp() OVERRIDE { + notifier_options_.request_context_getter = + new net::TestURLRequestContextGetter( + message_loop_.message_loop_proxy()); + } + + virtual void TearDown() OVERRIDE { + message_loop_.RunUntilIdle(); + EXPECT_EQ(0, fake_handler_.GetInvalidationCount()); + } + + base::MessageLoop message_loop_; + FakeInvalidationHandler fake_handler_; + notifier::NotifierOptions notifier_options_; + scoped_ptr<InvalidatorFactory> factory_; +}; + +// Test basic creation of a NonBlockingInvalidationNotifier. +TEST_F(InvalidatorFactoryTest, Basic) { + notifier_options_.notification_method = notifier::NOTIFICATION_SERVER; + InvalidatorFactory factory( + notifier_options_, + "test client info", + base::WeakPtr<InvalidationStateTracker>()); + scoped_ptr<Invalidator> invalidator(factory.CreateInvalidator()); +#if defined(OS_ANDROID) + ASSERT_FALSE(invalidator.get()); +#else + ASSERT_TRUE(invalidator.get()); + ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); + invalidator->RegisterHandler(&fake_handler_); + invalidator->UpdateRegisteredIds(&fake_handler_, ids); + invalidator->UnregisterHandler(&fake_handler_); +#endif +} + +// Test basic creation of a P2PNotifier. +TEST_F(InvalidatorFactoryTest, Basic_P2P) { + notifier_options_.notification_method = notifier::NOTIFICATION_P2P; + InvalidatorFactory factory( + notifier_options_, + "test client info", + base::WeakPtr<InvalidationStateTracker>()); + scoped_ptr<Invalidator> invalidator(factory.CreateInvalidator()); +#if defined(OS_ANDROID) + ASSERT_FALSE(invalidator.get()); +#else + ASSERT_TRUE(invalidator.get()); + ObjectIdSet ids = ModelTypeSetToObjectIdSet(ModelTypeSet(syncer::BOOKMARKS)); + invalidator->RegisterHandler(&fake_handler_); + invalidator->UpdateRegisteredIds(&fake_handler_, ids); + invalidator->UnregisterHandler(&fake_handler_); +#endif +} + +} // namespace +} // namespace syncer diff --git a/sync/notifier/invalidator_registrar.cc b/sync/notifier/invalidator_registrar.cc index c2a18f9..75db11fc 100644 --- a/sync/notifier/invalidator_registrar.cc +++ b/sync/notifier/invalidator_registrar.cc @@ -119,8 +119,7 @@ void InvalidatorRegistrar::DispatchInvalidationsToHandlers( void InvalidatorRegistrar::UpdateInvalidatorState(InvalidatorState state) { DCHECK(thread_checker_.CalledOnValidThread()); - DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_) - << " -> " << InvalidatorStateToString(state); + DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_); state_ = state; FOR_EACH_OBSERVER(InvalidationHandler, handlers_, OnInvalidatorStateChange(state)); diff --git a/sync/notifier/invalidator_registrar_unittest.cc b/sync/notifier/invalidator_registrar_unittest.cc index ad22247..070c134 100644 --- a/sync/notifier/invalidator_registrar_unittest.cc +++ b/sync/notifier/invalidator_registrar_unittest.cc @@ -57,6 +57,11 @@ class RegistrarInvalidator : public Invalidator { // Do nothing. } + virtual void SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map) OVERRIDE { + // Do nothing. + } + private: InvalidatorRegistrar registrar_; diff --git a/sync/notifier/non_blocking_invalidator.cc b/sync/notifier/non_blocking_invalidator.cc index 2834f28..99b5532 100644 --- a/sync/notifier/non_blocking_invalidator.cc +++ b/sync/notifier/non_blocking_invalidator.cc @@ -227,6 +227,13 @@ void NonBlockingInvalidator::UpdateCredentials(const std::string& email, } } +void NonBlockingInvalidator::SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map) { + DCHECK(parent_task_runner_->BelongsToCurrentThread()); + // InvalidationNotifier doesn't implement SendInvalidation(), so no + // need to forward on the call. +} + void NonBlockingInvalidator::OnInvalidatorStateChange(InvalidatorState state) { DCHECK(parent_task_runner_->BelongsToCurrentThread()); registrar_.UpdateInvalidatorState(state); diff --git a/sync/notifier/non_blocking_invalidator.h b/sync/notifier/non_blocking_invalidator.h index f2685c7..9c366fe 100644 --- a/sync/notifier/non_blocking_invalidator.h +++ b/sync/notifier/non_blocking_invalidator.h @@ -57,6 +57,8 @@ class SYNC_EXPORT_PRIVATE NonBlockingInvalidator virtual InvalidatorState GetInvalidatorState() const OVERRIDE; virtual void UpdateCredentials( const std::string& email, const std::string& token) OVERRIDE; + virtual void SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; // InvalidationHandler implementation. virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; diff --git a/sync/notifier/p2p_invalidator.h b/sync/notifier/p2p_invalidator.h index 515b27b..a56521e 100644 --- a/sync/notifier/p2p_invalidator.h +++ b/sync/notifier/p2p_invalidator.h @@ -16,8 +16,6 @@ #include "base/memory/weak_ptr.h" #include "base/observer_list.h" #include "base/threading/thread_checker.h" -#include "jingle/notifier/base/notifier_options.h" -#include "jingle/notifier/listener/push_client.h" #include "jingle/notifier/listener/push_client_observer.h" #include "sync/base/sync_export.h" #include "sync/internal_api/public/base/model_type.h" @@ -110,6 +108,8 @@ class SYNC_EXPORT_PRIVATE P2PInvalidator virtual InvalidatorState GetInvalidatorState() const OVERRIDE; virtual void UpdateCredentials( const std::string& email, const std::string& token) OVERRIDE; + virtual void SendInvalidation( + const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; // PushClientObserver implementation. virtual void OnNotificationsEnabled() OVERRIDE; @@ -118,9 +118,6 @@ class SYNC_EXPORT_PRIVATE P2PInvalidator virtual void OnIncomingNotification( const notifier::Notification& notification) OVERRIDE; - void SendInvalidation( - const ObjectIdInvalidationMap& invalidation_map); - void SendNotificationDataForTest( const P2PNotificationData& notification_data); diff --git a/sync/sync_notifier.gypi b/sync/sync_notifier.gypi index ba40772..18ef4b9 100644 --- a/sync/sync_notifier.gypi +++ b/sync/sync_notifier.gypi @@ -28,6 +28,8 @@ 'notifier/invalidation_state_tracker.h', 'notifier/invalidation_util.cc', 'notifier/invalidation_util.h', + 'notifier/invalidator_factory.cc', + 'notifier/invalidator_factory.h', 'notifier/invalidator.h', 'notifier/invalidator_registrar.cc', 'notifier/invalidator_registrar.h', diff --git a/sync/sync_tests.gypi b/sync/sync_tests.gypi index 3dff470..7c56492 100644 --- a/sync/sync_tests.gypi +++ b/sync/sync_tests.gypi @@ -328,6 +328,9 @@ 'include_dirs': [ '..', ], + 'sources': [ + 'notifier/invalidator_factory_unittest.cc', + ], 'conditions': [ ['OS != "android"', { 'sources': [ diff --git a/sync/tools/sync_client.cc b/sync/tools/sync_client.cc index 21a46fd..6ce8bde 100644 --- a/sync/tools/sync_client.cc +++ b/sync/tools/sync_client.cc @@ -17,7 +17,6 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" #include "base/message_loop.h" -#include "base/rand_util.h" #include "base/task_runner.h" #include "base/threading/thread.h" #include "jingle/notifier/base/notification_method.h" @@ -41,7 +40,8 @@ #include "sync/js/js_event_details.h" #include "sync/js/js_event_handler.h" #include "sync/notifier/invalidation_state_tracker.h" -#include "sync/notifier/non_blocking_invalidator.h" +#include "sync/notifier/invalidator.h" +#include "sync/notifier/invalidator_factory.h" #include "sync/test/fake_encryptor.h" #include "sync/tools/null_invalidation_state_tracker.h" @@ -215,12 +215,13 @@ notifier::NotifierOptions ParseNotifierOptions( LOG_IF(INFO, notifier_options.allow_insecure_connection) << "Allowing insecure XMPP connections."; - return notifier_options; -} + if (command_line.HasSwitch(kNotificationMethodSwitch)) { + notifier_options.notification_method = + notifier::StringToNotificationMethod( + command_line.GetSwitchValueASCII(kNotificationMethodSwitch)); + } -void StubNetworkTimeUpdateCallback(const base::Time&, - const base::TimeDelta&, - const base::TimeDelta&) { + return notifier_options; } int SyncClientMain(int argc, char* argv[]) { @@ -249,6 +250,7 @@ int SyncClientMain(int argc, char* argv[]) { if (credentials.email.empty() || credentials.sync_token.empty()) { std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" "[--%s=host:port] [--%s] [--%s]\n" + "[--%s=(server|p2p)]\n\n" "Run chrome and set a breakpoint on\n" "syncer::SyncManagerImpl::UpdateCredentials() " "after logging into\n" @@ -256,7 +258,8 @@ int SyncClientMain(int argc, char* argv[]) { argv[0], kEmailSwitch, kTokenSwitch, kXmppHostPortSwitch, kXmppTrySslTcpFirstSwitch, - kXmppAllowInsecureConnectionSwitch); + kXmppAllowInsecureConnectionSwitch, + kNotificationMethodSwitch); return -1; } @@ -269,49 +272,18 @@ int SyncClientMain(int argc, char* argv[]) { new MyTestURLRequestContextGetter(io_thread.message_loop_proxy()); const notifier::NotifierOptions& notifier_options = ParseNotifierOptions(command_line, context_getter); - const char kClientInfo[] = "standalone_sync_client"; - std::string invalidator_id = base::RandBytesAsString(8); + const char kClientInfo[] = "sync_listen_notifications"; NullInvalidationStateTracker null_invalidation_state_tracker; - scoped_ptr<Invalidator> invalidator(new NonBlockingInvalidator( - notifier_options, - invalidator_id, - null_invalidation_state_tracker.GetAllInvalidationStates(), - null_invalidation_state_tracker.GetBootstrapData(), - WeakHandle<InvalidationStateTracker>( - null_invalidation_state_tracker.AsWeakPtr()), - kClientInfo)); + InvalidatorFactory invalidator_factory( + notifier_options, kClientInfo, + null_invalidation_state_tracker.AsWeakPtr()); // Set up database directory for the syncer. base::ScopedTempDir database_dir; CHECK(database_dir.CreateUniqueTempDir()); - // Developers often add types to ModelTypeSet::All() before the server - // supports them. We need to be explicit about which types we want here. - ModelTypeSet model_types; - model_types.Put(BOOKMARKS); - model_types.Put(PREFERENCES); - model_types.Put(PASSWORDS); - model_types.Put(AUTOFILL); - model_types.Put(THEMES); - model_types.Put(TYPED_URLS); - model_types.Put(EXTENSIONS); - model_types.Put(NIGORI); - model_types.Put(SEARCH_ENGINES); - model_types.Put(SESSIONS); - model_types.Put(APPS); - model_types.Put(AUTOFILL_PROFILE); - model_types.Put(APP_SETTINGS); - model_types.Put(EXTENSION_SETTINGS); - model_types.Put(APP_NOTIFICATIONS); - model_types.Put(HISTORY_DELETE_DIRECTIVES); - model_types.Put(SYNCED_NOTIFICATIONS); - model_types.Put(DEVICE_INFO); - model_types.Put(EXPERIMENTS); - model_types.Put(PRIORITY_PREFERENCES); - model_types.Put(DICTIONARY); - model_types.Put(FAVICON_IMAGES); - model_types.Put(FAVICON_TRACKING); - + // Set up model type parameters. + const ModelTypeSet model_types = ModelTypeSet::All(); ModelSafeRoutingInfo routing_info; for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { @@ -335,10 +307,8 @@ int SyncClientMain(int argc, char* argv[]) { const char kUserAgent[] = "sync_client"; // TODO(akalin): Replace this with just the context getter once // HttpPostProviderFactory is removed. - scoped_ptr<HttpPostProviderFactory> post_factory( - new HttpBridgeFactory(context_getter, - kUserAgent, - base::Bind(&StubNetworkTimeUpdateCallback))); + scoped_ptr<HttpPostProviderFactory> post_factory(new HttpBridgeFactory( + context_getter.get(), kUserAgent, NetworkTimeUpdateCallback())); // Used only when committing bookmarks, so it's okay to leave this // as NULL. ExtensionsActivityMonitor* extensions_activity_monitor = NULL; @@ -363,7 +333,9 @@ int SyncClientMain(int argc, char* argv[]) { extensions_activity_monitor, &change_delegate, credentials, - invalidator_id, + scoped_ptr<Invalidator>( + invalidator_factory.CreateInvalidator()), + invalidator_factory.GetInvalidatorClientId(), kRestoredKeyForBootstrapping, kRestoredKeystoreKeyForBootstrapping, scoped_ptr<InternalComponentsFactory>( @@ -373,10 +345,7 @@ int SyncClientMain(int argc, char* argv[]) { &LogUnrecoverableErrorContext, false); // TODO(akalin): Avoid passing in model parameters multiple times by // organizing handling of model types. - invalidator->UpdateCredentials(credentials.email, credentials.sync_token); - invalidator->RegisterHandler(sync_manager.get()); - invalidator->UpdateRegisteredIds( - sync_manager.get(), ModelTypeSetToObjectIdSet(model_types)); + sync_manager->UpdateEnabledTypes(model_types); sync_manager->StartSyncingNormally(routing_info); sync_loop.Run(); diff --git a/sync/tools/sync_listen_notifications.cc b/sync/tools/sync_listen_notifications.cc index 615d6bd..dc54886 100644 --- a/sync/tools/sync_listen_notifications.cc +++ b/sync/tools/sync_listen_notifications.cc @@ -13,7 +13,6 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "base/message_loop.h" -#include "base/rand_util.h" #include "base/threading/thread.h" #include "jingle/notifier/base/notification_method.h" #include "jingle/notifier/base/notifier_options.h" @@ -28,7 +27,7 @@ #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/invalidation_util.h" #include "sync/notifier/invalidator.h" -#include "sync/notifier/non_blocking_invalidator.h" +#include "sync/notifier/invalidator_factory.h" #include "sync/tools/null_invalidation_state_tracker.h" #if defined(OS_MACOSX) @@ -135,6 +134,12 @@ notifier::NotifierOptions ParseNotifierOptions( LOG_IF(INFO, notifier_options.allow_insecure_connection) << "Allowing insecure XMPP connections."; + if (command_line.HasSwitch(kNotificationMethodSwitch)) { + notifier_options.notification_method = + notifier::StringToNotificationMethod( + command_line.GetSwitchValueASCII(kNotificationMethodSwitch)); + } + return notifier_options; } @@ -164,13 +169,15 @@ int SyncListenNotificationsMain(int argc, char* argv[]) { if (email.empty() || token.empty()) { std::printf("Usage: %s --%s=foo@bar.com --%s=token\n" "[--%s=host:port] [--%s] [--%s]\n" + "[--%s=(server|p2p)]\n\n" "Run chrome and set a breakpoint on\n" "syncer::SyncManagerImpl::UpdateCredentials() " "after logging into\n" "sync to get the token to pass into this utility.\n", argv[0], kEmailSwitch, kTokenSwitch, kHostPortSwitch, - kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch); + kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch, + kNotificationMethodSwitch); return -1; } @@ -184,16 +191,11 @@ int SyncListenNotificationsMain(int argc, char* argv[]) { new MyTestURLRequestContextGetter(io_thread.message_loop_proxy())); const char kClientInfo[] = "sync_listen_notifications"; NullInvalidationStateTracker null_invalidation_state_tracker; + InvalidatorFactory invalidator_factory( + notifier_options, kClientInfo, + null_invalidation_state_tracker.AsWeakPtr()); scoped_ptr<Invalidator> invalidator( - new NonBlockingInvalidator( - notifier_options, - base::RandBytesAsString(8), - null_invalidation_state_tracker.GetAllInvalidationStates(), - null_invalidation_state_tracker.GetBootstrapData(), - WeakHandle<InvalidationStateTracker>( - null_invalidation_state_tracker.AsWeakPtr()), - kClientInfo)); - + invalidator_factory.CreateInvalidator()); NotificationPrinter notification_printer; invalidator->UpdateCredentials(email, token); diff --git a/sync/tools/testserver/xmppserver.py b/sync/tools/testserver/xmppserver.py index 3f7c7d05..0b32933 100644 --- a/sync/tools/testserver/xmppserver.py +++ b/sync/tools/testserver/xmppserver.py @@ -575,14 +575,6 @@ class XmppServer(asyncore.dispatcher): def SetAuthenticated(self, auth_valid): self._authenticated = auth_valid - # We check authentication only when establishing new connections. We close - # all existing connections here to make sure previously connected clients - # pick up on the change. It's a hack, but it works well enough for our - # purposes. - if not self._authenticated: - for connection in self._handshake_done_connections: - connection.close() - def GetAuthenticated(self): return self._authenticated |