1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
#define CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
#include <stdint.h>
#include <string_view>
#include "base/gtest_prod_util.h"
#include "build/build_config.h"
#include "chrome/browser/metrics/metrics_reporting_state.h"
#include "chrome/common/buildflags.h"
#include "components/metrics/metrics_service_accessor.h"
#include "components/signin/public/base/signin_buildflags.h"
#include "components/variations/synthetic_trials.h"
#include "ppapi/buildflags/buildflags.h"
#include "chrome/browser/supervised_user/metrics_service_accessor_delegate.h"
#if BUILDFLAG(ENABLE_GLIC)
#include "chrome/browser/glic/host/glic_synthetic_trial_manager.h"
#endif
#if BUILDFLAG(ENABLE_PPAPI)
#include "chrome/common/ppapi_metrics.mojom.h"
#endif
#if BUILDFLAG(ENABLE_BOUND_SESSION_CREDENTIALS)
#include "chrome/browser/signin/bound_session_credentials/bound_session_cookie_refresh_service_impl.h"
#endif
class BrowserProcessImpl;
class CampaignsManagerClientImpl;
class ChromeMetricsServiceClient;
class ChromePasswordManagerClient;
class GlobalFeatures;
class HttpsFirstModeService;
class NavigationMetricsRecorder;
class PrefService;
namespace {
class CrashesDOMHandler;
}
#if BUILDFLAG(IS_ANDROID)
namespace autofill {
class AutofillClientProvider;
}
#endif // BUILDFLAG(IS_ANDROID)
#if BUILDFLAG(IS_CHROMEOS)
class ChromeCameraAppUIDelegate;
namespace app_list::federated {
class FederatedMetricsManager;
} // namespace app_list::federated
namespace ash::input_method {
class AutocorrectManager;
} // namespace ash::input_method
#endif // BUILDFLAG(IS_CHROMEOS)
namespace browser_sync {
class ChromeSyncClient;
}
namespace domain_reliability {
bool ShouldCreateService();
}
namespace extensions {
class ChromeGuestViewManagerDelegate;
class ChromeMetricsPrivateDelegate;
} // namespace extensions
namespace first_run {
class FirstRunMasterPrefsVariationsSeedTest;
}
namespace metrics {
class ChromeOSPerUserMetricsBrowserTestBase;
class UkmConsentParamBrowserTest;
class CrOSPreConsentMetricsManagerTest;
} // namespace metrics
namespace optimization_guide {
class ChromeOnDeviceModelServiceController;
} // namespace optimization_guide
namespace safe_browsing {
class ChromeSafeBrowsingUIManagerDelegate;
class DownloadUrlSBClient;
class IncidentReportingService;
class ServicesDelegateDesktop;
namespace internal {
class ReporterRunner;
} // namespace internal
} // namespace safe_browsing
namespace settings {
class MetricsReportingHandler;
}
namespace segmentation_platform {
class FieldTrialRegisterImpl;
}
namespace feed {
class FeedServiceDelegateImpl;
class WebFeedSubscriptionCoordinator;
} // namespace feed
namespace browser_sync {
class DeviceInfoSyncClientImpl;
} // namespace browser_sync
namespace webauthn {
namespace authenticator {
class IsMetricsAndCrashReportingEnabled;
}
} // namespace webauthn
namespace ash {
class DemoSession;
namespace settings {
class PerSessionSettingsUserActionTracker;
} // namespace settings
} // namespace ash
namespace tpcd::experiment {
class ExperimentManagerImpl;
}
namespace readaloud {
class SyntheticTrial;
}
namespace tab_groups {
class TabGroupTrial;
} // namespace tab_groups
// This class limits and documents access to metrics service helper methods.
// Since these methods are private, each user has to be explicitly declared
// as a 'friend' below.
class ChromeMetricsServiceAccessor : public metrics::MetricsServiceAccessor {
public:
ChromeMetricsServiceAccessor() = delete;
ChromeMetricsServiceAccessor(const ChromeMetricsServiceAccessor&) = delete;
ChromeMetricsServiceAccessor& operator=(const ChromeMetricsServiceAccessor&) =
delete;
// This test method is public so tests don't need to befriend this class.
// If arg is non-null, the value will be returned from future calls to
// IsMetricsAndCrashReportingEnabled(). Pointer must be valid until
// it is reset to null here.
static void SetMetricsAndCrashReportingForTesting(const bool* value);
private:
#if BUILDFLAG(ENABLE_BOUND_SESSION_CREDENTIALS)
friend class BoundSessionCookieRefreshServiceImpl;
#endif
friend class ::CrashesDOMHandler;
#if BUILDFLAG(IS_ANDROID)
friend class autofill::AutofillClientProvider;
#endif // BUILDFLAG(IS_ANDROID)
friend class ChromeBrowserFieldTrials;
// For ClangPGO.
friend class ChromeBrowserMainExtraPartsMetrics;
// For ThreadProfilerConfiguration.
friend class ChromeBrowserMainParts;
friend class ChromeContentBrowserClient;
friend class ChromeMetricsServicesManagerClient;
friend class ChromeSigninClient;
friend class browser_sync::ChromeSyncClient;
friend bool domain_reliability::ShouldCreateService();
friend class extensions::ChromeGuestViewManagerDelegate;
friend class extensions::ChromeMetricsPrivateDelegate;
friend void ChangeMetricsReportingStateWithReply(
bool,
OnMetricsReportingCallbackType,
ChangeMetricsReportingStateCalledFrom);
friend void ApplyMetricsReportingPolicy();
friend class ash::settings::PerSessionSettingsUserActionTracker;
friend class settings::MetricsReportingHandler;
friend class UmaSessionStats;
friend class safe_browsing::ChromeSafeBrowsingUIManagerDelegate;
friend class safe_browsing::DownloadUrlSBClient;
friend class safe_browsing::IncidentReportingService;
friend class safe_browsing::ServicesDelegateDesktop;
friend class safe_browsing::internal::ReporterRunner;
friend class segmentation_platform::FieldTrialRegisterImpl;
friend class ChromeMetricsServiceClient;
friend class ChromePasswordManagerClient;
friend class NavigationMetricsRecorder;
friend class ChromeBrowserMainExtraPartsGpu;
friend class Browser;
friend class BrowserProcessImpl;
friend class GlobalFeatures;
friend class supervised_user::MetricsServiceAccessorDelegateImpl;
#if BUILDFLAG(ENABLE_GLIC)
friend class glic::GlicSyntheticTrialManager;
#endif
friend class OptimizationGuideKeyedService;
friend class optimization_guide::ChromeOnDeviceModelServiceController;
friend class WebUITabStripFieldTrial;
friend class feed::FeedServiceDelegateImpl;
friend class FirstRunService;
friend class browser_sync::DeviceInfoSyncClientImpl;
friend class feed::WebFeedSubscriptionCoordinator;
friend class HttpsFirstModeService;
friend class ash::DemoSession;
friend class DataSharingUI;
// Used to register synthetic trials for ongoing growth experiments.
friend class CampaignsManagerClientImpl;
friend class tpcd::experiment::ExperimentManagerImpl;
friend class readaloud::SyntheticTrial;
friend class tab_groups::TabGroupTrial;
#if !BUILDFLAG(IS_ANDROID)
friend class DefaultBrowserPromptTrial;
#endif
#if BUILDFLAG(IS_CHROMEOS)
friend class ChromeCameraAppUIDelegate;
// The following classes are friended because they check UMA consent status
// for the purpose of federated metrics collection.
friend class app_list::federated::FederatedMetricsManager;
friend class ash::input_method::AutocorrectManager;
#endif // BUILDFLAG(IS_CHROMEOS)
// Testing related friends.
friend class first_run::FirstRunMasterPrefsVariationsSeedTest;
friend class ForceFieldTrialsBrowserTest;
friend class MetricsReportingStateTest;
friend class metrics::UkmConsentParamBrowserTest;
friend class ClonedInstallClientIdResetBrowserTest;
friend class metrics::ChromeOSPerUserMetricsBrowserTestBase;
friend class SampledOutClientIdSavedBrowserTest;
friend class MetricsInternalsUIBrowserTestWithLog;
friend class metrics::CrOSPreConsentMetricsManagerTest;
FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServiceAccessorTest,
MetricsReportingEnabled);
FRIEND_TEST_ALL_PREFIXES(ChromeMetricsServicesManagerClientTest,
ForceTrialsDisablesReporting);
// Returns true if metrics reporting is enabled. This does NOT necessary mean
// that it is active as configuration may prevent it on some devices (i.e.
// the "MetricsReporting" field trial that controls sampling). To include
// that, call: metrics_services_manager->IsReportingEnabled().
//
// For Ash Chrome, if a user is logged in and the device has an owner or is
// managed, the current user's consent (if applicable) will be used if metrics
// reporting for the device has been enabled.
static bool IsMetricsAndCrashReportingEnabled();
// This is identical to the function without the |local_state| param but can
// be called before |g_browser_process| has been created by specifying the
// Local State pref service.
static bool IsMetricsAndCrashReportingEnabled(PrefService* local_state);
// Registers a field trial name and group by calling
// metrics::MetricsServiceAccessor::RegisterSyntheticFieldTrial() with
// g_browser_process->metrics_service(). The |annotation_mode| parameter
// determines when UMA reports should start being annotated with this trial
// and group. When set to |kCurrentLog|, the UMA report that will be generated
// from the log that is open at the time of registration will be annotated.
// When set to |kNextLog|, only reports after the one generated from the log
// that is open at the time of registration will be annotated. |kNextLog| is
// particularly useful when ambiguity is unacceptable, as |kCurrentLog| will
// annotate the report generated from the current log even if it may include
// data from when this trial and group were not active. Returns true on
// success.
static bool RegisterSyntheticFieldTrial(
std::string_view trial_name,
std::string_view group_name,
variations::SyntheticTrialAnnotationMode annotation_mode =
variations::SyntheticTrialAnnotationMode::kNextLog);
// Cover for function of same name in MetricsServiceAccessor. See
// ChromeMetricsServiceAccessor for details.
static void SetForceIsMetricsReportingEnabledPrefLookup(bool value);
#if BUILDFLAG(ENABLE_PPAPI)
// Provides an implementation of chrome::mojom::PpapiMetricsService.
static void BindPpapiMetricsServiceReceiver(
mojo::PendingReceiver<chrome::mojom::PpapiMetricsService> receiver);
#endif // BUILDFLAG(ENABLE_PPAPI)
};
#endif // CHROME_BROWSER_METRICS_CHROME_METRICS_SERVICE_ACCESSOR_H_
|