Index: chrome/browser/sync/test/integration/profile_sync_service_harness.cc |
diff --git a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc |
index 97f45645a54a9bc05db265383cc7f7fa1849b5c1..f736de0e4b6f3185731028f42273ab680cb57318 100644 |
--- a/chrome/browser/sync/test/integration/profile_sync_service_harness.cc |
+++ b/chrome/browser/sync/test/integration/profile_sync_service_harness.cc |
@@ -130,19 +130,30 @@ void ProfileSyncServiceHarness::SetCredentials(const std::string& username, |
} |
bool ProfileSyncServiceHarness::SetupSync() { |
- bool result = SetupSync(syncer::UserSelectableTypes()); |
- if (result == false) { |
- std::string status = GetServiceStatus(); |
- LOG(ERROR) << profile_debug_name_ |
- << ": SetupSync failed. Syncer status:\n" << status; |
+ bool result = SetupSync(syncer::UserSelectableTypes(), false); |
+ if (!result) { |
+ LOG(ERROR) << profile_debug_name_ << ": SetupSync failed. Syncer status:\n" |
+ << GetServiceStatus(); |
} else { |
DVLOG(1) << profile_debug_name_ << ": SetupSync successful."; |
} |
return result; |
} |
-bool ProfileSyncServiceHarness::SetupSync( |
- syncer::ModelTypeSet synced_datatypes) { |
+bool ProfileSyncServiceHarness::SetupSyncForClear() { |
pavely
2017/03/08 21:15:14
This function is only used in sync_test when setti
wylieb
2017/03/09 18:42:26
This is a helper to call into SetupSync with the c
|
+ bool result = SetupSync(syncer::UserSelectableTypes(), true); |
+ if (!result) { |
+ LOG(ERROR) << profile_debug_name_ |
+ << ": SetupSyncForClear failed. Syncer status:\n" |
+ << GetServiceStatus(); |
+ } else { |
+ DVLOG(1) << profile_debug_name_ << ": SetupSyncForClear successful."; |
+ } |
+ return result; |
+} |
+ |
+bool ProfileSyncServiceHarness::SetupSync(syncer::ModelTypeSet synced_datatypes, |
+ bool for_clear) { |
pavely
2017/03/08 21:15:13
"for_clear" name is not very clear. It denotes sce
wylieb
2017/03/09 18:42:26
It makes sense to rename this variable to skip_pas
|
DCHECK(!profile_->IsLegacySupervised()) |
<< "SetupSync should not be used for legacy supervised users."; |
@@ -179,7 +190,9 @@ bool ProfileSyncServiceHarness::SetupSync( |
// Now that auth is completed, request that sync actually start. |
service()->RequestStart(); |
- if (!AwaitEngineInitialization()) { |
+ if (for_clear && !AwaitEngineInitializationForClear()) { |
+ return false; |
+ } else if (!for_clear && !AwaitEngineInitialization()) { |
return false; |
} |
@@ -199,6 +212,11 @@ bool ProfileSyncServiceHarness::SetupSync( |
return false; |
} |
+ // If we're setting up for clear, we don't need to wait. |
+ if (for_clear) { |
+ return true; |
+ } |
+ |
// Set an implicit passphrase for encryption if an explicit one hasn't already |
// been set. If an explicit passphrase has been set, immediately return false, |
// since a decryption passphrase is required. |
@@ -212,13 +230,40 @@ bool ProfileSyncServiceHarness::SetupSync( |
// Wait for initial sync cycle to be completed. |
if (!AwaitSyncSetupCompletion()) { |
- LOG(ERROR) << "Initial sync cycle timed out."; |
return false; |
} |
return true; |
} |
+bool ProfileSyncServiceHarness::RestartSyncService() { |
+ std::unique_ptr<syncer::SyncSetupInProgressHandle> blocker = |
+ service()->GetSetupInProgressHandle(); |
+ DVLOG(1) << "Requesting stop for service."; |
+ service()->RequestStop(ProfileSyncService::CLEAR_DATA); |
+ DVLOG(1) << "Requesting start for service"; |
+ |
+ service()->RequestStart(); |
+ if (!AwaitEngineInitialization()) { |
+ LOG(ERROR) << "AwaitEngineInitialization failed."; |
+ return false; |
+ } |
+ |
+ // This passphrase should be implicit because ClearServerData should be called |
+ // prior. |
+ if (!service()->IsUsingSecondaryPassphrase()) { |
+ service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); |
+ } else { |
+ LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" |
+ " until SetDecryptionPassphrase is called."; |
+ return false; |
+ } |
+ |
+ service()->SetFirstSetupComplete(); |
+ |
+ return true; |
+} |
+ |
bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( |
ProfileSyncServiceHarness* partner) { |
std::vector<ProfileSyncServiceHarness*> harnesses; |
@@ -272,6 +317,27 @@ bool ProfileSyncServiceHarness::AwaitEngineInitialization() { |
return true; |
} |
+bool ProfileSyncServiceHarness::AwaitEngineInitializationForClear() { |
pavely
2017/03/08 21:15:13
Could you add "bool ensure_valid_passphrase" param
wylieb
2017/03/09 18:42:26
Done.
|
+ if (!EngineInitializeChecker(service()).Wait()) { |
+ LOG(ERROR) |
+ << "Initializing up for clear: EngineInitializeChecker timed out."; |
+ return false; |
+ } |
+ |
+ if (!service()->IsEngineInitialized()) { |
+ LOG(ERROR) << "Initializing up for clear: Service engine not initialized."; |
+ return false; |
+ } |
+ |
+ if (HasAuthError(service())) { |
+ LOG(ERROR) << "Initializing up for clear: Credentials were rejected. Sync " |
+ "cannot proceed."; |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() { |
if (!SyncSetupChecker(service()).Wait()) { |
LOG(ERROR) << "SyncSetupChecker timed out."; |