File: guest_os_terminal_provider_registry.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 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 (74 lines) | stat: -rw-r--r-- 2,865 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
// Copyright 2022 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_ASH_GUEST_OS_PUBLIC_GUEST_OS_TERMINAL_PROVIDER_REGISTRY_H_
#define CHROME_BROWSER_ASH_GUEST_OS_PUBLIC_GUEST_OS_TERMINAL_PROVIDER_REGISTRY_H_

#include "base/containers/flat_map.h"
#include "base/memory/raw_ptr.h"
#include "chrome/browser/ash/guest_os/guest_id.h"

class Profile;

namespace guest_os {

class GuestOsTerminalProvider;

class GuestOsTerminalProviderRegistry {
 public:
  // Id used to reference a specific provider within the registry. Note: These
  // IDs are not stable across restarts and there's no correlation between a
  // provider's ID and its VM/Guest, or between different providers.
  // Use int and start at 0 so we can serialise it to json without any
  // conversions.
  using Id = int;

  // Gets a list of `Id`s for all provider's in the registry.
  std::vector<Id> List();

  explicit GuestOsTerminalProviderRegistry(Profile* profile);
  ~GuestOsTerminalProviderRegistry();
  GuestOsTerminalProviderRegistry(const GuestOsTerminalProviderRegistry&) =
      delete;
  GuestOsTerminalProviderRegistry& operator=(
      const GuestOsTerminalProviderRegistry&) = delete;

  // Returns the provider with the specified `id`. Returns nullptr if the
  // provider doesn't exist.
  GuestOsTerminalProvider* Get(Id id) const;

  // Returns the provider with the specified `id`. Returns nullptr if the
  // provider doesn't exist. Convenience method which converts std::string to
  // Id for you.
  GuestOsTerminalProvider* Get(const std::string& id) const;

  // Returns the provider with the specified `id`. Returns nullptr if the
  // provider doesn't exist. Searches the registry for the first provider for
  // the specified guest.
  GuestOsTerminalProvider* Get(const guest_os::GuestId& id) const;

  // Registers a new provider with the registry. The registry takes ownership of
  // the provider, holding on to it until it's unregistered. Returns the id of
  // the newly-registered provider.
  Id Register(std::unique_ptr<GuestOsTerminalProvider> provider);

  // The terminal reads configuration data from prefs, which means changes to
  // provider properties at runtime aren't automatically reflected in the
  // terminal window. This method updates prefs to match the current provider
  // state.
  void SyncPrefs(Id provider);

  // Removes a provider from the registry, returning the provider. The specified
  // provider must be in the registry.
  std::unique_ptr<GuestOsTerminalProvider> Unregister(Id provider);

 private:
  raw_ptr<Profile> profile_;
  Id next_id_ = 0;
  base::flat_map<Id, std::unique_ptr<GuestOsTerminalProvider>> providers_;
};

}  // namespace guest_os

#endif  // CHROME_BROWSER_ASH_GUEST_OS_PUBLIC_GUEST_OS_TERMINAL_PROVIDER_REGISTRY_H_