Skip to content

Commit

Permalink
Added bulk password check API endpoint for Android
Browse files Browse the repository at this point in the history
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
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 0 deletions.
1 change: 1 addition & 0 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3037,6 +3037,7 @@ static_library("browser") {
"//chrome/browser/notifications/scheduler/public",
"//chrome/browser/offline_pages/prefetch/notifications",
"//chrome/browser/optimization_guide/android:jni_headers",
"//chrome/browser/password_check/android",
"//chrome/browser/payments/android:jni_headers",
"//chrome/browser/safety_check/android",
"//chrome/browser/share",
Expand Down
23 changes: 23 additions & 0 deletions chrome/browser/password_check/android/BUILD.gn
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",
]
}
5 changes: 5 additions & 0 deletions chrome/browser/password_check/android/OWNERS
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
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;
}
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_
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());
}
1 change: 1 addition & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3924,6 +3924,7 @@ test("unit_tests") {
"//chrome/android/features/media_router:java",
"//chrome/browser/optimization_guide/android:native_j_unittests_jni_headers",
"//chrome/browser/optimization_guide/android:native_java_unittests",
"//chrome/browser/password_check/android:unit_tests",
"//chrome/browser/thumbnail:unit_tests",
"//chrome/browser/updates:unit_tests",
"//chrome/services/media_gallery_util:unit_tests",
Expand Down

0 comments on commit 0085860

Please sign in to comment.