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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/performance_manager/execution_context/execution_context_impl.h"
#include "base/sequence_checker.h"
#include "components/performance_manager/graph/frame_node_impl.h"
#include "components/performance_manager/graph/process_node_impl.h"
#include "components/performance_manager/graph/worker_node_impl.h"
#include "components/performance_manager/public/execution_context/execution_context_registry.h"
#include "components/performance_manager/public/graph/graph.h"
#include "third_party/blink/public/common/tokens/tokens.h"
namespace performance_manager {
namespace execution_context {
// Declared in execution_context.h.
blink::ExecutionContextToken ToExecutionContextToken(
const blink::WorkerToken& token) {
if (token.Is<blink::DedicatedWorkerToken>()) {
return blink::ExecutionContextToken(
token.GetAs<blink::DedicatedWorkerToken>());
}
if (token.Is<blink::ServiceWorkerToken>()) {
return blink::ExecutionContextToken(
token.GetAs<blink::ServiceWorkerToken>());
}
if (token.Is<blink::SharedWorkerToken>()) {
return blink::ExecutionContextToken(
token.GetAs<blink::SharedWorkerToken>());
}
// Unfortunately there's no enum of input types, so no way to ensure that
// all types are handled at compile time. This at least ensures via the CQ
// that all types are handled.
NOTREACHED();
}
FrameExecutionContext::FrameExecutionContext(const FrameNodeImpl* frame_node)
: frame_node_(frame_node) {}
FrameExecutionContext::FrameExecutionContext(FrameExecutionContext&&) = default;
FrameExecutionContext& FrameExecutionContext::operator=(
FrameExecutionContext&&) = default;
FrameExecutionContext::~FrameExecutionContext() = default;
ExecutionContextType FrameExecutionContext::GetType() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return ExecutionContextType::kFrameNode;
}
blink::ExecutionContextToken FrameExecutionContext::GetToken() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return blink::ExecutionContextToken(frame_node_->GetFrameToken());
}
Graph* FrameExecutionContext::GetGraph() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return frame_node_->graph();
}
NodeState FrameExecutionContext::GetNodeState() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return frame_node_->GetNodeState();
}
const GURL& FrameExecutionContext::GetUrl() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return frame_node_->GetURL();
}
const ProcessNode* FrameExecutionContext::GetProcessNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return frame_node_->process_node();
}
const PriorityAndReason& FrameExecutionContext::GetPriorityAndReason() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return frame_node_->GetPriorityAndReason();
}
const FrameNode* FrameExecutionContext::GetFrameNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return frame_node_;
}
const WorkerNode* FrameExecutionContext::GetWorkerNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return nullptr;
}
WorkerExecutionContext::WorkerExecutionContext(
const WorkerNodeImpl* worker_node)
: worker_node_(worker_node) {}
WorkerExecutionContext::WorkerExecutionContext(WorkerExecutionContext&&) =
default;
WorkerExecutionContext& WorkerExecutionContext::operator=(
WorkerExecutionContext&&) = default;
WorkerExecutionContext::~WorkerExecutionContext() = default;
ExecutionContextType WorkerExecutionContext::GetType() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return ExecutionContextType::kWorkerNode;
}
blink::ExecutionContextToken WorkerExecutionContext::GetToken() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return ToExecutionContextToken(worker_node_->GetWorkerToken());
}
Graph* WorkerExecutionContext::GetGraph() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return worker_node_->graph();
}
NodeState WorkerExecutionContext::GetNodeState() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return worker_node_->GetNodeState();
}
const GURL& WorkerExecutionContext::GetUrl() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return worker_node_->GetURL();
}
const ProcessNode* WorkerExecutionContext::GetProcessNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return worker_node_->process_node();
}
const PriorityAndReason& WorkerExecutionContext::GetPriorityAndReason() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return worker_node_->GetPriorityAndReason();
}
const FrameNode* WorkerExecutionContext::GetFrameNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return nullptr;
}
const WorkerNode* WorkerExecutionContext::GetWorkerNode() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return worker_node_;
}
// Declared in execution_context.h.
// static
const ExecutionContext* ExecutionContext::From(const FrameNode* frame_node) {
return ExecutionContextRegistry::GetExecutionContextForFrameNode(frame_node);
}
// Declared in execution_context.h.
// static
const ExecutionContext* ExecutionContext::From(const WorkerNode* worker_node) {
return ExecutionContextRegistry::GetExecutionContextForWorkerNode(
worker_node);
}
} // namespace execution_context
} // namespace performance_manager
|