OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstddef> | 7 #include <cstddef> |
8 #include <iterator> | 8 #include <iterator> |
9 #include <ostream> | 9 #include <ostream> |
10 #include <set> | 10 #include <set> |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 } | 272 } |
273 break; | 273 break; |
274 } | 274 } |
275 case WAITING_FOR_FULL_SYNC: { | 275 case WAITING_FOR_FULL_SYNC: { |
276 DVLOG(1) << GetClientInfoString("WAITING_FOR_FULL_SYNC"); | 276 DVLOG(1) << GetClientInfoString("WAITING_FOR_FULL_SYNC"); |
277 if (IsFullySynced()) { | 277 if (IsFullySynced()) { |
278 // The sync cycle we were waiting for is complete. | 278 // The sync cycle we were waiting for is complete. |
279 SignalStateCompleteWithNextState(FULLY_SYNCED); | 279 SignalStateCompleteWithNextState(FULLY_SYNCED); |
280 break; | 280 break; |
281 } | 281 } |
282 if (!GetStatus().server_reachable) { | |
283 // The client cannot reach the sync server because the network is | |
284 // disabled. There is no need to wait anymore. | |
285 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | |
286 break; | |
287 } | |
288 break; | 282 break; |
289 } | 283 } |
290 case WAITING_FOR_DATA_SYNC: { | 284 case WAITING_FOR_DATA_SYNC: { |
291 if (IsDataSynced()) { | 285 if (IsDataSynced()) { |
292 SignalStateCompleteWithNextState(FULLY_SYNCED); | 286 SignalStateCompleteWithNextState(FULLY_SYNCED); |
293 break; | 287 break; |
294 } | 288 } |
295 break; | 289 break; |
296 } | 290 } |
297 case WAITING_FOR_UPDATES: { | 291 case WAITING_FOR_UPDATES: { |
(...skipping 30 matching lines...) Expand all Loading... |
328 // The correctness of this if condition may depend on the ordering of its | 322 // The correctness of this if condition may depend on the ordering of its |
329 // sub-expressions. See crbug.com/98607, crbug.com/95619. | 323 // sub-expressions. See crbug.com/98607, crbug.com/95619. |
330 // TODO(rlarocque): Figure out a less brittle way of detecting this. | 324 // TODO(rlarocque): Figure out a less brittle way of detecting this. |
331 if (IsTypeEncrypted(waiting_for_encryption_type_) && | 325 if (IsTypeEncrypted(waiting_for_encryption_type_) && |
332 IsFullySynced() && | 326 IsFullySynced() && |
333 GetLastSessionSnapshot()->num_encryption_conflicts == 0) { | 327 GetLastSessionSnapshot()->num_encryption_conflicts == 0) { |
334 // Encryption is now complete for the the type in which we were waiting. | 328 // Encryption is now complete for the the type in which we were waiting. |
335 SignalStateCompleteWithNextState(FULLY_SYNCED); | 329 SignalStateCompleteWithNextState(FULLY_SYNCED); |
336 break; | 330 break; |
337 } | 331 } |
338 if (!GetStatus().server_reachable) { | |
339 // The client cannot reach the sync server because the network is | |
340 // disabled. There is no need to wait anymore. | |
341 SignalStateCompleteWithNextState(SERVER_UNREACHABLE); | |
342 break; | |
343 } | |
344 break; | 332 break; |
345 } | 333 } |
346 case WAITING_FOR_SYNC_CONFIGURATION: { | 334 case WAITING_FOR_SYNC_CONFIGURATION: { |
347 DVLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_CONFIGURATION"); | 335 DVLOG(1) << GetClientInfoString("WAITING_FOR_SYNC_CONFIGURATION"); |
348 if (service()->ShouldPushChanges()) { | 336 if (service()->ShouldPushChanges()) { |
349 // The Datatype manager is configured and sync is fully initialized. | 337 // The Datatype manager is configured and sync is fully initialized. |
350 SignalStateCompleteWithNextState(FULLY_SYNCED); | 338 SignalStateCompleteWithNextState(FULLY_SYNCED); |
351 } | 339 } |
352 break; | 340 break; |
353 } | 341 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 case WAITING_FOR_ACTIONABLE_ERROR: { | 379 case WAITING_FOR_ACTIONABLE_ERROR: { |
392 DVLOG(1) << GetClientInfoString("WAITING_FOR_ACTIONABLE_ERROR"); | 380 DVLOG(1) << GetClientInfoString("WAITING_FOR_ACTIONABLE_ERROR"); |
393 ProfileSyncService::Status status = GetStatus(); | 381 ProfileSyncService::Status status = GetStatus(); |
394 if (status.sync_protocol_error.action != browser_sync::UNKNOWN_ACTION && | 382 if (status.sync_protocol_error.action != browser_sync::UNKNOWN_ACTION && |
395 service_->unrecoverable_error_detected() == true) { | 383 service_->unrecoverable_error_detected() == true) { |
396 // An actionable error has been detected. | 384 // An actionable error has been detected. |
397 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); | 385 SignalStateCompleteWithNextState(WAITING_FOR_NOTHING); |
398 } | 386 } |
399 break; | 387 break; |
400 } | 388 } |
401 case SERVER_UNREACHABLE: { | |
402 DVLOG(1) << GetClientInfoString("SERVER_UNREACHABLE"); | |
403 if (GetStatus().server_reachable) { | |
404 // The client was offline due to the network being disabled, but is now | |
405 // back online. Wait for the pending sync cycle to complete. | |
406 SignalStateCompleteWithNextState(WAITING_FOR_FULL_SYNC); | |
407 } | |
408 break; | |
409 } | |
410 case SET_PASSPHRASE_FAILED: { | 389 case SET_PASSPHRASE_FAILED: { |
411 // A passphrase is required for decryption. There is nothing the sync | 390 // A passphrase is required for decryption. There is nothing the sync |
412 // client can do until SetPassphrase() is called. | 391 // client can do until SetPassphrase() is called. |
413 DVLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); | 392 DVLOG(1) << GetClientInfoString("SET_PASSPHRASE_FAILED"); |
414 break; | 393 break; |
415 } | 394 } |
416 case FULLY_SYNCED: { | 395 case FULLY_SYNCED: { |
417 // The client is online and fully synced. There is nothing to do. | 396 // The client is online and fully synced. There is nothing to do. |
418 DVLOG(1) << GetClientInfoString("FULLY_SYNCED"); | 397 DVLOG(1) << GetClientInfoString("FULLY_SYNCED"); |
419 break; | 398 break; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, | 509 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, |
531 "Waiting for sync configuration."); | 510 "Waiting for sync configuration."); |
532 } | 511 } |
533 | 512 |
534 bool ProfileSyncServiceHarness::AwaitDataSyncCompletion( | 513 bool ProfileSyncServiceHarness::AwaitDataSyncCompletion( |
535 const std::string& reason) { | 514 const std::string& reason) { |
536 DVLOG(1) << GetClientInfoString("AwaitDataSyncCompletion"); | 515 DVLOG(1) << GetClientInfoString("AwaitDataSyncCompletion"); |
537 | 516 |
538 CHECK(service()->sync_initialized()); | 517 CHECK(service()->sync_initialized()); |
539 CHECK_NE(wait_state_, SYNC_DISABLED); | 518 CHECK_NE(wait_state_, SYNC_DISABLED); |
540 CHECK_NE(wait_state_, SERVER_UNREACHABLE); | |
541 | 519 |
542 if (IsDataSynced()) { | 520 if (IsDataSynced()) { |
543 // Client is already synced; don't wait. | 521 // Client is already synced; don't wait. |
544 return true; | 522 return true; |
545 } | 523 } |
546 | 524 |
547 wait_state_ = WAITING_FOR_DATA_SYNC; | 525 wait_state_ = WAITING_FOR_DATA_SYNC; |
548 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 526 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
549 if (wait_state_ == FULLY_SYNCED) { | 527 if (wait_state_ == FULLY_SYNCED) { |
550 return true; | 528 return true; |
(...skipping 10 matching lines...) Expand all Loading... |
561 if (wait_state_ == SYNC_DISABLED) { | 539 if (wait_state_ == SYNC_DISABLED) { |
562 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; | 540 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; |
563 return false; | 541 return false; |
564 } | 542 } |
565 | 543 |
566 if (IsFullySynced()) { | 544 if (IsFullySynced()) { |
567 // Client is already synced; don't wait. | 545 // Client is already synced; don't wait. |
568 return true; | 546 return true; |
569 } | 547 } |
570 | 548 |
571 if (wait_state_ == SERVER_UNREACHABLE) { | |
572 // Client was offline; wait for it to go online, and then wait for sync. | |
573 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | |
574 DCHECK_EQ(wait_state_, WAITING_FOR_FULL_SYNC); | |
575 return AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | |
576 } | |
577 | |
578 DCHECK(service()->sync_initialized()); | 549 DCHECK(service()->sync_initialized()); |
579 wait_state_ = WAITING_FOR_FULL_SYNC; | 550 wait_state_ = WAITING_FOR_FULL_SYNC; |
580 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); | 551 AwaitStatusChangeWithTimeout(kLiveSyncOperationTimeoutMs, reason); |
581 if (wait_state_ == FULLY_SYNCED) { | 552 if (wait_state_ == FULLY_SYNCED) { |
582 // Client is online; sync was successful. | 553 // Client is online; sync was successful. |
583 return true; | 554 return true; |
584 } else if (wait_state_ == SERVER_UNREACHABLE) { | |
585 // Client is offline; sync was unsuccessful. | |
586 LOG(ERROR) << "Client went offline after waiting for sync to finish"; | |
587 return false; | |
588 } else { | 555 } else { |
589 LOG(ERROR) << "Invalid wait state: " << wait_state_; | 556 LOG(ERROR) << "Invalid wait state: " << wait_state_; |
590 return false; | 557 return false; |
591 } | 558 } |
592 } | 559 } |
593 | 560 |
594 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { | 561 bool ProfileSyncServiceHarness::AwaitSyncDisabled(const std::string& reason) { |
595 DCHECK(service()->HasSyncSetupCompleted()); | 562 DCHECK(service()->HasSyncSetupCompleted()); |
596 DCHECK_NE(wait_state_, SYNC_DISABLED); | 563 DCHECK_NE(wait_state_, SYNC_DISABLED); |
597 wait_state_ = WAITING_FOR_SYNC_DISABLED; | 564 wait_state_ = WAITING_FOR_SYNC_DISABLED; |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 return state_map.size(); | 1088 return state_map.size(); |
1122 } | 1089 } |
1123 | 1090 |
1124 std::string ProfileSyncServiceHarness::GetServiceStatus() { | 1091 std::string ProfileSyncServiceHarness::GetServiceStatus() { |
1125 DictionaryValue value; | 1092 DictionaryValue value; |
1126 sync_ui_util::ConstructAboutInformation(service_, &value); | 1093 sync_ui_util::ConstructAboutInformation(service_, &value); |
1127 std::string service_status; | 1094 std::string service_status; |
1128 base::JSONWriter::Write(&value, true, &service_status); | 1095 base::JSONWriter::Write(&value, true, &service_status); |
1129 return service_status; | 1096 return service_status; |
1130 } | 1097 } |
OLD | NEW |