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/sync_ui_util.h" | 5 #include "chrome/browser/sync/sync_ui_util.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } else { | 538 } else { |
539 // This bypasses regular inter-thread communication mechanisms to grab a | 539 // This bypasses regular inter-thread communication mechanisms to grab a |
540 // very recent snapshot from the syncer thread. It should be up to date | 540 // very recent snapshot from the syncer thread. It should be up to date |
541 // with the last snapshot emitted by the syncer. Keep in mind, though, that | 541 // with the last snapshot emitted by the syncer. Keep in mind, though, that |
542 // not all events that update these values will ping the UI thread, so you | 542 // not all events that update these values will ping the UI thread, so you |
543 // might not see all intermediate values. | 543 // might not see all intermediate values. |
544 sync_api::SyncManager::Status full_status( | 544 sync_api::SyncManager::Status full_status( |
545 service->QueryDetailedSyncStatus()); | 545 service->QueryDetailedSyncStatus()); |
546 | 546 |
547 // This is a cache of the last snapshot of type SYNC_CYCLE_ENDED where | 547 // This is a cache of the last snapshot of type SYNC_CYCLE_ENDED where |
548 // !snapshot->has_more_to_sync. In other words, it's the last in this | 548 // !snapshot.has_more_to_sync(). In other words, it's the last in this |
549 // series of sync cycles. The series ends only when we've done all we can | 549 // series of sync cycles. The series ends only when we've done all we can |
550 // to resolve conflicts and there is nothing left to commit, or an error | 550 // to resolve conflicts and there is nothing left to commit, or an error |
551 // occurs. | 551 // occurs. |
552 // | 552 // |
553 // Despite the fact that it is updated only at the end of a series of | 553 // Despite the fact that it is updated only at the end of a series of |
554 // commits, its values do not reflect the series. Its counters are based on | 554 // commits, its values do not reflect the series. Its counters are based on |
555 // the values from a single sync cycle. | 555 // the values from a single sync cycle. |
556 // | 556 // |
557 // |snapshot| could be NULL if sync is not yet initialized. | 557 // |snapshot| could be NULL if sync is not yet initialized. |
558 const browser_sync::sessions::SyncSessionSnapshot* snapshot = | 558 const browser_sync::sessions::SyncSessionSnapshot& snapshot = |
559 service->sync_initialized() ? | 559 service->sync_initialized() ? |
560 service->GetLastSessionSnapshot() : NULL; | 560 service->GetLastSessionSnapshot() : |
| 561 browser_sync::sessions::SyncSessionSnapshot(); |
561 | 562 |
562 sync_ui_util::AddStringSyncDetails(sync_summary, "Summary", | 563 sync_ui_util::AddStringSyncDetails(sync_summary, "Summary", |
563 service->QuerySyncStatusSummary()); | 564 service->QuerySyncStatusSummary()); |
564 | 565 |
565 ListValue* version_info = AddSyncDetailsSection(details, "Version Info"); | 566 ListValue* version_info = AddSyncDetailsSection(details, "Version Info"); |
566 sync_ui_util::AddStringSyncDetails(version_info, "Client Version", | 567 sync_ui_util::AddStringSyncDetails(version_info, "Client Version", |
567 GetVersionString()); | 568 GetVersionString()); |
568 sync_ui_util::AddStringSyncDetails(version_info, "Server URL", | 569 sync_ui_util::AddStringSyncDetails(version_info, "Server URL", |
569 service->sync_service_url().spec()); | 570 service->sync_service_url().spec()); |
570 | 571 |
(...skipping 21 matching lines...) Expand all Loading... |
592 service->sync_initialized()); | 593 service->sync_initialized()); |
593 | 594 |
594 // Whether or not we're currently syncing. Will almost always be false | 595 // Whether or not we're currently syncing. Will almost always be false |
595 // because we do not usually update about:sync until a sync cycle has | 596 // because we do not usually update about:sync until a sync cycle has |
596 // completed. | 597 // completed. |
597 sync_ui_util::AddBoolSyncDetail(local_state, "Syncing", | 598 sync_ui_util::AddBoolSyncDetail(local_state, "Syncing", |
598 full_status.syncing); | 599 full_status.syncing); |
599 | 600 |
600 // Network status indicators. | 601 // Network status indicators. |
601 ListValue* network = AddSyncDetailsSection(details, "Network"); | 602 ListValue* network = AddSyncDetailsSection(details, "Network"); |
602 if (snapshot) { | 603 sync_ui_util::AddBoolSyncDetail(network, "Throttled", |
603 sync_ui_util::AddBoolSyncDetail(network, "Throttled", | 604 snapshot.is_silenced()); |
604 snapshot->is_silenced); | |
605 } | |
606 sync_ui_util::AddBoolSyncDetail(network, "Notifications Enabled", | 605 sync_ui_util::AddBoolSyncDetail(network, "Notifications Enabled", |
607 full_status.notifications_enabled); | 606 full_status.notifications_enabled); |
608 | 607 |
609 // Encryption status indicators. | 608 // Encryption status indicators. |
610 // | 609 // |
611 // Only safe to call IsUsingSecondaryPassphrase() if the backend is | 610 // Only safe to call IsUsingSecondaryPassphrase() if the backend is |
612 // initialized already - otherwise, we have no idea whether we are | 611 // initialized already - otherwise, we have no idea whether we are |
613 // using a secondary passphrase or not. | 612 // using a secondary passphrase or not. |
614 ListValue* encryption = AddSyncDetailsSection(details, "Encryption"); | 613 ListValue* encryption = AddSyncDetailsSection(details, "Encryption"); |
615 if (service->sync_initialized()) { | 614 if (service->sync_initialized()) { |
(...skipping 10 matching lines...) Expand all Loading... |
626 sync_ui_util::AddBoolSyncDetail(encryption, | 625 sync_ui_util::AddBoolSyncDetail(encryption, |
627 "Cryptographer Has Pending Keys", | 626 "Cryptographer Has Pending Keys", |
628 full_status.crypto_has_pending_keys); | 627 full_status.crypto_has_pending_keys); |
629 sync_ui_util::AddStringSyncDetails(encryption, | 628 sync_ui_util::AddStringSyncDetails(encryption, |
630 "Encrypted Types", | 629 "Encrypted Types", |
631 syncable::ModelTypeSetToString(full_status.encrypted_types)); | 630 syncable::ModelTypeSetToString(full_status.encrypted_types)); |
632 | 631 |
633 | 632 |
634 ListValue* cycles = AddSyncDetailsSection( | 633 ListValue* cycles = AddSyncDetailsSection( |
635 details, "Status from Last Completed Session"); | 634 details, "Status from Last Completed Session"); |
636 if (snapshot) { | 635 sync_ui_util::AddStringSyncDetails( |
637 sync_ui_util::AddStringSyncDetails( | 636 cycles, "Sync Source", |
638 cycles, "Sync Source", | 637 browser_sync::GetUpdatesSourceString( |
639 browser_sync::GetUpdatesSourceString( | 638 snapshot.source().updates_source)); |
640 snapshot->source.updates_source)); | 639 sync_ui_util::AddStringSyncDetails( |
641 sync_ui_util::AddStringSyncDetails( | 640 cycles, "Download Updates", |
642 cycles, "Download Updates", | 641 GetSyncerErrorString(snapshot.errors().last_download_updates_result)); |
643 GetSyncerErrorString(snapshot->errors.last_download_updates_result)); | 642 sync_ui_util::AddStringSyncDetails( |
644 sync_ui_util::AddStringSyncDetails( | 643 cycles, "Post Commit", |
645 cycles, "Post Commit", | 644 GetSyncerErrorString(snapshot.errors().last_post_commit_result)); |
646 GetSyncerErrorString(snapshot->errors.last_post_commit_result)); | 645 sync_ui_util::AddStringSyncDetails( |
647 sync_ui_util::AddStringSyncDetails( | 646 cycles, "Process Commit Response", |
648 cycles, "Process Commit Response", | 647 GetSyncerErrorString( |
649 GetSyncerErrorString( | 648 snapshot.errors().last_process_commit_response_result)); |
650 snapshot->errors.last_process_commit_response_result)); | |
651 } | |
652 | 649 |
653 // Strictly increasing counters. | 650 // Strictly increasing counters. |
654 ListValue* counters = AddSyncDetailsSection(details, "Running Totals"); | 651 ListValue* counters = AddSyncDetailsSection(details, "Running Totals"); |
655 sync_ui_util::AddIntSyncDetail(counters, | 652 sync_ui_util::AddIntSyncDetail(counters, |
656 "Notifications Received", | 653 "Notifications Received", |
657 full_status.notifications_received); | 654 full_status.notifications_received); |
658 | 655 |
659 sync_ui_util::AddIntSyncDetail(counters, | 656 sync_ui_util::AddIntSyncDetail(counters, |
660 "Cycles Without Updates", | 657 "Cycles Without Updates", |
661 full_status.empty_get_updates); | 658 full_status.empty_get_updates); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 | 712 |
716 sync_ui_util::AddIntSyncDetail( | 713 sync_ui_util::AddIntSyncDetail( |
717 transient_cycle, "Committed Items", | 714 transient_cycle, "Committed Items", |
718 full_status.committed_count); | 715 full_status.committed_count); |
719 sync_ui_util::AddIntSyncDetail( | 716 sync_ui_util::AddIntSyncDetail( |
720 transient_cycle, "Updates Remaining", | 717 transient_cycle, "Updates Remaining", |
721 full_status.updates_available); | 718 full_status.updates_available); |
722 | 719 |
723 ListValue* transient_session = AddSyncDetailsSection( | 720 ListValue* transient_session = AddSyncDetailsSection( |
724 details, "Transient Counters (last cycle of last completed session)"); | 721 details, "Transient Counters (last cycle of last completed session)"); |
725 if (snapshot) { | 722 sync_ui_util::AddIntSyncDetail( |
726 sync_ui_util::AddIntSyncDetail( | 723 transient_session, "Updates Downloaded", |
727 transient_session, "Updates Downloaded", | 724 snapshot.syncer_status().num_updates_downloaded_total); |
728 snapshot->syncer_status.num_updates_downloaded_total); | 725 sync_ui_util::AddIntSyncDetail( |
729 sync_ui_util::AddIntSyncDetail( | 726 transient_session, "Committed Count", |
730 transient_session, "Committed Count", | 727 snapshot.syncer_status().num_successful_commits); |
731 snapshot->syncer_status.num_successful_commits); | |
732 } | |
733 | 728 |
734 if (snapshot) { | 729 // This counter is stale. The warnings related to the snapshot still |
735 // This counter is stale. The warnings related to the snapshot still | 730 // apply, see the comments near call to GetLastSessionSnapshot() above. |
736 // apply, see the comments near call to GetLastSessionSnapshot() above. | 731 // Also, because this is updated only following a complete sync cycle, |
737 // Also, because this is updated only following a complete sync cycle, | 732 // local changes affecting this count will not be displayed until the |
738 // local changes affecting this count will not be displayed until the | 733 // syncer has attempted to commit those changes. |
739 // syncer has attempted to commit those changes. | 734 sync_ui_util::AddIntSyncDetail(transient_session, "Entries", |
740 sync_ui_util::AddIntSyncDetail(transient_session, "Entries", | 735 snapshot.num_entries()); |
741 snapshot->num_entries); | |
742 } | |
743 | 736 |
744 // Now set the actionable errors. | 737 // Now set the actionable errors. |
745 if ((full_status.sync_protocol_error.error_type != | 738 if ((full_status.sync_protocol_error.error_type != |
746 browser_sync::UNKNOWN_ERROR) && | 739 browser_sync::UNKNOWN_ERROR) && |
747 (full_status.sync_protocol_error.error_type != | 740 (full_status.sync_protocol_error.error_type != |
748 browser_sync::SYNC_SUCCESS)) { | 741 browser_sync::SYNC_SUCCESS)) { |
749 strings->Set("actionable_error_detected", | 742 strings->Set("actionable_error_detected", |
750 base::Value::CreateBooleanValue(true)); | 743 base::Value::CreateBooleanValue(true)); |
751 ListValue* actionable_error = new ListValue(); | 744 ListValue* actionable_error = new ListValue(); |
752 strings->Set("actionable_error", actionable_error); | 745 strings->Set("actionable_error", actionable_error); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
819 } | 812 } |
820 } else { | 813 } else { |
821 version_modifier = " " + version_modifier; | 814 version_modifier = " " + version_modifier; |
822 } | 815 } |
823 return chrome_version.Name() + " " + chrome_version.OSType() + " " + | 816 return chrome_version.Name() + " " + chrome_version.OSType() + " " + |
824 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + | 817 chrome_version.Version() + " (" + chrome_version.LastChange() + ")" + |
825 version_modifier; | 818 version_modifier; |
826 } | 819 } |
827 | 820 |
828 } // namespace sync_ui_util | 821 } // namespace sync_ui_util |
OLD | NEW |