File: beacons.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 (107 lines) | stat: -rw-r--r-- 3,061 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2015 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_INSTALLER_UTIL_BEACONS_H_
#define CHROME_INSTALLER_UTIL_BEACONS_H_

#include <windows.h>

#include <memory>
#include <string>
#include <string_view>

#include "base/time/time.h"
#include "chrome/installer/util/shell_util.h"

namespace base {
class FilePath;
}

// Checks the default state of the browser for the current user and updates the
// appropriate beacon (last was default or first not default).
void UpdateDefaultBrowserBeaconForPath(const base::FilePath& chrome_exe);

// Updates the last was default or first not default beacon for the current user
// based on |default_state|.
void UpdateDefaultBrowserBeaconWithState(ShellUtil::DefaultState default_state);

// Updates the last OS upgrade beacon for the install.
void UpdateOsUpgradeBeacon();

namespace installer_util {

class Beacon;

// Returns a Beacon representing the last time the machine's OS was ugpraded.
std::unique_ptr<Beacon> MakeLastOsUpgradeBeacon();

// Returns a Beacon representing the last time Chrome was the user's default
// browser.
std::unique_ptr<Beacon> MakeLastWasDefaultBeacon();

// Returns a Beacon representing the first time Chrome was not the user's
// default browser.
std::unique_ptr<Beacon> MakeFirstNotDefaultBeacon();

// A named beacon stored in the registry representing the first or last time at
// which some event took place. A beacon may apply to a per-user event or a
// per-install event. In general, beacons should be created via factory methods
// such as those above.
class Beacon {
 public:
  enum class BeaconType {
    // A beacon that marks the first occurrence of an event.
    FIRST,
    // A beacon that marks the last occurrence of an event.
    LAST,
  };

  enum class BeaconScope {
    // A beacon that applies to a per-user event.
    PER_USER,
    // A beacon that applies to a per-install event.
    PER_INSTALL,
  };

  Beacon(std::wstring_view name, BeaconType type, BeaconScope scope);

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

  ~Beacon();

  // Updates the beacon. For a type LAST beacon, the current time is written
  // unconditionally. For a type FIRST beacon, the beacon is only updated if it
  // does not already exist.
  void Update();

  // Removes the beacon.
  void Remove();

  // Returns the beacon's value or a null time if not found.
  base::Time Get();

 private:
  // Initializes the key_path_ and value_name_ fields of the beacon.
  void Initialize(std::wstring_view name);

  // The type of beacon.
  const BeaconType type_;

  // The root key in the registry where this beacon is stored.
  const HKEY root_;

  // The scope of the beacon.
  const BeaconScope scope_;

  // The path to the registry key holding the beacon.
  std::wstring key_path_;

  // The name of the registry value holding the beacon.
  std::wstring value_name_;
};

}  // namespace installer_util

#endif  // CHROME_INSTALLER_UTIL_BEACONS_H_