OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_INSTALLER_UTIL_BEACONS_H_ |
| 6 #define CHROME_INSTALLER_UTIL_BEACONS_H_ |
| 7 |
| 8 #include <windows.h> |
| 9 |
| 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" |
| 16 |
| 17 class AppRegistrationData; |
| 18 class BrowserDistribution; |
| 19 |
| 20 namespace base { |
| 21 class FilePath; |
| 22 } |
| 23 |
| 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); |
| 27 |
| 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); |
| 33 |
| 34 // Updates the last OS upgrade beacon for the install. |
| 35 void UpdateOsUpgradeBeacon(bool system_install, |
| 36 BrowserDistribution* distribution); |
| 37 |
| 38 namespace installer_util { |
| 39 |
| 40 class Beacon; |
| 41 |
| 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); |
| 46 |
| 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); |
| 52 |
| 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); |
| 58 |
| 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, |
| 70 }; |
| 71 |
| 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, |
| 77 }; |
| 78 |
| 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(); |
| 88 |
| 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(); |
| 93 |
| 94 // Removes the beacon. |
| 95 void Remove(); |
| 96 |
| 97 // Returns the beacon's value or a null time if not found. |
| 98 base::Time Get(); |
| 99 |
| 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); |
| 105 |
| 106 // The type of beacon. |
| 107 const BeaconType type_; |
| 108 |
| 109 // The root key in the registry where this beacon is stored. |
| 110 const HKEY root_; |
| 111 |
| 112 // The scope of the beacon. |
| 113 const BeaconScope scope_; |
| 114 |
| 115 // The path to the registry key holding the beacon. |
| 116 base::string16 key_path_; |
| 117 |
| 118 // The name of the registry value holding the beacon. |
| 119 base::string16 value_name_; |
| 120 |
| 121 DISALLOW_COPY_AND_ASSIGN(Beacon); |
| 122 }; |
| 123 |
| 124 } // namespace installer_util |
| 125 |
| 126 #endif // CHROME_INSTALLER_UTIL_BEACONS_H_ |
OLD | NEW |