diff options
-rw-r--r-- | chrome/browser/sync/profile_sync_service.cc | 17 | ||||
-rw-r--r-- | chrome/browser/sync/profile_sync_service.h | 12 | ||||
-rw-r--r-- | chrome/browser/sync/test/integration/sync_test.cc | 2 |
3 files changed, 17 insertions, 14 deletions
diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 7e8dd1b1..300f056 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -1649,21 +1649,24 @@ const FailedDatatypesHandler& ProfileSyncService::failed_datatypes_handler() { return failed_datatypes_handler_; } -void ProfileSyncService::ResetForTest(ProfileSyncService* service) { - DCHECK(service) << "Cannot reset null ProfileSyncService object."; - Profile* profile = service->profile(); +void ProfileSyncService::ResetForTest() { + Profile* profile = profile_; SigninManager* signin = SigninManagerFactory::GetForProfile(profile); ProfileSyncService::StartBehavior behavior = browser_defaults::kSyncAutoStarts ? ProfileSyncService::AUTO_START : ProfileSyncService::MANUAL_START; - void* place = service; - service->~ProfileSyncService(); - service = new(place) ProfileSyncService( + // We call the destructor and placement new here because we want to explicitly + // recreate a new ProfileSyncService instance at the same memory location as + // the old one. Doing so is fine because this code is run only from within + // integration tests, and the message loop is not running at this point. + // See http://stackoverflow.com/questions/6224121/is-new-this-myclass-undefined-behaviour-after-directly-calling-the-destru. + ProfileSyncService* old_this = this; + this->~ProfileSyncService(); + new(old_this) ProfileSyncService( new ProfileSyncComponentsFactoryImpl(profile, CommandLine::ForCurrentProcess()), profile, signin, behavior); - DCHECK(service) << "Could not create new ProfileSyncService."; } diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index 8e45f95..79adcf07 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -697,12 +697,12 @@ class ProfileSyncService : public browser_sync::SyncFrontend, // Keep track of where we are in a server clear operation ClearServerDataState clear_server_data_state_; - // Deletes / recreates an instance of ProfileSyncService using placement new. - // Used exclusively by the sync integration tests so they can restart sync - // from scratch without tearing down and recreating the browser process. - // Needed because simply calling Shutdown() and Initialize() will not recreate - // other internal objects like SyncBackendHost, SyncManager, etc. - static void ResetForTest(ProfileSyncService* service); + // Destroys / recreates an instance of ProfileSyncService. Used exclusively by + // the sync integration tests so they can restart sync from scratch without + // tearing down and recreating the browser process. Needed because simply + // calling Shutdown() and Initialize() will not recreate other internal + // objects like SyncBackendHost, SyncManager, etc. + void ResetForTest(); // Timeout for the clear data command. This timeout is a temporary hack // and is necessary because the nudge sync framework can drop nudges for diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc index 6a1debf..77bda23 100644 --- a/chrome/browser/sync/test/integration/sync_test.cc +++ b/chrome/browser/sync/test/integration/sync_test.cc @@ -327,7 +327,7 @@ void SyncTest::RestartSyncService(int index) { Profile* profile = GetProfile(index); ProfileSyncService* service = ProfileSyncServiceFactory::GetForProfile(profile); - ProfileSyncService::ResetForTest(service); + service->ResetForTest(); clients_[index] = new ProfileSyncServiceHarness(profile, username_, password_); |