Commit 66a8b746 authored by Mohamed Amir Yosef's avatar Mohamed Amir Yosef Committed by Commit Bot

[Passwords] PasswordFeatureManager::ShouldCheckReuseOnLeakDetection()

This CL moves the logic to decide whether leaked passwords should be
checked for reuse or not to PasswordFeatureManager class.

This will simplify the code when introducing Butter4Passwords.

Change-Id: I0ab39edfe84f089ded5fc530e53a36d5c87c0958

Bug: 1001122
Change-Id: Ib5c9a1087bf4ba601d1643b2217c279449004dbf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1789586
Commit-Queue: Mohamed Amir Yosef <mamir@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#694816}
parent d3e6d0d7
......@@ -11,6 +11,7 @@
#include "components/password_manager/core/browser/leak_detection/leak_detection_check_factory_impl.h"
#include "components/password_manager/core/browser/leak_detection_delegate_helper.h"
#include "components/password_manager/core/browser/leak_detection_dialog_utils.h"
#include "components/password_manager/core/browser/password_feature_manager.h"
#include "components/password_manager/core/browser/password_manager_client.h"
#include "components/password_manager/core/browser/password_manager_util.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
......@@ -58,9 +59,11 @@ void LeakDetectionDelegate::OnLeakDetectionDone(bool is_leaked,
logger.LogBoolean(Logger::STRING_LEAK_DETECTION_FINISHED, is_leaked);
}
if (is_leaked) {
if (client_->GetPasswordSyncState() != SYNCING_NORMAL_ENCRYPTION) {
// If the credentials are not synced, the |CredentialLeakType| needed to
// show the correct notification is already determined.
if (!client_->GetPasswordFeatureManager()
->ShouldCheckReuseOnLeakDetection()) {
// If we should not check leaked password reuse, then the
// |CredentialLeakType| needed to show the correct notification is already
// determined.
OnShowLeakDetectionNotification(
CreateLeakType(IsSaved(false), IsReused(false), IsSyncing(false)),
std::move(url), std::move(username));
......
......@@ -16,6 +16,7 @@ class MockPasswordFeatureManager : public PasswordFeatureManager {
~MockPasswordFeatureManager() override;
MOCK_CONST_METHOD0(IsGenerationEnabled, bool());
MOCK_CONST_METHOD0(ShouldCheckReuseOnLeakDetection, bool());
};
} // namespace password_manager
......
......@@ -17,6 +17,11 @@ class PasswordFeatureManager {
virtual bool IsGenerationEnabled() const = 0;
// Whether we should, upon the detection of a leaked password, check if the
// same password is reused on other website. That's used only for the UI
// string.
virtual bool ShouldCheckReuseOnLeakDetection() const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(PasswordFeatureManager);
};
......
......@@ -23,4 +23,17 @@ bool PasswordFeatureManagerImpl::IsGenerationEnabled() const {
}
}
bool PasswordFeatureManagerImpl::ShouldCheckReuseOnLeakDetection() const {
switch (password_manager_util::GetPasswordSyncState(sync_service_)) {
// We currently check the reuse of the leaked password only for users who
// can access passwords.google.com. Therefore, if the credentials are not
// synced, no need to check for password use.
case NOT_SYNCING:
case SYNCING_WITH_CUSTOM_PASSPHRASE:
return false;
case SYNCING_NORMAL_ENCRYPTION:
return true;
}
}
} // namespace password_manager
......@@ -23,6 +23,8 @@ class PasswordFeatureManagerImpl : public PasswordFeatureManager {
bool IsGenerationEnabled() const override;
bool ShouldCheckReuseOnLeakDetection() const override;
private:
const syncer::SyncService* const sync_service_;
DISALLOW_COPY_AND_ASSIGN(PasswordFeatureManagerImpl);
......
......@@ -18,6 +18,8 @@ class WebViewPasswordFeatureManager
bool IsGenerationEnabled() const override;
bool ShouldCheckReuseOnLeakDetection() const override;
private:
DISALLOW_COPY_AND_ASSIGN(WebViewPasswordFeatureManager);
};
......
......@@ -14,4 +14,8 @@ bool WebViewPasswordFeatureManager::IsGenerationEnabled() const {
return false;
}
bool WebViewPasswordFeatureManager::ShouldCheckReuseOnLeakDetection() const {
return false;
}
} // namespace ios_web_view
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