123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- // Copyright 2019 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 COMPONENTS_PERFORMANCE_MANAGER_GRAPH_GRAPH_IMPL_OPERATIONS_H_
- #define COMPONENTS_PERFORMANCE_MANAGER_GRAPH_GRAPH_IMPL_OPERATIONS_H_
- #include "base/containers/flat_set.h"
- #include "components/performance_manager/graph/frame_node_impl.h"
- #include "components/performance_manager/graph/page_node_impl.h"
- namespace performance_manager {
- class ProcessNodeImpl;
- // A collection of utilities for performing common queries and traversals on a
- // graph.
- struct GraphImplOperations {
- // Returns the collection of page nodes that are associated with the given
- // |process|. A page is associated with a process if the page's frame tree
- // contains 1 or more frames hosted in the given |process|.
- static base::flat_set<PageNodeImpl*> GetAssociatedPageNodes(
- const ProcessNodeImpl* process);
- // Returns the collection of process nodes associated with the given |page|.
- // A |process| is associated with a page if the page's frame tree contains 1
- // or more frames hosted in that |process|.
- static base::flat_set<ProcessNodeImpl*> GetAssociatedProcessNodes(
- const PageNodeImpl* page);
- // Returns the collection of frame nodes associated with a page. This is
- // returned in level order, with main frames first (level 0), main frame
- // children next (level 1), all the way down to the deepest leaf frames.
- static std::vector<FrameNodeImpl*> GetFrameNodes(const PageNodeImpl* page);
- // Traverse the frame tree of a |page| in the given order, invoking the
- // provided |callable| for each frame node in the tree. The |callable| has to
- // provide a "bool operator()(FrameNodeImpl*)". If the visitor returns false
- // then the iteration is halted. Returns true if all calls to the visitor
- // returned true, false otherwise.
- template <typename Callable>
- static bool VisitFrameTreePreOrder(const PageNodeImpl* page,
- Callable callable);
- template <typename Callable>
- static bool VisitFrameTreePostOrder(const PageNodeImpl* page,
- Callable callable);
- // Returns true if the given |frame| is in the frame tree associated with the
- // given |page|.
- static bool HasFrame(const PageNodeImpl* page, FrameNodeImpl* frame);
- };
- // Implementation details for VisitFrameTree*.
- namespace internal {
- template <typename Callable>
- bool VisitFrameAndChildren(FrameNodeImpl* frame,
- Callable callable,
- bool pre_order) {
- if (pre_order && !callable(frame))
- return false;
- for (auto* child : frame->child_frame_nodes()) {
- if (!VisitFrameAndChildren(child, callable, pre_order))
- return false;
- }
- if (!pre_order && !callable(frame))
- return false;
- return true;
- }
- template <typename Callable>
- bool VisitFrameTree(const PageNodeImpl* page,
- Callable callable,
- bool pre_order) {
- for (auto* main_frame_node : page->main_frame_nodes()) {
- if (!VisitFrameAndChildren(main_frame_node, callable, pre_order))
- return false;
- }
- return true;
- }
- } // namespace internal
- // static
- template <typename Callable>
- bool GraphImplOperations::VisitFrameTreePreOrder(const PageNodeImpl* page,
- Callable callable) {
- return internal::VisitFrameTree(page, callable, true);
- }
- // static
- template <typename Callable>
- bool GraphImplOperations::VisitFrameTreePostOrder(const PageNodeImpl* page,
- Callable callable) {
- return internal::VisitFrameTree(page, callable, false);
- }
- } // namespace performance_manager
- #endif // COMPONENTS_PERFORMANCE_MANAGER_GRAPH_GRAPH_IMPL_OPERATIONS_H_
|