OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_harness.h" | 5 #include "chrome/browser/sync/profile_sync_service_harness.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 aborted_ = true; | 77 aborted_ = true; |
78 caller_ = NULL; | 78 caller_ = NULL; |
79 return !did_timeout_; | 79 return !did_timeout_; |
80 } | 80 } |
81 | 81 |
82 ProfileSyncServiceHarness::ProfileSyncServiceHarness( | 82 ProfileSyncServiceHarness::ProfileSyncServiceHarness( |
83 Profile* profile, | 83 Profile* profile, |
84 const std::string& username, | 84 const std::string& username, |
85 const std::string& password, | 85 const std::string& password, |
86 int id) | 86 int id) |
87 : waiting_for_encryption_type_(syncable::UNSPECIFIED), | 87 : wait_state_(INITIAL_WAIT_STATE), |
88 wait_state_(INITIAL_WAIT_STATE), | |
89 profile_(profile), | 88 profile_(profile), |
90 service_(NULL), | 89 service_(NULL), |
91 timestamp_match_partner_(NULL), | 90 timestamp_match_partner_(NULL), |
92 username_(username), | 91 username_(username), |
93 password_(password), | 92 password_(password), |
94 id_(id) { | 93 id_(id) { |
95 if (IsSyncAlreadySetup()) { | 94 if (IsSyncAlreadySetup()) { |
96 service_ = profile_->GetProfileSyncService(); | 95 service_ = profile_->GetProfileSyncService(); |
97 service_->AddObserver(this); | 96 service_->AddObserver(this); |
98 wait_state_ = FULLY_SYNCED; | 97 wait_state_ = FULLY_SYNCED; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 case FULLY_SYNCED: { | 281 case FULLY_SYNCED: { |
283 // The client is online and fully synced. There is nothing to do. | 282 // The client is online and fully synced. There is nothing to do. |
284 LogClientInfo("FULLY_SYNCED"); | 283 LogClientInfo("FULLY_SYNCED"); |
285 break; | 284 break; |
286 } | 285 } |
287 case SYNC_DISABLED: { | 286 case SYNC_DISABLED: { |
288 // Syncing is disabled for the client. There is nothing to do. | 287 // Syncing is disabled for the client. There is nothing to do. |
289 LogClientInfo("SYNC_DISABLED"); | 288 LogClientInfo("SYNC_DISABLED"); |
290 break; | 289 break; |
291 } | 290 } |
292 case WAITING_FOR_ENCRYPTION: { | |
293 // If the type whose encryption we are waiting for is now complete, there | |
294 // is nothing to do. | |
295 LogClientInfo("WAITING_FOR_ENCRYPTION"); | |
296 if (IsTypeEncrypted(waiting_for_encryption_type_)) | |
297 SignalStateCompleteWithNextState(FULLY_SYNCED); | |
298 break; | |
299 } | |
300 default: | 291 default: |
301 // Invalid state during observer callback which may be triggered by other | 292 // Invalid state during observer callback which may be triggered by other |
302 // classes using the the UI message loop. Defer to their handling. | 293 // classes using the the UI message loop. Defer to their handling. |
303 break; | 294 break; |
304 } | 295 } |
305 return original_wait_state != wait_state_; | 296 return original_wait_state != wait_state_; |
306 } | 297 } |
307 | 298 |
308 void ProfileSyncServiceHarness::OnStateChanged() { | 299 void ProfileSyncServiceHarness::OnStateChanged() { |
309 RunStateChangeMachine(); | 300 RunStateChangeMachine(); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 << ", service_is_pushing_changes: " << ServiceIsPushingChanges(); | 590 << ", service_is_pushing_changes: " << ServiceIsPushingChanges(); |
600 } else { | 591 } else { |
601 VLOG(1) << "Client " << id_ << ": " << message | 592 VLOG(1) << "Client " << id_ << ": " << message |
602 << ": Sync session snapshot not available."; | 593 << ": Sync session snapshot not available."; |
603 } | 594 } |
604 } else { | 595 } else { |
605 VLOG(1) << "Client " << id_ << ": " << message | 596 VLOG(1) << "Client " << id_ << ": " << message |
606 << ": Sync service not available."; | 597 << ": Sync service not available."; |
607 } | 598 } |
608 } | 599 } |
609 | |
610 bool ProfileSyncServiceHarness::EnableEncryptionForType( | |
611 syncable::ModelType type) { | |
612 syncable::ModelTypeSet encrypted_types; | |
613 service_->GetEncryptedDataTypes(&encrypted_types); | |
614 if (encrypted_types.count(type) > 0) | |
615 return true; | |
616 encrypted_types.insert(type); | |
617 service_->EncryptDataTypes(encrypted_types); | |
618 | |
619 // Wait some time to let the enryption finish. | |
620 std::string reason = "Waiting for encryption."; | |
621 DCHECK_EQ(FULLY_SYNCED, wait_state_); | |
622 wait_state_ = WAITING_FOR_ENCRYPTION; | |
623 waiting_for_encryption_type_ = type; | |
624 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason)) { | |
625 LOG(ERROR) << "Did not receive EncryptionComplete notification after" | |
626 << kLiveSyncOperationTimeoutMs / 1000 | |
627 << " seconds."; | |
628 return false; | |
629 } | |
630 | |
631 return IsTypeEncrypted(type); | |
632 } | |
633 | |
634 bool ProfileSyncServiceHarness::IsTypeEncrypted(syncable::ModelType type) { | |
635 syncable::ModelTypeSet encrypted_types; | |
636 service_->GetEncryptedDataTypes(&encrypted_types); | |
637 if (encrypted_types.count(type) == 0) { | |
638 return false; | |
639 } | |
640 return true; | |
641 } | |
OLD | NEW |