forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added bulk password check API endpoint for Android
Bug: 1070620 Change-Id: I79ce779a1e11b32ae2d83f95e10160ffa7132450 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2232939 Commit-Queue: Andrey Zaytsev <andzaytsev@google.com> Reviewed-by: Colin Blundell <blundell@chromium.org> Reviewed-by: Ioana Pandele <ioanap@chromium.org> Auto-Submit: Andrey Zaytsev <andzaytsev@google.com> Cr-Commit-Position: refs/heads/master@{#777002}
- Loading branch information
Andrey Zaytsev
authored and
Commit Bot
committed
Jun 10, 2020
1 parent
1312dd5
commit 0085860
Showing
7 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2020 The Chromium Authors. All rights reserved. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# found in the LICENSE file. | ||
|
||
import("//build/config/android/rules.gni") | ||
|
||
source_set("android") { | ||
sources = [ | ||
"bulk_leak_check_controller_android.cc", | ||
"bulk_leak_check_controller_android.h", | ||
] | ||
deps = [ "//components/password_manager/core/browser" ] | ||
} | ||
|
||
source_set("unit_tests") { | ||
testonly = true | ||
sources = [ "bulk_leak_check_controller_android_unittest.cc" ] | ||
deps = [ | ||
":android", | ||
"//testing/gmock", | ||
"//testing/gtest", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
ioanap@chromium.org | ||
andzaytsev@google.com | ||
|
||
# COMPONENT: UI>Browser>Passwords | ||
# TEAM: chromium-dev@chromium.org |
34 changes: 34 additions & 0 deletions
34
chrome/browser/password_check/android/bulk_leak_check_controller_android.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/password_check/android/bulk_leak_check_controller_android.h" | ||
|
||
BulkLeakCheckControllerAndroid::BulkLeakCheckControllerAndroid() = default; | ||
|
||
BulkLeakCheckControllerAndroid::~BulkLeakCheckControllerAndroid() = default; | ||
|
||
void BulkLeakCheckControllerAndroid::AddObserver(Observer* obs) { | ||
observers_.AddObserver(obs); | ||
} | ||
|
||
void BulkLeakCheckControllerAndroid::RemoveObserver(Observer* obs) { | ||
observers_.RemoveObserver(obs); | ||
} | ||
|
||
void BulkLeakCheckControllerAndroid::StartPasswordCheck() { | ||
// TODO(crbug.com/1092444): connect with the actual passwords check logic. | ||
for (Observer& obs : observers_) { | ||
obs.OnStateChanged(password_manager::BulkLeakCheckService::State::kIdle); | ||
} | ||
} | ||
|
||
int BulkLeakCheckControllerAndroid::GetNumberOfSavedPasswords() { | ||
// TODO(crbug.com/1092444): connect with the actual passwords check logic. | ||
return 0; | ||
} | ||
|
||
int BulkLeakCheckControllerAndroid::GetNumberOfLeaksFromLastCheck() { | ||
// TODO(crbug.com/1092444): connect with the actual passwords check logic. | ||
return 0; | ||
} |
57 changes: 57 additions & 0 deletions
57
chrome/browser/password_check/android/bulk_leak_check_controller_android.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CHROME_BROWSER_PASSWORD_CHECK_ANDROID_BULK_LEAK_CHECK_CONTROLLER_ANDROID_H_ | ||
#define CHROME_BROWSER_PASSWORD_CHECK_ANDROID_BULK_LEAK_CHECK_CONTROLLER_ANDROID_H_ | ||
|
||
#include "base/observer_list.h" | ||
#include "components/password_manager/core/browser/bulk_leak_check_service.h" | ||
|
||
// This controller allows Android code to interact with the bulk credential leak | ||
// check. Supported interactions include starting the password check, as well as | ||
// getting notified when the state is changed and when each credential is | ||
// checked. | ||
class BulkLeakCheckControllerAndroid { | ||
public: | ||
class Observer : public base::CheckedObserver { | ||
public: | ||
using DoneCount = util::StrongAlias<class DoneCountTag, int>; | ||
using TotalCount = util::StrongAlias<class TotalCountTag, int>; | ||
|
||
// Invoked on every observer whenever the state of the bulk leak check | ||
// changes. | ||
virtual void OnStateChanged( | ||
password_manager::BulkLeakCheckService::State state) = 0; | ||
|
||
// Invoked on every observer whenever a new credential is successfully | ||
// checked. | ||
virtual void OnCredentialDone( | ||
const password_manager::LeakCheckCredential& credential, | ||
password_manager::IsLeaked is_leaked, | ||
DoneCount credentials_checked, | ||
TotalCount total_to_check) = 0; | ||
}; | ||
|
||
BulkLeakCheckControllerAndroid(); | ||
~BulkLeakCheckControllerAndroid(); | ||
|
||
void AddObserver(Observer* obs); | ||
void RemoveObserver(Observer* obs); | ||
|
||
// Starts the bulk passwords check using all the saved credentials in the | ||
// user's password store. | ||
void StartPasswordCheck(); | ||
|
||
// Returns the total number of passwords saved by the user. | ||
int GetNumberOfSavedPasswords(); | ||
|
||
// Returns the last known number of leaked password as of the latest check. | ||
// Does not affect the state of the bulk leak check. | ||
int GetNumberOfLeaksFromLastCheck(); | ||
|
||
private: | ||
base::ObserverList<Observer> observers_; | ||
}; | ||
|
||
#endif // CHROME_BROWSER_PASSWORD_CHECK_ANDROID_BULK_LEAK_CHECK_CONTROLLER_ANDROID_H_ |
55 changes: 55 additions & 0 deletions
55
chrome/browser/password_check/android/bulk_leak_check_controller_android_unittest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "chrome/browser/password_check/android/bulk_leak_check_controller_android.h" | ||
|
||
#include "testing/gmock/include/gmock/gmock.h" | ||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
using password_manager::BulkLeakCheckService; | ||
using password_manager::IsLeaked; | ||
using password_manager::LeakCheckCredential; | ||
using ::testing::AtLeast; | ||
using ::testing::NiceMock; | ||
|
||
namespace { | ||
class MockObserver : public BulkLeakCheckControllerAndroid::Observer { | ||
public: | ||
MOCK_METHOD(void, | ||
OnStateChanged, | ||
(BulkLeakCheckService::State state), | ||
(override)); | ||
|
||
MOCK_METHOD(void, | ||
OnCredentialDone, | ||
(const LeakCheckCredential& credential, | ||
IsLeaked is_leaked, | ||
DoneCount credentials_checked, | ||
TotalCount total_to_check), | ||
(override)); | ||
}; | ||
} // namespace | ||
|
||
class BulkLeakCheckControllerAndroidTest : public testing::Test { | ||
public: | ||
BulkLeakCheckControllerAndroidTest() { controller_.AddObserver(&observer_); } | ||
|
||
protected: | ||
BulkLeakCheckControllerAndroid controller_; | ||
NiceMock<MockObserver> observer_; | ||
}; | ||
|
||
TEST_F(BulkLeakCheckControllerAndroidTest, StartPasswordCheck) { | ||
EXPECT_CALL(observer_, OnStateChanged(BulkLeakCheckService::State::kIdle)) | ||
.Times(1); | ||
controller_.StartPasswordCheck(); | ||
} | ||
|
||
TEST_F(BulkLeakCheckControllerAndroidTest, GetNumberOfSavedPasswords) { | ||
EXPECT_EQ(0, controller_.GetNumberOfSavedPasswords()); | ||
} | ||
|
||
TEST_F(BulkLeakCheckControllerAndroidTest, GetNumberOfLeaksFromLastCheck) { | ||
EXPECT_EQ(0, controller_.GetNumberOfLeaksFromLastCheck()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters