summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/timing/performance_observer_entry_list.cc
blob: 7ec0c295816311ca8b3bc00c007e0a0385486280 (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
// Copyright 2015 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 "third_party/blink/renderer/core/timing/performance_observer_entry_list.h"

#include <algorithm>
#include "third_party/blink/renderer/core/timing/performance_entry.h"
#include "third_party/blink/renderer/platform/wtf/std_lib_extras.h"

namespace blink {

PerformanceObserverEntryList::PerformanceObserverEntryList(
    const PerformanceEntryVector& entry_vector)
    : performance_entries_(entry_vector) {}

PerformanceObserverEntryList::~PerformanceObserverEntryList() = default;

PerformanceEntryVector PerformanceObserverEntryList::getEntries() const {
  PerformanceEntryVector entries;

  entries.AppendVector(performance_entries_);

  std::sort(entries.begin(), entries.end(),
            PerformanceEntry::StartTimeCompareLessThan);
  return entries;
}

PerformanceEntryVector PerformanceObserverEntryList::getEntriesByType(
    const AtomicString& entry_type) {
  PerformanceEntryVector entries;
  PerformanceEntry::EntryType type =
      PerformanceEntry::ToEntryTypeEnum(entry_type);

  if (type == PerformanceEntry::kInvalid)
    return entries;

  for (const auto& entry : performance_entries_) {
    if (entry->EntryTypeEnum() == type) {
      entries.push_back(entry);
    }
  }

  std::sort(entries.begin(), entries.end(),
            PerformanceEntry::StartTimeCompareLessThan);
  return entries;
}

PerformanceEntryVector PerformanceObserverEntryList::getEntriesByName(
    const String& name,
    const AtomicString& entry_type) {
  PerformanceEntryVector entries;
  PerformanceEntry::EntryType type =
      PerformanceEntry::ToEntryTypeEnum(entry_type);

  if (!entry_type.IsNull() && type == PerformanceEntry::kInvalid)
    return entries;

  for (const auto& entry : performance_entries_) {
    if (entry->name() == name &&
        (entry_type.IsNull() || type == entry->EntryTypeEnum())) {
      entries.push_back(entry);
    }
  }

  std::sort(entries.begin(), entries.end(),
            PerformanceEntry::StartTimeCompareLessThan);
  return entries;
}

void PerformanceObserverEntryList::Trace(Visitor* visitor) const {
  visitor->Trace(performance_entries_);
  ScriptWrappable::Trace(visitor);
}

}  // namespace blink