Chromium Code Reviews| Index: chrome/browser/sync/glue/sync_backend_host.cc |
| diff --git a/chrome/browser/sync/glue/sync_backend_host.cc b/chrome/browser/sync/glue/sync_backend_host.cc |
| index 88208764d49f15f18ec1a5464a58cc8f88623aa4..e78a103ca8c84932945b771eb0d7809e9d4b8e95 100644 |
| --- a/chrome/browser/sync/glue/sync_backend_host.cc |
| +++ b/chrome/browser/sync/glue/sync_backend_host.cc |
| @@ -2,8 +2,6 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "build/build_config.h" |
| - |
| #include "chrome/browser/sync/glue/sync_backend_host.h" |
| #include <algorithm> |
| @@ -21,13 +19,12 @@ |
| #include "base/tracked_objects.h" |
| #include "base/utf_string_conversions.h" |
| #include "build/build_config.h" |
| -#include "chrome/browser/invalidation/invalidator_storage.h" |
| +#include "chrome/browser/invalidation/invalidation_service.h" |
| +#include "chrome/browser/invalidation/invalidation_service_factory.h" |
| #include "chrome/browser/net/network_time_tracker.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/signin/token_service.h" |
| #include "chrome/browser/signin/token_service_factory.h" |
| -#include "chrome/browser/sync/glue/android_invalidator_bridge.h" |
| -#include "chrome/browser/sync/glue/android_invalidator_bridge_proxy.h" |
| #include "chrome/browser/sync/glue/change_processor.h" |
| #include "chrome/browser/sync/glue/chrome_encryptor.h" |
| #include "chrome/browser/sync/glue/device_info.h" |
| @@ -56,7 +53,6 @@ |
| #include "sync/internal_api/public/sync_manager_factory.h" |
| #include "sync/internal_api/public/util/experiments.h" |
| #include "sync/internal_api/public/util/sync_string_conversions.h" |
| -#include "sync/notifier/invalidator.h" |
| #include "sync/protocol/encryption.pb.h" |
| #include "sync/protocol/sync.pb.h" |
| #include "sync/util/nigori.h" |
| @@ -87,8 +83,7 @@ using syncer::SyncCredentials; |
| class SyncBackendHost::Core |
| : public base::RefCountedThreadSafe<SyncBackendHost::Core>, |
| public syncer::SyncEncryptionHandler::Observer, |
| - public syncer::SyncManager::Observer, |
| - public syncer::InvalidationHandler { |
| + public syncer::SyncManager::Observer { |
| public: |
| Core(const std::string& name, |
| const base::FilePath& sync_data_folder_path, |
| @@ -129,11 +124,12 @@ class SyncBackendHost::Core |
| virtual void OnPassphraseTypeChanged(syncer::PassphraseType type, |
| base::Time passphrase_time) OVERRIDE; |
| - // syncer::InvalidationHandler implementation. |
| - virtual void OnInvalidatorStateChange( |
| - syncer::InvalidatorState state) OVERRIDE; |
| - virtual void OnIncomingInvalidation( |
| - const syncer::ObjectIdInvalidationMap& invalidation_map) OVERRIDE; |
| + // Forwards an invalidation state change to the sync manager. |
| + void DoOnInvalidatorStateChange(syncer::InvalidatorState state); |
| + |
| + // Forwards an invalidation to the sync manager. |
| + void DoOnIncomingInvalidation( |
| + syncer::ObjectIdInvalidationMap invalidation_map); |
| // Note: |
| // |
| @@ -150,15 +146,6 @@ class SyncBackendHost::Core |
| // SyncBackendHost::UpdateCredentials. |
| void DoUpdateCredentials(const syncer::SyncCredentials& credentials); |
| - // Called to update the given registered ids on behalf of |
| - // SyncBackendHost::UpdateRegisteredInvalidationIds. |
| - void DoUpdateRegisteredInvalidationIds(const syncer::ObjectIdSet& ids); |
| - |
| - // Called to acknowledge an invalidation on behalf of |
| - // SyncBackendHost::AcknowledgeInvalidation. |
| - void DoAcknowledgeInvalidation(const invalidation::ObjectId& id, |
| - const syncer::AckHandle& ack_handle); |
| - |
| // Called to tell the syncapi to start syncing (generally after |
| // initialization and authentication). |
| void DoStartSyncing(const syncer::ModelSafeRoutingInfo& routing_info); |
| @@ -290,67 +277,13 @@ class SyncBackendHost::Core |
| // The top-level syncapi entry point. Lives on the sync thread. |
| scoped_ptr<syncer::SyncManager> sync_manager_; |
| - // Whether or not we registered with |sync_manager_| as an invalidation |
| - // handler. Necessary since we may end up trying to unregister before we |
| - // register in tests (in synchronous initialization mode). |
| - // |
| - // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
| - bool registered_as_invalidation_handler_; |
| - |
| DISALLOW_COPY_AND_ASSIGN(Core); |
| }; |
| -namespace { |
| - |
| -// Parses the given command line for notifier options. |
| -notifier::NotifierOptions ParseNotifierOptions( |
| - const CommandLine& command_line, |
| - const scoped_refptr<net::URLRequestContextGetter>& |
| - request_context_getter) { |
| - notifier::NotifierOptions notifier_options; |
| - notifier_options.request_context_getter = request_context_getter; |
| - |
| - if (command_line.HasSwitch(switches::kSyncNotificationHostPort)) { |
| - notifier_options.xmpp_host_port = |
| - net::HostPortPair::FromString( |
| - command_line.GetSwitchValueASCII( |
| - switches::kSyncNotificationHostPort)); |
| - DVLOG(1) << "Using " << notifier_options.xmpp_host_port.ToString() |
| - << " for test sync notification server."; |
| - } |
| - |
| - notifier_options.try_ssltcp_first = |
| - command_line.HasSwitch(switches::kSyncTrySsltcpFirstForXmpp); |
| - DVLOG_IF(1, notifier_options.try_ssltcp_first) |
| - << "Trying SSL/TCP port before XMPP port for notifications."; |
| - |
| - notifier_options.invalidate_xmpp_login = |
| - command_line.HasSwitch(switches::kSyncInvalidateXmppLogin); |
| - DVLOG_IF(1, notifier_options.invalidate_xmpp_login) |
| - << "Invalidating sync XMPP login."; |
| - |
| - notifier_options.allow_insecure_connection = |
| - command_line.HasSwitch(switches::kSyncAllowInsecureXmppConnection); |
| - DVLOG_IF(1, notifier_options.allow_insecure_connection) |
| - << "Allowing insecure XMPP connections."; |
| - |
| - if (command_line.HasSwitch(switches::kSyncNotificationMethod)) { |
| - const std::string notification_method_str( |
| - command_line.GetSwitchValueASCII(switches::kSyncNotificationMethod)); |
| - notifier_options.notification_method = |
| - notifier::StringToNotificationMethod(notification_method_str); |
| - } |
| - |
| - return notifier_options; |
| -} |
| - |
| -} // namespace |
| - |
| SyncBackendHost::SyncBackendHost( |
| const std::string& name, |
| Profile* profile, |
| - const base::WeakPtr<SyncPrefs>& sync_prefs, |
| - const base::WeakPtr<invalidation::InvalidatorStorage>& invalidator_storage) |
| + const base::WeakPtr<SyncPrefs>& sync_prefs) |
| : weak_ptr_factory_(this), |
| sync_thread_("Chrome_SyncThread"), |
| frontend_loop_(MessageLoop::current()), |
| @@ -360,13 +293,10 @@ SyncBackendHost::SyncBackendHost( |
| weak_ptr_factory_.GetWeakPtr())), |
| initialization_state_(NOT_ATTEMPTED), |
| sync_prefs_(sync_prefs), |
| - invalidator_factory_( |
| - ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
| - profile_->GetRequestContext()), |
| - content::GetUserAgent(GURL()), |
| - invalidator_storage), |
| frontend_(NULL), |
| - cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { |
| + cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE), |
| + invalidator_( |
| + invalidation::InvalidationServiceFactory::GetForProfile(profile)) { |
| } |
| SyncBackendHost::SyncBackendHost(Profile* profile) |
| @@ -376,18 +306,12 @@ SyncBackendHost::SyncBackendHost(Profile* profile) |
| profile_(profile), |
| name_("Unknown"), |
| initialization_state_(NOT_ATTEMPTED), |
| - invalidator_factory_( |
| - ParseNotifierOptions(*CommandLine::ForCurrentProcess(), |
| - profile_->GetRequestContext()), |
| - content::GetUserAgent(GURL()), |
| - base::WeakPtr<syncer::InvalidationStateTracker>()), |
| frontend_(NULL), |
| cached_passphrase_type_(syncer::IMPLICIT_PASSPHRASE) { |
| } |
| SyncBackendHost::~SyncBackendHost() { |
| DCHECK(!core_ && !frontend_) << "Must call Shutdown before destructor."; |
| - DCHECK(!android_invalidator_bridge_.get()); |
| DCHECK(!registrar_.get()); |
| } |
| @@ -419,10 +343,6 @@ void SyncBackendHost::Initialize( |
| if (!sync_thread_.Start()) |
| return; |
| - android_invalidator_bridge_.reset( |
| - new AndroidInvalidatorBridge( |
| - profile_, sync_thread_.message_loop_proxy())); |
| - |
| frontend_ = frontend; |
| DCHECK(frontend); |
| @@ -445,6 +365,8 @@ void SyncBackendHost::Initialize( |
| InternalComponentsFactoryImpl::BACKOFF_SHORT_INITIAL_RETRY_OVERRIDE; |
| } |
| + invalidator_->RegisterInvalidationHandler(this); |
| + |
| initialization_state_ = CREATING_SYNC_MANAGER; |
| InitCore(DoInitializeOptions( |
| sync_thread_.message_loop(), |
| @@ -458,8 +380,7 @@ void SyncBackendHost::Initialize( |
| make_scoped_refptr(profile_->GetRequestContext()), |
| NetworkTimeTracker::BuildNotifierUpdateCallback()), |
| credentials, |
| - android_invalidator_bridge_.get(), |
| - &invalidator_factory_, |
| + invalidator_->GetInvalidatorClientId(), |
| sync_manager_factory, |
| delete_sync_data_folder, |
| sync_prefs_->GetEncryptionBootstrapToken(), |
| @@ -476,24 +397,6 @@ void SyncBackendHost::UpdateCredentials(const SyncCredentials& credentials) { |
| credentials)); |
| } |
| -void SyncBackendHost::UpdateRegisteredInvalidationIds( |
| - const syncer::ObjectIdSet& ids) { |
| - DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| - DCHECK(sync_thread_.IsRunning()); |
| - sync_thread_.message_loop()->PostTask(FROM_HERE, |
| - base::Bind(&SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds, |
| - core_.get(), ids)); |
| -} |
| - |
| -void SyncBackendHost::AcknowledgeInvalidation( |
| - const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { |
| - DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| - DCHECK(sync_thread_.IsRunning()); |
| - sync_thread_.message_loop()->PostTask(FROM_HERE, |
| - base::Bind(&SyncBackendHost::Core::DoAcknowledgeInvalidation, |
| - core_.get(), id, ack_handle)); |
| -} |
| - |
| void SyncBackendHost::StartSyncingWithServer() { |
| SDVLOG(1) << "SyncBackendHost::StartSyncingWithServer called."; |
| @@ -637,14 +540,17 @@ void SyncBackendHost::Shutdown(bool sync_disabled) { |
| // StopSyncingForShutdown() (which nulls out |frontend_|) should be |
| // called first. |
| DCHECK(!frontend_); |
| + |
| + if (sync_disabled) |
| + invalidator_->UpdateRegisteredInvalidationIds(this, syncer::ObjectIdSet()); |
| + invalidator_->UnregisterInvalidationHandler(this); |
| + invalidator_ = NULL; |
| + |
| // TODO(tim): DCHECK(registrar_->StoppedOnUIThread()) would be nice. |
| if (sync_thread_.IsRunning()) { |
| sync_thread_.message_loop()->PostTask(FROM_HERE, |
| base::Bind(&SyncBackendHost::Core::DoShutdown, core_.get(), |
| sync_disabled)); |
| - |
| - if (android_invalidator_bridge_) |
| - android_invalidator_bridge_->StopForShutdown(); |
| } |
| // Stop will return once the thread exits, which will be after DoShutdown |
| @@ -670,7 +576,6 @@ void SyncBackendHost::Shutdown(bool sync_disabled) { |
| registrar_.reset(); |
| js_backend_.Reset(); |
| - android_invalidator_bridge_.reset(); |
| core_ = NULL; // Releases reference to core_. |
| } |
| @@ -842,13 +747,18 @@ void SyncBackendHost::RequestConfigureSyncer( |
| } |
| void SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop( |
| + const syncer::ModelTypeSet enabled_types, |
| const syncer::ModelTypeSet succeeded_configuration_types, |
| const syncer::ModelTypeSet failed_configuration_types, |
| const base::Callback<void(syncer::ModelTypeSet, |
| syncer::ModelTypeSet)>& ready_task) { |
| if (!frontend_) |
| return; |
| - DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| + |
| + invalidator_->UpdateRegisteredInvalidationIds( |
| + this, |
| + ModelTypeSetToObjectIdSet(enabled_types)); |
| + |
| if (!ready_task.is_null()) |
| ready_task.Run(succeeded_configuration_types, failed_configuration_types); |
| } |
| @@ -879,6 +789,10 @@ void SyncBackendHost::HandleSyncManagerInitializationOnFrontendLoop( |
| syncer::CONFIGURE_REASON_NEWLY_ENABLED_DATA_TYPE : |
| syncer::CONFIGURE_REASON_NEW_CLIENT); |
| + // Fake a state change to initialize the SyncManager's cached invalidator |
| + // state. |
| + OnInvalidatorStateChange(invalidator_->GetInvalidatorState()); |
| + |
| // Kick off the next step in SyncBackendHost initialization by downloading |
| // any necessary control types. |
| sync_thread_.message_loop()->PostTask( |
| @@ -915,8 +829,7 @@ SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
| const GURL& service_url, |
| MakeHttpBridgeFactoryFn make_http_bridge_factory_fn, |
| const syncer::SyncCredentials& credentials, |
| - AndroidInvalidatorBridge* android_invalidator_bridge, |
| - syncer::InvalidatorFactory* invalidator_factory, |
| + const std::string& invalidator_client_id, |
| syncer::SyncManagerFactory* sync_manager_factory, |
| bool delete_sync_data_folder, |
| const std::string& restored_key_for_bootstrapping, |
| @@ -934,8 +847,7 @@ SyncBackendHost::DoInitializeOptions::DoInitializeOptions( |
| service_url(service_url), |
| make_http_bridge_factory_fn(make_http_bridge_factory_fn), |
| credentials(credentials), |
| - android_invalidator_bridge(android_invalidator_bridge), |
| - invalidator_factory(invalidator_factory), |
| + invalidator_client_id(invalidator_client_id), |
| sync_manager_factory(sync_manager_factory), |
| delete_sync_data_folder(delete_sync_data_folder), |
| restored_key_for_bootstrapping(restored_key_for_bootstrapping), |
| @@ -956,8 +868,7 @@ SyncBackendHost::Core::Core(const std::string& name, |
| sync_data_folder_path_(sync_data_folder_path), |
| host_(backend), |
| sync_loop_(NULL), |
| - registrar_(NULL), |
| - registered_as_invalidation_handler_(false) { |
| + registrar_(NULL) { |
| DCHECK(backend.get()); |
| } |
| @@ -1150,24 +1061,16 @@ void SyncBackendHost::Core::OnActionableError( |
| sync_error); |
| } |
| -void SyncBackendHost::Core::OnInvalidatorStateChange( |
| +void SyncBackendHost::Core::DoOnInvalidatorStateChange( |
| syncer::InvalidatorState state) { |
| - if (!sync_loop_) |
| - return; |
| DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| - host_.Call(FROM_HERE, |
| - &SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop, |
| - state); |
| + sync_manager_->OnInvalidatorStateChange(state); |
| } |
| -void SyncBackendHost::Core::OnIncomingInvalidation( |
| - const syncer::ObjectIdInvalidationMap& invalidation_map) { |
| - if (!sync_loop_) |
| - return; |
| +void SyncBackendHost::Core::DoOnIncomingInvalidation( |
| + syncer::ObjectIdInvalidationMap invalidation_map) { |
| DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| - host_.Call(FROM_HERE, |
| - &SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop, |
| - invalidation_map); |
| + sync_manager_->OnIncomingInvalidation(invalidation_map); |
| } |
| void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { |
| @@ -1204,15 +1107,7 @@ void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { |
| options.extensions_activity_monitor, |
| options.registrar /* as SyncManager::ChangeDelegate */, |
| options.credentials, |
| -#if defined(OS_ANDROID) |
| - scoped_ptr<syncer::Invalidator>( |
| - new AndroidInvalidatorBridgeProxy( |
| - options.android_invalidator_bridge)), |
| -#else |
| - scoped_ptr<syncer::Invalidator>( |
| - options.invalidator_factory->CreateInvalidator()), |
| -#endif |
| - options.invalidator_factory->GetInvalidatorClientId(), |
| + options.invalidator_client_id, |
| options.restored_key_for_bootstrapping, |
| options.restored_keystore_key_for_bootstrapping, |
| scoped_ptr<InternalComponentsFactory>( |
| @@ -1226,9 +1121,6 @@ void SyncBackendHost::Core::DoInitialize(const DoInitializeOptions& options) { |
| // |
| // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
| if (sync_manager_) { |
| - sync_manager_->RegisterInvalidationHandler(this); |
| - registered_as_invalidation_handler_ = true; |
| - |
| // Now check the command line to see if we need to simulate an |
| // unrecoverable error for testing purpose. Note the error is thrown |
| // only if the initialization succeeded. Also it makes sense to use this |
| @@ -1254,31 +1146,6 @@ void SyncBackendHost::Core::DoUpdateCredentials( |
| } |
| } |
| -void SyncBackendHost::Core::DoUpdateRegisteredInvalidationIds( |
| - const syncer::ObjectIdSet& ids) { |
| - DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| - // |sync_manager_| may end up being NULL here in tests (in |
| - // synchronous initialization mode) since this is called during |
| - // shutdown. |
| - // |
| - // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
| - if (sync_manager_) { |
| - sync_manager_->UpdateRegisteredInvalidationIds(this, ids); |
| - } |
| -} |
| - |
| -void SyncBackendHost::Core::DoAcknowledgeInvalidation( |
| - const invalidation::ObjectId& id, const syncer::AckHandle& ack_handle) { |
| - DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| - // |sync_manager_| may end up being NULL here in tests (in |
| - // synchronous initialization mode). |
| - // |
| - // TODO(akalin): Fix this behavior (see http://crbug.com/140354). |
| - if (sync_manager_) { |
| - sync_manager_->AcknowledgeInvalidation(id, ack_handle); |
| - } |
| -} |
| - |
| void SyncBackendHost::Core::DoStartSyncing( |
| const syncer::ModelSafeRoutingInfo& routing_info) { |
| DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| @@ -1388,10 +1255,6 @@ void SyncBackendHost::Core::DoDestroySyncManager() { |
| DCHECK_EQ(MessageLoop::current(), sync_loop_); |
| if (sync_manager_) { |
| save_changes_timer_.reset(); |
| - if (registered_as_invalidation_handler_) { |
| - sync_manager_->UnregisterInvalidationHandler(this); |
| - registered_as_invalidation_handler_ = false; |
| - } |
| sync_manager_->RemoveObserver(this); |
| sync_manager_->ShutdownOnSyncThread(); |
| sync_manager_.reset(); |
| @@ -1432,7 +1295,6 @@ void SyncBackendHost::Core::DoFinishConfigureDataTypes( |
| registrar_->GetModelSafeRoutingInfo(&routing_info); |
| syncer::ModelTypeSet enabled_types = GetRoutingInfoTypes(routing_info); |
| enabled_types.RemoveAll(syncer::ProxyTypes()); |
| - sync_manager_->UpdateEnabledTypes(enabled_types); |
| const syncer::ModelTypeSet failed_configuration_types = |
| Difference(types_to_config, sync_manager_->InitialSyncEndedTypes()); |
| @@ -1440,7 +1302,9 @@ void SyncBackendHost::Core::DoFinishConfigureDataTypes( |
| Difference(types_to_config, failed_configuration_types); |
| host_.Call(FROM_HERE, |
| &SyncBackendHost::FinishConfigureDataTypesOnFrontendLoop, |
| - succeeded_configuration_types, failed_configuration_types, |
| + enabled_types, |
| + succeeded_configuration_types, |
| + failed_configuration_types, |
| ready_task); |
| } |
| @@ -1570,20 +1434,30 @@ void SyncBackendHost::HandleActionableErrorEventOnFrontendLoop( |
| frontend_->OnActionableError(sync_error); |
| } |
| -void SyncBackendHost::HandleInvalidatorStateChangeOnFrontendLoop( |
| - syncer::InvalidatorState state) { |
| - if (!frontend_) |
| - return; |
| - DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| - frontend_->OnInvalidatorStateChange(state); |
| +void SyncBackendHost::OnInvalidatorStateChange(syncer::InvalidatorState state) { |
| + sync_thread_.message_loop()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&SyncBackendHost::Core::DoOnInvalidatorStateChange, |
| + core_.get(), |
| + state)); |
| } |
| -void SyncBackendHost::HandleIncomingInvalidationOnFrontendLoop( |
| +void SyncBackendHost::OnIncomingInvalidation( |
| const syncer::ObjectIdInvalidationMap& invalidation_map) { |
| - if (!frontend_) |
| - return; |
| - DCHECK_EQ(MessageLoop::current(), frontend_loop_); |
| - frontend_->OnIncomingInvalidation(invalidation_map); |
| + // TODO(dcheng): Acknowledge immediately for now. Fix this once the |
|
akalin
2013/05/24 22:58:46
ah, here it is.
|
| + // 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 (syncer::ObjectIdInvalidationMap::const_iterator it = |
| + invalidation_map.begin(); it != invalidation_map.end(); ++it) { |
| + invalidator_->AcknowledgeInvalidation(it->first, it->second.ack_handle); |
| + } |
| + |
| + sync_thread_.message_loop()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&SyncBackendHost::Core::DoOnIncomingInvalidation, |
| + core_.get(), |
| + invalidation_map)); |
| } |
| bool SyncBackendHost::CheckPassphraseAgainstCachedPendingKeys( |