Commit 8d720de8 authored by edchin's avatar edchin Committed by Commit Bot

[ios][PhishGuard] Port code to ios_chrome_password_store_factory

Design doc: go/bling-phishguard

The password_store_factory had already been forked between
//chrome and //ios. This CL ports password reuse detection code
from //chrome into the //ios implementation.

Runtime changes are behind the kPasswordReuseDetectionEnabled
feature flag.

Bug: 1147962
Change-Id: Iaa5c31759383870753ab94aac14f798ab6634cfe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2544748
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828562}
parent 868cc225
......@@ -63,6 +63,7 @@ source_set("passwords") {
"//components/password_manager/ios",
"//components/prefs",
"//components/security_state/core",
"//components/signin/public/identity_manager",
"//components/strings",
"//components/sync",
"//components/translate/core/browser:browser",
......
......@@ -9,6 +9,7 @@
#include "base/callback_helpers.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/no_destructor.h"
#include "base/sequenced_task_runner.h"
#include "base/task/post_task.h"
......@@ -20,15 +21,39 @@
#include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/browser/password_store_default.h"
#include "components/password_manager/core/browser/password_store_factory_util.h"
#include "components/password_manager/core/browser/password_store_signin_notifier_impl.h"
#include "components/password_manager/core/common/password_manager_features.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/sync/driver/sync_service.h"
#include "ios/chrome/browser/application_context.h"
#include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/passwords/credentials_cleaner_runner_factory.h"
#include "ios/chrome/browser/signin/identity_manager_factory.h"
#include "ios/chrome/browser/sync/profile_sync_service_factory.h"
#include "ios/chrome/browser/webdata_services/web_data_service_factory.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace {
bool IsPasswordReuseDetectionEnabled() {
return base::FeatureList::IsEnabled(
password_manager::features::kPasswordReuseDetectionEnabled);
}
std::string GetSyncUsername(signin::IdentityManager* identity_manager) {
return identity_manager ? identity_manager->GetPrimaryAccountInfo().email
: std::string();
}
bool IsSignedIn(signin::IdentityManager* identity_manager) {
return identity_manager
? !identity_manager->GetAccountsWithRefreshTokens().empty()
: false;
}
} // namespace
// static
scoped_refptr<password_manager::PasswordStore>
IOSChromePasswordStoreFactory::GetForBrowserState(
......@@ -69,6 +94,12 @@ IOSChromePasswordStoreFactory::IOSChromePasswordStoreFactory()
"PasswordStore",
BrowserStateDependencyManager::GetInstance()) {
DependsOn(ios::WebDataServiceFactory::GetInstance());
if (IsPasswordReuseDetectionEnabled()) {
// TODO(crbug.com/715987). Remove when PasswordReuseDetector is decoupled
// from PasswordStore.
DependsOn(IdentityManagerFactory::GetInstance());
}
}
IOSChromePasswordStoreFactory::~IOSChromePasswordStoreFactory() {}
......@@ -99,6 +130,19 @@ IOSChromePasswordStoreFactory::BuildServiceInstanceFor(
LOG(WARNING) << "Could not initialize password store.";
return nullptr;
}
if (IsPasswordReuseDetectionEnabled()) {
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForBrowserState(
ChromeBrowserState::FromBrowserState(context));
store->PreparePasswordHashData(GetSyncUsername(identity_manager),
IsSignedIn(identity_manager));
store->SetPasswordStoreSigninNotifier(
std::make_unique<password_manager::PasswordStoreSigninNotifierImpl>(
identity_manager));
}
password_manager_util::RemoveUselessCredentials(
CredentialsCleanerRunnerFactory::GetForBrowserState(context), store,
ChromeBrowserState::FromBrowserState(context)->GetPrefs(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment