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 2023 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_PUBLIC_RESOURCE_ATTRIBUTION_FRAME_CONTEXT_H_
#define COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_RESOURCE_ATTRIBUTION_FRAME_CONTEXT_H_
#include <compare>
#include <optional>
#include <string>
#include "base/memory/weak_ptr.h"
#include "content/public/browser/global_routing_id.h"
namespace content {
class RenderFrameHost;
}
namespace performance_manager {
class FrameNode;
}
namespace resource_attribution {
class FrameContext {
public:
~FrameContext();
FrameContext(const FrameContext& other);
FrameContext& operator=(const FrameContext& other);
FrameContext(FrameContext&& other);
FrameContext& operator=(FrameContext&& other);
// UI thread methods.
// Returns the FrameContext for `host`, which must be non-null and have a
// valid GlobalRenderFrameHostId. Returns nullopt if the RenderFrameHost is
// not registered with PerformanceManager. (There is a brief window after the
// RenderFrameHost is created before a PerformanceManager FrameNode is created
// for it.)
static std::optional<FrameContext> FromRenderFrameHost(
content::RenderFrameHost* host);
// Returns the RenderFrameHost for this context, or nullptr if it no longer
// exists.
content::RenderFrameHost* GetRenderFrameHost() const;
// Return the GlobalRenderFrameHostId that was assigned to this context's
// RenderFrameHost.
content::GlobalRenderFrameHostId GetRenderFrameHostId() const;
// Returns the FrameNode for this context, or a null WeakPtr if it no longer
// exists.
base::WeakPtr<performance_manager::FrameNode> GetWeakFrameNode() const;
// PM sequence methods.
// Returns the FrameContext for `node`. Equivalent to
// node->GetResourceContext().
static FrameContext FromFrameNode(const performance_manager::FrameNode* node);
// Returns the FrameContext for `node`, or nullopt if `node` is null.
static std::optional<FrameContext> FromWeakFrameNode(
base::WeakPtr<performance_manager::FrameNode> node);
// Returns the FrameNode for this context, or nullptr if it no longer exists.
performance_manager::FrameNode* GetFrameNode() const;
// Returns a string representation of the context for debugging. This matches
// the interface of base::TokenType and base::UnguessableToken, for
// convenience.
std::string ToString() const;
// Compare FrameContexts by GlobalRenderFrameHostId.
constexpr friend auto operator<=>(const FrameContext& a,
const FrameContext& b) {
return a.id_ <=> b.id_;
}
// Test FrameContexts for equality by GlobalRenderFrameHostId.
constexpr friend bool operator==(const FrameContext& a,
const FrameContext& b) {
return a.id_ == b.id_;
}
private:
FrameContext(content::GlobalRenderFrameHostId id,
base::WeakPtr<performance_manager::FrameNode> weak_node);
content::GlobalRenderFrameHostId id_;
base::WeakPtr<performance_manager::FrameNode> weak_node_;
};
} // namespace resource_attribution
#endif // COMPONENTS_PERFORMANCE_MANAGER_PUBLIC_RESOURCE_ATTRIBUTION_FRAME_CONTEXT_H_
|