| Index: chrome/browser/sync/profile_sync_service.cc
|
| ===================================================================
|
| --- chrome/browser/sync/profile_sync_service.cc (revision 208727)
|
| +++ chrome/browser/sync/profile_sync_service.cc (working copy)
|
| @@ -66,7 +66,6 @@
|
| #include "google_apis/gaia/gaia_constants.h"
|
| #include "grit/generated_resources.h"
|
| #include "net/cookies/cookie_monster.h"
|
| -#include "net/url_request/url_request_context_getter.h"
|
| #include "sync/api/sync_error.h"
|
| #include "sync/internal_api/public/configure_reason.h"
|
| #include "sync/internal_api/public/sync_encryption_handler.h"
|
| @@ -74,6 +73,8 @@
|
| #include "sync/internal_api/public/util/sync_string_conversions.h"
|
| #include "sync/js/js_arg_list.h"
|
| #include "sync/js/js_event_details.h"
|
| +#include "sync/notifier/invalidator_registrar.h"
|
| +#include "sync/notifier/invalidator_state.h"
|
| #include "sync/util/cryptographer.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
|
|
| @@ -113,6 +114,8 @@
|
|
|
| static const char* kOAuth2Scopes[] = {
|
| GaiaConstants::kChromeSyncOAuth2Scope,
|
| + // GoogleTalk scope is needed for notifications.
|
| + GaiaConstants::kGoogleTalkOAuth2Scope
|
| };
|
|
|
| static const char* kManagedOAuth2Scopes[] = {
|
| @@ -167,6 +170,7 @@
|
| profile_(profile),
|
| // |profile| may be NULL in unit tests.
|
| sync_prefs_(profile_ ? profile_->GetPrefs() : NULL),
|
| + invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL),
|
| sync_service_url_(kDevServerUrl),
|
| data_type_requested_sync_startup_(false),
|
| is_first_time_sync_configure_(false),
|
| @@ -183,6 +187,7 @@
|
| auto_start_enabled_(start_behavior == AUTO_START),
|
| configure_status_(DataTypeManager::UNKNOWN),
|
| setup_in_progress_(false),
|
| + invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR),
|
| request_access_token_backoff_(&kRequestAccessTokenBackoffPolicy) {
|
| // By default, dev, canary, and unbranded Chromium users will go to the
|
| // development servers. Development servers have more features than standard
|
| @@ -235,6 +240,9 @@
|
| }
|
|
|
| void ProfileSyncService::Initialize() {
|
| + DCHECK(!invalidator_registrar_.get());
|
| + invalidator_registrar_.reset(new syncer::InvalidatorRegistrar());
|
| +
|
| InitSettings();
|
|
|
| // We clear this here (vs Shutdown) because we want to remember that an error
|
| @@ -499,7 +507,8 @@
|
| void ProfileSyncService::CreateBackend() {
|
| backend_.reset(
|
| new SyncBackendHost(profile_->GetDebugName(),
|
| - profile_, sync_prefs_.AsWeakPtr()));
|
| + profile_, sync_prefs_.AsWeakPtr(),
|
| + invalidator_storage_.AsWeakPtr()));
|
| }
|
|
|
| bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
|
| @@ -625,8 +634,62 @@
|
| // we'll want to start from a fresh SyncDB, so delete any old one that might
|
| // be there.
|
| InitializeBackend(!HasSyncSetupCompleted());
|
| +
|
| + // |backend_| may end up being NULL here in tests (in synchronous
|
| + // initialization mode).
|
| + //
|
| + // TODO(akalin): Fix this horribly non-intuitive behavior (see
|
| + // http://crbug.com/140354).
|
| + if (backend_) {
|
| + backend_->UpdateRegisteredInvalidationIds(
|
| + invalidator_registrar_->GetAllRegisteredIds());
|
| + for (AckHandleReplayQueue::const_iterator it = ack_replay_queue_.begin();
|
| + it != ack_replay_queue_.end(); ++it) {
|
| + backend_->AcknowledgeInvalidation(it->first, it->second);
|
| + }
|
| + ack_replay_queue_.clear();
|
| + }
|
| }
|
|
|
| +void ProfileSyncService::RegisterInvalidationHandler(
|
| + syncer::InvalidationHandler* handler) {
|
| + invalidator_registrar_->RegisterHandler(handler);
|
| +}
|
| +
|
| +void ProfileSyncService::UpdateRegisteredInvalidationIds(
|
| + syncer::InvalidationHandler* handler,
|
| + const syncer::ObjectIdSet& ids) {
|
| + invalidator_registrar_->UpdateRegisteredIds(handler, ids);
|
| +
|
| + // If |backend_| is NULL, its registered IDs will be updated when
|
| + // it's created and initialized.
|
| + if (backend_) {
|
| + backend_->UpdateRegisteredInvalidationIds(
|
| + invalidator_registrar_->GetAllRegisteredIds());
|
| + }
|
| +}
|
| +
|
| +void ProfileSyncService::UnregisterInvalidationHandler(
|
| + syncer::InvalidationHandler* handler) {
|
| + invalidator_registrar_->UnregisterHandler(handler);
|
| +}
|
| +
|
| +void ProfileSyncService::AcknowledgeInvalidation(
|
| + const invalidation::ObjectId& id,
|
| + const syncer::AckHandle& ack_handle) {
|
| + if (backend_) {
|
| + backend_->AcknowledgeInvalidation(id, ack_handle);
|
| + } else {
|
| + // If |backend_| is NULL, save the acknowledgements to replay when
|
| + // it's created and initialized.
|
| + ack_replay_queue_.push_back(std::make_pair(id, ack_handle));
|
| + }
|
| +}
|
| +
|
| +syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const {
|
| + return invalidator_registrar_->GetInvalidatorState();
|
| +}
|
| +
|
| void ProfileSyncService::OnGetTokenSuccess(
|
| const OAuth2TokenService::Request* request,
|
| const std::string& access_token,
|
| @@ -688,7 +751,23 @@
|
| }
|
| }
|
|
|
| +void ProfileSyncService::EmitInvalidationForTest(
|
| + const invalidation::ObjectId& id,
|
| + const std::string& payload) {
|
| + syncer::ObjectIdSet notify_ids;
|
| + notify_ids.insert(id);
|
| +
|
| + const syncer::ObjectIdInvalidationMap& invalidation_map =
|
| + ObjectIdSetToInvalidationMap(notify_ids, payload);
|
| + OnIncomingInvalidation(invalidation_map);
|
| +}
|
| +
|
| void ProfileSyncService::Shutdown() {
|
| + DCHECK(invalidator_registrar_.get());
|
| + // Reset |invalidator_registrar_| first so that ShutdownImpl cannot
|
| + // use it.
|
| + invalidator_registrar_.reset();
|
| +
|
| if (signin_)
|
| signin_->signin_global_error()->RemoveProvider(this);
|
|
|
| @@ -743,6 +822,9 @@
|
| expect_sync_configuration_aborted_ = false;
|
| is_auth_in_progress_ = false;
|
| backend_initialized_ = false;
|
| + // NULL if we're called from Shutdown().
|
| + if (invalidator_registrar_)
|
| + UpdateInvalidatorRegistrarState();
|
| cached_passphrase_.clear();
|
| encryption_pending_ = false;
|
| encrypt_everything_ = false;
|
| @@ -767,6 +849,7 @@
|
| // Clear prefs (including SyncSetupHasCompleted) before shutting down so
|
| // PSS clients don't think we're set up while we're shutting down.
|
| sync_prefs_.ClearPreferences();
|
| + invalidator_storage_.Clear();
|
| ClearUnrecoverableError();
|
| ShutdownImpl(true);
|
| }
|
| @@ -788,11 +871,6 @@
|
| FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
|
| // TODO(akalin): Make an Observer subclass that listens and does the
|
| // event routing.
|
| - sync_js_controller_.HandleJsEvent("onServiceStateChanged", JsEventDetails());
|
| -}
|
| -
|
| -void ProfileSyncService::NotifySyncCycleCompleted() {
|
| - FOR_EACH_OBSERVER(Observer, observers_, OnSyncCycleCompleted());
|
| sync_js_controller_.HandleJsEvent(
|
| "onServiceStateChanged", JsEventDetails());
|
| }
|
| @@ -876,6 +954,17 @@
|
| weak_factory_.GetWeakPtr()));
|
| }
|
|
|
| +void ProfileSyncService::OnInvalidatorStateChange(
|
| + syncer::InvalidatorState state) {
|
| + invalidator_state_ = state;
|
| + UpdateInvalidatorRegistrarState();
|
| +}
|
| +
|
| +void ProfileSyncService::OnIncomingInvalidation(
|
| + const syncer::ObjectIdInvalidationMap& invalidation_map) {
|
| + invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map);
|
| +}
|
| +
|
| void ProfileSyncService::OnBackendInitialized(
|
| const syncer::WeakHandle<syncer::JsBackend>& js_backend,
|
| const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
|
| @@ -919,6 +1008,7 @@
|
| }
|
|
|
| backend_initialized_ = true;
|
| + UpdateInvalidatorRegistrarState();
|
|
|
| sync_js_controller_.AttachJsBackend(js_backend);
|
| debug_info_listener_ = debug_info_listener;
|
| @@ -967,7 +1057,7 @@
|
| GetSessionModelAssociator()->AsWeakPtr()));
|
| }
|
| DVLOG(2) << "Notifying observers sync cycle completed";
|
| - NotifySyncCycleCompleted();
|
| + NotifyObservers();
|
| }
|
|
|
| void ProfileSyncService::OnExperimentsChanged(
|
| @@ -1063,10 +1153,10 @@
|
| void ProfileSyncService::OnConnectionStatusChange(
|
| syncer::ConnectionStatus status) {
|
| if (use_oauth2_token_ && status == syncer::CONNECTION_AUTH_ERROR) {
|
| - // Sync server returned error indicating that access token is invalid. It
|
| - // could be either expired or access is revoked. Let's request another
|
| - // access token and if access is revoked then request for token will fail
|
| - // with corresponding error.
|
| + // Sync or Tango server returned error indicating that access token is
|
| + // invalid. It could be either expired or access is revoked. Let's request
|
| + // another access token and if access is revoked then request for token will
|
| + // fail with corresponding error.
|
| RequestAccessToken();
|
| } else {
|
| const GoogleServiceAuthError auth_error =
|
| @@ -2091,6 +2181,17 @@
|
| OnUnrecoverableErrorImpl(from_here, message, delete_sync_database);
|
| }
|
|
|
| +void ProfileSyncService::UpdateInvalidatorRegistrarState() {
|
| + const syncer::InvalidatorState effective_state =
|
| + backend_initialized_ ?
|
| + invalidator_state_ : syncer::TRANSIENT_INVALIDATION_ERROR;
|
| + DVLOG(1) << "New invalidator state: "
|
| + << syncer::InvalidatorStateToString(invalidator_state_)
|
| + << ", effective state: "
|
| + << syncer::InvalidatorStateToString(effective_state);
|
| + invalidator_registrar_->UpdateInvalidatorState(effective_state);
|
| +}
|
| +
|
| std::string ProfileSyncService::GetEffectiveUsername() {
|
| #if defined(ENABLE_MANAGED_USERS)
|
| if (ManagedUserService::ProfileIsManaged(profile_)) {
|
|
|