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

content / public / browser / xr_runtime_manager.h [blame]

// 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 CONTENT_PUBLIC_BROWSER_XR_RUNTIME_MANAGER_H_
#define CONTENT_PUBLIC_BROWSER_XR_RUNTIME_MANAGER_H_

#include "base/functional/callback_forward.h"
#include "base/observer_list_types.h"
#include "content/common/content_export.h"
#include "device/vr/public/mojom/vr_service.mojom-forward.h"
#include "device/vr/public/mojom/xr_device.mojom-forward.h"

namespace content {
class BrowserXRRuntime;

// The XRRuntimeManager is a singleton responsible for managing access to the
// active BrowserXRRuntime instances. An Observer interface is provided in case
// runtimes need to interact with runtimes when they are added (e.g. to notify
// them of any current state that they may need to know about).
class CONTENT_EXPORT XRRuntimeManager {
 public:
  class Observer : public base::CheckedObserver {
   public:
    virtual void OnRuntimeAdded(content::BrowserXRRuntime* runtime) {}
  };

  // Provides access to the XRRuntimeManager singleton, if it exists.
  // This method does not extend the lifetime of the singleton, so you should be
  // careful with the lifetime of this reference.
  static content::XRRuntimeManager* GetInstanceIfCreated();

  // Exits any currently presenting immersive session.
  static void ExitImmersivePresentation();

  // Observer registration methods are static so that observers may subscribe
  // and unsubscribe independent of the lifecycle of the XRRuntimeManager
  // Singleton.
  static void AddObserver(content::XRRuntimeManager::Observer* observer);
  static void RemoveObserver(content::XRRuntimeManager::Observer* observer);

  XRRuntimeManager() = default;
  virtual ~XRRuntimeManager() = default;

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

  // Provides access to the BrowserXRRuntime corresponding to the given
  // XRDeviceId, or nullptr if no such device exists/has been registered.
  virtual content::BrowserXRRuntime* GetRuntime(
      device::mojom::XRDeviceId id) = 0;
};

}  // namespace content

#endif  // CONTENT_PUBLIC_BROWSER_XR_RUNTIME_MANAGER_H_