Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 13197004: Draft: InvalidationService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Passes tests Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/sync/profile_sync_service.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 #include <utility> 10 #include <utility>
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 #include "chrome/common/pref_names.h" 56 #include "chrome/common/pref_names.h"
57 #include "chrome/common/time_format.h" 57 #include "chrome/common/time_format.h"
58 #include "chrome/common/url_constants.h" 58 #include "chrome/common/url_constants.h"
59 #include "components/user_prefs/pref_registry_syncable.h" 59 #include "components/user_prefs/pref_registry_syncable.h"
60 #include "content/public/browser/notification_details.h" 60 #include "content/public/browser/notification_details.h"
61 #include "content/public/browser/notification_service.h" 61 #include "content/public/browser/notification_service.h"
62 #include "content/public/browser/notification_source.h" 62 #include "content/public/browser/notification_source.h"
63 #include "google_apis/gaia/gaia_constants.h" 63 #include "google_apis/gaia/gaia_constants.h"
64 #include "grit/generated_resources.h" 64 #include "grit/generated_resources.h"
65 #include "net/cookies/cookie_monster.h" 65 #include "net/cookies/cookie_monster.h"
66 #include "net/url_request/url_request_context_getter.h"
66 #include "sync/api/sync_error.h" 67 #include "sync/api/sync_error.h"
67 #include "sync/internal_api/public/configure_reason.h" 68 #include "sync/internal_api/public/configure_reason.h"
68 #include "sync/internal_api/public/sync_encryption_handler.h" 69 #include "sync/internal_api/public/sync_encryption_handler.h"
69 #include "sync/internal_api/public/util/experiments.h" 70 #include "sync/internal_api/public/util/experiments.h"
70 #include "sync/internal_api/public/util/sync_string_conversions.h" 71 #include "sync/internal_api/public/util/sync_string_conversions.h"
71 #include "sync/js/js_arg_list.h" 72 #include "sync/js/js_arg_list.h"
72 #include "sync/js/js_event_details.h" 73 #include "sync/js/js_event_details.h"
73 #include "sync/notifier/invalidator_registrar.h"
74 #include "sync/notifier/invalidator_state.h"
75 #include "sync/util/cryptographer.h" 74 #include "sync/util/cryptographer.h"
76 #include "ui/base/l10n/l10n_util.h" 75 #include "ui/base/l10n/l10n_util.h"
77 76
78 #if defined(OS_ANDROID) 77 #if defined(OS_ANDROID)
79 #include "sync/internal_api/public/read_transaction.h" 78 #include "sync/internal_api/public/read_transaction.h"
80 #endif 79 #endif
81 80
82 using browser_sync::ChangeProcessor; 81 using browser_sync::ChangeProcessor;
83 using browser_sync::DataTypeController; 82 using browser_sync::DataTypeController;
84 using browser_sync::DataTypeManager; 83 using browser_sync::DataTypeManager;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory, 130 ProfileSyncService::ProfileSyncService(ProfileSyncComponentsFactory* factory,
132 Profile* profile, 131 Profile* profile,
133 SigninManager* signin_manager, 132 SigninManager* signin_manager,
134 StartBehavior start_behavior) 133 StartBehavior start_behavior)
135 : last_auth_error_(AuthError::AuthErrorNone()), 134 : last_auth_error_(AuthError::AuthErrorNone()),
136 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED), 135 passphrase_required_reason_(syncer::REASON_PASSPHRASE_NOT_REQUIRED),
137 factory_(factory), 136 factory_(factory),
138 profile_(profile), 137 profile_(profile),
139 // |profile| may be NULL in unit tests. 138 // |profile| may be NULL in unit tests.
140 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL), 139 sync_prefs_(profile_ ? profile_->GetPrefs() : NULL),
141 invalidator_storage_(profile_ ? profile_->GetPrefs(): NULL),
142 sync_service_url_(kDevServerUrl), 140 sync_service_url_(kDevServerUrl),
143 is_first_time_sync_configure_(false), 141 is_first_time_sync_configure_(false),
144 backend_initialized_(false), 142 backend_initialized_(false),
145 is_auth_in_progress_(false), 143 is_auth_in_progress_(false),
146 signin_(signin_manager), 144 signin_(signin_manager),
147 unrecoverable_error_reason_(ERROR_REASON_UNSET), 145 unrecoverable_error_reason_(ERROR_REASON_UNSET),
148 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 146 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
149 expect_sync_configuration_aborted_(false), 147 expect_sync_configuration_aborted_(false),
150 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()), 148 encrypted_types_(syncer::SyncEncryptionHandler::SensitiveTypes()),
151 encrypt_everything_(false), 149 encrypt_everything_(false),
152 encryption_pending_(false), 150 encryption_pending_(false),
153 auto_start_enabled_(start_behavior == AUTO_START), 151 auto_start_enabled_(start_behavior == AUTO_START),
154 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 152 failed_datatypes_handler_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
155 configure_status_(DataTypeManager::UNKNOWN), 153 configure_status_(DataTypeManager::UNKNOWN),
156 setup_in_progress_(false), 154 setup_in_progress_(false) {
157 invalidator_state_(syncer::DEFAULT_INVALIDATION_ERROR) {
158 // By default, dev, canary, and unbranded Chromium users will go to the 155 // By default, dev, canary, and unbranded Chromium users will go to the
159 // development servers. Development servers have more features than standard 156 // development servers. Development servers have more features than standard
160 // sync servers. Users with officially-branded Chrome stable and beta builds 157 // sync servers. Users with officially-branded Chrome stable and beta builds
161 // will go to the standard sync servers. 158 // will go to the standard sync servers.
162 // 159 //
163 // GetChannel hits the registry on Windows. See http://crbug.com/70380. 160 // GetChannel hits the registry on Windows. See http://crbug.com/70380.
164 base::ThreadRestrictions::ScopedAllowIO allow_io; 161 base::ThreadRestrictions::ScopedAllowIO allow_io;
165 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel(); 162 chrome::VersionInfo::Channel channel = chrome::VersionInfo::GetChannel();
166 if (channel == chrome::VersionInfo::CHANNEL_STABLE || 163 if (channel == chrome::VersionInfo::CHANNEL_STABLE ||
167 channel == chrome::VersionInfo::CHANNEL_BETA) { 164 channel == chrome::VersionInfo::CHANNEL_BETA) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 if (!preferred_types.Has(syncer::PASSWORDS)) 197 if (!preferred_types.Has(syncer::PASSWORDS))
201 return false; 198 return false;
202 // On Android we do not want to prompt user to enter a passphrase. If 199 // On Android we do not want to prompt user to enter a passphrase. If
203 // passwords cannot be decrypted we just disable them. 200 // passwords cannot be decrypted we just disable them.
204 syncer::ReadTransaction trans(FROM_HERE, GetUserShare()); 201 syncer::ReadTransaction trans(FROM_HERE, GetUserShare());
205 return IsCryptographerReady(&trans); 202 return IsCryptographerReady(&trans);
206 } 203 }
207 #endif 204 #endif
208 205
209 void ProfileSyncService::Initialize() { 206 void ProfileSyncService::Initialize() {
210 DCHECK(!invalidator_registrar_.get());
211 invalidator_registrar_.reset(new syncer::InvalidatorRegistrar());
212
213 InitSettings(); 207 InitSettings();
214 208
215 // We clear this here (vs Shutdown) because we want to remember that an error 209 // We clear this here (vs Shutdown) because we want to remember that an error
216 // happened on shutdown so we can display details (message, location) about it 210 // happened on shutdown so we can display details (message, location) about it
217 // in about:sync. 211 // in about:sync.
218 ClearStaleErrors(); 212 ClearStaleErrors();
219 213
220 sync_prefs_.AddSyncPrefObserver(this); 214 sync_prefs_.AddSyncPrefObserver(this);
221 215
222 // For now, the only thing we can do through policy is to turn sync off. 216 // For now, the only thing we can do through policy is to turn sync off.
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 credentials, 429 credentials,
436 delete_stale_data, 430 delete_stale_data,
437 &sync_manager_factory_, 431 &sync_manager_factory_,
438 backend_unrecoverable_error_handler_.get(), 432 backend_unrecoverable_error_handler_.get(),
439 &browser_sync::ChromeReportUnrecoverableError); 433 &browser_sync::ChromeReportUnrecoverableError);
440 } 434 }
441 435
442 void ProfileSyncService::CreateBackend() { 436 void ProfileSyncService::CreateBackend() {
443 backend_.reset( 437 backend_.reset(
444 new SyncBackendHost(profile_->GetDebugName(), 438 new SyncBackendHost(profile_->GetDebugName(),
445 profile_, sync_prefs_.AsWeakPtr(), 439 profile_, sync_prefs_.AsWeakPtr()));
446 invalidator_storage_.AsWeakPtr()));
447 } 440 }
448 441
449 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 442 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
450 if (encryption_pending()) 443 if (encryption_pending())
451 return true; 444 return true;
452 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); 445 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes();
453 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); 446 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes();
454 DCHECK(encrypted_types.Has(syncer::PASSWORDS)); 447 DCHECK(encrypted_types.Has(syncer::PASSWORDS));
455 return !Intersection(preferred_types, encrypted_types).Empty(); 448 return !Intersection(preferred_types, encrypted_types).Empty();
456 } 449 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred); 519 UMA_HISTOGRAM_TIMES("Sync.Startup.TimeDeferred", time_deferred);
527 } 520 }
528 521
529 DCHECK(IsSyncEnabledAndLoggedIn()); 522 DCHECK(IsSyncEnabledAndLoggedIn());
530 CreateBackend(); 523 CreateBackend();
531 524
532 // Initialize the backend. Every time we start up a new SyncBackendHost, 525 // Initialize the backend. Every time we start up a new SyncBackendHost,
533 // we'll want to start from a fresh SyncDB, so delete any old one that might 526 // we'll want to start from a fresh SyncDB, so delete any old one that might
534 // be there. 527 // be there.
535 InitializeBackend(!HasSyncSetupCompleted()); 528 InitializeBackend(!HasSyncSetupCompleted());
536
537 // |backend_| may end up being NULL here in tests (in synchronous
538 // initialization mode).
539 //
540 // TODO(akalin): Fix this horribly non-intuitive behavior (see
541 // http://crbug.com/140354).
542 if (backend_.get()) {
543 backend_->UpdateRegisteredInvalidationIds(
544 invalidator_registrar_->GetAllRegisteredIds());
545 for (AckHandleReplayQueue::const_iterator it = ack_replay_queue_.begin();
546 it != ack_replay_queue_.end(); ++it) {
547 backend_->AcknowledgeInvalidation(it->first, it->second);
548 }
549 ack_replay_queue_.clear();
550 }
551 }
552
553 void ProfileSyncService::RegisterInvalidationHandler(
554 syncer::InvalidationHandler* handler) {
555 invalidator_registrar_->RegisterHandler(handler);
556 }
557
558 void ProfileSyncService::UpdateRegisteredInvalidationIds(
559 syncer::InvalidationHandler* handler,
560 const syncer::ObjectIdSet& ids) {
561 invalidator_registrar_->UpdateRegisteredIds(handler, ids);
562
563 // If |backend_| is NULL, its registered IDs will be updated when
564 // it's created and initialized.
565 if (backend_.get()) {
566 backend_->UpdateRegisteredInvalidationIds(
567 invalidator_registrar_->GetAllRegisteredIds());
568 }
569 }
570
571 void ProfileSyncService::UnregisterInvalidationHandler(
572 syncer::InvalidationHandler* handler) {
573 invalidator_registrar_->UnregisterHandler(handler);
574 }
575
576 void ProfileSyncService::AcknowledgeInvalidation(
577 const invalidation::ObjectId& id,
578 const syncer::AckHandle& ack_handle) {
579 if (backend_.get()) {
580 backend_->AcknowledgeInvalidation(id, ack_handle);
581 } else {
582 // If |backend_| is NULL, save the acknowledgements to replay when
583 // it's created and initialized.
584 ack_replay_queue_.push_back(std::make_pair(id, ack_handle));
585 }
586 }
587
588 syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const {
589 return invalidator_registrar_->GetInvalidatorState();
590 }
591
592 void ProfileSyncService::EmitInvalidationForTest(
593 const invalidation::ObjectId& id,
594 const std::string& payload) {
595 syncer::ObjectIdSet notify_ids;
596 notify_ids.insert(id);
597
598 const syncer::ObjectIdInvalidationMap& invalidation_map =
599 ObjectIdSetToInvalidationMap(notify_ids, payload);
600 OnIncomingInvalidation(invalidation_map);
601 } 529 }
602 530
603 void ProfileSyncService::Shutdown() { 531 void ProfileSyncService::Shutdown() {
604 DCHECK(invalidator_registrar_.get());
605 // Reset |invalidator_registrar_| first so that ShutdownImpl cannot
606 // use it.
607 invalidator_registrar_.reset();
608
609 if (signin_) 532 if (signin_)
610 signin_->signin_global_error()->RemoveProvider(this); 533 signin_->signin_global_error()->RemoveProvider(this);
611 534
612 ShutdownImpl(false); 535 ShutdownImpl(false);
613 } 536 }
614 537
615 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { 538 void ProfileSyncService::ShutdownImpl(bool sync_disabled) {
616 // First, we spin down the backend and wait for it to stop syncing completely 539 // First, we spin down the backend and wait for it to stop syncing completely
617 // before we Stop the data type manager. This is to avoid a late sync cycle 540 // before we Stop the data type manager. This is to avoid a late sync cycle
618 // applying changes to the sync db that wouldn't get applied via 541 // applying changes to the sync db that wouldn't get applied via
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 } 575 }
653 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time; 576 base::TimeDelta shutdown_time = base::Time::Now() - shutdown_start_time;
654 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time); 577 UMA_HISTOGRAM_TIMES("Sync.Shutdown.BackendDestroyedTime", shutdown_time);
655 578
656 weak_factory_.InvalidateWeakPtrs(); 579 weak_factory_.InvalidateWeakPtrs();
657 580
658 // Clear various flags. 581 // Clear various flags.
659 expect_sync_configuration_aborted_ = false; 582 expect_sync_configuration_aborted_ = false;
660 is_auth_in_progress_ = false; 583 is_auth_in_progress_ = false;
661 backend_initialized_ = false; 584 backend_initialized_ = false;
662 // NULL if we're called from Shutdown(). 585
663 if (invalidator_registrar_.get())
664 UpdateInvalidatorRegistrarState();
665 cached_passphrase_.clear(); 586 cached_passphrase_.clear();
666 encryption_pending_ = false; 587 encryption_pending_ = false;
667 encrypt_everything_ = false; 588 encrypt_everything_ = false;
668 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes(); 589 encrypted_types_ = syncer::SyncEncryptionHandler::SensitiveTypes();
669 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED; 590 passphrase_required_reason_ = syncer::REASON_PASSPHRASE_NOT_REQUIRED;
670 // Revert to "no auth error". 591 // Revert to "no auth error".
671 if (last_auth_error_.state() != GoogleServiceAuthError::NONE) 592 if (last_auth_error_.state() != GoogleServiceAuthError::NONE)
672 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone()); 593 UpdateAuthErrorState(GoogleServiceAuthError::AuthErrorNone());
673 594
674 if (sync_global_error_.get()) { 595 if (sync_global_error_.get()) {
675 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError( 596 GlobalErrorServiceFactory::GetForProfile(profile_)->RemoveGlobalError(
676 sync_global_error_.get()); 597 sync_global_error_.get());
677 RemoveObserver(sync_global_error_.get()); 598 RemoveObserver(sync_global_error_.get());
678 sync_global_error_.reset(NULL); 599 sync_global_error_.reset(NULL);
679 } 600 }
680 } 601 }
681 602
682 void ProfileSyncService::DisableForUser() { 603 void ProfileSyncService::DisableForUser() {
683 // Clear prefs (including SyncSetupHasCompleted) before shutting down so 604 // Clear prefs (including SyncSetupHasCompleted) before shutting down so
684 // PSS clients don't think we're set up while we're shutting down. 605 // PSS clients don't think we're set up while we're shutting down.
685 sync_prefs_.ClearPreferences(); 606 sync_prefs_.ClearPreferences();
686 invalidator_storage_.Clear();
687 ClearUnrecoverableError(); 607 ClearUnrecoverableError();
688 ShutdownImpl(true); 608 ShutdownImpl(true);
689 NotifyObservers(); 609 NotifyObservers();
690 } 610 }
691 611
692 bool ProfileSyncService::HasSyncSetupCompleted() const { 612 bool ProfileSyncService::HasSyncSetupCompleted() const {
693 return sync_prefs_.HasSyncSetupCompleted(); 613 return sync_prefs_.HasSyncSetupCompleted();
694 } 614 }
695 615
696 void ProfileSyncService::SetSyncSetupCompleted() { 616 void ProfileSyncService::SetSyncSetupCompleted() {
697 sync_prefs_.SetSyncSetupCompleted(); 617 sync_prefs_.SetSyncSetupCompleted();
698 } 618 }
699 619
700 void ProfileSyncService::UpdateLastSyncedTime() { 620 void ProfileSyncService::UpdateLastSyncedTime() {
701 last_synced_time_ = base::Time::Now(); 621 last_synced_time_ = base::Time::Now();
702 sync_prefs_.SetLastSyncedTime(last_synced_time_); 622 sync_prefs_.SetLastSyncedTime(last_synced_time_);
703 } 623 }
704 624
705 void ProfileSyncService::NotifyObservers() { 625 void ProfileSyncService::NotifyObservers() {
706 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged()); 626 FOR_EACH_OBSERVER(Observer, observers_, OnStateChanged());
707 // TODO(akalin): Make an Observer subclass that listens and does the 627 // TODO(akalin): Make an Observer subclass that listens and does the
708 // event routing. 628 // event routing.
709 sync_js_controller_.HandleJsEvent( 629 sync_js_controller_.HandleJsEvent(
710 "onServiceStateChanged", JsEventDetails()); 630 "onServiceStateChanged", JsEventDetails());
711 } 631 }
712 632
633 void ProfileSyncService::NotifySyncCycleCompleted() {
634 FOR_EACH_OBSERVER(Observer, observers_, OnSyncCycleCompleted());
635 sync_js_controller_.HandleJsEvent(
636 "onServiceStateChanged", JsEventDetails());
637 }
638
713 void ProfileSyncService::ClearStaleErrors() { 639 void ProfileSyncService::ClearStaleErrors() {
714 ClearUnrecoverableError(); 640 ClearUnrecoverableError();
715 last_actionable_error_ = SyncProtocolError(); 641 last_actionable_error_ = SyncProtocolError();
716 } 642 }
717 643
718 void ProfileSyncService::ClearUnrecoverableError() { 644 void ProfileSyncService::ClearUnrecoverableError() {
719 unrecoverable_error_reason_ = ERROR_REASON_UNSET; 645 unrecoverable_error_reason_ = ERROR_REASON_UNSET;
720 unrecoverable_error_message_.clear(); 646 unrecoverable_error_message_.clear();
721 unrecoverable_error_location_ = tracked_objects::Location(); 647 unrecoverable_error_location_ = tracked_objects::Location();
722 } 648 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 // Update this before posting a task. So if a configure happens before 712 // Update this before posting a task. So if a configure happens before
787 // the task that we are going to post, this type would still be disabled. 713 // the task that we are going to post, this type would still be disabled.
788 failed_datatypes_handler_.UpdateFailedDatatypes(errors, 714 failed_datatypes_handler_.UpdateFailedDatatypes(errors,
789 FailedDatatypesHandler::RUNTIME); 715 FailedDatatypesHandler::RUNTIME);
790 716
791 MessageLoop::current()->PostTask(FROM_HERE, 717 MessageLoop::current()->PostTask(FROM_HERE,
792 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 718 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
793 weak_factory_.GetWeakPtr())); 719 weak_factory_.GetWeakPtr()));
794 } 720 }
795 721
796 void ProfileSyncService::OnInvalidatorStateChange(
797 syncer::InvalidatorState state) {
798 invalidator_state_ = state;
799 UpdateInvalidatorRegistrarState();
800 }
801
802 void ProfileSyncService::OnIncomingInvalidation(
803 const syncer::ObjectIdInvalidationMap& invalidation_map) {
804 invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map);
805 }
806
807 void ProfileSyncService::OnBackendInitialized( 722 void ProfileSyncService::OnBackendInitialized(
808 const syncer::WeakHandle<syncer::JsBackend>& js_backend, 723 const syncer::WeakHandle<syncer::JsBackend>& js_backend,
809 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>& 724 const syncer::WeakHandle<syncer::DataTypeDebugInfoListener>&
810 debug_info_listener, 725 debug_info_listener,
811 bool success) { 726 bool success) {
812 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 727 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
813 728
814 if (is_first_time_sync_configure_) { 729 if (is_first_time_sync_configure_) {
815 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 730 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
816 } else { 731 } else {
(...skipping 24 matching lines...) Expand all
841 // we get here, we will have already tried and failed to delete the 756 // we get here, we will have already tried and failed to delete the
842 // directory. It would be no big deal if we tried to delete it again. 757 // directory. It would be no big deal if we tried to delete it again.
843 OnInternalUnrecoverableError(FROM_HERE, 758 OnInternalUnrecoverableError(FROM_HERE,
844 "BackendInitialize failure", 759 "BackendInitialize failure",
845 false, 760 false,
846 ERROR_REASON_BACKEND_INIT_FAILURE); 761 ERROR_REASON_BACKEND_INIT_FAILURE);
847 return; 762 return;
848 } 763 }
849 764
850 backend_initialized_ = true; 765 backend_initialized_ = true;
851 UpdateInvalidatorRegistrarState();
852 766
853 sync_js_controller_.AttachJsBackend(js_backend); 767 sync_js_controller_.AttachJsBackend(js_backend);
854 debug_info_listener_ = debug_info_listener; 768 debug_info_listener_ = debug_info_listener;
855 769
856 // If we have a cached passphrase use it to decrypt/encrypt data now that the 770 // If we have a cached passphrase use it to decrypt/encrypt data now that the
857 // backend is initialized. We want to call this before notifying observers in 771 // backend is initialized. We want to call this before notifying observers in
858 // case this operation affects the "passphrase required" status. 772 // case this operation affects the "passphrase required" status.
859 ConsumeCachedPassphraseIfPossible(); 773 ConsumeCachedPassphraseIfPossible();
860 774
861 // The very first time the backend initializes is effectively the first time 775 // The very first time the backend initializes is effectively the first time
(...skipping 25 matching lines...) Expand all
887 // Trigger garbage collection of old sessions now that we've downloaded 801 // Trigger garbage collection of old sessions now that we've downloaded
888 // any new session data. TODO(zea): Have this be a notification the session 802 // any new session data. TODO(zea): Have this be a notification the session
889 // model associator listens too. Also consider somehow plumbing the current 803 // model associator listens too. Also consider somehow plumbing the current
890 // server time as last reported by CheckServerReachable, so we don't have to 804 // server time as last reported by CheckServerReachable, so we don't have to
891 // rely on the local clock, which may be off significantly. 805 // rely on the local clock, which may be off significantly.
892 MessageLoop::current()->PostTask(FROM_HERE, 806 MessageLoop::current()->PostTask(FROM_HERE,
893 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions, 807 base::Bind(&browser_sync::SessionModelAssociator::DeleteStaleSessions,
894 GetSessionModelAssociator()->AsWeakPtr())); 808 GetSessionModelAssociator()->AsWeakPtr()));
895 } 809 }
896 DVLOG(2) << "Notifying observers sync cycle completed"; 810 DVLOG(2) << "Notifying observers sync cycle completed";
897 NotifyObservers(); 811 NotifySyncCycleCompleted();
898 } 812 }
899 813
900 void ProfileSyncService::OnExperimentsChanged( 814 void ProfileSyncService::OnExperimentsChanged(
901 const syncer::Experiments& experiments) { 815 const syncer::Experiments& experiments) {
902 if (current_experiments_.Matches(experiments)) 816 if (current_experiments_.Matches(experiments))
903 return; 817 return;
904 818
905 // If this is a first time sync for a client, this will be called before 819 // If this is a first time sync for a client, this will be called before
906 // OnBackendInitialized() to ensure the new datatypes are available at sync 820 // OnBackendInitialized() to ensure the new datatypes are available at sync
907 // setup. As a result, the migrator won't exist yet. This is fine because for 821 // setup. As a result, the migrator won't exist yet. This is fine because for
(...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 void ProfileSyncService::OnInternalUnrecoverableError( 1910 void ProfileSyncService::OnInternalUnrecoverableError(
1997 const tracked_objects::Location& from_here, 1911 const tracked_objects::Location& from_here,
1998 const std::string& message, 1912 const std::string& message,
1999 bool delete_sync_database, 1913 bool delete_sync_database,
2000 UnrecoverableErrorReason reason) { 1914 UnrecoverableErrorReason reason) {
2001 DCHECK(!HasUnrecoverableError()); 1915 DCHECK(!HasUnrecoverableError());
2002 unrecoverable_error_reason_ = reason; 1916 unrecoverable_error_reason_ = reason;
2003 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database); 1917 OnUnrecoverableErrorImpl(from_here, message, delete_sync_database);
2004 } 1918 }
2005 1919
2006 void ProfileSyncService::UpdateInvalidatorRegistrarState() {
2007 const syncer::InvalidatorState effective_state =
2008 backend_initialized_ ?
2009 invalidator_state_ : syncer::TRANSIENT_INVALIDATION_ERROR;
2010 DVLOG(1) << "New invalidator state: "
2011 << syncer::InvalidatorStateToString(invalidator_state_)
2012 << ", effective state: "
2013 << syncer::InvalidatorStateToString(effective_state);
2014 invalidator_registrar_->UpdateInvalidatorState(effective_state);
2015 }
2016
2017 void ProfileSyncService::ResetForTest() { 1920 void ProfileSyncService::ResetForTest() {
2018 Profile* profile = profile_; 1921 Profile* profile = profile_;
2019 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); 1922 SigninManager* signin = SigninManagerFactory::GetForProfile(profile);
2020 ProfileSyncService::StartBehavior behavior = 1923 ProfileSyncService::StartBehavior behavior =
2021 browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START 1924 browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START
2022 : ProfileSyncService::MANUAL_START; 1925 : ProfileSyncService::MANUAL_START;
2023 1926
2024 // We call the destructor and placement new here because we want to explicitly 1927 // We call the destructor and placement new here because we want to explicitly
2025 // recreate a new ProfileSyncService instance at the same memory location as 1928 // recreate a new ProfileSyncService instance at the same memory location as
2026 // the old one. Doing so is fine because this code is run only from within 1929 // the old one. Doing so is fine because this code is run only from within
2027 // integration tests, and the message loop is not running at this point. 1930 // integration tests, and the message loop is not running at this point.
2028 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. 1931 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru.
2029 ProfileSyncService* old_this = this; 1932 ProfileSyncService* old_this = this;
2030 this->~ProfileSyncService(); 1933 this->~ProfileSyncService();
2031 new(old_this) ProfileSyncService( 1934 new(old_this) ProfileSyncService(
2032 new ProfileSyncComponentsFactoryImpl(profile, 1935 new ProfileSyncComponentsFactoryImpl(profile,
2033 CommandLine::ForCurrentProcess()), 1936 CommandLine::ForCurrentProcess()),
2034 profile, 1937 profile,
2035 signin, 1938 signin,
2036 behavior); 1939 behavior);
2037 } 1940 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698