#include "components/performance_manager/worker_watcher.h"
#include <map>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/functional/overloaded.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "components/performance_manager/frame_node_source.h"
#include "components/performance_manager/graph/frame_node_impl.h"
#include "components/performance_manager/graph/worker_node_impl.h"
#include "components/performance_manager/performance_manager_impl.h"
#include "components/performance_manager/process_node_source.h"
#include "components/performance_manager/public/features.h"
#include "third_party/blink/public/common/tokens/tokens.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace performance_manager {
WorkerNodeSet;
namespace {
void ConnectClientFrameOnGraph(WorkerNodeImpl* worker_node,
FrameNodeImpl* client_frame_node) { … }
void DisconnectClientFrameOnGraph(WorkerNodeImpl* worker_node,
FrameNodeImpl* client_frame_node) { … }
void ConnectClientWorkerOnGraph(WorkerNodeImpl* worker_node,
WorkerNodeImpl* client_worker_node) { … }
void DisconnectClientWorkerOnGraph(WorkerNodeImpl* worker_node,
WorkerNodeImpl* client_worker_node) { … }
void DisconnectClientsOnGraph(WorkerNodeSet worker_nodes,
FrameNodeImpl* client_frame_node) { … }
void DisconnectClientsOnGraph(
base::flat_map<WorkerNodeImpl*, size_t> worker_node_connections,
FrameNodeImpl* client_frame_node) { … }
void DisconnectClientsOnGraph(WorkerNodeSet worker_nodes,
WorkerNodeImpl* client_worker_node) { … }
void SetFinalResponseURL(WorkerNodeImpl* worker_node, const GURL& url) { … }
}
WorkerWatcher::WorkerWatcher(
const std::string& browser_context_id,
content::DedicatedWorkerService* dedicated_worker_service,
content::SharedWorkerService* shared_worker_service,
ServiceWorkerContextAdapter* service_worker_context_adapter,
ProcessNodeSource* process_node_source,
FrameNodeSource* frame_node_source)
: … { … }
WorkerWatcher::~WorkerWatcher() { … }
void WorkerWatcher::TearDown() { … }
void WorkerWatcher::OnWorkerCreated(
const blink::DedicatedWorkerToken& dedicated_worker_token,
int worker_process_id,
const url::Origin& security_origin,
content::DedicatedWorkerCreator creator) { … }
void WorkerWatcher::OnBeforeWorkerDestroyed(
const blink::DedicatedWorkerToken& dedicated_worker_token,
content::DedicatedWorkerCreator creator) { … }
void WorkerWatcher::OnFinalResponseURLDetermined(
const blink::DedicatedWorkerToken& dedicated_worker_token,
const GURL& url) { … }
void WorkerWatcher::OnWorkerCreated(
const blink::SharedWorkerToken& shared_worker_token,
int worker_process_id,
const url::Origin& security_origin,
const base::UnguessableToken& ) { … }
void WorkerWatcher::OnBeforeWorkerDestroyed(
const blink::SharedWorkerToken& shared_worker_token) { … }
void WorkerWatcher::OnFinalResponseURLDetermined(
const blink::SharedWorkerToken& shared_worker_token,
const GURL& url) { … }
void WorkerWatcher::OnClientAdded(
const blink::SharedWorkerToken& shared_worker_token,
content::GlobalRenderFrameHostId render_frame_host_id) { … }
void WorkerWatcher::OnClientRemoved(
const blink::SharedWorkerToken& shared_worker_token,
content::GlobalRenderFrameHostId render_frame_host_id) { … }
void WorkerWatcher::OnVersionStartedRunning(
int64_t version_id,
const content::ServiceWorkerRunningInfo& running_info) { … }
void WorkerWatcher::OnVersionStoppedRunning(int64_t version_id) { … }
void WorkerWatcher::OnControlleeAdded(
int64_t version_id,
const std::string& client_uuid,
const content::ServiceWorkerClientInfo& client_info) { … }
void WorkerWatcher::OnControlleeRemoved(int64_t version_id,
const std::string& client_uuid) { … }
void WorkerWatcher::OnControlleeNavigationCommitted(
int64_t version_id,
const std::string& client_uuid,
content::GlobalRenderFrameHostId render_frame_host_id) { … }
WorkerNodeImpl* WorkerWatcher::FindWorkerNodeForToken(
const blink::WorkerToken& token) const { … }
void WorkerWatcher::AddFrameClientConnection(
WorkerNodeImpl* worker_node,
content::GlobalRenderFrameHostId client_render_frame_host_id) { … }
void WorkerWatcher::RemoveFrameClientConnection(
WorkerNodeImpl* worker_node,
content::GlobalRenderFrameHostId client_render_frame_host_id) { … }
void WorkerWatcher::ConnectDedicatedWorkerClient(
WorkerNodeImpl* worker_node,
blink::DedicatedWorkerToken client_dedicated_worker_token) { … }
void WorkerWatcher::DisconnectDedicatedWorkerClient(
WorkerNodeImpl* worker_node,
blink::DedicatedWorkerToken client_dedicated_worker_token) { … }
void WorkerWatcher::ConnectSharedWorkerClient(
WorkerNodeImpl* worker_node,
blink::SharedWorkerToken client_shared_worker_token) { … }
void WorkerWatcher::DisconnectSharedWorkerClient(
WorkerNodeImpl* worker_node,
blink::SharedWorkerToken client_shared_worker_token) { … }
void WorkerWatcher::ConnectAllServiceWorkerClients(
WorkerNodeImpl* service_worker_node,
int64_t version_id) { … }
void WorkerWatcher::DisconnectAllServiceWorkerClients(
WorkerNodeImpl* service_worker_node,
int64_t version_id) { … }
void WorkerWatcher::OnBeforeFrameNodeRemoved(
content::GlobalRenderFrameHostId render_frame_host_id,
FrameNodeImpl* frame_node) { … }
void WorkerWatcher::AddChildWorkerConnection(
content::GlobalRenderFrameHostId render_frame_host_id,
WorkerNodeImpl* child_worker_node,
bool* is_first_child_worker,
bool* is_first_child_worker_connection) { … }
void WorkerWatcher::RemoveChildWorkerConnection(
content::GlobalRenderFrameHostId render_frame_host_id,
WorkerNodeImpl* child_worker_node,
bool* was_last_child_worker,
bool* was_last_child_worker_connection) { … }
WorkerNodeImpl* WorkerWatcher::GetDedicatedWorkerNode(
const blink::DedicatedWorkerToken& dedicated_worker_token) const { … }
WorkerNodeImpl* WorkerWatcher::GetSharedWorkerNode(
const blink::SharedWorkerToken& shared_worker_token) const { … }
WorkerNodeImpl* WorkerWatcher::GetServiceWorkerNode(int64_t version_id) const { … }
#if DCHECK_IS_ON()
bool WorkerWatcher::IsServiceWorkerNode(WorkerNodeImpl* worker_node) { … }
#endif
}