File: resource_coordinator_parts.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (82 lines) | stat: -rw-r--r-- 2,658 bytes parent folder | download | duplicates (7)
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
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_RESOURCE_COORDINATOR_PARTS_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_RESOURCE_COORDINATOR_PARTS_H_

#include "build/build_config.h"
#include "chrome/browser/resource_coordinator/tab_load_tracker.h"
#include "chrome/browser/resource_coordinator/tab_memory_metrics_reporter.h"

#if !BUILDFLAG(IS_ANDROID)
#include "chrome/browser/resource_coordinator/tab_lifecycle_unit_source.h"
#include "chrome/browser/resource_coordinator/tab_manager.h"
#endif

namespace resource_coordinator {

#if BUILDFLAG(IS_ANDROID)
class TabManager;
class TabLifecycleUnitSource;
#endif

// Contains the various parts of the resource coordinator. There should be only
// one instance of this class created early during the initialization of the
// browser process.
class ResourceCoordinatorParts {
 public:
  ResourceCoordinatorParts();

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

  ~ResourceCoordinatorParts();

  TabMemoryMetricsReporter* tab_memory_metrics_reporter() {
    if (!tab_memory_metrics_reporter_.get())
      tab_memory_metrics_reporter_.reset(new TabMemoryMetricsReporter());
    return tab_memory_metrics_reporter_.get();
  }

  TabLoadTracker* tab_load_tracker() { return &tab_load_tracker_; }

  TabManager* tab_manager() {
#if BUILDFLAG(IS_ANDROID)
    return nullptr;
#else
    return &tab_manager_;
#endif  // BUILDFLAG(IS_ANDROID)
  }

  TabLifecycleUnitSource* tab_lifecycle_unit_source() {
#if BUILDFLAG(IS_ANDROID)
    return nullptr;
#else
    return &tab_lifecycle_unit_source_;
#endif  // BUILDFLAG(IS_ANDROID)
  }

 private:
  // This should be declared before |tab_memory_metrics_reporter_| because it
  // depends on this at shutdown.
  TabLoadTracker tab_load_tracker_;

  // Created on demand the first time it's being accessed.
  std::unique_ptr<TabMemoryMetricsReporter> tab_memory_metrics_reporter_;

#if !BUILDFLAG(IS_ANDROID)
  // Any change to this #ifdef must be reflected as well in
  // chrome/browser/resource_coordinator/tab_manager_browsertest.cc
  //
  // The order of these 2 members matters, TabLifecycleUnitSource must be
  // deleted before TabManager because it has a raw pointer to a UsageClock
  // owned by TabManager.
  TabManager tab_manager_;
  TabLifecycleUnitSource tab_lifecycle_unit_source_;
#endif
};

}  // namespace resource_coordinator

#endif  // CHROME_BROWSER_RESOURCE_COORDINATOR_RESOURCE_COORDINATOR_PARTS_H__