Index: chrome/browser/sync/profile_sync_service_harness.cc |
diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc |
index 95eaff179992291f3dd132f4a1a61044bb8f72ec..72bb584d9892a892ab4b91b83b8a556113e194d8 100644 |
--- a/chrome/browser/sync/profile_sync_service_harness.cc |
+++ b/chrome/browser/sync/profile_sync_service_harness.cc |
@@ -84,7 +84,8 @@ ProfileSyncServiceHarness::ProfileSyncServiceHarness( |
const std::string& username, |
const std::string& password, |
int id) |
- : wait_state_(INITIAL_WAIT_STATE), |
+ : waiting_for_encryption_type_(syncable::UNSPECIFIED), |
+ wait_state_(INITIAL_WAIT_STATE), |
profile_(profile), |
service_(NULL), |
timestamp_match_partner_(NULL), |
@@ -288,6 +289,14 @@ bool ProfileSyncServiceHarness::RunStateChangeMachine() { |
LogClientInfo("SYNC_DISABLED"); |
break; |
} |
+ case WAITING_FOR_ENCRYPTION: { |
+ // If the type whose encryption we are waiting for is now complete, there |
+ // is nothing to do. |
+ LogClientInfo("WAITING_FOR_ENCRYPTION"); |
+ if (IsTypeEncrypted(waiting_for_encryption_type_)) |
+ SignalStateCompleteWithNextState(FULLY_SYNCED); |
+ break; |
+ } |
default: |
// Invalid state during observer callback which may be triggered by other |
// classes using the the UI message loop. Defer to their handling. |
@@ -597,3 +606,36 @@ void ProfileSyncServiceHarness::LogClientInfo(std::string message) { |
<< ": Sync service not available."; |
} |
} |
+ |
+bool ProfileSyncServiceHarness::EnableEncryptionForType( |
+ syncable::ModelType type) { |
+ syncable::ModelTypeSet encrypted_types; |
+ service_->GetEncryptedDataTypes(&encrypted_types); |
+ if (encrypted_types.count(type) > 0) |
+ return true; |
+ encrypted_types.insert(type); |
+ service_->EncryptDataTypes(encrypted_types); |
+ |
+ // Wait some time to let the enryption finish. |
+ std::string reason = "Waiting for encryption."; |
+ DCHECK_EQ(FULLY_SYNCED, wait_state_); |
+ wait_state_ = WAITING_FOR_ENCRYPTION; |
+ waiting_for_encryption_type_ = type; |
+ if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { |
+ LOG(ERROR) << "Did not receive EncryptionComplete notification after" |
+ << kLiveSyncOperationTimeoutMs / 1000 |
+ << " seconds."; |
+ return false; |
+ } |
+ |
+ return IsTypeEncrypted(type); |
+} |
+ |
+bool ProfileSyncServiceHarness::IsTypeEncrypted(syncable::ModelType type) { |
+ syncable::ModelTypeSet encrypted_types; |
+ service_->GetEncryptedDataTypes(&encrypted_types); |
+ if (encrypted_types.count(type) == 0) { |
+ return false; |
+ } |
+ return true; |
+} |