graph_features.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_GRAPH_FEATURES_H_
  5. #define COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_GRAPH_FEATURES_H_
  6. #include <cstdint>
  7. namespace performance_manager {
  8. class Graph;
  9. // A helper for configuring and enabling Graph features. This object is
  10. // constexpr so that it can be easily used with static storage without
  11. // requiring an initializer.
  12. class GraphFeatures {
  13. public:
  14. // Returns a configuration with no graph features. Mostly intended for
  15. // unittests, where tests pick and choose exactly which decorators they want.
  16. static constexpr GraphFeatures WithNone() { return GraphFeatures(); }
  17. // Returns a configuration with the minimal set of graph features required
  18. // for content_shell to work.
  19. static constexpr GraphFeatures WithMinimal() {
  20. return GraphFeatures().EnableMinimal();
  21. }
  22. // Returns a configuration with the default set of graph features shipped
  23. // with a full-featured Chromium browser.
  24. static constexpr GraphFeatures WithDefault() {
  25. return GraphFeatures().EnableDefault();
  26. }
  27. // Helper for housing the actual configuration data.
  28. union Flags {
  29. uint32_t flags;
  30. struct {
  31. // When adding new features here, the following also needs to happen:
  32. // (1) Add a corresponding EnableFeatureFoo() member function.
  33. // (2) Add the feature to EnableDefault() if necessary.
  34. // (3) Add the feature to the implementation of ConfigureGraph().
  35. bool execution_context_priority_decorator : 1;
  36. bool execution_context_registry : 1;
  37. bool frame_node_impl_describer : 1;
  38. bool frame_visibility_decorator : 1;
  39. bool freezing_vote_decorator : 1;
  40. bool metrics_collector : 1;
  41. bool page_live_state_decorator : 1;
  42. bool page_load_tracker_decorator : 1;
  43. bool page_node_impl_describer : 1;
  44. bool process_hosted_content_types_aggregator : 1;
  45. bool process_node_impl_describer : 1;
  46. bool site_data_recorder : 1;
  47. bool tab_properties_decorator : 1;
  48. bool v8_context_tracker : 1;
  49. bool worker_node_impl_describer : 1;
  50. };
  51. };
  52. constexpr GraphFeatures() = default;
  53. constexpr GraphFeatures(const GraphFeatures& other) = default;
  54. GraphFeatures& operator=(const GraphFeatures& other) = default;
  55. constexpr GraphFeatures& EnableExecutionContextPriorityDecorator() {
  56. EnableExecutionContextRegistry();
  57. flags_.execution_context_priority_decorator = true;
  58. return *this;
  59. }
  60. constexpr GraphFeatures& EnableExecutionContextRegistry() {
  61. flags_.execution_context_registry = true;
  62. return *this;
  63. }
  64. constexpr GraphFeatures& EnableFrameNodeImplDescriber() {
  65. flags_.frame_node_impl_describer = true;
  66. return *this;
  67. }
  68. constexpr GraphFeatures& EnableFrameVisibilityDecorator() {
  69. flags_.frame_visibility_decorator = true;
  70. return *this;
  71. }
  72. constexpr GraphFeatures& EnableMetricsCollector() {
  73. flags_.metrics_collector = true;
  74. return *this;
  75. }
  76. constexpr GraphFeatures& EnableFreezingVoteDecorator() {
  77. flags_.freezing_vote_decorator = true;
  78. return *this;
  79. }
  80. constexpr GraphFeatures& EnablePageLiveStateDecorator() {
  81. flags_.page_live_state_decorator = true;
  82. return *this;
  83. }
  84. constexpr GraphFeatures& EnablePageLoadTrackerDecorator() {
  85. flags_.page_load_tracker_decorator = true;
  86. return *this;
  87. }
  88. constexpr GraphFeatures& EnablePageNodeImplDescriber() {
  89. flags_.page_node_impl_describer = true;
  90. return *this;
  91. }
  92. constexpr GraphFeatures& EnableProcessHostedContentTypesAggregator() {
  93. flags_.process_hosted_content_types_aggregator = true;
  94. return *this;
  95. }
  96. constexpr GraphFeatures& EnableProcessNodeImplDescriber() {
  97. flags_.process_node_impl_describer = true;
  98. return *this;
  99. }
  100. // This is a nop on the Android platform, as the feature isn't available
  101. // there.
  102. constexpr GraphFeatures& EnableSiteDataRecorder() {
  103. flags_.site_data_recorder = true;
  104. return *this;
  105. }
  106. constexpr GraphFeatures& EnableTabPropertiesDecorator() {
  107. flags_.tab_properties_decorator = true;
  108. return *this;
  109. }
  110. constexpr GraphFeatures& EnableV8ContextTracker() {
  111. EnableExecutionContextRegistry();
  112. flags_.v8_context_tracker = true;
  113. return *this;
  114. }
  115. constexpr GraphFeatures& EnableWorkerNodeImplDescriber() {
  116. flags_.worker_node_impl_describer = true;
  117. return *this;
  118. }
  119. // Helper to enable the minimal set of features required for a content_shell
  120. // browser to work.
  121. constexpr GraphFeatures& EnableMinimal() {
  122. EnableExecutionContextRegistry();
  123. EnableV8ContextTracker();
  124. return *this;
  125. }
  126. // Helper to enable the default set of features. This is only intended for use
  127. // from production code.
  128. constexpr GraphFeatures& EnableDefault() {
  129. EnableExecutionContextRegistry();
  130. EnableFrameNodeImplDescriber();
  131. EnableFrameVisibilityDecorator();
  132. EnableFreezingVoteDecorator();
  133. EnableMetricsCollector();
  134. EnablePageLiveStateDecorator();
  135. EnablePageLoadTrackerDecorator();
  136. EnablePageNodeImplDescriber();
  137. EnableProcessHostedContentTypesAggregator();
  138. EnableProcessNodeImplDescriber();
  139. EnableSiteDataRecorder();
  140. EnableTabPropertiesDecorator();
  141. EnableV8ContextTracker();
  142. EnableWorkerNodeImplDescriber();
  143. return *this;
  144. }
  145. // Accessor for the current set of flags_.
  146. constexpr const Flags& flags() const { return flags_; }
  147. // Applies the configuration specified on this object to the provided
  148. // graph. This will unconditionally try to install all of the enabled
  149. // features, even if they have already been installed; it is generally
  150. // preferable to call this exactly once on a brand new |graph| instance that
  151. // has had no features installed. Otherwise, it is safe to call this to
  152. // install new features that the caller knows have not yet been installed.
  153. void ConfigureGraph(Graph* graph) const;
  154. private:
  155. Flags flags_ = {0};
  156. };
  157. } // namespace performance_manager
  158. #endif // COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_GRAPH_FEATURES_H_