Commit 84d56293 authored by Ramin Halavati's avatar Ramin Halavati Committed by Chromium LUCI CQ

Add Guest profile lifetime metric.

Adds Profile.Guest.Ephemeral.Lifetime and Profile.Guest.OTR.Lifetime
metrics to separately measure the life time of ephemeral and off the
record Guest profiles.

Bug: 1125474
Change-Id: I30b576b330367629198f800a5fea1248a7c65810
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2574848Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarCaitlin Fischer <caitlinfischer@google.com>
Commit-Queue: Ramin Halavati <rhalavati@chromium.org>
Cr-Commit-Position: refs/heads/master@{#834697}
parent bd74662a
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/task/thread_pool/thread_pool_instance.h" #include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/bind.h" #include "base/test/bind.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "base/values.h" #include "base/values.h"
...@@ -40,6 +41,7 @@ ...@@ -40,6 +41,7 @@
#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/profiles/profile_observer.h" #include "chrome/browser/profiles/profile_observer.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
...@@ -223,6 +225,28 @@ void SpinThreads() { ...@@ -223,6 +225,28 @@ void SpinThreads() {
base::ThreadPoolInstance::Get()->FlushForTesting(); base::ThreadPoolInstance::Get()->FlushForTesting();
} }
class BrowserCloseObserver : public BrowserListObserver {
public:
explicit BrowserCloseObserver(Browser* browser) : browser_(browser) {
BrowserList::AddObserver(this);
}
~BrowserCloseObserver() override { BrowserList::RemoveObserver(this); }
void Wait() { run_loop_.Run(); }
// BrowserListObserver implementation.
void OnBrowserRemoved(Browser* browser) override {
if (browser == browser_)
run_loop_.Quit();
}
private:
Browser* browser_;
base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(BrowserCloseObserver);
};
} // namespace } // namespace
class ProfileBrowserTest : public InProcessBrowserTest { class ProfileBrowserTest : public InProcessBrowserTest {
...@@ -921,6 +945,30 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ...@@ -921,6 +945,30 @@ IN_PROC_BROWSER_TEST_F(ProfileBrowserTest,
} }
#if !defined(OS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH) #if !defined(OS_ANDROID) && !BUILDFLAG(IS_CHROMEOS_ASH)
// TODO(https://crbug.com/1125474): Expand to cover ChromeOS.
IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileLifetimeTestUnderOneMinute) {
base::HistogramTester tester;
Browser* browser = CreateGuestBrowser();
BrowserCloseObserver close_observer(browser);
BrowserList::CloseAllBrowsersWithProfile(browser->profile());
close_observer.Wait();
tester.ExpectUniqueSample("Profile.Guest.OTR.Lifetime", 0, 1);
}
IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileLifetimeTestOneHour) {
base::HistogramTester tester;
Browser* browser = CreateGuestBrowser();
BrowserCloseObserver close_observer(browser);
browser->profile()->SetCreationTimeForTesting(
base::Time::Now() - base::TimeDelta::FromSeconds(60) * 60);
BrowserList::CloseAllBrowsersWithProfile(browser->profile());
close_observer.Wait();
tester.ExpectUniqueSample("Profile.Guest.OTR.Lifetime", 60, 1);
}
class EphemeralGuestProfileBrowserTest : public ProfileBrowserTest { class EphemeralGuestProfileBrowserTest : public ProfileBrowserTest {
public: public:
EphemeralGuestProfileBrowserTest() { EphemeralGuestProfileBrowserTest() {
...@@ -942,6 +990,30 @@ IN_PROC_BROWSER_TEST_F(EphemeralGuestProfileBrowserTest, TestProfileType) { ...@@ -942,6 +990,30 @@ IN_PROC_BROWSER_TEST_F(EphemeralGuestProfileBrowserTest, TestProfileType) {
EXPECT_TRUE(guest_profile->IsEphemeralGuestProfile()); EXPECT_TRUE(guest_profile->IsEphemeralGuestProfile());
} }
IN_PROC_BROWSER_TEST_F(EphemeralGuestProfileBrowserTest,
ProfileLifetimeTestUnderOneMinute) {
base::HistogramTester tester;
Browser* browser = CreateGuestBrowser();
BrowserCloseObserver close_observer(browser);
BrowserList::CloseAllBrowsersWithProfile(browser->profile());
close_observer.Wait();
tester.ExpectUniqueSample("Profile.Guest.Ephemeral.Lifetime", 0, 1);
}
IN_PROC_BROWSER_TEST_F(EphemeralGuestProfileBrowserTest,
ProfileLifetimeTestOneHour) {
base::HistogramTester tester;
Browser* browser = CreateGuestBrowser();
BrowserCloseObserver close_observer(browser);
browser->profile()->SetCreationTimeForTesting(
base::Time::Now() - base::TimeDelta::FromSeconds(60) * 60);
BrowserList::CloseAllBrowsersWithProfile(browser->profile());
close_observer.Wait();
tester.ExpectUniqueSample("Profile.Guest.Ephemeral.Lifetime", 60, 1);
}
// Tests if ephemeral Guest profile paths are persistent as long as one does not // Tests if ephemeral Guest profile paths are persistent as long as one does not
// close all Guest browsers. // close all Guest browsers.
IN_PROC_BROWSER_TEST_F(EphemeralGuestProfileBrowserTest, IN_PROC_BROWSER_TEST_F(EphemeralGuestProfileBrowserTest,
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "base/files/file_enumerator.h" #include "base/files/file_enumerator.h"
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/file_util.h" #include "base/files/file_util.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
...@@ -1994,8 +1995,20 @@ void ProfileManager::OnBrowserClosed(Browser* browser) { ...@@ -1994,8 +1995,20 @@ void ProfileManager::OnBrowserClosed(Browser* browser) {
return; return;
} }
if (profile->IsGuestSession() || profile->IsEphemeralGuestProfile()) if (profile->IsGuestSession() || profile->IsEphemeralGuestProfile()) {
auto duration = base::Time::Now() - profile->GetCreationTime();
if (profile->IsEphemeralGuestProfile()) {
base::UmaHistogramCustomCounts(
"Profile.Guest.Ephemeral.Lifetime", duration.InMinutes(), 1,
base::TimeDelta::FromDays(28).InMinutes(), 100);
} else {
base::UmaHistogramCustomCounts(
"Profile.Guest.OTR.Lifetime", duration.InMinutes(), 1,
base::TimeDelta::FromDays(28).InMinutes(), 100);
}
CleanUpGuestProfile(); CleanUpGuestProfile();
}
#if !BUILDFLAG(IS_CHROMEOS_ASH) #if !BUILDFLAG(IS_CHROMEOS_ASH)
ProfileAttributesEntry* entry; ProfileAttributesEntry* entry;
......
...@@ -207,6 +207,20 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -207,6 +207,20 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
<summary>Size of the favicons database.</summary> <summary>Size of the favicons database.</summary>
</histogram> </histogram>
<histogram name="Profile.Guest.{Type}.Lifetime" units="minutes"
expires_after="2021-06-01">
<owner>rhalavati@chromium.org</owner>
<owner>chrome-privacy-core@google.com</owner>
<summary>
This histogram records the lifetime duration of {Type} Guest profiles. It is
recorded once the profile for an {Type} Guest session is closed.
</summary>
<token key="Type">
<variant name="Ephemeral"/>
<variant name="OTR"/>
</token>
</histogram>
<histogram name="Profile.HistorySize" units="MB" expires_after="M82"> <histogram name="Profile.HistorySize" units="MB" expires_after="M82">
<owner>hajimehoshi@chromium.org</owner> <owner>hajimehoshi@chromium.org</owner>
<owner>kouhei@chromium.org</owner> <owner>kouhei@chromium.org</owner>
......
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