| // Copyright 2018 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "components/password_manager/core/browser/sync/password_model_type_controller.h" |
| |
| #include <utility> |
| |
| #include "base/feature_list.h" |
| #include "base/metrics/histogram_functions.h" |
| #include "base/task/sequenced_task_runner.h" |
| #include "build/build_config.h" |
| #include "components/password_manager/core/browser/features/password_features.h" |
| #include "components/password_manager/core/browser/features/password_manager_features_util.h" |
| #include "components/signin/public/identity_manager/accounts_in_cookie_jar_info.h" |
| #include "components/sync/base/features.h" |
| #include "components/sync/base/model_type.h" |
| #include "components/sync/base/passphrase_enums.h" |
| #include "components/sync/model/model_type_controller_delegate.h" |
| #include "components/sync/service/sync_service.h" |
| |
| namespace password_manager { |
| |
| PasswordModelTypeController::PasswordModelTypeController( |
| std::unique_ptr<syncer::ModelTypeControllerDelegate> |
| delegate_for_full_sync_mode, |
| std::unique_ptr<syncer::ModelTypeControllerDelegate> |
| delegate_for_transport_mode, |
| PrefService* pref_service, |
| signin::IdentityManager* identity_manager, |
| syncer::SyncService* sync_service) |
| : ModelTypeController(syncer::PASSWORDS, |
| std::move(delegate_for_full_sync_mode), |
| std::move(delegate_for_transport_mode)), |
| pref_service_(pref_service), |
| identity_manager_(identity_manager), |
| sync_service_(sync_service) { |
| identity_manager_observation_.Observe(identity_manager_); |
| } |
| |
| PasswordModelTypeController::~PasswordModelTypeController() = default; |
| |
| void PasswordModelTypeController::LoadModels( |
| const syncer::ConfigureContext& configure_context, |
| const ModelLoadCallback& model_load_callback) { |
| DCHECK(CalledOnValidThread()); |
| syncer::ConfigureContext overridden_context = configure_context; |
| if (features_util::CanCreateAccountStore(pref_service_) && |
| base::FeatureList::IsEnabled( |
| syncer::kEnablePasswordsAccountStorageForSyncingUsers)) { |
| overridden_context.sync_mode = syncer::SyncMode::kTransportOnly; |
| } |
| ModelTypeController::LoadModels(overridden_context, model_load_callback); |
| } |
| |
| void PasswordModelTypeController::Stop(syncer::SyncStopMetadataFate fate, |
| StopCallback callback) { |
| DCHECK(CalledOnValidThread()); |
| ModelTypeController::Stop(fate, std::move(callback)); |
| } |
| |
| void PasswordModelTypeController::OnAccountsInCookieUpdated( |
| const signin::AccountsInCookieJarInfo& accounts_in_cookie_jar_info, |
| const GoogleServiceAuthError& error) { |
| #if !BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_ANDROID) |
| // If the account information is stale, do nothing for now - wait until there |
| // is fresh information. |
| if (!accounts_in_cookie_jar_info.accounts_are_fresh) { |
| return; |
| } |
| // Collect all the known accounts (signed-in or signed-out). |
| std::vector<std::string> gaia_ids; |
| for (const gaia::ListedAccount& account : |
| accounts_in_cookie_jar_info.signed_in_accounts) { |
| gaia_ids.push_back(account.gaia_id); |
| } |
| for (const gaia::ListedAccount& account : |
| accounts_in_cookie_jar_info.signed_out_accounts) { |
| gaia_ids.push_back(account.gaia_id); |
| } |
| // Keep any account-storage settings only for known accounts. |
| features_util::KeepAccountStorageSettingsOnlyForUsers(pref_service_, |
| gaia_ids); |
| #endif // !BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_ANDROID) |
| } |
| |
| void PasswordModelTypeController::OnAccountsCookieDeletedByUserAction() { |
| #if !BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_ANDROID) |
| features_util::KeepAccountStorageSettingsOnlyForUsers(pref_service_, {}); |
| #endif // !BUILDFLAG(IS_IOS) && !BUILDFLAG(IS_ANDROID) |
| } |
| |
| } // namespace password_manager |