Add tos-accepted
preference for metrics collection
Added ToS preference and use it when checking if consent is given for metrics collection. Bug: b/287129788 Change-Id: Ib8894d2772a7aee146ad1d8a26753bcf7fcab78b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4727188 Commit-Queue: Xyan Bhatnagar <xbhatnag@google.com> Reviewed-by: Vigen Issahhanjan <vigeni@google.com> Cr-Commit-Position: refs/heads/main@{#1181032}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
4914dcc2b5
commit
015f53a141
chromecast
@@ -20,6 +20,9 @@ const char kMetricsIsNewClientID[] = "user_experience_metrics.is_new_client_id";
|
|||||||
// Whether or not to report metrics and crashes.
|
// Whether or not to report metrics and crashes.
|
||||||
const char kOptInStats[] = "opt-in.stats";
|
const char kOptInStats[] = "opt-in.stats";
|
||||||
|
|
||||||
|
// Whether or not TOS has been accepted by user.
|
||||||
|
const char kTosAccepted[] = "tos-accepted";
|
||||||
|
|
||||||
// Total number of kernel crashes since the last report.
|
// Total number of kernel crashes since the last report.
|
||||||
const char kStabilityKernelCrashCount[] =
|
const char kStabilityKernelCrashCount[] =
|
||||||
"user_experience_metrics.stability.kernel_crash_count";
|
"user_experience_metrics.stability.kernel_crash_count";
|
||||||
|
@@ -12,6 +12,7 @@ extern const char kActiveDCSExperiments[];
|
|||||||
extern const char kLatestDCSFeatures[];
|
extern const char kLatestDCSFeatures[];
|
||||||
extern const char kMetricsIsNewClientID[];
|
extern const char kMetricsIsNewClientID[];
|
||||||
extern const char kOptInStats[];
|
extern const char kOptInStats[];
|
||||||
|
extern const char kTosAccepted[];
|
||||||
extern const char kStabilityKernelCrashCount[];
|
extern const char kStabilityKernelCrashCount[];
|
||||||
extern const char kStabilityOtherUserCrashCount[];
|
extern const char kStabilityOtherUserCrashCount[];
|
||||||
extern const char kStabilitySystemUncleanShutdownCount[];
|
extern const char kStabilitySystemUncleanShutdownCount[];
|
||||||
|
@@ -97,12 +97,13 @@ std::unique_ptr<PrefService> PrefServiceHelper::CreatePrefService(
|
|||||||
DVLOG(1) << "Loading config from " << config_path.value();
|
DVLOG(1) << "Loading config from " << config_path.value();
|
||||||
|
|
||||||
registry->RegisterBooleanPref(prefs::kMetricsIsNewClientID, false);
|
registry->RegisterBooleanPref(prefs::kMetricsIsNewClientID, false);
|
||||||
|
registry->RegisterBooleanPref(prefs::kTosAccepted, false);
|
||||||
// Opt-in stats default to true to handle two different cases:
|
// Opt-in stats default to true to handle two different cases:
|
||||||
// 1) Any crashes or UMA logs are recorded prior to setup completing
|
// 1) Any crashes or UMA logs recorded after accepting Terms of Service.
|
||||||
// successfully (even though we can't send them yet). Unless the user
|
// Unless the user ends up actually opting out, we don't want to lose
|
||||||
// ends up actually opting out, we don't want to lose this data once
|
// this data once we get network connectivity and are able to send it.
|
||||||
// we get network connectivity and are able to send it. If the user
|
// If the user opts out, nothing further will be sent (honoring the
|
||||||
// opts out, nothing further will be sent (honoring the user's setting).
|
// user's setting).
|
||||||
// 2) Dogfood users (see dogfood agreement).
|
// 2) Dogfood users (see dogfood agreement).
|
||||||
registry->RegisterBooleanPref(prefs::kOptInStats, true);
|
registry->RegisterBooleanPref(prefs::kOptInStats, true);
|
||||||
registry->RegisterListPref(prefs::kActiveDCSExperiments);
|
registry->RegisterListPref(prefs::kActiveDCSExperiments);
|
||||||
|
@@ -270,22 +270,52 @@ bool CastMetricsServiceClient::IsConsentGiven() const {
|
|||||||
return pref_service_->GetBoolean(prefs::kOptInStats);
|
return pref_service_->GetBoolean(prefs::kOptInStats);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CastMetricsServiceClient::EnableMetricsService(bool enabled) {
|
bool CastMetricsServiceClient::IsReportingEnabled() const {
|
||||||
|
// Recording metrics is controlled by the opt-in stats preference
|
||||||
|
// (`IsConsentGiven()`), but reporting them to Google is controlled by
|
||||||
|
// ToS being accepted.
|
||||||
|
return pref_service_->GetBoolean(prefs::kTosAccepted) &&
|
||||||
|
::metrics::EnabledStateProvider::IsReportingEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CastMetricsServiceClient::UpdateMetricsServiceState() {
|
||||||
if (!task_runner_->BelongsToCurrentThread()) {
|
if (!task_runner_->BelongsToCurrentThread()) {
|
||||||
task_runner_->PostTask(
|
task_runner_->PostTask(
|
||||||
FROM_HERE,
|
FROM_HERE,
|
||||||
base::BindOnce(&CastMetricsServiceClient::EnableMetricsService,
|
base::BindOnce(&CastMetricsServiceClient::UpdateMetricsServiceState,
|
||||||
base::Unretained(this), enabled));
|
base::Unretained(this)));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enabled) {
|
if (IsConsentGiven()) {
|
||||||
metrics_service_->Start();
|
metrics_service_->Start();
|
||||||
|
if (!IsReportingEnabled()) {
|
||||||
|
// Metrics are only reported after ToS have been accepted. If usage
|
||||||
|
// reporting is enabled, but ToS is not accepted, we can record metrics
|
||||||
|
// but must not report/upload them.
|
||||||
|
//
|
||||||
|
// `MetricsServiceImpl::Start()` will start recording and reporting.
|
||||||
|
// We must call `DisableReporting()` which will update the internal
|
||||||
|
// state machine of the reporting service and stop the upload scheduler
|
||||||
|
// from running.
|
||||||
|
metrics_service_->DisableReporting();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
metrics_service_->Stop();
|
metrics_service_->Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CastMetricsServiceClient::DisableMetricsService() {
|
||||||
|
if (!task_runner_->BelongsToCurrentThread()) {
|
||||||
|
task_runner_->PostTask(
|
||||||
|
FROM_HERE,
|
||||||
|
base::BindOnce(&CastMetricsServiceClient::DisableMetricsService,
|
||||||
|
base::Unretained(this)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
metrics_service_->Stop();
|
||||||
|
}
|
||||||
|
|
||||||
CastMetricsServiceClient::CastMetricsServiceClient(
|
CastMetricsServiceClient::CastMetricsServiceClient(
|
||||||
CastMetricsServiceDelegate* delegate,
|
CastMetricsServiceDelegate* delegate,
|
||||||
PrefService* pref_service,
|
PrefService* pref_service,
|
||||||
@@ -365,8 +395,7 @@ void CastMetricsServiceClient::StartMetricsService() {
|
|||||||
metrics_state_manager_->LogHasSessionShutdownCleanly(false);
|
metrics_state_manager_->LogHasSessionShutdownCleanly(false);
|
||||||
#endif // !BUILDFLAG(IS_ANDROID)
|
#endif // !BUILDFLAG(IS_ANDROID)
|
||||||
|
|
||||||
if (IsReportingEnabled())
|
UpdateMetricsServiceState();
|
||||||
metrics_service_->Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CastMetricsServiceClient::Finalize() {
|
void CastMetricsServiceClient::Finalize() {
|
||||||
|
@@ -110,9 +110,11 @@ class CastMetricsServiceClient : public ::metrics::MetricsServiceClient,
|
|||||||
|
|
||||||
// ::metrics::EnabledStateProvider:
|
// ::metrics::EnabledStateProvider:
|
||||||
bool IsConsentGiven() const override;
|
bool IsConsentGiven() const override;
|
||||||
|
bool IsReportingEnabled() const override;
|
||||||
|
|
||||||
// Starts/stops the metrics service.
|
// Starts/stops the metrics service.
|
||||||
void EnableMetricsService(bool enabled);
|
void UpdateMetricsServiceState();
|
||||||
|
void DisableMetricsService();
|
||||||
|
|
||||||
std::string client_id() const { return client_id_; }
|
std::string client_id() const { return client_id_; }
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user