summaryrefslogtreecommitdiff
path: root/chromium/components/performance_manager/graph/frame_node_impl_describer.cc
blob: 3c84b68648aa811909624a33d81dd4929ab6784e (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// 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.

#include "components/performance_manager/graph/frame_node_impl_describer.h"

#include <sstream>
#include <string>
#include <utility>

#include "base/values.h"
#include "components/performance_manager/graph/frame_node_impl.h"
#include "components/performance_manager/public/graph/node_data_describer_registry.h"
#include "components/performance_manager/public/graph/node_data_describer_util.h"

namespace performance_manager {

namespace {

std::string ViewportIntersectionToString(
    const absl::optional<gfx::Rect>& viewport_intersection) {
  if (!viewport_intersection.has_value())
    return "Nullopt";

  return viewport_intersection->ToString();
}

std::string FrameNodeVisibilityToString(FrameNode::Visibility visibility) {
  switch (visibility) {
    // using FrameNode::Visibility;
    case FrameNode::Visibility::kUnknown:
      return "Unknown";
    case FrameNode::Visibility::kVisible:
      return "Visible";
    case FrameNode::Visibility::kNotVisible:
      return "Not visible";
  }
}

}  // namespace

FrameNodeImplDescriber::~FrameNodeImplDescriber() = default;

void FrameNodeImplDescriber::OnPassedToGraph(Graph* graph) {
  graph->GetNodeDataDescriberRegistry()->RegisterDescriber(this,
                                                           "FrameNodeImpl");
}

void FrameNodeImplDescriber::OnTakenFromGraph(Graph* graph) {
  graph->GetNodeDataDescriberRegistry()->UnregisterDescriber(this);
}

base::Value FrameNodeImplDescriber::DescribeFrameNodeData(
    const FrameNode* node) const {
  const FrameNodeImpl* impl = FrameNodeImpl::FromNode(node);

  base::Value ret(base::Value::Type::DICTIONARY);

  // Document specific properties. These are emitted in a nested dictionary, as
  // a frame node can be reused for different documents.
  base::Value doc(base::Value::Type::DICTIONARY);
  doc.SetStringKey("url", impl->document_.url.value().possibly_invalid_spec());
  doc.SetBoolKey("has_nonempty_beforeunload",
                 impl->document_.has_nonempty_beforeunload);
  doc.SetBoolKey("network_almost_idle",
                 impl->document_.network_almost_idle.value());
  doc.SetBoolKey("had_form_interaction",
                 impl->document_.had_form_interaction.value());
  ret.SetKey("document", std::move(doc));

  // Frame node properties.
  ret.SetIntKey("frame_tree_node_id", impl->frame_tree_node_id_);
  ret.SetIntKey("render_frame_id", impl->render_frame_id_);
  ret.SetStringKey("frame_token", impl->frame_token_.value().ToString());
  ret.SetIntKey("browsing_instance_id", impl->browsing_instance_id_);
  ret.SetIntKey("site_instance_id", impl->site_instance_id_);
  ret.SetStringKey("lifecycle_state",
                   MojoEnumToString(impl->lifecycle_state_.value()));
  ret.SetBoolKey("is_ad_frame", impl->is_ad_frame_.value());
  ret.SetBoolKey("is_holding_weblock", impl->is_holding_weblock_.value());
  ret.SetBoolKey("is_holding_indexeddb_lock",
                 impl->is_holding_indexeddb_lock_.value());
  ret.SetBoolKey("is_current", impl->is_current_.value());
  ret.SetKey("priority",
             PriorityAndReasonToValue(impl->priority_and_reason_.value()));
  ret.SetBoolKey("is_audible", impl->is_audible_.value());
  ret.SetStringKey(
      "viewport_intersection",
      ViewportIntersectionToString(impl->viewport_intersection_.value()));
  ret.SetStringKey("visibility",
                   FrameNodeVisibilityToString(impl->visibility_.value()));

  return ret;
}

}  // namespace performance_manager