diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-31 02:08:43 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-31 02:08:43 +0000 |
commit | 1325b2b2a621627c099bece87725cc0eb582a891 (patch) | |
tree | d8e589df2ae7923364efb2e25c3d288068350d04 | |
parent | 6c6863ca1f1d713021026461bd2691fbf0293ea7 (diff) | |
download | chromium_src-1325b2b2a621627c099bece87725cc0eb582a891.zip chromium_src-1325b2b2a621627c099bece87725cc0eb582a891.tar.gz chromium_src-1325b2b2a621627c099bece87725cc0eb582a891.tar.bz2 |
[Sync] Split GetPreferredTypes into GetActiveTypes and GetPreferredTypes
GetPreferredDataTypes was being used as an accessor for getting the set of
active types. This has now been split into its own method, GetActiveDataTypes,
and GetPreferredDataTypes now just returns what the name implies, the set of
preferred types.
BUG=none
TBR=brettw@chromium.org, kinuko@chromium.org, dbeam@chromium.org
Review URL: https://chromiumcodereview.appspot.com/14789020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@203308 0039d316-1c4b-4281-b951-d872f2087c98
11 files changed, 34 insertions, 31 deletions
diff --git a/chrome/browser/history/web_history_service_factory.cc b/chrome/browser/history/web_history_service_factory.cc index e922bc0..00c1bf5 100644 --- a/chrome/browser/history/web_history_service_factory.cc +++ b/chrome/browser/history/web_history_service_factory.cc @@ -23,7 +23,7 @@ bool IsHistorySyncEnabled(Profile* profile) { ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); return sync && sync->sync_initialized() && - sync->GetPreferredDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES); + sync->GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES); } return false; } diff --git a/chrome/browser/password_manager/password_generation_manager.cc b/chrome/browser/password_manager/password_generation_manager.cc index f7715d3..81d18cb 100644 --- a/chrome/browser/password_manager/password_generation_manager.cc +++ b/chrome/browser/password_manager/password_generation_manager.cc @@ -130,7 +130,7 @@ void PasswordGenerationManager::UpdateState(content::RenderViewHost* host, ProfileSyncService* sync_service = ProfileSyncServiceFactory::GetForProfile(profile); if (sync_service) { - syncer::ModelTypeSet sync_set = sync_service->GetPreferredDataTypes(); + syncer::ModelTypeSet sync_set = sync_service->GetActiveDataTypes(); password_sync_enabled = (sync_service->HasSyncSetupCompleted() && sync_set.Has(syncer::PASSWORDS)); } diff --git a/chrome/browser/password_manager/password_generation_manager_unittest.cc b/chrome/browser/password_manager/password_generation_manager_unittest.cc index e474e03..3f4a75e 100644 --- a/chrome/browser/password_manager/password_generation_manager_unittest.cc +++ b/chrome/browser/password_manager/password_generation_manager_unittest.cc @@ -164,7 +164,7 @@ TEST_F(PasswordGenerationManagerTest, UpdatePasswordSyncState) { preferred_set.Put(syncer::EXTENSIONS); preferred_set.Put(syncer::PREFERENCES); sync_service->ChangePreferredDataTypes(preferred_set); - syncer::ModelTypeSet new_set = sync_service->GetPreferredDataTypes(); + syncer::ModelTypeSet new_set = sync_service->GetActiveDataTypes(); UpdateState(false); EXPECT_EQ(0u, password_generation_manager_->GetSentStates().size()); diff --git a/chrome/browser/sync/failed_datatypes_handler.cc b/chrome/browser/sync/failed_datatypes_handler.cc index effba20..a95dd09 100644 --- a/chrome/browser/sync/failed_datatypes_handler.cc +++ b/chrome/browser/sync/failed_datatypes_handler.cc @@ -20,7 +20,6 @@ syncer::ModelTypeSet GetTypesFromErrorsList( syncer::ModelTypeSet result; for (std::vector<syncer::SyncError>::const_iterator it = errors.begin(); it != errors.end(); ++it) { - DCHECK(!result.Has(it->type())); result.Put(it->type()); } return result; diff --git a/chrome/browser/sync/profile_sync_service.cc b/chrome/browser/sync/profile_sync_service.cc index 6dec2fd..471f1b4 100644 --- a/chrome/browser/sync/profile_sync_service.cc +++ b/chrome/browser/sync/profile_sync_service.cc @@ -203,10 +203,7 @@ bool ProfileSyncService::IsSyncTokenAvailable() { } #if defined(OS_ANDROID) bool ProfileSyncService::ShouldEnablePasswordSyncForAndroid() const { - const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); - const syncer::ModelTypeSet preferred_types = - sync_prefs_.GetPreferredDataTypes(registered_types); - if (!preferred_types.Has(syncer::PASSWORDS)) + if (!GetPreferredDataTypes().Has(syncer::PASSWORDS)) return false; // If backend has not completed initializing we cannot check if the // cryptographer is ready. @@ -263,8 +260,7 @@ void ProfileSyncService::TrySyncDatatypePrefRecovery() { PrefService* const pref_service = profile_->GetPrefs(); if (!pref_service) return; - const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); - if (sync_prefs_.GetPreferredDataTypes(registered_types).Size() > 1) + if (GetPreferredDataTypes().Size() > 1) return; const PrefService::Preference* keep_everything_synced = @@ -278,6 +274,7 @@ void ProfileSyncService::TrySyncDatatypePrefRecovery() { // types now, before we configure. UMA_HISTOGRAM_COUNTS("Sync.DatatypePrefRecovery", 1); sync_prefs_.SetKeepEverythingSynced(true); + syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); sync_prefs_.SetPreferredDataTypes(registered_types, registered_types); } @@ -560,7 +557,7 @@ void ProfileSyncService::OnDataTypeRequestsSyncStartup( return; } - if (!GetPreferredDataTypes().Has(type)) { + if (!GetActiveDataTypes().Has(type)) { // We can get here as datatype SyncableServices are typically wired up // to the native datatype even if sync isn't enabled. DVLOG(1) << "Dropping sync startup request because type " @@ -1146,8 +1143,7 @@ void ProfileSyncService::OnPassphraseAccepted() { // Make sure the data types that depend on the passphrase are started at // this time. - const syncer::ModelTypeSet types = GetPreferredDataTypes(); - + const syncer::ModelTypeSet types = GetActiveDataTypes(); if (data_type_manager_) { // Unblock the data type manager if necessary. data_type_manager_->Configure(types, @@ -1170,7 +1166,7 @@ void ProfileSyncService::OnEncryptedTypesChanged( // If sessions are encrypted, full history sync is not possible, and // delete directives are unnecessary. - if (GetPreferredDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && + if (GetActiveDataTypes().Has(syncer::HISTORY_DELETE_DIRECTIVES) && encrypted_types_.Has(syncer::SESSIONS)) { DisableBrokenDatatype(syncer::HISTORY_DELETE_DIRECTIVES, FROM_HERE, @@ -1437,8 +1433,6 @@ bool ProfileSyncService::IsPassphraseRequired() const { syncer::REASON_PASSPHRASE_NOT_REQUIRED; } -// TODO(zea): Rename this IsPassphraseNeededFromUI and ensure it's used -// appropriately (see http://crbug.com/91379). bool ProfileSyncService::IsPassphraseRequiredForDecryption() const { // If there is an encrypted datatype enabled and we don't have the proper // passphrase, we must prompt the user for a passphrase. The only way for the @@ -1554,13 +1548,18 @@ void ProfileSyncService::ChangePreferredDataTypes( ReconfigureDatatypeManager(); } +syncer::ModelTypeSet ProfileSyncService::GetActiveDataTypes() const { + const syncer::ModelTypeSet preferred_types = GetPreferredDataTypes(); + const syncer::ModelTypeSet failed_types = + failed_datatypes_handler_.GetFailedTypes(); + return Difference(preferred_types, failed_types); +} + syncer::ModelTypeSet ProfileSyncService::GetPreferredDataTypes() const { const syncer::ModelTypeSet registered_types = GetRegisteredDataTypes(); const syncer::ModelTypeSet preferred_types = sync_prefs_.GetPreferredDataTypes(registered_types); - const syncer::ModelTypeSet failed_types = - failed_datatypes_handler_.GetFailedTypes(); - return Difference(preferred_types, failed_types); + return preferred_types; } syncer::ModelTypeSet ProfileSyncService::GetRegisteredDataTypes() const { @@ -1643,13 +1642,12 @@ void ProfileSyncService::ConfigureDataTypeManager() { // datatypes, but we need to resolve crbug.com/226195 first. #if defined(OS_ANDROID) - if (GetPreferredDataTypes().Has(syncer::PASSWORDS) && + if (GetActiveDataTypes().Has(syncer::PASSWORDS) && !ShouldEnablePasswordSyncForAndroid()) { DisableBrokenDatatype(syncer::PASSWORDS, FROM_HERE, "Not supported."); } #endif - const syncer::ModelTypeSet types = GetPreferredDataTypes(); if (IsPassphraseRequiredForDecryption()) { // We need a passphrase still. We don't bother to attempt to configure // until we receive an OnPassphraseAccepted (which triggers a configure). @@ -1658,6 +1656,8 @@ void ProfileSyncService::ConfigureDataTypeManager() { NotifyObservers(); return; } + + const syncer::ModelTypeSet types = GetActiveDataTypes(); syncer::ConfigureReason reason = syncer::CONFIGURE_REASON_UNKNOWN; if (!HasSyncSetupCompleted()) { reason = syncer::CONFIGURE_REASON_NEW_CLIENT; diff --git a/chrome/browser/sync/profile_sync_service.h b/chrome/browser/sync/profile_sync_service.h index c8f8e039..a42cf16 100644 --- a/chrome/browser/sync/profile_sync_service.h +++ b/chrome/browser/sync/profile_sync_service.h @@ -126,6 +126,7 @@ class EncryptedData; // Additionally, the current sync configuration can be fetched by calling // * GetRegisteredDataTypes() // * GetPreferredDataTypes() +// * GetActiveDataTypes() // * IsUsingSecondaryPassphrase() // * EncryptEverythingEnabled() // * IsPassphraseRequired()/IsPassphraseRequiredForDecryption() @@ -233,7 +234,7 @@ class ProfileSyncService : public ProfileSyncServiceBase, // ProfileSyncServiceBase implementation. virtual bool HasSyncSetupCompleted() const OVERRIDE; virtual bool ShouldPushChanges() OVERRIDE; - virtual syncer::ModelTypeSet GetPreferredDataTypes() const OVERRIDE; + virtual syncer::ModelTypeSet GetActiveDataTypes() const OVERRIDE; virtual void AddObserver(Observer* observer) OVERRIDE; virtual void RemoveObserver(Observer* observer) OVERRIDE; virtual bool HasObserver(Observer* observer) const OVERRIDE; @@ -499,6 +500,10 @@ class ProfileSyncService : public ProfileSyncServiceBase, virtual void ChangePreferredDataTypes( syncer::ModelTypeSet preferred_types); + // Returns the set of types which are preferred for enabling. This is a + // superset of the active types (see GetActiveTypes()). + virtual syncer::ModelTypeSet GetPreferredDataTypes() const; + // Gets the set of all data types that could be allowed (the set that // should be advertised to the user). These will typically only change // via a command-line option. See class comment for more on what it means diff --git a/chrome/browser/sync/profile_sync_service_android.cc b/chrome/browser/sync/profile_sync_service_android.cc index 8a57d7d..9198bb1 100644 --- a/chrome/browser/sync/profile_sync_service_android.cc +++ b/chrome/browser/sync/profile_sync_service_android.cc @@ -464,7 +464,7 @@ jboolean ProfileSyncServiceAndroid::IsSyncKeystoreMigrationDone( jlong ProfileSyncServiceAndroid::GetEnabledDataTypes(JNIEnv* env, jobject obj) { jlong model_type_selection = 0; - syncer::ModelTypeSet types = sync_service_->GetPreferredDataTypes(); + syncer::ModelTypeSet types = sync_service_->GetActiveDataTypes(); types.PutAll(syncer::ControlTypes()); if (types.Has(syncer::BOOKMARKS)) { model_type_selection |= BOOKMARK; diff --git a/chrome/browser/sync/profile_sync_service_base.h b/chrome/browser/sync/profile_sync_service_base.h index dfb5386..c73ae31 100644 --- a/chrome/browser/sync/profile_sync_service_base.h +++ b/chrome/browser/sync/profile_sync_service_base.h @@ -31,10 +31,9 @@ class ProfileSyncServiceBase { // any model-modifying operations. virtual bool ShouldPushChanges() = 0; - // Get the set of currently enabled data types (as chosen or - // configured by the user). See class comment on ProfileSyncService - // for more on what it means for a datatype to be Preferred. - virtual syncer::ModelTypeSet GetPreferredDataTypes() const = 0; + // Get the set of current active data types (those chosen or configured by + // the user which have not also encountered a runtime error). + virtual syncer::ModelTypeSet GetActiveDataTypes() const = 0; // Adds/removes an observer. ProfileSyncServiceBase does not take // ownership of the observer. diff --git a/chrome/browser/sync/profile_sync_service_harness.cc b/chrome/browser/sync/profile_sync_service_harness.cc index 3d42e91..facbcaa 100644 --- a/chrome/browser/sync/profile_sync_service_harness.cc +++ b/chrome/browser/sync/profile_sync_service_harness.cc @@ -845,8 +845,8 @@ bool ProfileSyncServiceHarness::MatchesOtherClient( // Only look for a match if we have at least one enabled datatype in // common with the partner client. const syncer::ModelTypeSet common_types = - Intersection(service()->GetPreferredDataTypes(), - partner->service()->GetPreferredDataTypes()); + Intersection(service()->GetActiveDataTypes(), + partner->service()->GetActiveDataTypes()); DVLOG(2) << profile_debug_name_ << ", " << partner->profile_debug_name_ << ": common types are " diff --git a/chrome/browser/sync_file_system/sync_file_system_service.cc b/chrome/browser/sync_file_system/sync_file_system_service.cc index ca85aa3..4bdfe0c 100644 --- a/chrome/browser/sync_file_system/sync_file_system_service.cc +++ b/chrome/browser/sync_file_system/sync_file_system_service.cc @@ -564,7 +564,7 @@ void SyncFileSystemService::UpdateSyncEnabledStatus( ProfileSyncServiceBase* profile_sync_service) { if (!profile_sync_service->HasSyncSetupCompleted()) return; - sync_enabled_ = profile_sync_service->GetPreferredDataTypes().Has( + sync_enabled_ = profile_sync_service->GetActiveDataTypes().Has( syncer::APPS); remote_file_service_->SetSyncEnabled(sync_enabled_); if (sync_enabled_) { diff --git a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc index 61fa871..e8bb973 100644 --- a/chrome/browser/ui/webui/ntp/foreign_session_handler.cc +++ b/chrome/browser/ui/webui/ntp/foreign_session_handler.cc @@ -218,7 +218,7 @@ bool ForeignSessionHandler::IsTabSyncEnabled() { Profile* profile = Profile::FromWebUI(web_ui()); ProfileSyncService* service = ProfileSyncServiceFactory::GetInstance()->GetForProfile(profile); - return service && service->GetPreferredDataTypes().Has(syncer::PROXY_TABS); + return service && service->GetActiveDataTypes().Has(syncer::PROXY_TABS); } string16 ForeignSessionHandler::FormatSessionTime(const base::Time& time) { |