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 : wait_state_(INITIAL_WAIT_STATE), | 87 : waiting_for_encryption_type_(syncable::UNSPECIFIED), |
| 88 wait_state_(INITIAL_WAIT_STATE), |
88 profile_(profile), | 89 profile_(profile), |
89 service_(NULL), | 90 service_(NULL), |
90 timestamp_match_partner_(NULL), | 91 timestamp_match_partner_(NULL), |
91 username_(username), | 92 username_(username), |
92 password_(password), | 93 password_(password), |
93 id_(id) { | 94 id_(id) { |
94 if (IsSyncAlreadySetup()) { | 95 if (IsSyncAlreadySetup()) { |
95 service_ = profile_->GetProfileSyncService(); | 96 service_ = profile_->GetProfileSyncService(); |
96 service_->AddObserver(this); | 97 service_->AddObserver(this); |
97 wait_state_ = FULLY_SYNCED; | 98 wait_state_ = FULLY_SYNCED; |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 case FULLY_SYNCED: { | 282 case FULLY_SYNCED: { |
282 // The client is online and fully synced. There is nothing to do. | 283 // The client is online and fully synced. There is nothing to do. |
283 LogClientInfo("FULLY_SYNCED"); | 284 LogClientInfo("FULLY_SYNCED"); |
284 break; | 285 break; |
285 } | 286 } |
286 case SYNC_DISABLED: { | 287 case SYNC_DISABLED: { |
287 // Syncing is disabled for the client. There is nothing to do. | 288 // Syncing is disabled for the client. There is nothing to do. |
288 LogClientInfo("SYNC_DISABLED"); | 289 LogClientInfo("SYNC_DISABLED"); |
289 break; | 290 break; |
290 } | 291 } |
| 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 } |
291 default: | 300 default: |
292 // Invalid state during observer callback which may be triggered by other | 301 // Invalid state during observer callback which may be triggered by other |
293 // classes using the the UI message loop. Defer to their handling. | 302 // classes using the the UI message loop. Defer to their handling. |
294 break; | 303 break; |
295 } | 304 } |
296 return original_wait_state != wait_state_; | 305 return original_wait_state != wait_state_; |
297 } | 306 } |
298 | 307 |
299 void ProfileSyncServiceHarness::OnStateChanged() { | 308 void ProfileSyncServiceHarness::OnStateChanged() { |
300 RunStateChangeMachine(); | 309 RunStateChangeMachine(); |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 << ", service_is_pushing_changes: " << ServiceIsPushingChanges(); | 599 << ", service_is_pushing_changes: " << ServiceIsPushingChanges(); |
591 } else { | 600 } else { |
592 VLOG(1) << "Client " << id_ << ": " << message | 601 VLOG(1) << "Client " << id_ << ": " << message |
593 << ": Sync session snapshot not available."; | 602 << ": Sync session snapshot not available."; |
594 } | 603 } |
595 } else { | 604 } else { |
596 VLOG(1) << "Client " << id_ << ": " << message | 605 VLOG(1) << "Client " << id_ << ": " << message |
597 << ": Sync service not available."; | 606 << ": Sync service not available."; |
598 } | 607 } |
599 } | 608 } |
| 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 |