chromium/components/performance_manager/v8_memory/v8_detailed_memory_decorator.h

// 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.

#ifndef COMPONENTS_PERFORMANCE_MANAGER_V8_MEMORY_V8_DETAILED_MEMORY_DECORATOR_H_
#define COMPONENTS_PERFORMANCE_MANAGER_V8_MEMORY_V8_DETAILED_MEMORY_DECORATOR_H_

#include <memory>

#include "base/functional/callback_forward.h"
#include "base/functional/function_ref.h"
#include "base/sequence_checker.h"
#include "base/types/pass_key.h"
#include "components/performance_manager/public/graph/graph_registered.h"
#include "components/performance_manager/public/graph/node_data_describer.h"
#include "components/performance_manager/public/graph/process_node.h"
#include "components/performance_manager/public/v8_memory/v8_detailed_memory.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "third_party/blink/public/mojom/performance_manager/v8_detailed_memory_reporter.mojom.h"

namespace performance_manager {

class FrameNode;
class Graph;

namespace v8_memory {

class V8DetailedMemoryRequestQueue;

// A decorator that queries each renderer process for the amount of memory used
// by V8 in each frame. The public interface to create requests for this
// decorator is in
// //components/performance_manager/public/v8_detailed_memory.h.
class V8DetailedMemoryDecorator
    : public ProcessNode::ObserverDefaultImpl,
      public GraphOwnedAndRegistered<V8DetailedMemoryDecorator>,
      public NodeDataDescriberDefaultImpl {};

//////////////////////////////////////////////////////////////////////////////
// The following internal functions are exposed in the header for testing.

namespace internal {

// A callback that will bind a V8DetailedMemoryReporter interface to
// communicate with the given process. Exposed so that it can be overridden to
// implement the interface with a test fake.
BindV8DetailedMemoryReporterCallback;

// Sets a callback that will be used to bind the V8DetailedMemoryReporter
// interface. The callback is owned by the caller and must live until this
// function is called again with nullptr.
void SetBindV8DetailedMemoryReporterCallbackForTesting(
    BindV8DetailedMemoryReporterCallback* callback);

// Destroys the V8DetailedMemoryDecorator. Exposed for testing.
void DestroyV8DetailedMemoryDecoratorForTesting(Graph* graph);

}  // namespace internal

}  // namespace v8_memory

}  // namespace performance_manager

#endif  // COMPONENTS_PERFORMANCE_MANAGER_V8_MEMORY_V8_DETAILED_MEMORY_DECORATOR_H_