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
|
// Copyright 2019 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_EMBEDDER_PERFORMANCE_MANAGER_REGISTRY_H_
#define COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_PERFORMANCE_MANAGER_REGISTRY_H_
#include <memory>
#include "components/performance_manager/public/graph/page_node.h"
namespace content {
class BrowserContext;
class RenderProcessHost;
class WebContents;
} // namespace content
namespace performance_manager {
class Binders;
// Allows tracking of WebContents, RenderProcessHosts and SharedWorkerInstances
// in the PerformanceManager.
//
// A process that embeds the PerformanceManager should create a single instance
// of this and notify it when WebContents, RenderProcessHosts or BrowserContexts
// are created.
//
// TearDown() must be called prior to destroying this object. This will schedule
// deletion of PageNodes, ProcessNodes and WorkerNodes retained by this
// registry, even if the associated WebContents, RenderProcessHosts and
// SharedWorkerInstances still exist.
//
// This class can only be accessed on the main thread.
class PerformanceManagerRegistry {
public:
virtual ~PerformanceManagerRegistry() = default;
PerformanceManagerRegistry(const PerformanceManagerRegistry&) = delete;
void operator=(const PerformanceManagerRegistry&) = delete;
// Creates a PerformanceManagerRegistry instance.
static std::unique_ptr<PerformanceManagerRegistry> Create();
// Returns the only instance of PerformanceManagerRegistry living in this
// process, or nullptr if there is none.
static PerformanceManagerRegistry* GetInstance();
// Returns a helper that binds Mojo interfaces for PerformanceManager.
virtual Binders& GetBinders() = 0;
// Helper function that invokes CreatePageNodeForWebContents only if it hasn't
// already been called for the provided WebContents.
void MaybeCreatePageNodeForWebContents(content::WebContents* web_contents);
// Must be invoked when a WebContents is created. Creates an associated
// PageNode in the PerformanceManager, if it doesn't already exist. This
// should only be called once for a given |web_contents|.
virtual void CreatePageNodeForWebContents(
content::WebContents* web_contents) = 0;
// Sets the page type for a WebContents.
virtual void SetPageType(content::WebContents* web_contents,
PageType type) = 0;
// Must be invoked when a BrowserContext is added/removed.
// Registers/unregisters an observer that creates WorkerNodes when
// SharedWorkerInstances are added in the BrowserContext.
virtual void NotifyBrowserContextAdded(
content::BrowserContext* browser_context) = 0;
virtual void NotifyBrowserContextRemoved(
content::BrowserContext* browser_context) = 0;
// Must be invoked when a renderer process is starting up to ensure that a
// process node is created for the RPH. Typically wired up via
// ContentBrowserClient::ExposeInterfacesToRenderer, which should also call
// GetBinders().ExposeInterfacesToRendererProcess().
// NOTE: Ideally we'd have a separate CreateProcessNode notification, but the
// current content architecture makes it very difficult to get this
// notification.
virtual void CreateProcessNode(
content::RenderProcessHost* render_process_host) = 0;
// Must be invoked prior to destroying the object. Schedules deletion of
// PageNodes and ProcessNodes retained by this registry, even if the
// associated WebContents and RenderProcessHosts still exist.
virtual void TearDown() = 0;
protected:
PerformanceManagerRegistry() = default;
};
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_EMBEDDER_PERFORMANCE_MANAGER_REGISTRY_H_
|