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

Side by Side Diff: chrome/browser/sync/profile_sync_service.cc

Issue 612573005: [Sync] Clean up ProfileSyncService observer events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
OLDNEW
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.h" 5 #include "chrome/browser/sync/profile_sync_service.h"
6 6
7 #include <cstddef> 7 #include <cstddef>
8 #include <map> 8 #include <map>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 541
542 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const { 542 bool ProfileSyncService::IsEncryptedDatatypeEnabled() const {
543 if (encryption_pending()) 543 if (encryption_pending())
544 return true; 544 return true;
545 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); 545 const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes();
546 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes(); 546 const syncer::ModelTypeSet encrypted_types = GetEncryptedDataTypes();
547 DCHECK(encrypted_types.Has(syncer::PASSWORDS)); 547 DCHECK(encrypted_types.Has(syncer::PASSWORDS));
548 return !Intersection(preferred_types, encrypted_types).Empty(); 548 return !Intersection(preferred_types, encrypted_types).Empty();
549 } 549 }
550 550
551 void ProfileSyncService::OnSyncConfigureRetry() {
552 // Note: in order to handle auth failures that arise before the backend is
553 // initialized (e.g. from invalidation notifier, or downloading new control
554 // types), we have to gracefully handle configuration retries at all times.
555 // At this point an auth error badge should be shown, which once resolved
556 // will trigger a new sync cycle.
557 NotifyObservers();
558 }
559
560 void ProfileSyncService::OnProtocolEvent( 551 void ProfileSyncService::OnProtocolEvent(
561 const syncer::ProtocolEvent& event) { 552 const syncer::ProtocolEvent& event) {
562 FOR_EACH_OBSERVER(browser_sync::ProtocolEventObserver, 553 FOR_EACH_OBSERVER(browser_sync::ProtocolEventObserver,
563 protocol_event_observers_, 554 protocol_event_observers_,
564 OnProtocolEvent(event)); 555 OnProtocolEvent(event));
565 } 556 }
566 557
567 void ProfileSyncService::OnDirectoryTypeCommitCounterUpdated( 558 void ProfileSyncService::OnDirectoryTypeCommitCounterUpdated(
568 syncer::ModelType type, 559 syncer::ModelType type,
569 const syncer::CommitCounters& counters) { 560 const syncer::CommitCounters& counters) {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 invalidator, 678 invalidator,
688 sync_prefs_.AsWeakPtr(), 679 sync_prefs_.AsWeakPtr(),
689 sync_folder)); 680 sync_folder));
690 681
691 // Initialize the backend. Every time we start up a new SyncBackendHost, 682 // Initialize the backend. Every time we start up a new SyncBackendHost,
692 // we'll want to start from a fresh SyncDB, so delete any old one that might 683 // we'll want to start from a fresh SyncDB, so delete any old one that might
693 // be there. 684 // be there.
694 InitializeBackend(ShouldDeleteSyncFolder()); 685 InitializeBackend(ShouldDeleteSyncFolder());
695 686
696 UpdateFirstSyncTimePref(); 687 UpdateFirstSyncTimePref();
697
698 NotifyObservers();
maniscalco 2014/09/29 22:01:37 Just to confirm, this one is redundant because of
Nicolas Zea 2014/09/29 23:37:17 Right, InitializeBackend will eventually trigger a
699 } 688 }
700 689
701 void ProfileSyncService::OnGetTokenSuccess( 690 void ProfileSyncService::OnGetTokenSuccess(
702 const OAuth2TokenService::Request* request, 691 const OAuth2TokenService::Request* request,
703 const std::string& access_token, 692 const std::string& access_token,
704 const base::Time& expiration_time) { 693 const base::Time& expiration_time) {
705 DCHECK_EQ(access_token_request_, request); 694 DCHECK_EQ(access_token_request_, request);
706 access_token_request_.reset(); 695 access_token_request_.reset();
707 access_token_ = access_token; 696 access_token_ = access_token;
708 token_receive_time_ = base::Time::Now(); 697 token_receive_time_ = base::Time::Now();
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 const tracked_objects::Location& from_here, 947 const tracked_objects::Location& from_here,
959 const std::string& message, 948 const std::string& message,
960 bool delete_sync_database) { 949 bool delete_sync_database) {
961 DCHECK(HasUnrecoverableError()); 950 DCHECK(HasUnrecoverableError());
962 unrecoverable_error_message_ = message; 951 unrecoverable_error_message_ = message;
963 unrecoverable_error_location_ = from_here; 952 unrecoverable_error_location_ = from_here;
964 953
965 UMA_HISTOGRAM_ENUMERATION(kSyncUnrecoverableErrorHistogram, 954 UMA_HISTOGRAM_ENUMERATION(kSyncUnrecoverableErrorHistogram,
966 unrecoverable_error_reason_, 955 unrecoverable_error_reason_,
967 ERROR_REASON_LIMIT); 956 ERROR_REASON_LIMIT);
968 NotifyObservers();
maniscalco 2014/09/29 22:01:37 Given the comment for OnStateChange about notifyin
Nicolas Zea 2014/09/29 23:37:17 ShutDownImpl (posted just below) will trigger a No
969 std::string location; 957 std::string location;
970 from_here.Write(true, true, &location); 958 from_here.Write(true, true, &location);
971 LOG(ERROR) 959 LOG(ERROR)
972 << "Unrecoverable error detected at " << location 960 << "Unrecoverable error detected at " << location
973 << " -- ProfileSyncService unusable: " << message; 961 << " -- ProfileSyncService unusable: " << message;
974 962
975 // Shut all data types down. 963 // Shut all data types down.
976 base::MessageLoop::current()->PostTask(FROM_HERE, 964 base::MessageLoop::current()->PostTask(FROM_HERE,
977 base::Bind(&ProfileSyncService::ShutdownImpl, 965 base::Bind(&ProfileSyncService::ShutdownImpl,
978 weak_factory_.GetWeakPtr(), 966 weak_factory_.GetWeakPtr(),
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 migrator_->state() != browser_sync::BackendMigrator::IDLE) { 1549 migrator_->state() != browser_sync::BackendMigrator::IDLE) {
1562 // Migration in progress. Let the migrator know we just finished 1550 // Migration in progress. Let the migrator know we just finished
1563 // configuring something. It will be up to the migrator to call 1551 // configuring something. It will be up to the migrator to call
1564 // StartSyncingWithServer() if migration is now finished. 1552 // StartSyncingWithServer() if migration is now finished.
1565 migrator_->OnConfigureDone(result); 1553 migrator_->OnConfigureDone(result);
1566 } else { 1554 } else {
1567 StartSyncingWithServer(); 1555 StartSyncingWithServer();
1568 } 1556 }
1569 } 1557 }
1570 1558
1571 void ProfileSyncService::OnConfigureRetry() {
1572 // We should have cleared our cached passphrase before we get here (in
1573 // OnBackendInitialized()).
1574 DCHECK(cached_passphrase_.empty());
1575
1576 OnSyncConfigureRetry();
1577 }
1578
1579 void ProfileSyncService::OnConfigureStart() { 1559 void ProfileSyncService::OnConfigureStart() {
1580 sync_configure_start_time_ = base::Time::Now(); 1560 sync_configure_start_time_ = base::Time::Now();
1581 NotifyObservers(); 1561 NotifyObservers();
1582 } 1562 }
1583 1563
1584 ProfileSyncService::SyncStatusSummary 1564 ProfileSyncService::SyncStatusSummary
1585 ProfileSyncService::QuerySyncStatusSummary() { 1565 ProfileSyncService::QuerySyncStatusSummary() {
1586 if (HasUnrecoverableError()) { 1566 if (HasUnrecoverableError()) {
1587 return UNRECOVERABLE_ERROR; 1567 return UNRECOVERABLE_ERROR;
1588 } else if (!backend_) { 1568 } else if (!backend_) {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1789 return; 1769 return;
1790 } 1770 }
1791 1771
1792 UpdateSelectedTypesHistogram(sync_everything, chosen_types); 1772 UpdateSelectedTypesHistogram(sync_everything, chosen_types);
1793 sync_prefs_.SetKeepEverythingSynced(sync_everything); 1773 sync_prefs_.SetKeepEverythingSynced(sync_everything);
1794 1774
1795 if (directory_data_type_manager_.get()) 1775 if (directory_data_type_manager_.get())
1796 directory_data_type_manager_->ResetDataTypeErrors(); 1776 directory_data_type_manager_->ResetDataTypeErrors();
1797 ChangePreferredDataTypes(chosen_types); 1777 ChangePreferredDataTypes(chosen_types);
1798 AcknowledgeSyncedTypes(); 1778 AcknowledgeSyncedTypes();
1799 NotifyObservers();
1800 } 1779 }
1801 1780
1802 void ProfileSyncService::ChangePreferredDataTypes( 1781 void ProfileSyncService::ChangePreferredDataTypes(
1803 syncer::ModelTypeSet preferred_types) { 1782 syncer::ModelTypeSet preferred_types) {
1804 1783
1805 DVLOG(1) << "ChangePreferredDataTypes invoked"; 1784 DVLOG(1) << "ChangePreferredDataTypes invoked";
1806 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); 1785 const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes();
1807 const syncer::ModelTypeSet registered_preferred_types = 1786 const syncer::ModelTypeSet registered_preferred_types =
1808 Intersection(registered_types, preferred_types); 1787 Intersection(registered_types, preferred_types);
1809 sync_prefs_.SetPreferredDataTypes(registered_types, 1788 sync_prefs_.SetPreferredDataTypes(registered_types,
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
2217 } 2196 }
2218 2197
2219 syncer::ModelTypeSet ProfileSyncService::GetEncryptedDataTypes() const { 2198 syncer::ModelTypeSet ProfileSyncService::GetEncryptedDataTypes() const {
2220 DCHECK(encrypted_types_.Has(syncer::PASSWORDS)); 2199 DCHECK(encrypted_types_.Has(syncer::PASSWORDS));
2221 // We may be called during the setup process before we're 2200 // We may be called during the setup process before we're
2222 // initialized. In this case, we default to the sensitive types. 2201 // initialized. In this case, we default to the sensitive types.
2223 return encrypted_types_; 2202 return encrypted_types_;
2224 } 2203 }
2225 2204
2226 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) { 2205 void ProfileSyncService::OnSyncManagedPrefChange(bool is_sync_managed) {
2227 NotifyObservers();
2228 if (is_sync_managed) { 2206 if (is_sync_managed) {
2229 DisableForUser(); 2207 DisableForUser();
2230 } else { 2208 } else {
2231 // Sync is no longer disabled by policy. Try starting it up if appropriate. 2209 // Sync is no longer disabled by policy. Try starting it up if appropriate.
2232 startup_controller_.TryStart(); 2210 startup_controller_.TryStart();
2233 } 2211 }
2234 } 2212 }
2235 2213
2236 void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id, 2214 void ProfileSyncService::GoogleSigninSucceeded(const std::string& account_id,
2237 const std::string& username, 2215 const std::string& username,
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
2722 true)); 2700 true));
2723 } 2701 }
2724 2702
2725 bool ProfileSyncService::NeedBackup() const { 2703 bool ProfileSyncService::NeedBackup() const {
2726 return need_backup_; 2704 return need_backup_;
2727 } 2705 }
2728 2706
2729 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const { 2707 base::Time ProfileSyncService::GetDeviceBackupTimeForTesting() const {
2730 return device_info_sync_service_->GetLocalDeviceBackupTime(); 2708 return device_info_sync_service_->GetLocalDeviceBackupTime();
2731 } 2709 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service.h ('k') | chrome/browser/sync/profile_sync_service_mock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698