| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 return profile_->HasProfileSyncService(); | 127 return profile_->HasProfileSyncService(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 bool ProfileSyncServiceHarness::SetupSync() { | 130 bool ProfileSyncServiceHarness::SetupSync() { |
| 131 syncable::ModelTypeSet synced_datatypes; | 131 syncable::ModelTypeSet synced_datatypes; |
| 132 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 132 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 133 i < syncable::MODEL_TYPE_COUNT; ++i) { | 133 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 134 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); | 134 synced_datatypes.insert(syncable::ModelTypeFromInt(i)); |
| 135 } | 135 } |
| 136 bool result = SetupSync(synced_datatypes); | 136 bool result = SetupSync(synced_datatypes); |
| 137 VLOG(0) << "Client " << id_ << ": Set up sync completed with result " | |
| 138 << result; | |
| 139 if (result == false) { | 137 if (result == false) { |
| 140 std::string pss_status = GetServiceStatus(); | 138 std::string status = GetServiceStatus(); |
| 141 VLOG(0) << pss_status; | 139 LOG(ERROR) << "Client " << id_ << ": SetupSync failed. Syncer status:\n" |
| 140 << status; |
| 141 } else { |
| 142 VLOG(1) << "Client " << id_ << ": SetupSync successful."; |
| 142 } | 143 } |
| 143 return result; | 144 return result; |
| 144 } | 145 } |
| 145 | 146 |
| 146 bool ProfileSyncServiceHarness::SetupSync( | 147 bool ProfileSyncServiceHarness::SetupSync( |
| 147 const syncable::ModelTypeSet& synced_datatypes) { | 148 const syncable::ModelTypeSet& synced_datatypes) { |
| 148 // Initialize the sync client's profile sync service object. | 149 // Initialize the sync client's profile sync service object. |
| 149 service_ = profile_->GetProfileSyncService(""); | 150 service_ = profile_->GetProfileSyncService(""); |
| 150 if (service_ == NULL) { | 151 if (service_ == NULL) { |
| 151 LOG(ERROR) << "SetupSync(): service_ is null."; | 152 LOG(ERROR) << "SetupSync(): service_ is null."; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 176 // Wait for initial sync cycle to be completed. | 177 // Wait for initial sync cycle to be completed. |
| 177 DCHECK_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); | 178 DCHECK_EQ(wait_state_, WAITING_FOR_INITIAL_SYNC); |
| 178 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 179 if (!AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 179 "Waiting for initial sync cycle to complete.")) { | 180 "Waiting for initial sync cycle to complete.")) { |
| 180 LOG(ERROR) << "Initial sync cycle did not complete after " | 181 LOG(ERROR) << "Initial sync cycle did not complete after " |
| 181 << kLiveSyncOperationTimeoutMs / 1000 | 182 << kLiveSyncOperationTimeoutMs / 1000 |
| 182 << " seconds."; | 183 << " seconds."; |
| 183 return false; | 184 return false; |
| 184 } | 185 } |
| 185 | 186 |
| 187 if (wait_state_ == SET_PASSPHRASE_FAILED) { |
| 188 // A passphrase is required for decryption. Sync cannot proceed until |
| 189 // SetPassphrase is called. |
| 190 return false; |
| 191 } |
| 192 |
| 186 // Indicate to the browser that sync setup is complete. | 193 // Indicate to the browser that sync setup is complete. |
| 187 service()->SetSyncSetupCompleted(); | 194 service()->SetSyncSetupCompleted(); |
| 188 | 195 |
| 189 return true; | 196 return true; |
| 190 } | 197 } |
| 191 | 198 |
| 192 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( | 199 void ProfileSyncServiceHarness::SignalStateCompleteWithNextState( |
| 193 WaitState next_state) { | 200 WaitState next_state) { |
| 194 wait_state_ = next_state; | 201 wait_state_ = next_state; |
| 195 SignalStateComplete(); | 202 SignalStateComplete(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 208 // The sync backend is initialized. | 215 // The sync backend is initialized. |
| 209 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); | 216 SignalStateCompleteWithNextState(WAITING_FOR_INITIAL_SYNC); |
| 210 } | 217 } |
| 211 break; | 218 break; |
| 212 } | 219 } |
| 213 case WAITING_FOR_INITIAL_SYNC: { | 220 case WAITING_FOR_INITIAL_SYNC: { |
| 214 LogClientInfo("WAITING_FOR_INITIAL_SYNC"); | 221 LogClientInfo("WAITING_FOR_INITIAL_SYNC"); |
| 215 if (IsSynced()) { | 222 if (IsSynced()) { |
| 216 // The first sync cycle is now complete. We can start running tests. | 223 // The first sync cycle is now complete. We can start running tests. |
| 217 SignalStateCompleteWithNextState(FULLY_SYNCED); | 224 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 225 break; |
| 226 } |
| 227 if (service()->passphrase_required_reason() == |
| 228 sync_api::REASON_SET_PASSPHRASE_FAILED) { |
| 229 // A passphrase is required for decryption and we don't have it. Do not |
| 230 // wait any more. |
| 231 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); |
| 232 break; |
| 218 } | 233 } |
| 219 break; | 234 break; |
| 220 } | 235 } |
| 221 case WAITING_FOR_SYNC_TO_FINISH: { | 236 case WAITING_FOR_SYNC_TO_FINISH: { |
| 222 LogClientInfo("WAITING_FOR_SYNC_TO_FINISH"); | 237 LogClientInfo("WAITING_FOR_SYNC_TO_FINISH"); |
| 223 if (!IsSynced()) { | 238 if (IsSynced()) { |
| 224 // The client is not yet fully synced. Continue waiting. | 239 // The sync cycle we were waiting for is complete. |
| 225 if (!GetStatus().server_reachable) { | 240 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 226 // The client cannot reach the sync server because the network is | |
| 227 // disabled. There is no need to wait anymore. | |
| 228 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | |
| 229 } | |
| 230 break; | 241 break; |
| 231 } | 242 } |
| 232 SignalStateCompleteWithNextState(FULLY_SYNCED); | 243 if (service()->passphrase_required_reason() == |
| 244 sync_api::REASON_SET_PASSPHRASE_FAILED) { |
| 245 // A passphrase is required for decryption and we don't have it. Do not |
| 246 // wait any more. |
| 247 SignalStateCompleteWithNextState(SET_PASSPHRASE_FAILED); |
| 248 break; |
| 249 } |
| 250 if (!GetStatus().server_reachable) { |
| 251 // The client cannot reach the sync server because the network is |
| 252 // disabled. There is no need to wait anymore. |
| 253 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); |
| 254 break; |
| 255 } |
| 233 break; | 256 break; |
| 234 } | 257 } |
| 235 case WAITING_FOR_UPDATES: { | 258 case WAITING_FOR_UPDATES: { |
| 236 LogClientInfo("WAITING_FOR_UPDATES"); | 259 LogClientInfo("WAITING_FOR_UPDATES"); |
| 237 DCHECK(timestamp_match_partner_); | 260 DCHECK(timestamp_match_partner_); |
| 238 if (!MatchesOtherClient(timestamp_match_partner_)) { | 261 if (!MatchesOtherClient(timestamp_match_partner_)) { |
| 239 // The client is not yet fully synced; keep waiting until we converge. | 262 // The client is not yet fully synced; keep waiting until we converge. |
| 240 break; | 263 break; |
| 241 } | 264 } |
| 242 timestamp_match_partner_->service()->RemoveObserver(this); | 265 timestamp_match_partner_->service()->RemoveObserver(this); |
| 243 timestamp_match_partner_ = NULL; | 266 timestamp_match_partner_ = NULL; |
| 244 | 267 |
| 245 SignalStateCompleteWithNextState(FULLY_SYNCED); | 268 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 246 break; | 269 break; |
| 247 } | 270 } |
| 248 case WAITING_FOR_PASSPHRASE_ACCEPTED: { | 271 case WAITING_FOR_PASSPHRASE_ACCEPTED: { |
| 249 LogClientInfo("WAITING_FOR_PASSPHRASE_ACCEPTED"); | 272 LogClientInfo("WAITING_FOR_PASSPHRASE_ACCEPTED"); |
| 250 if (service()->ShouldPushChanges() && | 273 if (service()->ShouldPushChanges() && |
| 251 !service()->observed_passphrase_required()) { | 274 !service()->ObservedPassphraseRequired()) { |
| 252 // The passphrase has been accepted, and sync has been restarted. | 275 // The passphrase has been accepted, and sync has been restarted. |
| 253 SignalStateCompleteWithNextState(FULLY_SYNCED); | 276 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| 254 } | 277 } |
| 255 break; | 278 break; |
| 256 } | 279 } |
| 257 case WAITING_FOR_ENCRYPTION: { | 280 case WAITING_FOR_ENCRYPTION: { |
| 258 LogClientInfo("WAITING_FOR_ENCRYPTION"); | 281 LogClientInfo("WAITING_FOR_ENCRYPTION"); |
| 259 if (IsTypeEncrypted(waiting_for_encryption_type_)) { | 282 if (IsTypeEncrypted(waiting_for_encryption_type_)) { |
| 260 // Encryption is complete for the type we are waiting on. | 283 // Encryption is complete for the type we are waiting on. |
| 261 SignalStateCompleteWithNextState(FULLY_SYNCED); | 284 SignalStateCompleteWithNextState(FULLY_SYNCED); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 272 } | 295 } |
| 273 case SERVER_UNREACHABLE: { | 296 case SERVER_UNREACHABLE: { |
| 274 LogClientInfo("SERVER_UNREACHABLE"); | 297 LogClientInfo("SERVER_UNREACHABLE"); |
| 275 if (GetStatus().server_reachable) { | 298 if (GetStatus().server_reachable) { |
| 276 // The client was offline due to the network being disabled, but is now | 299 // The client was offline due to the network being disabled, but is now |
| 277 // back online. Wait for the pending sync cycle to complete. | 300 // back online. Wait for the pending sync cycle to complete. |
| 278 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); | 301 SignalStateCompleteWithNextState(WAITING_FOR_SYNC_TO_FINISH); |
| 279 } | 302 } |
| 280 break; | 303 break; |
| 281 } | 304 } |
| 305 case SET_PASSPHRASE_FAILED: { |
| 306 // A passphrase is required for decryption. There is nothing the sync |
| 307 // client can do until SetPassphrase() is called. |
| 308 LogClientInfo("SET_PASSPHRASE_FAILED"); |
| 309 break; |
| 310 } |
| 282 case FULLY_SYNCED: { | 311 case FULLY_SYNCED: { |
| 283 // The client is online and fully synced. There is nothing to do. | 312 // The client is online and fully synced. There is nothing to do. |
| 284 LogClientInfo("FULLY_SYNCED"); | 313 LogClientInfo("FULLY_SYNCED"); |
| 285 break; | 314 break; |
| 286 } | 315 } |
| 287 case SYNC_DISABLED: { | 316 case SYNC_DISABLED: { |
| 288 // Syncing is disabled for the client. There is nothing to do. | 317 // Syncing is disabled for the client. There is nothing to do. |
| 289 LogClientInfo("SYNC_DISABLED"); | 318 LogClientInfo("SYNC_DISABLED"); |
| 290 break; | 319 break; |
| 291 } | 320 } |
| 292 default: | 321 default: |
| 293 // Invalid state during observer callback which may be triggered by other | 322 // Invalid state during observer callback which may be triggered by other |
| 294 // classes using the the UI message loop. Defer to their handling. | 323 // classes using the the UI message loop. Defer to their handling. |
| 295 break; | 324 break; |
| 296 } | 325 } |
| 297 return original_wait_state != wait_state_; | 326 return original_wait_state != wait_state_; |
| 298 } | 327 } |
| 299 | 328 |
| 300 void ProfileSyncServiceHarness::OnStateChanged() { | 329 void ProfileSyncServiceHarness::OnStateChanged() { |
| 301 RunStateChangeMachine(); | 330 RunStateChangeMachine(); |
| 302 } | 331 } |
| 303 | 332 |
| 304 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { | 333 bool ProfileSyncServiceHarness::AwaitPassphraseAccepted() { |
| 305 LogClientInfo("AwaitPassphraseAccepted"); | 334 LogClientInfo("AwaitPassphraseAccepted"); |
| 306 if (wait_state_ == SYNC_DISABLED) { | 335 if (wait_state_ == SYNC_DISABLED) { |
| 307 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; | 336 LOG(ERROR) << "Sync disabled for Client " << id_ << "."; |
| 308 return false; | 337 return false; |
| 309 } | 338 } |
| 310 | 339 |
| 311 // TODO(atwilson): After ProfileSyncService::OnPassphraseAccepted() is | 340 if (service()->ShouldPushChanges() && |
| 312 // fixed, add an extra check to make sure that the value of | 341 !service()->ObservedPassphraseRequired()) { |
| 313 // service()->observed_passphrase_required() is false. | |
| 314 if (service()->ShouldPushChanges()) { | |
| 315 // Passphrase is already accepted; don't wait. | 342 // Passphrase is already accepted; don't wait. |
| 316 return true; | 343 return true; |
| 317 } | 344 } |
| 318 | 345 |
| 319 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; | 346 wait_state_ = WAITING_FOR_PASSPHRASE_ACCEPTED; |
| 320 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 347 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
| 321 "Waiting for passphrase accepted."); | 348 "Waiting for passphrase accepted."); |
| 322 } | 349 } |
| 323 | 350 |
| 324 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { | 351 bool ProfileSyncServiceHarness::AwaitBackendInitialized() { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 } | 640 } |
| 614 | 641 |
| 615 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( | 642 std::string ProfileSyncServiceHarness::GetUpdatedTimestamp( |
| 616 syncable::ModelType model_type) { | 643 syncable::ModelType model_type) { |
| 617 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 644 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 618 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; | 645 DCHECK(snap != NULL) << "GetUpdatedTimestamp(): Sync snapshot is NULL."; |
| 619 return snap->download_progress_markers[model_type]; | 646 return snap->download_progress_markers[model_type]; |
| 620 } | 647 } |
| 621 | 648 |
| 622 void ProfileSyncServiceHarness::LogClientInfo(const std::string& message) { | 649 void ProfileSyncServiceHarness::LogClientInfo(const std::string& message) { |
| 623 // TODO(lipalani): Change VLOG(0) to VLOG(1) | 650 // TODO(lipalani): Change VLOG(0) to VLOG(1) -- See http://crbug.com/80706. |
| 624 // http://crbug.com/80706 | |
| 625 if (service()) { | 651 if (service()) { |
| 626 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); | 652 const SyncSessionSnapshot* snap = GetLastSessionSnapshot(); |
| 627 if (snap) { | 653 if (snap) { |
| 628 VLOG(0) << "Client " << id_ << ": " << message | 654 VLOG(0) << "Client " << id_ << ": " << message |
| 629 << ": num_updates_downloaded : " | 655 << ": num_updates_downloaded : " |
| 630 << snap->syncer_status.num_updates_downloaded_total | 656 << snap->syncer_status.num_updates_downloaded_total |
| 631 << ", has_more_to_sync: " << snap->has_more_to_sync | 657 << ", has_more_to_sync: " << snap->has_more_to_sync |
| 632 << ", unsynced_count: " << snap->unsynced_count | 658 << ", unsynced_count: " << snap->unsynced_count |
| 633 << ", num_conflicting_updates: " << snap->num_conflicting_updates | 659 << ", num_conflicting_updates: " << snap->num_conflicting_updates |
| 634 << ", has_unsynced_items: " | 660 << ", has_unsynced_items: " |
| 635 << service()->HasUnsyncedItems() | 661 << service()->HasUnsyncedItems() |
| 636 << ", observed_passphrase_required: " | 662 << ", observed_passphrase_required: " |
| 637 << service()->observed_passphrase_required() | 663 << service()->ObservedPassphraseRequired() |
| 638 << ", notifications_enabled: " | 664 << ", notifications_enabled: " |
| 639 << GetStatus().notifications_enabled | 665 << GetStatus().notifications_enabled |
| 640 << ", service_is_pushing_changes: " << ServiceIsPushingChanges() | 666 << ", service_is_pushing_changes: " << ServiceIsPushingChanges() |
| 641 << ", has_pending_backend_migration: " | 667 << ", has_pending_backend_migration: " |
| 642 << service()->HasPendingBackendMigration(); | 668 << service()->HasPendingBackendMigration(); |
| 643 } else { | 669 } else { |
| 644 VLOG(0) << "Client " << id_ << ": " << message | 670 VLOG(0) << "Client " << id_ << ": " << message |
| 645 << ": Sync session snapshot not available."; | 671 << ": Sync session snapshot not available."; |
| 646 } | 672 } |
| 647 } else { | 673 } else { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 683 return true; | 709 return true; |
| 684 } | 710 } |
| 685 | 711 |
| 686 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 712 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
| 687 DictionaryValue value; | 713 DictionaryValue value; |
| 688 sync_ui_util::ConstructAboutInformation(service_, &value); | 714 sync_ui_util::ConstructAboutInformation(service_, &value); |
| 689 std::string service_status; | 715 std::string service_status; |
| 690 base::JSONWriter::Write(&value, true, &service_status); | 716 base::JSONWriter::Write(&value, true, &service_status); |
| 691 return service_status; | 717 return service_status; |
| 692 } | 718 } |
| OLD | NEW |