File: process_selection_deferring_condition_runner.h

package info (click to toggle)
chromium 142.0.7444.175-1~deb13u1
  • links: PTS, VCS
  • area: main
  • in suites: trixie-proposed-updates
  • size: 6,295,408 kB
  • sloc: cpp: 35,488,378; ansic: 7,479,680; javascript: 4,259,373; python: 1,466,843; xml: 757,444; asm: 710,716; pascal: 187,980; sh: 89,247; perl: 88,690; objc: 79,984; sql: 56,984; cs: 42,192; fortran: 24,137; makefile: 22,913; tcl: 15,277; php: 14,018; yacc: 9,005; ruby: 7,553; awk: 3,720; lisp: 3,096; lex: 1,330; ada: 727; jsp: 228; sed: 36
file content (88 lines) | stat: -rw-r--r-- 3,403 bytes parent folder | download | duplicates (6)
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
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_BROWSER_RENDERER_HOST_PROCESS_SELECTION_DEFERRING_CONDITION_RUNNER_H_
#define CONTENT_BROWSER_RENDERER_HOST_PROCESS_SELECTION_DEFERRING_CONDITION_RUNNER_H_

#include <memory>
#include <vector>

#include "base/functional/callback.h"
#include "base/memory/raw_ref.h"
#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"

namespace content {
class NavigationRequest;
class ProcessSelectionDeferringCondition;

// Helper class to defer renderer process selection until dependencies are
// ready.
//
// Clients subclass the `ProcessSelectionDeferringCondition` class in order to
// initiate asynchronous tasks at navigation start, update the tasks on
// redirects, and be given the opportunity to defer the selection of the
// renderer process until the condition's tasks have completed. The client
// should register their subclass in
// `RegisterProcessSelectionDeferringConditions`, or in the embedder's
// `ContentBrowserClient::CreateProcessSelectionDeferringConditionsForNavigation()`
// method.
//
// The mechanism is not applied for prerender activations or about:blank or
// same-document navigations.
//
// TODO(crbug.com/439013866): add support for tracing.
class CONTENT_EXPORT ProcessSelectionDeferringConditionRunner {
 public:
  // Creates the runner, asks the embedder for any conditions that it wishes to
  // register, and then starts the conditions.
  static std::unique_ptr<ProcessSelectionDeferringConditionRunner> Create(
      NavigationRequest& navigation_request);

  ProcessSelectionDeferringConditionRunner(
      const ProcessSelectionDeferringConditionRunner&) = delete;
  ProcessSelectionDeferringConditionRunner& operator=(
      const ProcessSelectionDeferringConditionRunner&) = delete;

  ~ProcessSelectionDeferringConditionRunner();

  // Called by NavigationRequest::OnRequestRedirected(). This calls
  // OnRequestRedirected() on each of the conditions that have been registered.
  void OnRequestRedirected();

  // Called prior to process selection. This calls
  // `ProcessSelectionDeferringCondition::OnWillSelectFinalProcess()` on each
  // registered condition. Registered conditions are given the opportunity to
  // defer the process selection.
  void WillSelectFinalProcess(base::OnceClosure on_completion_callback);

 private:
  friend class ProcessSelectionDeferringConditionRunnerTest;

  ProcessSelectionDeferringConditionRunner();

  // Registers `ProcessSelectionDeferringCondition` instances that will be
  // processed during the navigation.
  void RegisterProcessSelectionDeferringConditions(
      NavigationRequest& navigation_request);

  // Processes the next condition on the list.
  void ProcessNextCondition();

  // Called asynchronously by `RegisterProcessSelectionDeferringConditions` to
  // continue processing after deferring.
  void ResumeProcessing();

  std::vector<std::unique_ptr<ProcessSelectionDeferringCondition>>
      deferring_conditions_;

  // Called after all conditions have completed.
  base::OnceClosure on_completion_callback_;

  base::WeakPtrFactory<ProcessSelectionDeferringConditionRunner> weak_factory_{
      this};
};
}  // namespace content

#endif  // CONTENT_BROWSER_RENDERER_HOST_PROCESS_SELECTION_DEFERRING_CONDITION_RUNNER_H_