summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/scheduler/main_thread/attribution_group.h
blob: 4d5b3b0bf4b01b90b94bfb8aed774a1c4e7e9211 (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
// Copyright 2020 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_RENDERER_PLATFORM_SCHEDULER_MAIN_THREAD_ATTRIBUTION_GROUP_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_MAIN_THREAD_ATTRIBUTION_GROUP_H_

#include "third_party/blink/public/common/input/web_input_event_attribution.h"
#include "third_party/blink/renderer/platform/wtf/hash_functions.h"
#include "third_party/blink/renderer/platform/wtf/hash_traits.h"

namespace blink {
namespace scheduler {

// A hashable wrapper around a WebInputEventAttribution that can be used to
// group pending events together.
struct AttributionGroup {
  explicit AttributionGroup(WebInputEventAttribution attribution)
      : attribution(attribution) {}

  explicit AttributionGroup(WTF::HashTableDeletedValueType)
      : is_deleted_value(true) {}

  AttributionGroup() = default;

  bool IsHashTableDeletedValue() const { return is_deleted_value; }

  bool operator==(const AttributionGroup& other) const {
    return attribution == other.attribution &&
           is_deleted_value == other.is_deleted_value;
  }

  WebInputEventAttribution attribution = {};
  bool is_deleted_value = false;
};

struct AttributionGroupHash {
  STATIC_ONLY(AttributionGroupHash);

  static unsigned GetHash(const AttributionGroup& group) {
    return group.attribution.GetHash();
  }

  static bool Equal(const AttributionGroup& a, const AttributionGroup& b) {
    return a == b;
  }

  static const bool safe_to_compare_to_empty_or_deleted = true;
};

}  // namespace scheduler
}  // namespace blink

namespace WTF {

template <>
struct DefaultHash<blink::scheduler::AttributionGroup> {
  using Hash = blink::scheduler::AttributionGroupHash;
};

template <>
struct HashTraits<blink::scheduler::AttributionGroup>
    : SimpleClassHashTraits<blink::scheduler::AttributionGroup> {
  static const bool kEmptyValueIsZero = false;
};

}  // namespace WTF

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_SCHEDULER_MAIN_THREAD_ATTRIBUTION_GROUP_H_