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

content / browser / gpu / browser_child_process_backgrounded_bridge.h [blame]

// Copyright 2023 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_GPU_BROWSER_CHILD_PROCESS_BACKGROUNDED_BRIDGE_H_
#define CONTENT_BROWSER_GPU_BROWSER_CHILD_PROCESS_BACKGROUNDED_BRIDGE_H_

#include <memory>

#include "base/memory/raw_ptr.h"
#include "base/process/port_provider_mac.h"
#include "base/scoped_observation.h"
#include "content/common/content_export.h"

namespace content {

class BrowserChildProcessHostImpl;

// This class ensures that the priority of `process` mirrors the priority of the
// browser process.
class CONTENT_EXPORT BrowserChildProcessBackgroundedBridge
    : public base::PortProvider::Observer {
 public:
  explicit BrowserChildProcessBackgroundedBridge(
      BrowserChildProcessHostImpl* process);
  ~BrowserChildProcessBackgroundedBridge() override;

  void SimulateBrowserProcessForegroundedForTesting();
  void SimulateBrowserProcessBackgroundedForTesting();

  static void SetOSNotificationsEnabledForTesting(bool enabled);

 private:
  void Initialize();

  void OnReceivedTaskPort(base::ProcessHandle process) override;

  void OnBrowserProcessForegrounded();
  void OnBrowserProcessBackgrounded();

  raw_ptr<BrowserChildProcessHostImpl> process_;

  base::ScopedObservation<base::PortProvider, base::PortProvider::Observer>
      scoped_port_provider_observer_{this};

  struct ObjCStorage;
  std::unique_ptr<ObjCStorage> objc_storage_;
};

}  // namespace content

#endif  // CONTENT_BROWSER_GPU_BROWSER_CHILD_PROCESS_BACKGROUNDED_BRIDGE_H_