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

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

Issue 11046008: [Invalidations] Require there to be no registered handlers on Invalidator destruction (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync to HEAD Created 8 years, 2 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #include "google_apis/gaia/gaia_constants.h" 60 #include "google_apis/gaia/gaia_constants.h"
61 #include "grit/generated_resources.h" 61 #include "grit/generated_resources.h"
62 #include "net/cookies/cookie_monster.h" 62 #include "net/cookies/cookie_monster.h"
63 #include "sync/api/sync_error.h" 63 #include "sync/api/sync_error.h"
64 #include "sync/internal_api/public/configure_reason.h" 64 #include "sync/internal_api/public/configure_reason.h"
65 #include "sync/internal_api/public/sync_encryption_handler.h" 65 #include "sync/internal_api/public/sync_encryption_handler.h"
66 #include "sync/internal_api/public/util/experiments.h" 66 #include "sync/internal_api/public/util/experiments.h"
67 #include "sync/internal_api/public/util/sync_string_conversions.h" 67 #include "sync/internal_api/public/util/sync_string_conversions.h"
68 #include "sync/js/js_arg_list.h" 68 #include "sync/js/js_arg_list.h"
69 #include "sync/js/js_event_details.h" 69 #include "sync/js/js_event_details.h"
70 #include "sync/notifier/invalidator_registrar.h"
70 #include "sync/util/cryptographer.h" 71 #include "sync/util/cryptographer.h"
71 #include "ui/base/l10n/l10n_util.h" 72 #include "ui/base/l10n/l10n_util.h"
72 73
73 using browser_sync::ChangeProcessor; 74 using browser_sync::ChangeProcessor;
74 using browser_sync::DataTypeController; 75 using browser_sync::DataTypeController;
75 using browser_sync::DataTypeManager; 76 using browser_sync::DataTypeManager;
76 using browser_sync::SyncBackendHost; 77 using browser_sync::SyncBackendHost;
77 using syncer::ModelType; 78 using syncer::ModelType;
78 using syncer::ModelTypeSet; 79 using syncer::ModelTypeSet;
79 using syncer::JsBackend; 80 using syncer::JsBackend;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 } 183 }
183 184
184 bool ProfileSyncService::IsSyncTokenAvailable() { 185 bool ProfileSyncService::IsSyncTokenAvailable() {
185 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_); 186 TokenService* token_service = TokenServiceFactory::GetForProfile(profile_);
186 if (!token_service) 187 if (!token_service)
187 return false; 188 return false;
188 return token_service->HasTokenForService(GaiaConstants::kSyncService); 189 return token_service->HasTokenForService(GaiaConstants::kSyncService);
189 } 190 }
190 191
191 void ProfileSyncService::Initialize() { 192 void ProfileSyncService::Initialize() {
193 DCHECK(!invalidator_registrar_.get());
194 invalidator_registrar_.reset(new syncer::InvalidatorRegistrar());
195
192 InitSettings(); 196 InitSettings();
193 197
194 // We clear this here (vs Shutdown) because we want to remember that an error 198 // We clear this here (vs Shutdown) because we want to remember that an error
195 // happened on shutdown so we can display details (message, location) about it 199 // happened on shutdown so we can display details (message, location) about it
196 // in about:sync. 200 // in about:sync.
197 ClearStaleErrors(); 201 ClearStaleErrors();
198 202
199 sync_prefs_.AddSyncPrefObserver(this); 203 sync_prefs_.AddSyncPrefObserver(this);
200 204
201 // For now, the only thing we can do through policy is to turn sync off. 205 // For now, the only thing we can do through policy is to turn sync off.
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 // be there. 432 // be there.
429 InitializeBackend(!HasSyncSetupCompleted()); 433 InitializeBackend(!HasSyncSetupCompleted());
430 434
431 // |backend_| may end up being NULL here in tests (in synchronous 435 // |backend_| may end up being NULL here in tests (in synchronous
432 // initialization mode). 436 // initialization mode).
433 // 437 //
434 // TODO(akalin): Fix this horribly non-intuitive behavior (see 438 // TODO(akalin): Fix this horribly non-intuitive behavior (see
435 // http://crbug.com/140354). 439 // http://crbug.com/140354).
436 if (backend_.get()) { 440 if (backend_.get()) {
437 backend_->UpdateRegisteredInvalidationIds( 441 backend_->UpdateRegisteredInvalidationIds(
438 invalidator_registrar_.GetAllRegisteredIds()); 442 invalidator_registrar_->GetAllRegisteredIds());
439 } 443 }
440 444
441 if (!sync_global_error_.get()) { 445 if (!sync_global_error_.get()) {
442 #if !defined(OS_ANDROID) 446 #if !defined(OS_ANDROID)
443 sync_global_error_.reset(new SyncGlobalError(this, signin())); 447 sync_global_error_.reset(new SyncGlobalError(this, signin()));
444 #endif 448 #endif
445 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError( 449 GlobalErrorServiceFactory::GetForProfile(profile_)->AddGlobalError(
446 sync_global_error_.get()); 450 sync_global_error_.get());
447 AddObserver(sync_global_error_.get()); 451 AddObserver(sync_global_error_.get());
448 } 452 }
449 } 453 }
450 454
451 void ProfileSyncService::RegisterInvalidationHandler( 455 void ProfileSyncService::RegisterInvalidationHandler(
452 syncer::InvalidationHandler* handler) { 456 syncer::InvalidationHandler* handler) {
453 invalidator_registrar_.RegisterHandler(handler); 457 invalidator_registrar_->RegisterHandler(handler);
454 } 458 }
455 459
456 void ProfileSyncService::UpdateRegisteredInvalidationIds( 460 void ProfileSyncService::UpdateRegisteredInvalidationIds(
457 syncer::InvalidationHandler* handler, 461 syncer::InvalidationHandler* handler,
458 const syncer::ObjectIdSet& ids) { 462 const syncer::ObjectIdSet& ids) {
459 invalidator_registrar_.UpdateRegisteredIds(handler, ids); 463 invalidator_registrar_->UpdateRegisteredIds(handler, ids);
460 464
461 // If |backend_| is NULL, its registered IDs will be updated when 465 // If |backend_| is NULL, its registered IDs will be updated when
462 // it's created and initialized. 466 // it's created and initialized.
463 if (backend_.get()) { 467 if (backend_.get()) {
464 backend_->UpdateRegisteredInvalidationIds( 468 backend_->UpdateRegisteredInvalidationIds(
465 invalidator_registrar_.GetAllRegisteredIds()); 469 invalidator_registrar_->GetAllRegisteredIds());
466 } 470 }
467 } 471 }
468 472
469 void ProfileSyncService::UnregisterInvalidationHandler( 473 void ProfileSyncService::UnregisterInvalidationHandler(
470 syncer::InvalidationHandler* handler) { 474 syncer::InvalidationHandler* handler) {
471 invalidator_registrar_.UnregisterHandler(handler); 475 invalidator_registrar_->UnregisterHandler(handler);
472 } 476 }
473 477
474 syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const { 478 syncer::InvalidatorState ProfileSyncService::GetInvalidatorState() const {
475 return invalidator_registrar_.GetInvalidatorState(); 479 return invalidator_registrar_->GetInvalidatorState();
476 } 480 }
477 481
478 void ProfileSyncService::EmitInvalidationForTest( 482 void ProfileSyncService::EmitInvalidationForTest(
479 const invalidation::ObjectId& id, 483 const invalidation::ObjectId& id,
480 const std::string& payload) { 484 const std::string& payload) {
481 syncer::ObjectIdSet notify_ids; 485 syncer::ObjectIdSet notify_ids;
482 notify_ids.insert(id); 486 notify_ids.insert(id);
483 487
484 const syncer::ObjectIdInvalidationMap& invalidation_map = 488 const syncer::ObjectIdInvalidationMap& invalidation_map =
485 ObjectIdSetToInvalidationMap(notify_ids, payload); 489 ObjectIdSetToInvalidationMap(notify_ids, payload);
486 OnIncomingInvalidation(invalidation_map, syncer::REMOTE_INVALIDATION); 490 OnIncomingInvalidation(invalidation_map, syncer::REMOTE_INVALIDATION);
487 } 491 }
488 492
489 void ProfileSyncService::Shutdown() { 493 void ProfileSyncService::Shutdown() {
494 DCHECK(invalidator_registrar_.get());
490 // TODO(akalin): Remove this once http://crbug.com/153827 is fixed. 495 // TODO(akalin): Remove this once http://crbug.com/153827 is fixed.
491 ExtensionService* const extension_service = 496 ExtensionService* const extension_service =
492 extensions::ExtensionSystem::Get(profile_)->extension_service(); 497 extensions::ExtensionSystem::Get(profile_)->extension_service();
493 // |extension_service| may be NULL if it was never initialized 498 // |extension_service| may be NULL if it was never initialized
494 // (e.g., extension sync wasn't enabled in tests). 499 // (e.g., extension sync wasn't enabled in tests).
495 if (extension_service) 500 if (extension_service)
496 extension_service->OnProfileSyncServiceShutdown(); 501 extension_service->OnProfileSyncServiceShutdown();
497 502
503 // Reset |invalidator_registrar_| first so that ShutdownImpl cannot
504 // use it.
505 invalidator_registrar_.reset();
506
498 ShutdownImpl(false); 507 ShutdownImpl(false);
499 } 508 }
500 509
501 void ProfileSyncService::ShutdownImpl(bool sync_disabled) { 510 void ProfileSyncService::ShutdownImpl(bool sync_disabled) {
502 // First, we spin down the backend and wait for it to stop syncing completely 511 // First, we spin down the backend and wait for it to stop syncing completely
503 // before we Stop the data type manager. This is to avoid a late sync cycle 512 // before we Stop the data type manager. This is to avoid a late sync cycle
504 // applying changes to the sync db that wouldn't get applied via 513 // applying changes to the sync db that wouldn't get applied via
505 // ChangeProcessors, leading to back-from-the-dead bugs. 514 // ChangeProcessors, leading to back-from-the-dead bugs.
506 base::Time shutdown_start_time = base::Time::Now(); 515 base::Time shutdown_start_time = base::Time::Now();
507 if (backend_.get()) { 516 if (backend_.get()) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 failed_datatypes_handler_.UpdateFailedDatatypes(errors, 690 failed_datatypes_handler_.UpdateFailedDatatypes(errors,
682 FailedDatatypesHandler::RUNTIME); 691 FailedDatatypesHandler::RUNTIME);
683 692
684 MessageLoop::current()->PostTask(FROM_HERE, 693 MessageLoop::current()->PostTask(FROM_HERE,
685 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager, 694 base::Bind(&ProfileSyncService::ReconfigureDatatypeManager,
686 weak_factory_.GetWeakPtr())); 695 weak_factory_.GetWeakPtr()));
687 } 696 }
688 697
689 void ProfileSyncService::OnInvalidatorStateChange( 698 void ProfileSyncService::OnInvalidatorStateChange(
690 syncer::InvalidatorState state) { 699 syncer::InvalidatorState state) {
691 invalidator_registrar_.UpdateInvalidatorState(state); 700 invalidator_registrar_->UpdateInvalidatorState(state);
692 } 701 }
693 702
694 void ProfileSyncService::OnIncomingInvalidation( 703 void ProfileSyncService::OnIncomingInvalidation(
695 const syncer::ObjectIdInvalidationMap& invalidation_map, 704 const syncer::ObjectIdInvalidationMap& invalidation_map,
696 syncer::IncomingInvalidationSource source) { 705 syncer::IncomingInvalidationSource source) {
697 invalidator_registrar_.DispatchInvalidationsToHandlers(invalidation_map, 706 invalidator_registrar_->DispatchInvalidationsToHandlers(invalidation_map,
698 source); 707 source);
699 } 708 }
700 709
701 void ProfileSyncService::OnBackendInitialized( 710 void ProfileSyncService::OnBackendInitialized(
702 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) { 711 const syncer::WeakHandle<syncer::JsBackend>& js_backend, bool success) {
703 is_first_time_sync_configure_ = !HasSyncSetupCompleted(); 712 is_first_time_sync_configure_ = !HasSyncSetupCompleted();
704 713
705 if (is_first_time_sync_configure_) { 714 if (is_first_time_sync_configure_) {
706 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success); 715 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeFirstTimeSuccess", success);
707 } else { 716 } else {
708 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success); 717 UMA_HISTOGRAM_BOOLEAN("Sync.BackendInitializeRestoreSuccess", success);
(...skipping 1124 matching lines...) Expand 10 before | Expand all | Expand 10 after
1833 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru. 1842 // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefine d-behaviour-after-directly-calling-the-destru.
1834 ProfileSyncService* old_this = this; 1843 ProfileSyncService* old_this = this;
1835 this->~ProfileSyncService(); 1844 this->~ProfileSyncService();
1836 new(old_this) ProfileSyncService( 1845 new(old_this) ProfileSyncService(
1837 new ProfileSyncComponentsFactoryImpl(profile, 1846 new ProfileSyncComponentsFactoryImpl(profile,
1838 CommandLine::ForCurrentProcess()), 1847 CommandLine::ForCurrentProcess()),
1839 profile, 1848 profile,
1840 signin, 1849 signin,
1841 behavior); 1850 behavior);
1842 } 1851 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698