summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/platform/instrumentation/resource_coordinator/renderer_resource_coordinator.h
blob: 1986d7a3b9bb591e843b0a642075222295872d88 (plain)
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
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_RENDERER_RESOURCE_COORDINATOR_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_RENDERER_RESOURCE_COORDINATOR_H_

#include "third_party/blink/renderer/platform/platform_export.h"

namespace blink {

// TODO(chrisha): Remove knowledge of ExecutionContext class from this code!
class ExecutionContext;
class Frame;
class HTMLFrameOwnerElement;
class ScriptState;

class PLATFORM_EXPORT RendererResourceCoordinator {
 public:
  static void Set(RendererResourceCoordinator* instance);

  // This will always return a valid object. However, unless an explicit
  // implementation has been provided via Set, it will be a dummy
  // implementation.
  static RendererResourceCoordinator* Get();

  RendererResourceCoordinator() = default;
  RendererResourceCoordinator(const RendererResourceCoordinator&) = delete;
  RendererResourceCoordinator& operator=(const RendererResourceCoordinator&) =
      delete;
  virtual ~RendererResourceCoordinator() = default;

  // Notifies the browser that the main thread task load is low.
  // TODO(chrisha): Move this to a per-agent interface, and drive this off of
  // a signal from each agent scheduler when those exist.
  virtual void SetMainThreadTaskLoadIsLow(bool) = 0;

  // Used for tracking content javascript contexts (frames, workers, worklets,
  // etc). These functions are thread-safe.

  // Called when a |script_state| is created. Note that |execution_context| may
  // be nullptr if the |script_state| is not associated with an
  // |execution_context|.
  virtual void OnScriptStateCreated(ScriptState* script_state,
                                    ExecutionContext* execution_context) = 0;
  // Called when the |script_state| has been detached from the v8::Context
  // (and ExecutionContext, if applicable) it was associated with at creation.
  // At this point the associated v8::Context is considered "detached" until it
  // is garbage collected.
  virtual void OnScriptStateDetached(ScriptState* script_state) = 0;
  // Called when the |script_state| itself is garbage collected.
  virtual void OnScriptStateDestroyed(ScriptState* script_state) = 0;

  // Called when |frame| is about to be set as the ContentFrame of |owner|.
  virtual void OnBeforeContentFrameAttached(
      const Frame& frame,
      const HTMLFrameOwnerElement& owner) = 0;
  // Called when |frame| is about to be unset as the ContentFrame of |owner|.
  virtual void OnBeforeContentFrameDetached(
      const Frame& frame,
      const HTMLFrameOwnerElement& owner) = 0;
};

}  // namespace blink

#endif  // THIRD_PARTY_BLINK_RENDERER_PLATFORM_INSTRUMENTATION_RESOURCE_COORDINATOR_RENDERER_RESOURCE_COORDINATOR_H_