File: extra_instances.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (66 lines) | stat: -rw-r--r-- 2,784 bytes parent folder | download | duplicates (8)
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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_ASH_COMPONENTS_KCER_EXTRA_INSTANCES_H_
#define CHROMEOS_ASH_COMPONENTS_KCER_EXTRA_INSTANCES_H_

#include "base/no_destructor.h"
#include "chromeos/ash/components/kcer/kcer.h"
#include "chromeos/ash/components/kcer/kcer_impl.h"

namespace kcer {

// This class is a singleton that provides access to some special Kcer
// instances. It is separate from KcerFactory primarily for the code under
// */components/* and other places that don't have access to Profile-s and
// cannot use KcerFactory. Using KcerFactory should be preferred whenever
// possible.
// TODO(miersh): This class was implemented to simplify the migration from NSS
// to Kcer. Eventually all the code should be refactored to either retrieve the
// correct Kcer instance by a Profile or receive the instance as an input. This
// class should be merged into KcerFactory after that.
class COMPONENT_EXPORT(KCER) ExtraInstances {
 public:
  static ExtraInstances* Get();

  // Retrieves the Kcer instance for the main profile (or EmptyKcer, if there's
  // none). This method is only introduced to migrate some existing code from
  // NSS to Kcer. If at all possible, all new code should either fetch Kcer from
  // KcerFactory by Profile or receive a pointer to the correct Kcer instance as
  // an argument.
  static base::WeakPtr<Kcer> GetDefaultKcer();
  // Returns a Kcer instance without any tokens.
  static base::WeakPtr<Kcer> GetEmptyKcer();
  // Returns a Kcer instance with just the device token (or with no tokens, if
  // the device token should not be available in the current environment, e.g.
  // in Lacros).
  static base::WeakPtr<Kcer> GetDeviceKcer();

  // Initializes DeviceKcer. DeviceKcer can be used immediately after creation,
  // but it won't complete any requests until it's initialized.
  void InitializeDeviceKcer(scoped_refptr<base::TaskRunner> token_task_runner,
                            base::WeakPtr<internal::KcerToken> device_token);

  // Used by KcerFactory to update the value returned from GetDefaultKcer().
  void SetDefaultKcer(base::WeakPtr<Kcer> default_kcer);

 private:
  friend class base::NoDestructor<ExtraInstances>;

  ExtraInstances();
  ~ExtraInstances();

  internal::KcerImpl empty_kcer_;
  // Only initialized in Ash.
  std::unique_ptr<internal::KcerImpl> device_kcer_;

  // Contains a nullptr on the login screen. In a user session contains Kcer for
  // the profile of the primary user. After the primary profile is destroyed,
  // the pointer is automatically invalidated.
  base::WeakPtr<Kcer> default_kcer_;
};

}  // namespace kcer

#endif  // CHROMEOS_ASH_COMPONENTS_KCER_EXTRA_INSTANCES_H_