diff options
author | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-29 01:45:09 +0000 |
---|---|---|
committer | rlarocque@chromium.org <rlarocque@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-29 01:45:09 +0000 |
commit | dbbec3a0133edaff11b16c6bc3fd73aac8ab4e31 (patch) | |
tree | 20b4a2df530ac7c83bcc5e7d460137e97846685e /sync | |
parent | c146a323f91c8376afe55c93c6a31df0075be62b (diff) | |
download | chromium_src-dbbec3a0133edaff11b16c6bc3fd73aac8ab4e31.zip chromium_src-dbbec3a0133edaff11b16c6bc3fd73aac8ab4e31.tar.gz chromium_src-dbbec3a0133edaff11b16c6bc3fd73aac8ab4e31.tar.bz2 |
Use InvalidationService (retry of r208315)
The InvalidationService was introduced r199520. That commit added the
InvalidationService interface and several implementations of it, but
made no use of the new code. This commit builds on that work.
Up until now, TICL invalidations were handled on the sync thread. The
related objects were instantiated and owned by the SyncBackendHost and
SyncManager. All requests to update the set of object registrations had
to be passed to the sync thread. Components that wanted to receive
invalidations but were not part of sync had to route their communication
with the invalidations server through ProfileSyncService to get to the
sync thread. Things were a bit different on Android, but the system
still tried to pretend that invalidations were owned by the sync thread.
The new InvalidationService implementation is a ProfileKeyedService that
is mostly independent from sync. It still relies on sync to manage sign
in and fetch the appropriate auth tokens. However, it's now much easier
for components outside of sync to communication with the invalidations
server.
The new system allows us to remove a lot of invalidations-related code
from the ProfileSyncService, SyncBackendHost and SyncManager. Sync is
now just one of many clients of the InvalidationService. The
SyncBackendHost is responsible for forwarding messages back and forth
between the InvalidationService and the sync thread.
TBR=dcheng,satorux1,battre,rsimha,bauerb,sky,erg
BUG=124137
Review URL: https://chromiumcodereview.appspot.com/17699005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@209264 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync')
24 files changed, 109 insertions, 594 deletions
diff --git a/sync/internal_api/public/sync_manager.h b/sync/internal_api/public/sync_manager.h index b3f03b0..bc6a137 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_util.h" +#include "sync/notifier/invalidation_handler.h" #include "sync/protocol/sync_protocol_error.h" namespace sync_pb { @@ -39,8 +39,6 @@ struct Experiments; class ExtensionsActivityMonitor; class HttpPostProviderFactory; class InternalComponentsFactory; -class InvalidationHandler; -class Invalidator; class JsBackend; class JsEventHandler; class SyncEncryptionHandler; @@ -75,7 +73,7 @@ struct SyncCredentials { // // Unless stated otherwise, all methods of SyncManager should be called on the // same thread. -class SYNC_EXPORT SyncManager { +class SYNC_EXPORT SyncManager : public syncer::InvalidationHandler { public: // An interface the embedding application implements to be notified // on change events. Note that these methods may be called on *any* @@ -315,7 +313,6 @@ class SYNC_EXPORT 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, @@ -344,27 +341,6 @@ class SYNC_EXPORT SyncManager { // 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; @@ -392,6 +368,13 @@ class SYNC_EXPORT SyncManager { 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 ba38ac6..ed69a52 100644 --- a/sync/internal_api/public/test/fake_sync_manager.h +++ b/sync/internal_api/public/test/fake_sync_manager.h @@ -62,10 +62,11 @@ class FakeSyncManager : public SyncManager { ConfigureReason GetAndResetConfigureReason(); // Posts a method to invalidate the given IDs on the sync thread. - void Invalidate(const ObjectIdInvalidationMap& invalidation_map); + virtual void OnIncomingInvalidation( + const ObjectIdInvalidationMap& invalidation_map) OVERRIDE; // Posts a method to update the invalidator state on the sync thread. - void UpdateInvalidatorState(InvalidatorState state); + virtual void OnInvalidatorStateChange(InvalidatorState state) OVERRIDE; // Block until the sync thread has finished processing any pending messages. void WaitForSyncThread(); @@ -84,7 +85,6 @@ 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,17 +100,6 @@ 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( @@ -136,10 +125,6 @@ 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 68f68f8..7b0e549 100644 --- a/sync/internal_api/sync_manager_impl.cc +++ b/sync/internal_api/sync_manager_impl.cc @@ -349,7 +349,6 @@ 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, @@ -369,9 +368,6 @@ void SyncManagerImpl::Init( change_delegate_ = change_delegate; - invalidator_ = invalidator.Pass(); - invalidator_->RegisterHandler(this); - AddObserver(&js_sync_manager_observer_); SetJsEventHandler(event_handler); @@ -609,49 +605,11 @@ 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); @@ -690,15 +648,10 @@ void SyncManagerImpl::ShutdownOnSyncThread() { RemoveObserver(&debug_info_event_listener_); - // |invalidator_| and |connection_manager_| may end up being NULL here in - // tests (in synchronous initialization mode). + // |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(); @@ -988,20 +941,6 @@ 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) { @@ -1224,6 +1163,8 @@ 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; @@ -1232,12 +1173,6 @@ 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); @@ -1252,15 +1187,6 @@ 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 c12eea7..153df81 100644 --- a/sync/internal_api/sync_manager_impl.h +++ b/sync/internal_api/sync_manager_impl.h @@ -51,7 +51,6 @@ class SYNC_EXPORT_PRIVATE SyncManagerImpl : public SyncManager, public net::NetworkChangeNotifier::IPAddressObserver, public net::NetworkChangeNotifier::ConnectionTypeObserver, - public InvalidationHandler, public JsBackend, public SyncEngineEventListener, public ServerConnectionEventListener, @@ -74,7 +73,6 @@ 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, @@ -90,17 +88,6 @@ 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( @@ -112,6 +99,9 @@ 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; @@ -177,11 +167,6 @@ 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; @@ -336,9 +321,6 @@ 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 a1ddd7f..2085ec3 100644 --- a/sync/internal_api/sync_manager_impl_unittest.cc +++ b/sync/internal_api/sync_manager_impl_unittest.cc @@ -46,7 +46,6 @@ #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" @@ -789,14 +788,12 @@ class SyncManagerTest : public testing::Test, }; SyncManagerTest() - : fake_invalidator_(NULL), - sync_manager_("Test sync manager") { + : sync_manager_("Test sync manager") { switches_.encryption_method = InternalComponentsFactory::ENCRYPTION_KEYSTORE; } virtual ~SyncManagerTest() { - EXPECT_FALSE(fake_invalidator_); } // Test implementation. @@ -807,8 +804,6 @@ 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_)); @@ -831,7 +826,6 @@ 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 @@ -851,17 +845,11 @@ 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(); } @@ -1027,7 +1015,6 @@ class SyncManagerTest : public testing::Test, protected: FakeEncryptor encryptor_; TestUnrecoverableErrorHandler handler_; - FakeInvalidator* fake_invalidator_; SyncManagerImpl sync_manager_; WeakHandle<JsBackend> js_backend_; StrictMock<SyncManagerObserverMock> manager_observer_; @@ -1035,29 +1022,6 @@ 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; @@ -1362,14 +1326,6 @@ 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))); @@ -1410,22 +1366,6 @@ 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 3a9beca..7a6d6a4 100644 --- a/sync/internal_api/test/fake_sync_manager.cc +++ b/sync/internal_api/test/fake_sync_manager.cc @@ -61,25 +61,6 @@ 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; @@ -103,7 +84,6 @@ 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, @@ -161,31 +141,6 @@ 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. @@ -201,7 +156,7 @@ void FakeSyncManager::ConfigureSyncer( const base::Closure& ready_task, const base::Closure& retry_task) { last_configure_reason_ = reason; - ModelTypeSet enabled_types = GetRoutingInfoTypes(new_routing_info); + enabled_types_ = GetRoutingInfoTypes(new_routing_info); ModelTypeSet success_types = to_download; success_types.RemoveAll(configure_fail_types_); @@ -291,20 +246,17 @@ void FakeSyncManager::RefreshTypes(ModelTypeSet types) { last_refresh_request_types_ = types; } -void FakeSyncManager::InvalidateOnSyncThread( - const ObjectIdInvalidationMap& invalidation_map) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - registrar_.DispatchInvalidationsToHandlers(invalidation_map); -} - -void FakeSyncManager::UpdateInvalidatorStateOnSyncThread( - InvalidatorState state) { - DCHECK(sync_task_runner_->RunsTasksOnCurrentThread()); - registrar_.UpdateInvalidatorState(state); +void FakeSyncManager::OnIncomingInvalidation( + const ObjectIdInvalidationMap& invalidation_map) { + // Do nothing. } ModelTypeSet FakeSyncManager::GetLastRefreshRequestTypes() { return last_refresh_request_types_; } +void FakeSyncManager::OnInvalidatorStateChange(InvalidatorState state) { + // Do nothing. +} + } // namespace syncer diff --git a/sync/notifier/fake_invalidator.cc b/sync/notifier/fake_invalidator.cc index 088d239..0b217f7 100644 --- a/sync/notifier/fake_invalidator.cc +++ b/sync/notifier/fake_invalidator.cc @@ -27,11 +27,6 @@ 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); } @@ -69,9 +64,4 @@ 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 87380d0..7913694 100644 --- a/sync/notifier/fake_invalidator.h +++ b/sync/notifier/fake_invalidator.h @@ -39,15 +39,12 @@ 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 d097560..e3c79a4 100644 --- a/sync/notifier/invalidation_notifier.cc +++ b/sync/notifier/invalidation_notifier.cc @@ -79,12 +79,6 @@ 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 269511f..b7a98f8 100644 --- a/sync/notifier/invalidation_notifier.h +++ b/sync/notifier/invalidation_notifier.h @@ -62,8 +62,6 @@ 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 a0f881e..ccb6922 100644 --- a/sync/notifier/invalidator.h +++ b/sync/notifier/invalidator.h @@ -83,13 +83,6 @@ 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 deleted file mode 100644 index f359ce8..0000000 --- a/sync/notifier/invalidator_factory.cc +++ /dev/null @@ -1,107 +0,0 @@ -// 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 deleted file mode 100644 index 782850e..0000000 --- a/sync/notifier/invalidator_factory.h +++ /dev/null @@ -1,55 +0,0 @@ -// 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 deleted file mode 100644 index 31b95fc..0000000 --- a/sync/notifier/invalidator_factory_unittest.cc +++ /dev/null @@ -1,85 +0,0 @@ -// 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 75db11fc..c2a18f9 100644 --- a/sync/notifier/invalidator_registrar.cc +++ b/sync/notifier/invalidator_registrar.cc @@ -119,7 +119,8 @@ void InvalidatorRegistrar::DispatchInvalidationsToHandlers( void InvalidatorRegistrar::UpdateInvalidatorState(InvalidatorState state) { DCHECK(thread_checker_.CalledOnValidThread()); - DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(state_); + DVLOG(1) << "New invalidator state: " << InvalidatorStateToString(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 070c134..ad22247 100644 --- a/sync/notifier/invalidator_registrar_unittest.cc +++ b/sync/notifier/invalidator_registrar_unittest.cc @@ -57,11 +57,6 @@ 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 99b5532..2834f28 100644 --- a/sync/notifier/non_blocking_invalidator.cc +++ b/sync/notifier/non_blocking_invalidator.cc @@ -227,13 +227,6 @@ 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 9c366fe..f2685c7 100644 --- a/sync/notifier/non_blocking_invalidator.h +++ b/sync/notifier/non_blocking_invalidator.h @@ -57,8 +57,6 @@ 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 a56521e..515b27b 100644 --- a/sync/notifier/p2p_invalidator.h +++ b/sync/notifier/p2p_invalidator.h @@ -16,6 +16,8 @@ #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" @@ -108,8 +110,6 @@ 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,6 +118,9 @@ 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 18ef4b9..ba40772 100644 --- a/sync/sync_notifier.gypi +++ b/sync/sync_notifier.gypi @@ -28,8 +28,6 @@ '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 e2f7c9e..3202b74 100644 --- a/sync/sync_tests.gypi +++ b/sync/sync_tests.gypi @@ -327,9 +327,6 @@ '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 6ce8bde..21a46fd 100644 --- a/sync/tools/sync_client.cc +++ b/sync/tools/sync_client.cc @@ -17,6 +17,7 @@ #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" @@ -40,8 +41,7 @@ #include "sync/js/js_event_details.h" #include "sync/js/js_event_handler.h" #include "sync/notifier/invalidation_state_tracker.h" -#include "sync/notifier/invalidator.h" -#include "sync/notifier/invalidator_factory.h" +#include "sync/notifier/non_blocking_invalidator.h" #include "sync/test/fake_encryptor.h" #include "sync/tools/null_invalidation_state_tracker.h" @@ -215,15 +215,14 @@ 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; } +void StubNetworkTimeUpdateCallback(const base::Time&, + const base::TimeDelta&, + const base::TimeDelta&) { +} + int SyncClientMain(int argc, char* argv[]) { #if defined(OS_MACOSX) base::mac::ScopedNSAutoreleasePool pool; @@ -250,7 +249,6 @@ 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" @@ -258,8 +256,7 @@ int SyncClientMain(int argc, char* argv[]) { argv[0], kEmailSwitch, kTokenSwitch, kXmppHostPortSwitch, kXmppTrySslTcpFirstSwitch, - kXmppAllowInsecureConnectionSwitch, - kNotificationMethodSwitch); + kXmppAllowInsecureConnectionSwitch); return -1; } @@ -272,18 +269,49 @@ 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[] = "sync_listen_notifications"; + const char kClientInfo[] = "standalone_sync_client"; + std::string invalidator_id = base::RandBytesAsString(8); NullInvalidationStateTracker null_invalidation_state_tracker; - InvalidatorFactory invalidator_factory( - notifier_options, kClientInfo, - null_invalidation_state_tracker.AsWeakPtr()); + 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)); // Set up database directory for the syncer. base::ScopedTempDir database_dir; CHECK(database_dir.CreateUniqueTempDir()); - // Set up model type parameters. - const ModelTypeSet model_types = ModelTypeSet::All(); + // 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); + ModelSafeRoutingInfo routing_info; for (ModelTypeSet::Iterator it = model_types.First(); it.Good(); it.Inc()) { @@ -307,8 +335,10 @@ 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.get(), kUserAgent, NetworkTimeUpdateCallback())); + scoped_ptr<HttpPostProviderFactory> post_factory( + new HttpBridgeFactory(context_getter, + kUserAgent, + base::Bind(&StubNetworkTimeUpdateCallback))); // Used only when committing bookmarks, so it's okay to leave this // as NULL. ExtensionsActivityMonitor* extensions_activity_monitor = NULL; @@ -333,9 +363,7 @@ int SyncClientMain(int argc, char* argv[]) { extensions_activity_monitor, &change_delegate, credentials, - scoped_ptr<Invalidator>( - invalidator_factory.CreateInvalidator()), - invalidator_factory.GetInvalidatorClientId(), + invalidator_id, kRestoredKeyForBootstrapping, kRestoredKeystoreKeyForBootstrapping, scoped_ptr<InternalComponentsFactory>( @@ -345,7 +373,10 @@ int SyncClientMain(int argc, char* argv[]) { &LogUnrecoverableErrorContext, false); // TODO(akalin): Avoid passing in model parameters multiple times by // organizing handling of model types. - sync_manager->UpdateEnabledTypes(model_types); + invalidator->UpdateCredentials(credentials.email, credentials.sync_token); + invalidator->RegisterHandler(sync_manager.get()); + invalidator->UpdateRegisteredIds( + sync_manager.get(), ModelTypeSetToObjectIdSet(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 dc54886..615d6bd 100644 --- a/sync/tools/sync_listen_notifications.cc +++ b/sync/tools/sync_listen_notifications.cc @@ -13,6 +13,7 @@ #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" @@ -27,7 +28,7 @@ #include "sync/notifier/invalidation_state_tracker.h" #include "sync/notifier/invalidation_util.h" #include "sync/notifier/invalidator.h" -#include "sync/notifier/invalidator_factory.h" +#include "sync/notifier/non_blocking_invalidator.h" #include "sync/tools/null_invalidation_state_tracker.h" #if defined(OS_MACOSX) @@ -134,12 +135,6 @@ 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; } @@ -169,15 +164,13 @@ 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, - kNotificationMethodSwitch); + kTrySslTcpFirstSwitch, kAllowInsecureConnectionSwitch); return -1; } @@ -191,11 +184,16 @@ 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( - invalidator_factory.CreateInvalidator()); + 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)); + NotificationPrinter notification_printer; invalidator->UpdateCredentials(email, token); diff --git a/sync/tools/testserver/xmppserver.py b/sync/tools/testserver/xmppserver.py index 0b32933..3f7c7d05 100644 --- a/sync/tools/testserver/xmppserver.py +++ b/sync/tools/testserver/xmppserver.py @@ -575,6 +575,14 @@ 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 |