File: context_collection.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (64 lines) | stat: -rw-r--r-- 2,382 bytes parent folder | download | duplicates (4)
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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_PERFORMANCE_MANAGER_RESOURCE_ATTRIBUTION_CONTEXT_COLLECTION_H_
#define COMPONENTS_PERFORMANCE_MANAGER_RESOURCE_ATTRIBUTION_CONTEXT_COLLECTION_H_

#include <bitset>
#include <set>
#include <variant>

#include "components/performance_manager/public/resource_attribution/resource_contexts.h"

namespace resource_attribution {

// A mixed collection of individual ResourceContext's and
// ResourceContextTypeId's.
//
// ResourceContextTypeId's are integers that map to specific context types (ie.
// alternatives in the ResourceContext variant). In this collection they
// represent "all contexts of the given type", which is a set that changes over
// time as contexts are created and deleted.
class ContextCollection {
 public:
  ContextCollection();
  ~ContextCollection();

  ContextCollection(const ContextCollection& other);
  ContextCollection& operator=(const ContextCollection& other);

  friend bool operator==(const ContextCollection&,
                         const ContextCollection&) = default;

  // Adds `context` to the collection.
  void AddResourceContext(const ResourceContext& context);

  // Adds `type_id` to the collection so that all contexts of that type will be
  // implicitly included.
  void AddAllContextsOfType(internal::ResourceContextTypeId type_id);

  // Returns true iff the collection contains nothing.
  bool IsEmpty() const;

  // Returns true iff the collection contains `context`, either explicitly or
  // because the collection tracks all contexts of its type.
  bool ContainsContext(const ResourceContext& context) const;

  static ContextCollection CreateForTesting(
      std::set<ResourceContext> resource_contexts,
      std::set<internal::ResourceContextTypeId> all_context_types);

 private:
  // Individual resource contexts to measure.
  std::set<ResourceContext> resource_contexts_;

  // A set of ResourceContextTypeId's (converted to int and stored in a bitset
  // for efficiency). For each of these context types, all contexts that exist
  // will be measured.
  std::bitset<std::variant_size<ResourceContext>::value> all_context_types_;
};

}  // namespace resource_attribution

#endif  // COMPONENTS_PERFORMANCE_MANAGER_RESOURCE_ATTRIBUTION_CONTEXT_COLLECTION_H_