123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // Copyright 2019 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #ifndef COMPONENTS_METRICS_DEMOGRAPHICS_DEMOGRAPHIC_METRICS_PROVIDER_H_
- #define COMPONENTS_METRICS_DEMOGRAPHICS_DEMOGRAPHIC_METRICS_PROVIDER_H_
- #include <memory>
- #include "base/time/time.h"
- #include "components/metrics/demographics/user_demographics.h"
- #include "components/metrics/metrics_log_uploader.h"
- #include "components/metrics/metrics_provider.h"
- #include "components/metrics/ukm_demographic_metrics_provider.h"
- #include "third_party/abseil-cpp/absl/types/optional.h"
- #include "third_party/metrics_proto/chrome_user_metrics_extension.pb.h"
- #include "third_party/metrics_proto/user_demographics.pb.h"
- class PrefService;
- namespace base {
- struct Feature;
- }
- namespace syncer {
- class SyncService;
- }
- namespace metrics {
- // Provider of the synced user’s noised birth year and gender to the UMA metrics
- // server. The synced user's birth year and gender were provided to Google when
- // the user created their Google account, to use in accordance with Google's
- // privacy policy. The provided birth year and gender are used in aggregate and
- // anonymized form to measure usage of Chrome features by age groups and gender
- // - helping Chrome ensure features are useful to a wide range of users. Users
- // can avoid aggregation of usage data by birth year and gender by either a)
- // turning off sending usage statistics to Google or b) turning off sync.
- class DemographicMetricsProvider : public MetricsProvider,
- public UkmDemographicMetricsProvider {
- public:
- // Interface that represents the client that retrieves Profile information.
- class ProfileClient {
- public:
- virtual ~ProfileClient() = default;
- // Gets the total number of profiles that are on disk (loaded + not loaded)
- // for the browser.
- virtual int GetNumberOfProfilesOnDisk() = 0;
- // Gets a pointer to the SyncService of the profile, which is required to
- // determine whether priority preferences carrying demographics information
- // is being synced.
- virtual syncer::SyncService* GetSyncService() = 0;
- // Gets a pointer to the PrefService of the profile.
- virtual PrefService* GetPrefService() = 0;
- // Gets the network time that represents now.
- // TODO(crbug/1145655): Remove this function and replace with
- // base::Time::Now().
- virtual base::Time GetNetworkTime() const = 0;
- };
- DemographicMetricsProvider(
- std::unique_ptr<ProfileClient> profile_client,
- MetricsLogUploader::MetricServiceType metrics_service_type);
- DemographicMetricsProvider(const DemographicMetricsProvider&) = delete;
- DemographicMetricsProvider& operator=(const DemographicMetricsProvider&) =
- delete;
- ~DemographicMetricsProvider() override;
- // Provides the synced user's noised birth year and gender to a metrics report
- // of type ReportType. This function is templated to support any type of proto
- // metrics report, e.g., ukm::Report and metrics::ChromeUserMetricsExtension.
- // The ReportType should be a proto message class that has a
- // metrics::UserDemographicsProto message field.
- template <class ReportType>
- void ProvideSyncedUserNoisedBirthYearAndGender(ReportType* report) {
- DCHECK(report);
- absl::optional<UserDemographics> user_demographics =
- ProvideSyncedUserNoisedBirthYearAndGender();
- if (user_demographics.has_value()) {
- report->mutable_user_demographics()->set_birth_year(
- user_demographics.value().birth_year);
- report->mutable_user_demographics()->set_gender(
- user_demographics.value().gender);
- }
- }
- // MetricsProvider:
- void ProvideCurrentSessionData(
- ChromeUserMetricsExtension* uma_proto) override;
- // UkmDemographicMetricsProvider:
- void ProvideSyncedUserNoisedBirthYearAndGenderToReport(
- ukm::Report* report) override;
- // Feature switch to report user's noised birth year and gender.
- static const base::Feature kDemographicMetricsReporting;
- private:
- // Provides the synced user's noised birth year and gender.
- absl::optional<UserDemographics> ProvideSyncedUserNoisedBirthYearAndGender();
- void LogUserDemographicsStatusInHistogram(UserDemographicsStatus status);
- std::unique_ptr<ProfileClient> profile_client_;
- // The type of the metrics service for which to emit the user demographics
- // status histogram (e.g., UMA).
- const MetricsLogUploader::MetricServiceType metrics_service_type_;
- };
- } // namespace metrics
- #endif // COMPONENTS_METRICS_DEMOGRAPHICS_DEMOGRAPHIC_METRICS_PROVIDER_H_
|