summaryrefslogtreecommitdiff
path: root/chromium/components/consent_auditor/fake_consent_auditor.cc
blob: 3301dc6d7d190621673f71cfc74e8dea3f7e162f (plain)
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
// 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 <string>
#include <utility>

#include "components/consent_auditor/consent_auditor.h"
#include "components/consent_auditor/fake_consent_auditor.h"
#include "components/sync/protocol/user_consent_specifics.pb.h"
#include "components/sync/protocol/user_consent_types.pb.h"

namespace {

consent_auditor::ConsentStatus ConvertConsentStatus(
    sync_pb::UserConsentTypes::ConsentStatus consent_status) {
  DCHECK_NE(consent_status,
            sync_pb::UserConsentTypes::ConsentStatus::
                UserConsentTypes_ConsentStatus_CONSENT_STATUS_UNSPECIFIED);

  if (consent_status == sync_pb::UserConsentTypes::ConsentStatus::
                            UserConsentTypes_ConsentStatus_GIVEN) {
    return consent_auditor::ConsentStatus::GIVEN;
  }
  return consent_auditor::ConsentStatus::NOT_GIVEN;
}

}  // namespace

namespace consent_auditor {

FakeConsentAuditor::FakeConsentAuditor() = default;

FakeConsentAuditor::~FakeConsentAuditor() = default;

void FakeConsentAuditor::RecordSyncConsent(
    const CoreAccountId& account_id,
    const sync_pb::UserConsentTypes::SyncConsent& consent) {
  // TODO(markusheintz): Change the Fake to store the proto instead of calling
  // RecordGaiaConsent.
  std::vector<int> description_grd_ids(consent.description_grd_ids().begin(),
                                       consent.description_grd_ids().end());
  RecordGaiaConsent(account_id, Feature::CHROME_SYNC, description_grd_ids,
                    consent.confirmation_grd_id(),
                    ConvertConsentStatus(consent.status()));
}

void FakeConsentAuditor::RecordAssistantActivityControlConsent(
    const CoreAccountId& account_id,
    const sync_pb::UserConsentTypes::AssistantActivityControlConsent& consent) {
  account_id_ = account_id;
  sync_pb::UserConsentSpecifics consent_specifics;
  *consent_specifics.mutable_assistant_activity_control_consent() = consent;
  recorded_consents_.push_back(std::move(consent_specifics));
}

void FakeConsentAuditor::RecordAccountPasswordsConsent(
    const CoreAccountId& account_id,
    const sync_pb::UserConsentTypes::AccountPasswordsConsent& consent) {
  account_id_ = account_id;
  sync_pb::UserConsentSpecifics consent_specifics;
  *consent_specifics.mutable_account_passwords_consent() = consent;
  recorded_consents_.push_back(std::move(consent_specifics));
}

void FakeConsentAuditor::RecordAutofillAssistantConsent(
    const CoreAccountId& account_id,
    const sync_pb::UserConsentTypes::AutofillAssistantConsent& consent) {
  account_id_ = account_id;
  sync_pb::UserConsentSpecifics consent_specifics;
  *consent_specifics.mutable_autofill_assistant_consent() = consent;
  recorded_consents_.push_back(std::move(consent_specifics));
}

void FakeConsentAuditor::RecordGaiaConsent(
    const CoreAccountId& account_id,
    consent_auditor::Feature feature,
    const std::vector<int>& description_grd_ids,
    int confirmation_grd_id,
    consent_auditor::ConsentStatus status) {
  account_id_ = account_id;
  recorded_id_vectors_.push_back(description_grd_ids);
  recorded_confirmation_ids_.push_back(confirmation_grd_id);
  recorded_features_.push_back(feature);
  recorded_statuses_.push_back(status);
}

void FakeConsentAuditor::RecordLocalConsent(
    const std::string& feature,
    const std::string& description_text,
    const std::string& confirmation_text) {
  NOTIMPLEMENTED();
}

base::WeakPtr<syncer::ModelTypeControllerDelegate>
FakeConsentAuditor::GetControllerDelegate() {
  NOTIMPLEMENTED();
  return nullptr;
}

}  // namespace consent_auditor