Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/sync/test/integration/profile_sync_service_harness.cc

Issue 148723002: [sync] Eliminate Await*SyncCompletion methods in integration tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove AwaitSteadyState Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/test/integration/profile_sync_service_harness.h" 5 #include "chrome/browser/sync/test/integration/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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "sync/internal_api/public/util/sync_string_conversions.h" 42 #include "sync/internal_api/public/util/sync_string_conversions.h"
43 43
44 #if defined(ENABLE_MANAGED_USERS) 44 #if defined(ENABLE_MANAGED_USERS)
45 #include "chrome/browser/managed_mode/managed_user_constants.h" 45 #include "chrome/browser/managed_mode/managed_user_constants.h"
46 #endif 46 #endif
47 47
48 using syncer::sessions::SyncSessionSnapshot; 48 using syncer::sessions::SyncSessionSnapshot;
49 using invalidation::P2PInvalidationService; 49 using invalidation::P2PInvalidationService;
50 50
51 // The amount of time for which we wait for a sync operation to complete. 51 // The amount of time for which we wait for a sync operation to complete.
52 // TODO(sync): This timeout must eventually be made less than the default 45
53 // second timeout for integration tests so that in case a sync operation times
54 // out, it is able to log a useful failure message before the test is killed.
52 static const int kSyncOperationTimeoutMs = 45000; 55 static const int kSyncOperationTimeoutMs = 45000;
53 56
54 namespace { 57 namespace {
55 58
56 // Checks if a desired change in the state of the sync engine has taken place by 59 // Checks if a desired change in the state of the sync engine has taken place by
57 // running the callback passed to it. 60 // running the callback passed to it.
58 class CallbackStatusChecker : public StatusChangeChecker { 61 class CallbackStatusChecker : public StatusChangeChecker {
59 public: 62 public:
60 CallbackStatusChecker(base::Callback<bool()> callback, 63 CallbackStatusChecker(base::Callback<bool()> callback,
61 const std::string& source) 64 const std::string& source)
(...skipping 27 matching lines...) Expand all
89 // Backend initialization is blocked by an auth error. 92 // Backend initialization is blocked by an auth error.
90 if (harness->HasAuthError()) 93 if (harness->HasAuthError())
91 return true; 94 return true;
92 // Backend initialization is blocked by a failure to fetch Oauth2 tokens. 95 // Backend initialization is blocked by a failure to fetch Oauth2 tokens.
93 if (harness->service()->IsRetryingAccessTokenFetchForTest()) 96 if (harness->service()->IsRetryingAccessTokenFetchForTest())
94 return true; 97 return true;
95 // Still waiting on backend initialization. 98 // Still waiting on backend initialization.
96 return false; 99 return false;
97 } 100 }
98 101
99 // Helper function which returns true if initial sync is complete, or if the
100 // initial sync is blocked for some reason.
101 bool DoneWaitingForInitialSync(const ProfileSyncServiceHarness* harness) {
102 DCHECK(harness);
103 // Initial sync is complete.
104 if (harness->IsFullySynced())
105 return true;
106 // Initial sync is blocked because custom passphrase is required.
107 if (harness->service()->passphrase_required_reason() ==
108 syncer::REASON_DECRYPTION) {
109 return true;
110 }
111 // Initial sync is blocked by an auth error.
112 if (harness->HasAuthError())
113 return true;
114 // Still waiting on initial sync.
115 return false;
116 }
117
118 // Helper function which returns true if the sync client is fully synced, or if
119 // sync is blocked for some reason.
120 bool DoneWaitingForFullSync(const ProfileSyncServiceHarness* harness) {
121 DCHECK(harness);
122 // Sync is complete.
123 if (harness->IsFullySynced())
124 return true;
125 // Sync is blocked by an auth error.
126 if (harness->HasAuthError())
127 return true;
128 // Sync is blocked by a failure to fetch Oauth2 tokens.
129 if (harness->service()->IsRetryingAccessTokenFetchForTest())
130 return true;
131 // Still waiting on sync.
132 return false;
133 }
134
135 // Helper function which returns true if the sync client requires a custom 102 // Helper function which returns true if the sync client requires a custom
136 // passphrase to be entered for decryption. 103 // passphrase to be entered for decryption.
137 bool IsPassphraseRequired(const ProfileSyncServiceHarness* harness) { 104 bool IsPassphraseRequired(const ProfileSyncServiceHarness* harness) {
138 DCHECK(harness); 105 DCHECK(harness);
139 return harness->service()->IsPassphraseRequired(); 106 return harness->service()->IsPassphraseRequired();
140 } 107 }
141 108
142 // Helper function which returns true if the custom passphrase entered was 109 // Helper function which returns true if the custom passphrase entered was
143 // accepted. 110 // accepted.
144 bool IsPassphraseAccepted(const ProfileSyncServiceHarness* harness) { 111 bool IsPassphraseAccepted(const ProfileSyncServiceHarness* harness) {
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 if (!service()->IsUsingSecondaryPassphrase()) { 247 if (!service()->IsUsingSecondaryPassphrase()) {
281 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT); 248 service()->SetEncryptionPassphrase(password_, ProfileSyncService::IMPLICIT);
282 } else { 249 } else {
283 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 250 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
284 " until SetDecryptionPassphrase is called."; 251 " until SetDecryptionPassphrase is called.";
285 return false; 252 return false;
286 } 253 }
287 254
288 // Wait for initial sync cycle to be completed. 255 // Wait for initial sync cycle to be completed.
289 DCHECK(service()->sync_initialized()); 256 DCHECK(service()->sync_initialized());
290 CallbackStatusChecker initial_sync_checker( 257 if (!AwaitSyncSetupCompletion()) {
rlarocque 2014/01/28 23:08:29 As I understand it, this will loop until ShouldPus
Raghu Simha 2014/01/29 00:28:43 Fair point. I've covered these error conditions in
291 base::Bind(&DoneWaitingForInitialSync, base::Unretained(this)),
292 "DoneWaitingForInitialSync");
293 if (!AwaitStatusChange(&initial_sync_checker, "SetupSync")) {
294 LOG(ERROR) << "Initial sync cycle did not complete after " 258 LOG(ERROR) << "Initial sync cycle did not complete after "
295 << kSyncOperationTimeoutMs / 1000 259 << kSyncOperationTimeoutMs / 1000
296 << " seconds."; 260 << " seconds.";
297 return false; 261 return false;
298 } 262 }
299 263
300 // Make sure that initial sync wasn't blocked by a missing passphrase. 264 // Make sure that initial sync wasn't blocked by a missing passphrase.
301 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) { 265 if (service()->passphrase_required_reason() == syncer::REASON_DECRYPTION) {
302 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed" 266 LOG(ERROR) << "A passphrase is required for decryption. Sync cannot proceed"
303 " until SetDecryptionPassphrase is called."; 267 " until SetDecryptionPassphrase is called.";
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 } 356 }
393 357
394 CallbackStatusChecker backend_initialized_checker( 358 CallbackStatusChecker backend_initialized_checker(
395 base::Bind(&DoneWaitingForBackendInitialization, 359 base::Bind(&DoneWaitingForBackendInitialization,
396 base::Unretained(this)), 360 base::Unretained(this)),
397 "DoneWaitingForBackendInitialization"); 361 "DoneWaitingForBackendInitialization");
398 AwaitStatusChange(&backend_initialized_checker, "AwaitBackendInitialized"); 362 AwaitStatusChange(&backend_initialized_checker, "AwaitBackendInitialized");
399 return service()->sync_initialized(); 363 return service()->sync_initialized();
400 } 364 }
401 365
402 bool ProfileSyncServiceHarness::AwaitDataSyncCompletion() { 366 bool ProfileSyncServiceHarness::AwaitCommitActivityCompletion() {
rlarocque 2014/01/28 23:08:29 You should change the name of this function, too.
Raghu Simha 2014/01/29 00:28:43 Actually, here's why I'd like to keep this name in
403 DVLOG(1) << GetClientInfoString("AwaitDataSyncCompletion"); 367 DVLOG(1) << GetClientInfoString("AwaitCommitActivityCompletion");
404
405 DCHECK(service()->sync_initialized());
406 DCHECK(!IsSyncDisabled());
407
408 if (IsDataSynced()) {
409 // Client is already synced; don't wait.
410 return true;
411 }
412
413 CallbackStatusChecker data_synced_checker(
414 base::Bind(&ProfileSyncServiceHarness::IsDataSynced,
415 base::Unretained(this)),
416 "IsDataSynced");
417 return AwaitStatusChange(&data_synced_checker, "AwaitDataSyncCompletion");
418 }
419
420 bool ProfileSyncServiceHarness::AwaitFullSyncCompletion() {
421 DVLOG(1) << GetClientInfoString("AwaitFullSyncCompletion");
422 if (IsSyncDisabled()) { 368 if (IsSyncDisabled()) {
423 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << "."; 369 LOG(ERROR) << "Sync disabled for " << profile_debug_name_ << ".";
424 return false; 370 return false;
425 } 371 }
426 372
427 if (IsFullySynced()) { 373 if (HasLatestProgressMarkers()) {
428 // Client is already synced; don't wait. 374 // Client has nothing to commit and already has latest progress markers;
375 // don't wait.
429 return true; 376 return true;
430 } 377 }
431 378
432 DCHECK(service()->sync_initialized()); 379 CallbackStatusChecker latest_progress_markers_checker(
433 CallbackStatusChecker fully_synced_checker( 380 base::Bind(&ProfileSyncServiceHarness::HasLatestProgressMarkers,
434 base::Bind(&DoneWaitingForFullSync, base::Unretained(this)), 381 base::Unretained(this)),
435 "DoneWaitingForFullSync"); 382 "HasLatestProgressMarkers");
436 AwaitStatusChange(&fully_synced_checker, "AwaitFullSyncCompletion"); 383 AwaitStatusChange(&latest_progress_markers_checker,
437 return IsFullySynced(); 384 "AwaitCommitActivityCompletion");
385 return HasLatestProgressMarkers();
438 } 386 }
439 387
440 bool ProfileSyncServiceHarness::AwaitSyncDisabled() { 388 bool ProfileSyncServiceHarness::AwaitSyncDisabled() {
441 DCHECK(service()->HasSyncSetupCompleted()); 389 DCHECK(service()->HasSyncSetupCompleted());
442 DCHECK(!IsSyncDisabled()); 390 DCHECK(!IsSyncDisabled());
443 CallbackStatusChecker sync_disabled_checker( 391 CallbackStatusChecker sync_disabled_checker(
444 base::Bind(&ProfileSyncServiceHarness::IsSyncDisabled, 392 base::Bind(&ProfileSyncServiceHarness::IsSyncDisabled,
445 base::Unretained(this)), 393 base::Unretained(this)),
446 "IsSyncDisabled"); 394 "IsSyncDisabled");
447 return AwaitStatusChange(&sync_disabled_checker, "AwaitSyncDisabled"); 395 return AwaitStatusChange(&sync_disabled_checker, "AwaitSyncDisabled");
448 } 396 }
449 397
398 bool ProfileSyncServiceHarness::AwaitSyncSetupCompletion() {
399 if (ServiceIsPushingChanges()) {
rlarocque 2014/01/28 23:08:29 If this is likely to become a pattern (ie. many St
Raghu Simha 2014/01/29 00:28:43 The following checks are now in AwaitStatusChange.
400 // Sync is already set up for the client, and it is pushing changes to the
401 // server; don't wait.
402 return true;
403 }
404
405 CallbackStatusChecker sync_setup_complete_checker(
406 base::Bind(&ProfileSyncServiceHarness::ServiceIsPushingChanges,
407 base::Unretained(this)),
408 "ServiceIsPushingChanges");
409 return AwaitStatusChange(&sync_setup_complete_checker,
410 "AwaitSyncSetupCompletion");
411 }
412
450 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion( 413 bool ProfileSyncServiceHarness::AwaitMutualSyncCycleCompletion(
451 ProfileSyncServiceHarness* partner) { 414 ProfileSyncServiceHarness* partner) {
452 DVLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion"); 415 DVLOG(1) << GetClientInfoString("AwaitMutualSyncCycleCompletion");
453 if (!AwaitFullSyncCompletion()) 416 if (!AwaitCommitActivityCompletion())
454 return false; 417 return false;
455 return partner->WaitUntilProgressMarkersMatch(this); 418 return partner->WaitUntilProgressMarkersMatch(this);
456 } 419 }
457 420
458 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion( 421 bool ProfileSyncServiceHarness::AwaitGroupSyncCycleCompletion(
459 std::vector<ProfileSyncServiceHarness*>& partners) { 422 std::vector<ProfileSyncServiceHarness*>& partners) {
460 DVLOG(1) << GetClientInfoString("AwaitGroupSyncCycleCompletion"); 423 DVLOG(1) << GetClientInfoString("AwaitGroupSyncCycleCompletion");
461 if (!AwaitFullSyncCompletion()) 424 if (!AwaitCommitActivityCompletion())
462 return false; 425 return false;
463 bool return_value = true; 426 bool return_value = true;
464 for (std::vector<ProfileSyncServiceHarness*>::iterator it = 427 for (std::vector<ProfileSyncServiceHarness*>::iterator it =
465 partners.begin(); it != partners.end(); ++it) { 428 partners.begin(); it != partners.end(); ++it) {
466 if ((this != *it) && (!(*it)->IsSyncDisabled())) { 429 if ((this != *it) && (!(*it)->IsSyncDisabled())) {
467 return_value = return_value && 430 return_value = return_value &&
468 (*it)->WaitUntilProgressMarkersMatch(this); 431 (*it)->WaitUntilProgressMarkersMatch(this);
469 } 432 }
470 } 433 }
471 return return_value; 434 return return_value;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 533
571 bool ProfileSyncServiceHarness::HasAuthError() const { 534 bool ProfileSyncServiceHarness::HasAuthError() const {
572 return service()->GetAuthError().state() == 535 return service()->GetAuthError().state() ==
573 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS || 536 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS ||
574 service()->GetAuthError().state() == 537 service()->GetAuthError().state() ==
575 GoogleServiceAuthError::SERVICE_ERROR || 538 GoogleServiceAuthError::SERVICE_ERROR ||
576 service()->GetAuthError().state() == 539 service()->GetAuthError().state() ==
577 GoogleServiceAuthError::REQUEST_CANCELED; 540 GoogleServiceAuthError::REQUEST_CANCELED;
578 } 541 }
579 542
580 // We use this function to share code between IsFullySynced and IsDataSynced. 543 // TODO(sync): Remove this method once we stop relying on self notifications and
581 bool ProfileSyncServiceHarness::IsDataSyncedImpl() const { 544 // comparing progress markers.
582 return ServiceIsPushingChanges() && 545 bool ProfileSyncServiceHarness::HasLatestProgressMarkers() const {
583 GetStatus().notifications_enabled &&
584 !service()->HasUnsyncedItems() &&
585 !HasPendingBackendMigration();
586 }
587
588 bool ProfileSyncServiceHarness::IsDataSynced() const {
589 if (service() == NULL) {
590 DVLOG(1) << GetClientInfoString("IsDataSynced(): false");
591 return false;
592 }
593
594 bool is_data_synced = IsDataSyncedImpl();
595
596 DVLOG(1) << GetClientInfoString(
597 is_data_synced ? "IsDataSynced: true" : "IsDataSynced: false");
598 return is_data_synced;
599 }
600
601 bool ProfileSyncServiceHarness::IsFullySynced() const {
602 if (service() == NULL) {
603 DVLOG(1) << GetClientInfoString("IsFullySynced: false");
604 return false;
605 }
606 // If we didn't try to commit anything in the previous cycle, there's a
607 // good chance that we're now fully up to date.
608 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); 546 const SyncSessionSnapshot& snap = GetLastSessionSnapshot();
609 bool is_fully_synced = 547 return snap.model_neutral_state().num_successful_commits == 0 &&
610 snap.model_neutral_state().num_successful_commits == 0 548 !service()->HasUnsyncedItems();
611 && snap.model_neutral_state().commit_result == syncer::SYNCER_OK
612 && IsDataSyncedImpl();
613
614 DVLOG(1) << GetClientInfoString(
615 is_fully_synced ? "IsFullySynced: true" : "IsFullySynced: false");
616 return is_fully_synced;
617 } 549 }
618 550
619 void ProfileSyncServiceHarness::FinishSyncSetup() { 551 void ProfileSyncServiceHarness::FinishSyncSetup() {
620 service()->SetSetupInProgress(false); 552 service()->SetSetupInProgress(false);
621 service()->SetSyncSetupCompleted(); 553 service()->SetSyncSetupCompleted();
622 } 554 }
623 555
624 bool ProfileSyncServiceHarness::HasPendingBackendMigration() const {
625 browser_sync::BackendMigrator* migrator =
626 service()->GetBackendMigratorForTest();
627 return migrator && migrator->state() != browser_sync::BackendMigrator::IDLE;
628 }
629
630 bool ProfileSyncServiceHarness::AutoStartEnabled() { 556 bool ProfileSyncServiceHarness::AutoStartEnabled() {
631 return service()->auto_start_enabled(); 557 return service()->auto_start_enabled();
632 } 558 }
633 559
634 bool ProfileSyncServiceHarness::MatchesPartnerClient() const { 560 bool ProfileSyncServiceHarness::MatchesPartnerClient() const {
635 // TODO(akalin): Shouldn't this belong with the intersection check?
636 // Otherwise, this function isn't symmetric.
637 DCHECK(progress_marker_partner_); 561 DCHECK(progress_marker_partner_);
638 if (!IsFullySynced()) {
639 DVLOG(2) << profile_debug_name_ << ": not synced, assuming doesn't match";
640 return false;
641 }
642 562
643 // Only look for a match if we have at least one enabled datatype in 563 // Only look for a match if we have at least one enabled datatype in
644 // common with the partner client. 564 // common with the partner client.
645 const syncer::ModelTypeSet common_types = 565 const syncer::ModelTypeSet common_types =
646 Intersection(service()->GetActiveDataTypes(), 566 Intersection(service()->GetActiveDataTypes(),
647 progress_marker_partner_->service()->GetActiveDataTypes()); 567 progress_marker_partner_->service()->GetActiveDataTypes());
648 568
649 DVLOG(2) << profile_debug_name_ << ", " 569 DVLOG(2) << profile_debug_name_ << ", "
650 << progress_marker_partner_->profile_debug_name_ 570 << progress_marker_partner_->profile_debug_name_
651 << ": common types are " 571 << ": common types are "
652 << syncer::ModelTypeSetToString(common_types); 572 << syncer::ModelTypeSetToString(common_types);
653 573
654 if (!common_types.Empty() && !progress_marker_partner_->IsFullySynced()) {
655 DVLOG(2) << "non-empty common types and "
656 << progress_marker_partner_->profile_debug_name_
657 << " isn't synced";
658 return false;
659 }
660
661 for (syncer::ModelTypeSet::Iterator i = common_types.First(); 574 for (syncer::ModelTypeSet::Iterator i = common_types.First();
662 i.Good(); i.Inc()) { 575 i.Good(); i.Inc()) {
663 const std::string marker = GetSerializedProgressMarker(i.Get()); 576 const std::string marker = GetSerializedProgressMarker(i.Get());
664 const std::string partner_marker = 577 const std::string partner_marker =
665 progress_marker_partner_->GetSerializedProgressMarker(i.Get()); 578 progress_marker_partner_->GetSerializedProgressMarker(i.Get());
666 if (marker != partner_marker) { 579 if (marker != partner_marker) {
667 if (VLOG_IS_ON(2)) { 580 if (VLOG_IS_ON(2)) {
668 std::string marker_base64, partner_marker_base64; 581 std::string marker_base64, partner_marker_base64;
669 base::Base64Encode(marker, &marker_base64); 582 base::Base64Encode(marker, &marker_base64);
670 base::Base64Encode(partner_marker, &partner_marker_base64); 583 base::Base64Encode(partner_marker, &partner_marker_base64);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes(); 619 syncer::ModelTypeSet synced_datatypes = service()->GetPreferredDataTypes();
707 if (synced_datatypes.Has(datatype)) { 620 if (synced_datatypes.Has(datatype)) {
708 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype " 621 DVLOG(1) << "EnableSyncForDatatype(): Sync already enabled for datatype "
709 << syncer::ModelTypeToString(datatype) 622 << syncer::ModelTypeToString(datatype)
710 << " on " << profile_debug_name_ << "."; 623 << " on " << profile_debug_name_ << ".";
711 return true; 624 return true;
712 } 625 }
713 626
714 synced_datatypes.Put(syncer::ModelTypeFromInt(datatype)); 627 synced_datatypes.Put(syncer::ModelTypeFromInt(datatype));
715 service()->OnUserChoseDatatypes(false, synced_datatypes); 628 service()->OnUserChoseDatatypes(false, synced_datatypes);
716 if (AwaitDataSyncCompletion()) { 629 if (AwaitSyncSetupCompletion()) {
717 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype " 630 DVLOG(1) << "EnableSyncForDatatype(): Enabled sync for datatype "
718 << syncer::ModelTypeToString(datatype) 631 << syncer::ModelTypeToString(datatype)
719 << " on " << profile_debug_name_ << "."; 632 << " on " << profile_debug_name_ << ".";
720 return true; 633 return true;
721 } 634 }
722 635
723 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed"); 636 DVLOG(0) << GetClientInfoString("EnableSyncForDatatype failed");
724 return false; 637 return false;
725 } 638 }
726 639
(...skipping 12 matching lines...) Expand all
739 if (!synced_datatypes.Has(datatype)) { 652 if (!synced_datatypes.Has(datatype)) {
740 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype " 653 DVLOG(1) << "DisableSyncForDatatype(): Sync already disabled for datatype "
741 << syncer::ModelTypeToString(datatype) 654 << syncer::ModelTypeToString(datatype)
742 << " on " << profile_debug_name_ << "."; 655 << " on " << profile_debug_name_ << ".";
743 return true; 656 return true;
744 } 657 }
745 658
746 synced_datatypes.RetainAll(syncer::UserSelectableTypes()); 659 synced_datatypes.RetainAll(syncer::UserSelectableTypes());
747 synced_datatypes.Remove(datatype); 660 synced_datatypes.Remove(datatype);
748 service()->OnUserChoseDatatypes(false, synced_datatypes); 661 service()->OnUserChoseDatatypes(false, synced_datatypes);
749 if (AwaitFullSyncCompletion()) { 662 if (AwaitSyncSetupCompletion()) {
750 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype " 663 DVLOG(1) << "DisableSyncForDatatype(): Disabled sync for datatype "
751 << syncer::ModelTypeToString(datatype) 664 << syncer::ModelTypeToString(datatype)
752 << " on " << profile_debug_name_ << "."; 665 << " on " << profile_debug_name_ << ".";
753 return true; 666 return true;
754 } 667 }
755 668
756 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed"); 669 DVLOG(0) << GetClientInfoString("DisableSyncForDatatype failed");
757 return false; 670 return false;
758 } 671 }
759 672
760 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() { 673 bool ProfileSyncServiceHarness::EnableSyncForAllDatatypes() {
761 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes"); 674 DVLOG(1) << GetClientInfoString("EnableSyncForAllDatatypes");
762 675
763 if (IsSyncDisabled()) 676 if (IsSyncDisabled())
764 return SetupSync(); 677 return SetupSync();
765 678
766 if (service() == NULL) { 679 if (service() == NULL) {
767 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null."; 680 LOG(ERROR) << "EnableSyncForAllDatatypes(): service() is null.";
768 return false; 681 return false;
769 } 682 }
770 683
771 service()->OnUserChoseDatatypes(true, syncer::ModelTypeSet::All()); 684 service()->OnUserChoseDatatypes(true, syncer::ModelTypeSet::All());
772 if (AwaitFullSyncCompletion()) { 685 if (AwaitSyncSetupCompletion()) {
773 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes " 686 DVLOG(1) << "EnableSyncForAllDatatypes(): Enabled sync for all datatypes "
774 << "on " << profile_debug_name_ << "."; 687 << "on " << profile_debug_name_ << ".";
775 return true; 688 return true;
776 } 689 }
777 690
778 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed"); 691 DVLOG(0) << GetClientInfoString("EnableSyncForAllDatatypes failed");
779 return false; 692 return false;
780 } 693 }
781 694
782 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() { 695 bool ProfileSyncServiceHarness::DisableSyncForAllDatatypes() {
(...skipping 15 matching lines...) Expand all
798 syncer::ModelType model_type) const { 711 syncer::ModelType model_type) const {
799 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); 712 const SyncSessionSnapshot& snap = GetLastSessionSnapshot();
800 const syncer::ProgressMarkerMap& markers_map = 713 const syncer::ProgressMarkerMap& markers_map =
801 snap.download_progress_markers(); 714 snap.download_progress_markers();
802 715
803 syncer::ProgressMarkerMap::const_iterator it = 716 syncer::ProgressMarkerMap::const_iterator it =
804 markers_map.find(model_type); 717 markers_map.find(model_type);
805 return (it != markers_map.end()) ? it->second : std::string(); 718 return (it != markers_map.end()) ? it->second : std::string();
806 } 719 }
807 720
721 // TODO(sync): Clean up this method in a separate CL. Remove all snapshot fields
722 // and log shorter, more meaningful messages.
808 std::string ProfileSyncServiceHarness::GetClientInfoString( 723 std::string ProfileSyncServiceHarness::GetClientInfoString(
809 const std::string& message) const { 724 const std::string& message) const {
810 std::stringstream os; 725 std::stringstream os;
811 os << profile_debug_name_ << ": " << message << ": "; 726 os << profile_debug_name_ << ": " << message << ": ";
812 if (service()) { 727 if (service()) {
813 const SyncSessionSnapshot& snap = GetLastSessionSnapshot(); 728 const SyncSessionSnapshot& snap = GetLastSessionSnapshot();
814 const ProfileSyncService::Status& status = GetStatus(); 729 const ProfileSyncService::Status& status = GetStatus();
815 // Capture select info from the sync session snapshot and syncer status. 730 // Capture select info from the sync session snapshot and syncer status.
816 // TODO(rsimha): Audit the list of fields below, and eventually eliminate
817 // the use of the sync session snapshot. See crbug.com/323380.
818 os << ", has_unsynced_items: " 731 os << ", has_unsynced_items: "
819 << (service()->sync_initialized() ? service()->HasUnsyncedItems() : 0) 732 << (service()->sync_initialized() ? service()->HasUnsyncedItems() : 0)
820 << ", did_commit: " 733 << ", did_commit: "
821 << (snap.model_neutral_state().num_successful_commits == 0 && 734 << (snap.model_neutral_state().num_successful_commits == 0 &&
822 snap.model_neutral_state().commit_result == syncer::SYNCER_OK) 735 snap.model_neutral_state().commit_result == syncer::SYNCER_OK)
823 << ", encryption conflicts: " 736 << ", encryption conflicts: "
824 << snap.num_encryption_conflicts() 737 << snap.num_encryption_conflicts()
825 << ", hierarchy conflicts: " 738 << ", hierarchy conflicts: "
826 << snap.num_hierarchy_conflicts() 739 << snap.num_hierarchy_conflicts()
827 << ", server conflicts: " 740 << ", server conflicts: "
828 << snap.num_server_conflicts() 741 << snap.num_server_conflicts()
829 << ", num_updates_downloaded : " 742 << ", num_updates_downloaded : "
830 << snap.model_neutral_state().num_updates_downloaded_total 743 << snap.model_neutral_state().num_updates_downloaded_total
831 << ", passphrase_required_reason: " 744 << ", passphrase_required_reason: "
832 << syncer::PassphraseRequiredReasonToString( 745 << syncer::PassphraseRequiredReasonToString(
833 service()->passphrase_required_reason()) 746 service()->passphrase_required_reason())
834 << ", notifications_enabled: " 747 << ", notifications_enabled: "
835 << status.notifications_enabled 748 << status.notifications_enabled
836 << ", service_is_pushing_changes: " 749 << ", service_is_pushing_changes: "
837 << ServiceIsPushingChanges() 750 << ServiceIsPushingChanges();
838 << ", has_pending_backend_migration: "
839 << HasPendingBackendMigration();
840 } else { 751 } else {
841 os << "Sync service not available"; 752 os << "Sync service not available";
842 } 753 }
843 return os.str(); 754 return os.str();
844 } 755 }
845 756
846 bool ProfileSyncServiceHarness::EnableEncryption() { 757 bool ProfileSyncServiceHarness::EnableEncryption() {
847 if (IsEncryptionComplete()) 758 if (IsEncryptionComplete())
848 return true; 759 return true;
849 service()->EnableEncryptEverything(); 760 service()->EnableEncryptEverything();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 817
907 std::string ProfileSyncServiceHarness::GetServiceStatus() { 818 std::string ProfileSyncServiceHarness::GetServiceStatus() {
908 scoped_ptr<base::DictionaryValue> value( 819 scoped_ptr<base::DictionaryValue> value(
909 sync_ui_util::ConstructAboutInformation(service())); 820 sync_ui_util::ConstructAboutInformation(service()));
910 std::string service_status; 821 std::string service_status;
911 base::JSONWriter::WriteWithOptions(value.get(), 822 base::JSONWriter::WriteWithOptions(value.get(),
912 base::JSONWriter::OPTIONS_PRETTY_PRINT, 823 base::JSONWriter::OPTIONS_PRETTY_PRINT,
913 &service_status); 824 &service_status);
914 return service_status; 825 return service_status;
915 } 826 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698