summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/public/common/interest_group/interest_group_mojom_traits.h
blob: 3950b3de07dcd96fba6e3044a9703e844848b5eb (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
// Copyright 2021 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 THIRD_PARTY_BLINK_PUBLIC_COMMON_INTEREST_GROUP_INTEREST_GROUP_MOJOM_TRAITS_H_
#define THIRD_PARTY_BLINK_PUBLIC_COMMON_INTEREST_GROUP_INTEREST_GROUP_MOJOM_TRAITS_H_

#include <string>
#include <vector>

#include "base/time/time.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
#include "third_party/blink/public/common/common_export.h"
#include "third_party/blink/public/common/interest_group/interest_group.h"
#include "third_party/blink/public/mojom/interest_group/interest_group_types.mojom-forward.h"
#include "url/gurl.h"
#include "url/origin.h"

namespace mojo {

template <>
struct BLINK_COMMON_EXPORT StructTraits<blink::mojom::InterestGroupAdDataView,
                                        blink::InterestGroup::Ad> {
  static const GURL& render_url(const blink::InterestGroup::Ad& ad) {
    return ad.render_url;
  }

  static const absl::optional<std::string>& metadata(
      const blink::InterestGroup::Ad& ad) {
    return ad.metadata;
  }

  static bool Read(blink::mojom::InterestGroupAdDataView data,
                   blink::InterestGroup::Ad* out);
};

template <>
struct BLINK_COMMON_EXPORT
    StructTraits<blink::mojom::InterestGroupDataView, blink::InterestGroup> {
  static base::Time expiry(const blink::InterestGroup& interest_group) {
    return interest_group.expiry;
  }

  static const url::Origin& owner(const blink::InterestGroup& interest_group) {
    return interest_group.owner;
  }

  static const std::string& name(const blink::InterestGroup& interest_group) {
    return interest_group.name;
  }

  static const absl::optional<GURL>& bidding_url(
      const blink::InterestGroup& interest_group) {
    return interest_group.bidding_url;
  }

  static const absl::optional<GURL>& update_url(
      const blink::InterestGroup& interest_group) {
    return interest_group.update_url;
  }

  static const absl::optional<GURL>& trusted_bidding_signals_url(
      const blink::InterestGroup& interest_group) {
    return interest_group.trusted_bidding_signals_url;
  }

  static const absl::optional<std::vector<std::string>>&
  trusted_bidding_signals_keys(const blink::InterestGroup& interest_group) {
    return interest_group.trusted_bidding_signals_keys;
  }

  static const absl::optional<std::string>& user_bidding_signals(
      const blink::InterestGroup& interest_group) {
    return interest_group.user_bidding_signals;
  }

  static const absl::optional<std::vector<blink::InterestGroup::Ad>>& ads(
      const blink::InterestGroup& interest_group) {
    return interest_group.ads;
  }

  static bool Read(blink::mojom::InterestGroupDataView data,
                   blink::InterestGroup* out);
};

}  // namespace mojo

#endif  // THIRD_PARTY_BLINK_PUBLIC_COMMON_INTEREST_GROUP_INTEREST_GROUP_MOJOM_TRAITS_H_