123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- // Copyright 2018 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.
- #include "components/consent_auditor/consent_auditor_impl.h"
- #include <memory>
- #include <utility>
- #include "base/values.h"
- #include "components/consent_auditor/pref_names.h"
- #include "components/prefs/pref_registry_simple.h"
- #include "components/prefs/pref_service.h"
- #include "components/prefs/scoped_user_pref_update.h"
- #include "components/sync/model/model_type_sync_bridge.h"
- #include "components/sync/protocol/user_consent_specifics.pb.h"
- #include "components/sync/protocol/user_consent_types.pb.h"
- using ArcPlayTermsOfServiceConsent =
- sync_pb::UserConsentTypes::ArcPlayTermsOfServiceConsent;
- using sync_pb::UserConsentTypes;
- using sync_pb::UserConsentSpecifics;
- namespace consent_auditor {
- namespace {
- constexpr char kLocalConsentDescriptionKey[] = "description";
- constexpr char kLocalConsentConfirmationKey[] = "confirmation";
- constexpr char kLocalConsentVersionKey[] = "version";
- constexpr char kLocalConsentLocaleKey[] = "locale";
- std::unique_ptr<sync_pb::UserConsentSpecifics> CreateUserConsentSpecifics(
- const CoreAccountId& account_id,
- const std::string& locale,
- base::Clock* clock) {
- std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
- std::make_unique<sync_pb::UserConsentSpecifics>();
- specifics->set_account_id(account_id.ToString());
- specifics->set_client_consent_time_usec(
- clock->Now().since_origin().InMicroseconds());
- specifics->set_locale(locale);
- return specifics;
- }
- } // namespace
- ConsentAuditorImpl::ConsentAuditorImpl(
- PrefService* pref_service,
- std::unique_ptr<ConsentSyncBridge> consent_sync_bridge,
- const std::string& app_version,
- const std::string& app_locale,
- base::Clock* clock)
- : pref_service_(pref_service),
- consent_sync_bridge_(std::move(consent_sync_bridge)),
- app_version_(app_version),
- app_locale_(app_locale),
- clock_(clock) {
- DCHECK(consent_sync_bridge_);
- DCHECK(pref_service_);
- }
- ConsentAuditorImpl::~ConsentAuditorImpl() {}
- void ConsentAuditorImpl::Shutdown() {}
- // static
- void ConsentAuditorImpl::RegisterProfilePrefs(PrefRegistrySimple* registry) {
- registry->RegisterDictionaryPref(prefs::kLocalConsentsDictionary);
- }
- void ConsentAuditorImpl::RecordArcPlayConsent(
- const CoreAccountId& account_id,
- const ArcPlayTermsOfServiceConsent& consent) {
- std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
- CreateUserConsentSpecifics(account_id, app_locale_, clock_);
- sync_pb::UserConsentTypes::ArcPlayTermsOfServiceConsent* arc_play_consent =
- specifics->mutable_arc_play_terms_of_service_consent();
- arc_play_consent->CopyFrom(consent);
- consent_sync_bridge_->RecordConsent(std::move(specifics));
- }
- void ConsentAuditorImpl::RecordArcGoogleLocationServiceConsent(
- const CoreAccountId& account_id,
- const UserConsentTypes::ArcGoogleLocationServiceConsent& consent) {
- std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
- CreateUserConsentSpecifics(account_id, app_locale_, clock_);
- sync_pb::UserConsentTypes::ArcGoogleLocationServiceConsent*
- arc_google_location_service_consent =
- specifics->mutable_arc_location_service_consent();
- arc_google_location_service_consent->CopyFrom(consent);
- consent_sync_bridge_->RecordConsent(std::move(specifics));
- }
- void ConsentAuditorImpl::RecordArcBackupAndRestoreConsent(
- const CoreAccountId& account_id,
- const UserConsentTypes::ArcBackupAndRestoreConsent& consent) {
- std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
- CreateUserConsentSpecifics(account_id, app_locale_, clock_);
- sync_pb::UserConsentTypes::ArcBackupAndRestoreConsent*
- arc_backup_and_restore_consent =
- specifics->mutable_arc_backup_and_restore_consent();
- arc_backup_and_restore_consent->CopyFrom(consent);
- consent_sync_bridge_->RecordConsent(std::move(specifics));
- }
- void ConsentAuditorImpl::RecordSyncConsent(
- const CoreAccountId& account_id,
- const UserConsentTypes::SyncConsent& consent) {
- std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
- CreateUserConsentSpecifics(account_id, app_locale_, clock_);
- sync_pb::UserConsentTypes::SyncConsent* sync_consent =
- specifics->mutable_sync_consent();
- sync_consent->CopyFrom(consent);
- consent_sync_bridge_->RecordConsent(std::move(specifics));
- }
- void ConsentAuditorImpl::RecordAssistantActivityControlConsent(
- const CoreAccountId& account_id,
- const sync_pb::UserConsentTypes::AssistantActivityControlConsent& consent) {
- std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
- CreateUserConsentSpecifics(account_id, app_locale_, clock_);
- sync_pb::UserConsentTypes::AssistantActivityControlConsent*
- assistant_consent =
- specifics->mutable_assistant_activity_control_consent();
- assistant_consent->CopyFrom(consent);
- consent_sync_bridge_->RecordConsent(std::move(specifics));
- }
- void ConsentAuditorImpl::RecordAccountPasswordsConsent(
- const CoreAccountId& account_id,
- const sync_pb::UserConsentTypes::AccountPasswordsConsent& consent) {
- std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
- CreateUserConsentSpecifics(account_id, app_locale_, clock_);
- specifics->mutable_account_passwords_consent()->CopyFrom(consent);
- consent_sync_bridge_->RecordConsent(std::move(specifics));
- }
- void ConsentAuditorImpl::RecordAutofillAssistantConsent(
- const CoreAccountId& account_id,
- const sync_pb::UserConsentTypes::AutofillAssistantConsent& consent) {
- std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
- CreateUserConsentSpecifics(account_id, app_locale_, clock_);
- *specifics->mutable_autofill_assistant_consent() = consent;
- consent_sync_bridge_->RecordConsent(std::move(specifics));
- }
- void ConsentAuditorImpl::RecordLocalConsent(
- const std::string& feature,
- const std::string& description_text,
- const std::string& confirmation_text) {
- DictionaryPrefUpdate consents_update(pref_service_,
- prefs::kLocalConsentsDictionary);
- base::Value* consents = consents_update.Get();
- DCHECK(consents);
- base::Value record(base::Value::Type::DICTIONARY);
- record.SetStringKey(kLocalConsentDescriptionKey, description_text);
- record.SetStringKey(kLocalConsentConfirmationKey, confirmation_text);
- record.SetStringKey(kLocalConsentVersionKey, app_version_);
- record.SetStringKey(kLocalConsentLocaleKey, app_locale_);
- consents->SetKey(feature, std::move(record));
- }
- base::WeakPtr<syncer::ModelTypeControllerDelegate>
- ConsentAuditorImpl::GetControllerDelegate() {
- if (consent_sync_bridge_) {
- return consent_sync_bridge_->GetControllerDelegate();
- }
- return base::WeakPtr<syncer::ModelTypeControllerDelegate>();
- }
- } // namespace consent_auditor
|