Add P3A metrics for Android Privacy Hub report

This commit is contained in:
Darnell Andries
2023-06-16 11:48:11 -07:00
parent 912eda9368
commit e1427279b3
26 changed files with 355 additions and 2 deletions
+1
View File
@@ -237,6 +237,7 @@ brave_java_sources = [
"../../brave/android/java/org/chromium/chrome/browser/local_database/DisplayAdsTable.java",
"../../brave/android/java/org/chromium/chrome/browser/local_database/SavedBandwidthTable.java",
"../../brave/android/java/org/chromium/chrome/browser/local_database/TopSiteTable.java",
"../../brave/android/java/org/chromium/chrome/browser/misc_metrics/PrivacyHubMetricsFactory.java",
"../../brave/android/java/org/chromium/chrome/browser/night_mode/settings/BraveRadioButtonGroupThemePreference.java",
"../../brave/android/java/org/chromium/chrome/browser/night_mode/settings/BraveThemePreferences.java",
"../../brave/android/java/org/chromium/chrome/browser/notifications/BraveNotificationPlatformBridge.java",
@@ -109,6 +109,7 @@ import org.chromium.chrome.browser.flags.ChromeSwitches;
import org.chromium.chrome.browser.fullscreen.BrowserControlsManager;
import org.chromium.chrome.browser.informers.BraveAndroidSyncDisabledInformer;
import org.chromium.chrome.browser.informers.BraveSyncAccountDeletedInformer;
import org.chromium.chrome.browser.misc_metrics.PrivacyHubMetricsFactory;
import org.chromium.chrome.browser.notifications.BraveNotificationWarningDialog;
import org.chromium.chrome.browser.notifications.BravePermissionUtils;
import org.chromium.chrome.browser.notifications.permissions.NotificationPermissionController;
@@ -184,6 +185,7 @@ import org.chromium.components.safe_browsing.BraveSafeBrowsingApiHandler;
import org.chromium.components.search_engines.TemplateUrl;
import org.chromium.components.user_prefs.UserPrefs;
import org.chromium.content_public.browser.WebContents;
import org.chromium.misc_metrics.mojom.PrivacyHubMetrics;
import org.chromium.mojo.bindings.ConnectionErrorHandler;
import org.chromium.mojo.system.MojoException;
import org.chromium.ui.widget.Toast;
@@ -247,6 +249,7 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
private BraveWalletService mBraveWalletService;
private KeyringService mKeyringService;
private JsonRpcService mJsonRpcService;
private PrivacyHubMetrics mPrivacyHubMetrics;
private SwapService mSwapService;
private WalletModel mWalletModel;
private BlockchainRegistry mBlockchainRegistry;
@@ -1314,6 +1317,10 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
startActivity(braveWalletIntent);
}
public PrivacyHubMetrics getPrivacyHubMetrics() {
return mPrivacyHubMetrics;
}
private void checkForYandexSE() {
String countryCode = Locale.getDefault().getCountry();
if (yandexRegions.contains(countryCode)) {
@@ -1970,6 +1977,16 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
mAssetRatioService = AssetRatioServiceFactory.getInstance().getAssetRatioService(this);
}
private void initPrivacyHubMetrics() {
if (mPrivacyHubMetrics != null) {
return;
}
mPrivacyHubMetrics = PrivacyHubMetricsFactory.getInstance().getMetricsService(this);
mPrivacyHubMetrics.recordEnabledStatus(
OnboardingPrefManager.getInstance().isBraveStatsEnabled());
}
private void initSwapService() {
if (mSwapService != null) {
return;
@@ -1986,6 +2003,7 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
InitBraveWalletService();
InitKeyringService();
InitJsonRpcService();
initPrivacyHubMetrics();
initSwapService();
setupWalletModel();
}
@@ -1999,6 +2017,7 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
if (mTxService != null) mTxService.close();
if (mEthTxManagerProxy != null) mEthTxManagerProxy.close();
if (mSolanaTxManagerProxy != null) mSolanaTxManagerProxy.close();
if (mPrivacyHubMetrics != null) mPrivacyHubMetrics.close();
if (mBraveWalletService != null) mBraveWalletService.close();
mKeyringService = null;
mBlockchainRegistry = null;
@@ -2007,6 +2026,7 @@ public abstract class BraveActivity<C extends ChromeActivityComponent> extends C
mEthTxManagerProxy = null;
mSolanaTxManagerProxy = null;
mAssetRatioService = null;
mPrivacyHubMetrics = null;
mBraveWalletService = null;
}
@@ -103,11 +103,12 @@ public class BraveStatsUtil {
public static void showBraveStats() {
try {
BraveActivity activity = BraveActivity.getBraveActivity();
BraveStatsBottomSheetDialogFragment braveStatsBottomSheetDialogFragment =
BraveStatsBottomSheetDialogFragment.newInstance();
braveStatsBottomSheetDialogFragment.show(
BraveActivity.getBraveActivity().getSupportFragmentManager(),
STATS_FRAGMENT_TAG);
activity.getSupportFragmentManager(), STATS_FRAGMENT_TAG);
activity.getPrivacyHubMetrics().recordView();
} catch (BraveActivity.BraveActivityNotFoundException e) {
Log.e(TAG, "showBraveStats " + e);
}
@@ -0,0 +1,51 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
package org.chromium.chrome.browser.misc_metrics;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.misc_metrics.mojom.PrivacyHubMetrics;
import org.chromium.mojo.bindings.ConnectionErrorHandler;
import org.chromium.mojo.bindings.Interface;
import org.chromium.mojo.bindings.Interface.Proxy.Handler;
import org.chromium.mojo.system.MessagePipeHandle;
import org.chromium.mojo.system.impl.CoreImpl;
@JNINamespace("chrome::android")
public class PrivacyHubMetricsFactory {
private static final Object lock = new Object();
private static PrivacyHubMetricsFactory instance;
public static PrivacyHubMetricsFactory getInstance() {
synchronized (lock) {
if (instance == null) {
instance = new PrivacyHubMetricsFactory();
}
}
return instance;
}
private PrivacyHubMetricsFactory() {}
public PrivacyHubMetrics getMetricsService(ConnectionErrorHandler connectionErrorHandler) {
long nativeHandle = PrivacyHubMetricsFactoryJni.get().getInterfaceToPrivacyHubMetrics();
MessagePipeHandle handle = wrapNativeHandle(nativeHandle);
PrivacyHubMetrics metricsService = PrivacyHubMetrics.MANAGER.attachProxy(handle, 0);
Handler handler = ((Interface.Proxy) metricsService).getProxyHandler();
handler.setErrorHandler(connectionErrorHandler);
return metricsService;
}
private MessagePipeHandle wrapNativeHandle(long nativeHandle) {
return CoreImpl.getInstance().acquireNativeHandle(nativeHandle).toMessagePipeHandle();
}
@NativeMethods
interface Natives {
long getInterfaceToPrivacyHubMetrics();
}
}
@@ -12,7 +12,10 @@ import android.content.Intent;
import android.content.SharedPreferences;
import org.chromium.base.ContextUtils;
import org.chromium.base.Log;
import org.chromium.chrome.browser.BraveAdsNativeHelper;
import org.chromium.chrome.browser.app.BraveActivity;
import org.chromium.chrome.browser.app.BraveActivity.BraveActivityNotFoundException;
import org.chromium.chrome.browser.notifications.BraveOnboardingNotification;
import org.chromium.chrome.browser.notifications.retention.RetentionNotificationUtil;
import org.chromium.chrome.browser.profiles.Profile;
@@ -27,6 +30,8 @@ import java.util.Map;
* Provides information regarding onboarding.
*/
public class OnboardingPrefManager {
private static final String TAG = "OnboardingPrefMgr";
private static final String PREF_ONBOARDING = "onboarding";
private static final String PREF_P3A_ONBOARDING = "p3a_onboarding";
private static final String PREF_CROSS_PROMO_MODAL = "cross_promo_modal";
@@ -173,6 +178,12 @@ public class OnboardingPrefManager {
SharedPreferences.Editor sharedPreferencesEditor = mSharedPreferences.edit();
sharedPreferencesEditor.putBoolean(PREF_BRAVE_STATS, enabled);
sharedPreferencesEditor.apply();
try {
BraveActivity activity = BraveActivity.getBraveActivity();
activity.getPrivacyHubMetrics().recordEnabledStatus(enabled);
} catch (BraveActivityNotFoundException e) {
Log.e(TAG, "Could not report privacy hub enabled change to P3A: " + e);
}
}
public boolean isBraveStatsNotificationEnabled() {
+2
View File
@@ -65,6 +65,7 @@ class LocalhostPermissionComponent;
namespace misc_metrics {
class MenuMetrics;
class PrivacyHubMetrics;
} // namespace misc_metrics
namespace request_otr {
@@ -148,6 +149,7 @@ class BraveBrowserProcess {
virtual brave_ads::ResourceComponent* resource_component() = 0;
virtual brave::BraveFarblingService* brave_farbling_service() = 0;
virtual misc_metrics::MenuMetrics* menu_metrics() = 0;
virtual misc_metrics::PrivacyHubMetrics* privacy_hub_metrics() = 0;
};
extern BraveBrowserProcess* g_brave_browser_process;
+10
View File
@@ -39,6 +39,7 @@
#include "brave/components/https_upgrade_exceptions/browser/https_upgrade_exceptions_service.h"
#include "brave/components/localhost_permission/localhost_permission_component.h"
#include "brave/components/misc_metrics/menu_metrics.h"
#include "brave/components/misc_metrics/privacy_hub_metrics.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
#include "brave/components/p3a/buildflags.h"
#include "brave/components/p3a/histograms_braveizer.h"
@@ -533,3 +534,12 @@ misc_metrics::MenuMetrics* BraveBrowserProcessImpl::menu_metrics() {
#endif
return menu_metrics_.get();
}
misc_metrics::PrivacyHubMetrics*
BraveBrowserProcessImpl::privacy_hub_metrics() {
if (!privacy_hub_metrics_) {
privacy_hub_metrics_ =
std::make_unique<misc_metrics::PrivacyHubMetrics>(local_state());
}
return privacy_hub_metrics_.get();
}
+3
View File
@@ -60,6 +60,7 @@ class DebounceComponentInstaller;
namespace misc_metrics {
class MenuMetrics;
class PrivacyHubMetrics;
} // namespace misc_metrics
namespace request_otr {
@@ -153,6 +154,7 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
#endif
brave::BraveFarblingService* brave_farbling_service() override;
misc_metrics::MenuMetrics* menu_metrics() override;
misc_metrics::PrivacyHubMetrics* privacy_hub_metrics() override;
private:
// BrowserProcessImpl overrides:
@@ -230,6 +232,7 @@ class BraveBrowserProcessImpl : public BraveBrowserProcess,
std::unique_ptr<brave::BraveFarblingService> brave_farbling_service_;
std::unique_ptr<misc_metrics::MenuMetrics> menu_metrics_;
std::unique_ptr<misc_metrics::PrivacyHubMetrics> privacy_hub_metrics_;
std::unique_ptr<brave_ads::BraveStatsHelper> brave_stats_helper_;
SEQUENCE_CHECKER(sequence_checker_);
+2
View File
@@ -27,6 +27,7 @@
#include "brave/components/misc_metrics/general_browser_usage.h"
#include "brave/components/misc_metrics/menu_metrics.h"
#include "brave/components/misc_metrics/page_metrics_service.h"
#include "brave/components/misc_metrics/privacy_hub_metrics.h"
#include "brave/components/ntp_background_images/browser/ntp_background_images_service.h"
#include "brave/components/ntp_background_images/browser/view_counter_service.h"
#include "brave/components/p3a/p3a_service.h"
@@ -139,6 +140,7 @@ void RegisterLocalStatePrefs(PrefRegistrySimple* registry) {
misc_metrics::PageMetricsService::RegisterPrefs(registry);
brave_ads::BraveStatsHelper::RegisterLocalStatePrefs(registry);
misc_metrics::GeneralBrowserUsage::RegisterPrefs(registry);
misc_metrics::PrivacyHubMetrics::RegisterPrefs(registry);
playlist::PlaylistServiceFactory::RegisterLocalStatePrefs(registry);
}
@@ -0,0 +1,21 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "base/android/jni_android.h"
#include "brave/browser/brave_browser_process.h"
#include "brave/build/android/jni_headers/PrivacyHubMetricsFactory_jni.h"
#include "brave/components/misc_metrics/privacy_hub_metrics.h"
namespace chrome {
namespace android {
static jlong JNI_PrivacyHubMetricsFactory_GetInterfaceToPrivacyHubMetrics(
JNIEnv* env) {
auto pending = g_brave_browser_process->privacy_hub_metrics()->MakeRemote();
return static_cast<jlong>(pending.PassPipe().release().value());
}
} // namespace android
} // namespace chrome
+3
View File
@@ -20,3 +20,6 @@ brave_browser_misc_metrics_deps = [
"//components/keyed_service/core",
"//content/public/browser",
]
brave_browser_misc_metrics_android_sources =
[ "//brave/browser/misc_metrics/privacy_hub_metrics_factory_android.cc" ]
+1
View File
@@ -305,6 +305,7 @@ if (is_android) {
]
brave_chrome_browser_sources += brave_browser_brave_wallet_android_sources
brave_chrome_browser_sources += brave_browser_misc_metrics_android_sources
brave_chrome_browser_deps += brave_browser_brave_wallet_android_deps
brave_chrome_browser_deps += [
+1
View File
@@ -228,6 +228,7 @@ generate_jni("jni_headers") {
"//brave/android/java/org/chromium/chrome/browser/crypto_wallet/permission/BraveDappPermissionPromptDialog.java",
"//brave/android/java/org/chromium/chrome/browser/crypto_wallet/util/WalletNativeUtils.java",
"//brave/android/java/org/chromium/chrome/browser/informers/BraveSyncAccountDeletedInformer.java",
"//brave/android/java/org/chromium/chrome/browser/misc_metrics/PrivacyHubMetricsFactory.java",
"//brave/android/java/org/chromium/chrome/browser/notifications/BraveNotificationPlatformBridge.java",
"//brave/android/java/org/chromium/chrome/browser/notifications/BraveNotificationSettingsBridge.java",
"//brave/android/java/org/chromium/chrome/browser/ntp_background_images/NTPBackgroundImagesBridge.java",
+1
View File
@@ -34,6 +34,7 @@ brave_chrome_java_deps = [
"//brave/components/brave_wallet/common:mojom_java",
"//brave/components/browser_ui/accessibility/android:java",
"//brave/components/browser_ui/site_settings/android:java",
"//brave/components/misc_metrics/common:mojom_java",
"//brave/components/playlist/common/mojom:mojom_java",
"//brave/components/safe_browsing/android:brave_safe_browsing_java",
"//brave/components/variations/android:java",
+4
View File
@@ -13,6 +13,8 @@ static_library("misc_metrics") {
"page_metrics_service.h",
"pref_names.cc",
"pref_names.h",
"privacy_hub_metrics.cc",
"privacy_hub_metrics.h",
]
deps = [
@@ -24,4 +26,6 @@ static_library("misc_metrics") {
"//components/prefs",
"//url",
]
public_deps = [ "//brave/components/misc_metrics/common:mojom" ]
}
+12
View File
@@ -0,0 +1,12 @@
# Copyright (c) 2023 The Brave Authors. All rights reserved.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at https://mozilla.org/MPL/2.0/.
import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") {
generate_java = true
sources = [ "misc_metrics.mojom" ]
public_deps = [ "//mojo/public/mojom/base" ]
}
@@ -0,0 +1,15 @@
// Copyright (c) 2023 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
module misc_metrics.mojom;
// Handler for Privacy Hub events from UI.
interface PrivacyHubMetrics {
// Records view of Privacy Hub report.
RecordView();
// Records enabled status of Privacy Hub report.
RecordEnabledStatus(bool isEnabled);
};
+2
View File
@@ -14,4 +14,6 @@ const char kMiscMetricsMenuGroupActionCounts[] =
const char kMiscMetricsMenuShownStorage[] =
"brave.misc_metrics.menu_shown_storage";
const char kMiscMetricsPagesLoadedCount[] = "brave.core_metrics.pages_loaded";
const char kMiscMetricsPrivacyHubViews[] =
"brave.misc_metrics.privacy_hub_views";
} // namespace misc_metrics
+1
View File
@@ -12,6 +12,7 @@ extern const char kMiscMetricsMenuDismissStorage[];
extern const char kMiscMetricsMenuGroupActionCounts[];
extern const char kMiscMetricsMenuShownStorage[];
extern const char kMiscMetricsPagesLoadedCount[];
extern const char kMiscMetricsPrivacyHubViews[];
} // namespace misc_metrics
#endif // BRAVE_COMPONENTS_MISC_METRICS_PREF_NAMES_H_
@@ -0,0 +1,70 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include "brave/components/misc_metrics/privacy_hub_metrics.h"
#include "base/metrics/histogram_macros.h"
#include "brave/components/misc_metrics/pref_names.h"
#include "brave/components/p3a_utils/bucket.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
namespace misc_metrics {
namespace {
const int kViewsMonthlyBucketValues[] = {1, 10, 20};
} // namespace
const char kViewsMonthlyHistogramName[] = "Brave.PrivacyHub.Views";
const char kIsEnabledHistogramName[] = "Brave.PrivacyHub.IsEnabled";
const base::TimeDelta kReportUpdateInterval = base::Days(1);
PrivacyHubMetrics::PrivacyHubMetrics(PrefService* local_state)
: view_storage_(local_state, kMiscMetricsPrivacyHubViews) {
SetUpTimer();
}
PrivacyHubMetrics::~PrivacyHubMetrics() = default;
void PrivacyHubMetrics::RegisterPrefs(PrefRegistrySimple* registry) {
registry->RegisterListPref(kMiscMetricsPrivacyHubViews);
}
#if BUILDFLAG(IS_ANDROID)
mojo::PendingRemote<mojom::PrivacyHubMetrics> PrivacyHubMetrics::MakeRemote() {
mojo::PendingRemote<mojom::PrivacyHubMetrics> remote;
receivers_.Add(this, remote.InitWithNewPipeAndPassReceiver());
return remote;
}
#endif // BUILDFLAG(IS_ANDROID)
void PrivacyHubMetrics::RecordView() {
view_storage_.AddDelta(1u);
RecordViewCount();
}
void PrivacyHubMetrics::RecordEnabledStatus(bool is_enabled) {
// suspend metric if not enabled; we only want to report
// if the feature is enabled
int histogram_value = is_enabled ? 1 : INT_MAX - 1;
UMA_HISTOGRAM_EXACT_LINEAR(kIsEnabledHistogramName, histogram_value, 2);
}
void PrivacyHubMetrics::RecordViewCount() {
auto sum = view_storage_.GetMonthlySum();
if (sum > 0) {
p3a_utils::RecordToHistogramBucket(kViewsMonthlyHistogramName,
kViewsMonthlyBucketValues, sum);
}
SetUpTimer();
}
void PrivacyHubMetrics::SetUpTimer() {
report_timer_.Start(FROM_HERE, base::Time::Now() + kReportUpdateInterval,
base::BindOnce(&PrivacyHubMetrics::RecordViewCount,
base::Unretained(this)));
}
} // namespace misc_metrics
@@ -0,0 +1,60 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#ifndef BRAVE_COMPONENTS_MISC_METRICS_PRIVACY_HUB_METRICS_H_
#define BRAVE_COMPONENTS_MISC_METRICS_PRIVACY_HUB_METRICS_H_
#include "base/timer/wall_clock_timer.h"
#include "brave/components/misc_metrics/common/misc_metrics.mojom.h"
#include "brave/components/time_period_storage/monthly_storage.h"
#if BUILDFLAG(IS_ANDROID)
#include "mojo/public/cpp/bindings/receiver_set.h"
#endif // BUILDFLAG(IS_ANDROID)
class PrefRegistrySimple;
class PrefService;
namespace misc_metrics {
extern const char kViewsMonthlyHistogramName[];
extern const char kIsEnabledHistogramName[];
// TODO(djandries): consider refactoring this into a more generic
// metrics service if we receive additional metric requests for features
// that don't have a mojo service that we can piggyback onto.
class PrivacyHubMetrics : public mojom::PrivacyHubMetrics {
public:
explicit PrivacyHubMetrics(PrefService* local_state);
~PrivacyHubMetrics() override;
PrivacyHubMetrics(const PrivacyHubMetrics&) = delete;
PrivacyHubMetrics& operator=(const PrivacyHubMetrics&) = delete;
static void RegisterPrefs(PrefRegistrySimple* registry);
#if BUILDFLAG(IS_ANDROID)
mojo::PendingRemote<mojom::PrivacyHubMetrics> MakeRemote();
#endif // BUILDFLAG(IS_ANDROID)
void RecordView() override;
void RecordEnabledStatus(bool is_enabled) override;
private:
void RecordViewCount();
void SetUpTimer();
MonthlyStorage view_storage_;
base::WallClockTimer report_timer_;
#if BUILDFLAG(IS_ANDROID)
mojo::ReceiverSet<mojom::PrivacyHubMetrics> receivers_;
#endif // BUILDFLAG(IS_ANDROID)
};
} // namespace misc_metrics
#endif // BRAVE_COMPONENTS_MISC_METRICS_PRIVACY_HUB_METRICS_H_
@@ -0,0 +1,50 @@
/* Copyright (c) 2023 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */
#include <memory>
#include "base/test/metrics/histogram_tester.h"
#include "brave/components/misc_metrics/privacy_hub_metrics.h"
#include "components/prefs/testing_pref_service.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace misc_metrics {
class PrivacyHubMetricsUnitTest : public testing::Test {
public:
PrivacyHubMetricsUnitTest()
: task_environment_(base::test::TaskEnvironment::TimeSource::MOCK_TIME) {}
void SetUp() override {
misc_metrics::PrivacyHubMetrics::RegisterPrefs(local_state_.registry());
privacy_hub_metrics_ = std::make_unique<PrivacyHubMetrics>(&local_state_);
}
protected:
content::BrowserTaskEnvironment task_environment_;
TestingPrefServiceSimple local_state_;
base::HistogramTester histogram_tester_;
std::unique_ptr<PrivacyHubMetrics> privacy_hub_metrics_;
};
TEST_F(PrivacyHubMetricsUnitTest, Views) {
histogram_tester_.ExpectTotalCount(kViewsMonthlyHistogramName, 0);
for (size_t i = 0; i < 4; i++) {
privacy_hub_metrics_->RecordView();
}
histogram_tester_.ExpectBucketCount(kViewsMonthlyHistogramName, 0, 1);
histogram_tester_.ExpectBucketCount(kViewsMonthlyHistogramName, 1, 3);
task_environment_.FastForwardBy(base::Days(30));
histogram_tester_.ExpectBucketCount(kViewsMonthlyHistogramName, 1, 32);
task_environment_.FastForwardBy(base::Days(10));
histogram_tester_.ExpectBucketCount(kViewsMonthlyHistogramName, 1, 32);
}
} // namespace misc_metrics
+3
View File
@@ -184,6 +184,8 @@ constexpr inline auto kCollectedSlowHistograms =
"Brave.General.BottomBarLocation",
"Brave.P3A.TestSlowMetric",
"Brave.Playlist.LastUsageTime",
"Brave.PrivacyHub.IsEnabled",
"Brave.PrivacyHub.Views",
"Brave.ReaderMode.NumberReaderModeActivated",
"Brave.Rewards.TipsSent",
"Brave.Sync.EnabledTypes",
@@ -207,6 +209,7 @@ constexpr inline auto kEphemeralHistograms =
base::MakeFixedFlatSet<base::StringPiece>({
"Brave.Playlist.UsageDaysInWeek",
"Brave.Playlist.FirstTimeOffset",
"Brave.PrivacyHub.Views",
"Brave.Rewards.EnabledInstallationTime",
"Brave.Rewards.EnabledSource",
"Brave.Rewards.InlineTipTrigger",
+1
View File
@@ -140,6 +140,7 @@ test("brave_unit_tests") {
"//brave/components/content_settings/core/browser/brave_content_settings_utils_unittest.cc",
"//brave/components/misc_metrics/general_browser_usage_unittest.cc",
"//brave/components/misc_metrics/menu_metrics_unittest.cc",
"//brave/components/misc_metrics/privacy_hub_metrics_unittest.cc",
"//brave/components/ntp_background_images/browser/ntp_background_images_service_unittest.cc",
"//brave/components/ntp_background_images/browser/ntp_background_images_source_unittest.cc",
"//brave/components/ntp_background_images/browser/view_counter_model_unittest.cc",
@@ -186,6 +186,12 @@ misc_metrics::MenuMetrics* TestingBraveBrowserProcess::menu_metrics() {
return nullptr;
}
misc_metrics::PrivacyHubMetrics*
TestingBraveBrowserProcess::privacy_hub_metrics() {
NOTREACHED();
return nullptr;
}
void TestingBraveBrowserProcess::SetAdBlockService(
std::unique_ptr<brave_shields::AdBlockService> service) {
ad_block_service_ = std::move(service);
@@ -87,6 +87,7 @@ class TestingBraveBrowserProcess : public BraveBrowserProcess {
brave_vpn::BraveVPNOSConnectionAPI* brave_vpn_os_connection_api() override;
#endif
misc_metrics::MenuMetrics* menu_metrics() override;
misc_metrics::PrivacyHubMetrics* privacy_hub_metrics() override;
// Populate the mock process with services. Consumer is responsible for
// cleaning these up after completion of a test.