diff --git a/chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller.cc b/chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller.cc index dadae59b05d111..8bcfb02abfddc6 100644 --- a/chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller.cc +++ b/chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller.cc @@ -200,11 +200,14 @@ void ItemsBubbleController::AuthenticateUserAndDisplayDetailsOf( // bubble is closed (and controller is destructed) while the reauth flow is // running, no callback will be invoked upon the conclusion of the // authentication flow. - delegate_->AuthenticateUserWithMessage( - message, + auto on_reath_complete = base::BindOnce(&ItemsBubbleController::OnUserAuthenticationCompleted, weak_ptr_factory_.GetWeakPtr(), std::move(password_form), - std::move(completion))); + std::move(completion)); + delegate_->AuthenticateUserWithMessage( + message, metrics_util::TimeCallback( + std::move(on_reath_complete), + "PasswordManager.ManagementBubble.AuthenticationTime")); } bool ItemsBubbleController::UsernameExists(const std::u16string& username) { diff --git a/chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller_unittest.cc b/chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller_unittest.cc index 05a03057daad77..c61fa4519c5498 100644 --- a/chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller_unittest.cc +++ b/chrome/browser/ui/passwords/bubble_controllers/items_bubble_controller_unittest.cc @@ -100,8 +100,11 @@ class ItemsBubbleControllerTest : public ::testing::Test { GetCurrentForms() const; void DestroyController(); + base::test::TaskEnvironment& task_environment() { return task_environment_; } + private: - content::BrowserTaskEnvironment task_environment_; + content::BrowserTaskEnvironment task_environment_{ + base::test::TaskEnvironment::TimeSource::MOCK_TIME}; content::RenderViewHostTestEnabler rvh_enabler_; std::unique_ptr profile_; raw_ptr test_sync_service_; @@ -310,12 +313,18 @@ TEST_F(ItemsBubbleControllerTest, OnUpdateUsernameAndPasswordNote) { TEST_F(ItemsBubbleControllerTest, ShouldChangeSelectedPasswordOnSuccessfulOsAuth) { + // The time it takes the user to complete the authentication flow in seconds. + const int kTimeToAuth = 10; + base::HistogramTester histogram_tester; Init(); password_manager::PasswordForm selected_form = CreateTestForm(); EXPECT_CALL(*delegate(), AuthenticateUserWithMessage) .WillOnce(testing::WithArg<1>(testing::Invoke( [&](PasswordsModelDelegate::AvailabilityCallback callback) { + // Waiting for kTimeToAuth seconds to simulate the time user will + // need to authenticate + task_environment().FastForwardBy(base::Seconds(kTimeToAuth)); // Respond with true to simulate a successful user reauth. std::move(callback).Run(true); }))); @@ -323,6 +332,9 @@ TEST_F(ItemsBubbleControllerTest, EXPECT_CALL(mock_callback, Run(true)); controller()->AuthenticateUserAndDisplayDetailsOf(selected_form, mock_callback.Get()); + histogram_tester.ExpectUniqueTimeSample( + "PasswordManager.ManagementBubble.AuthenticationTime", + base::Seconds(kTimeToAuth), 1); EXPECT_EQ(controller()->get_currently_selected_password(), selected_form); } diff --git a/tools/metrics/histograms/metadata/password/histograms.xml b/tools/metrics/histograms/metadata/password/histograms.xml index a454cd238fcd19..163868d4bff3a2 100644 --- a/tools/metrics/histograms/metadata/password/histograms.xml +++ b/tools/metrics/histograms/metadata/password/histograms.xml @@ -3761,11 +3761,13 @@ chromium-metrics-reviews@google.com. + expires_after="M120"> vsemeniuk@google.com vasilii@chromium.org Records the time it takes user to authenticate {Location}. +