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
|
// Copyright 2018 The Chromium Authors
// 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 "components/sync/model/data_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::UserConsentSpecifics;
using sync_pb::UserConsentTypes;
namespace consent_auditor {
namespace {
std::unique_ptr<sync_pb::UserConsentSpecifics> CreateUserConsentSpecifics(
const GaiaId& gaia_id,
const std::string& locale,
base::Clock* clock) {
std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
std::make_unique<sync_pb::UserConsentSpecifics>();
specifics->set_obfuscated_gaia_id(gaia_id.ToString());
specifics->set_client_consent_time_usec(
clock->Now().since_origin().InMicroseconds());
specifics->set_locale(locale);
return specifics;
}
} // namespace
ConsentAuditorImpl::ConsentAuditorImpl(
std::unique_ptr<ConsentSyncBridge> consent_sync_bridge,
const std::string& app_locale,
base::Clock* clock)
: consent_sync_bridge_(std::move(consent_sync_bridge)),
app_locale_(app_locale),
clock_(clock) {
DCHECK(consent_sync_bridge_);
}
ConsentAuditorImpl::~ConsentAuditorImpl() = default;
void ConsentAuditorImpl::Shutdown() {}
void ConsentAuditorImpl::RecordArcPlayConsent(
const GaiaId& gaia_id,
const ArcPlayTermsOfServiceConsent& consent) {
std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
CreateUserConsentSpecifics(gaia_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 GaiaId& gaia_id,
const UserConsentTypes::ArcGoogleLocationServiceConsent& consent) {
std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
CreateUserConsentSpecifics(gaia_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 GaiaId& gaia_id,
const UserConsentTypes::ArcBackupAndRestoreConsent& consent) {
std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
CreateUserConsentSpecifics(gaia_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 GaiaId& gaia_id,
const UserConsentTypes::SyncConsent& consent) {
std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
CreateUserConsentSpecifics(gaia_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 GaiaId& gaia_id,
const sync_pb::UserConsentTypes::AssistantActivityControlConsent& consent) {
std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
CreateUserConsentSpecifics(gaia_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 GaiaId& gaia_id,
const sync_pb::UserConsentTypes::AccountPasswordsConsent& consent) {
std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
CreateUserConsentSpecifics(gaia_id, app_locale_, clock_);
specifics->mutable_account_passwords_consent()->CopyFrom(consent);
consent_sync_bridge_->RecordConsent(std::move(specifics));
}
void ConsentAuditorImpl::RecordRecorderSpeakerLabelConsent(
const GaiaId& gaia_id,
const sync_pb::UserConsentTypes::RecorderSpeakerLabelConsent& consent) {
std::unique_ptr<sync_pb::UserConsentSpecifics> specifics =
CreateUserConsentSpecifics(gaia_id, app_locale_, clock_);
specifics->mutable_recorder_speaker_label_consent()->CopyFrom(consent);
consent_sync_bridge_->RecordConsent(std::move(specifics));
}
base::WeakPtr<syncer::DataTypeControllerDelegate>
ConsentAuditorImpl::GetControllerDelegate() {
if (consent_sync_bridge_) {
return consent_sync_bridge_->GetControllerDelegate();
}
return base::WeakPtr<syncer::DataTypeControllerDelegate>();
}
} // namespace consent_auditor
|