Skip to content

Commit

Permalink
Reland "[ios][PhishGuard] Port code to ios_chrome_password_store_fact…
Browse files Browse the repository at this point in the history
…ory"

This reverts commit cac286d.

Reason for revert:
This should have been landed after the CL to move the
password_store_signin_notifier_impl.


Original change's description:
> Revert "[ios][PhishGuard] Port code to ios_chrome_password_store_factory"
>
> This reverts commit 8d720de.
>
> Reason for revert: Compile failure on ios-device
>
> 'components/password_manager/core/browser/password_store_signin_notifier_impl.h' file not found
>
> https://ci.chromium.org/p/chromium/builders/ci/ios-device/172358
>
> Original change's description:
> > [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: Vasilii Sukhanov <vasilii@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#828562}
>
> TBR=vasilii@chromium.org,edchin@chromium.org
>
> Change-Id: I2286176790447a0dc192c01a6f4a888699f77c70
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: 1147962
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2546302
> Reviewed-by: Jiewei Qian  <qjw@chromium.org>
> Commit-Queue: Jiewei Qian  <qjw@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#828566}

TBR=vasilii@chromium.org,edchin@chromium.org,qjw@chromium.org

# Not skipping CQ checks because this is a reland.

Bug: 1147962
Change-Id: I5771528c764e83a7ce50f382eb65b93097283c1b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2546172
Reviewed-by: Vasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828831}
  • Loading branch information
edx246 authored and Commit Bot committed Nov 18, 2020
1 parent d82c9ff commit 7ab19b7
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions ios/chrome/browser/passwords/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 44 additions & 0 deletions ios/chrome/browser/passwords/ios_chrome_password_store_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -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() {}
Expand Down Expand Up @@ -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(),
Expand Down

0 comments on commit 7ab19b7

Please sign in to comment.