Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / installer / util / beacons.h
blobbec393e4ec09d26b0af389d46d765fe6ae28af21
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_INSTALLER_UTIL_BEACONS_H_
6 #define CHROME_INSTALLER_UTIL_BEACONS_H_
8 #include <windows.h>
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string16.h"
13 #include "base/strings/string_piece.h"
14 #include "base/time/time.h"
15 #include "chrome/installer/util/shell_util.h"
17 class AppRegistrationData;
18 class BrowserDistribution;
20 namespace base {
21 class FilePath;
24 // Checks the default state of the browser for the current user and updates the
25 // appropriate beacon (last was default or first not default).
26 void UpdateDefaultBrowserBeaconForPath(const base::FilePath& chrome_exe);
28 // Updates the last was default or first not default beacon for the current user
29 // based on |default_state|.
30 void UpdateDefaultBrowserBeaconWithState(const base::FilePath& chrome_exe,
31 BrowserDistribution* distribution,
32 ShellUtil::DefaultState default_state);
34 // Updates the last OS upgrade beacon for the install.
35 void UpdateOsUpgradeBeacon(bool system_install,
36 BrowserDistribution* distribution);
38 namespace installer_util {
40 class Beacon;
42 // Returns a Beacon representing the last time the machine's OS was ugpraded.
43 scoped_ptr<Beacon> MakeLastOsUpgradeBeacon(
44 bool system_install,
45 const AppRegistrationData& registration_data);
47 // Returns a Beacon representing the last time Chrome was the user's default
48 // browser.
49 scoped_ptr<Beacon> MakeLastWasDefaultBeacon(
50 bool system_install,
51 const AppRegistrationData& registration_data);
53 // Returns a Beacon representing the first time Chrome was not the user's
54 // default browser.
55 scoped_ptr<Beacon> MakeFirstNotDefaultBeacon(
56 bool system_install,
57 const AppRegistrationData& registration_data);
59 // A named beacon stored in the registry representing the first or last time at
60 // which some event took place. A beacon may apply to a per-user event or a
61 // per-install event. In general, beacons should be created via factory methods
62 // such as those above.
63 class Beacon {
64 public:
65 enum class BeaconType {
66 // A beacon that marks the first occurrence of an event.
67 FIRST,
68 // A beacon that marks the last occurrence of an event.
69 LAST,
72 enum class BeaconScope {
73 // A beacon that applies to a per-user event.
74 PER_USER,
75 // A beacon that applies to a per-install event.
76 PER_INSTALL,
79 // Creates a beacon named |name| for the product identified by
80 // |registration_data| installed as either a per-user or a per-machine app
81 // according to |system_install|.
82 Beacon(base::StringPiece16 name,
83 BeaconType type,
84 BeaconScope scope,
85 bool system_install,
86 const AppRegistrationData& registration_data);
87 ~Beacon();
89 // Updates the beacon. For a type LAST beacon, the current time is written
90 // unconditionally. For a type FIRST beacon, the beacon is only updated if it
91 // does not already exist.
92 void Update();
94 // Removes the beacon.
95 void Remove();
97 // Returns the beacon's value or a null time if not found.
98 base::Time Get();
100 private:
101 // Initializes the key_path_ and value_name_ fields of the beacon.
102 void Initialize(base::StringPiece16 name,
103 bool system_install,
104 const AppRegistrationData& registration_data);
106 // The type of beacon.
107 const BeaconType type_;
109 // The root key in the registry where this beacon is stored.
110 const HKEY root_;
112 // The scope of the beacon.
113 const BeaconScope scope_;
115 // The path to the registry key holding the beacon.
116 base::string16 key_path_;
118 // The name of the registry value holding the beacon.
119 base::string16 value_name_;
121 DISALLOW_COPY_AND_ASSIGN(Beacon);
124 } // namespace installer_util
126 #endif // CHROME_INSTALLER_UTIL_BEACONS_H_