summaryrefslogtreecommitdiffstats
path: root/chrome/installer/util/beacons.h
blob: bec393e4ec09d26b0af389d46d765fe6ae28af21 (plain)
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2015 The Chromium Authors. All rights reserved.
// 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 "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "base/time/time.h"
#include "chrome/installer/util/shell_util.h"

class AppRegistrationData;
class BrowserDistribution;

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(const base::FilePath& chrome_exe,
                                         BrowserDistribution* distribution,
                                         ShellUtil::DefaultState default_state);

// Updates the last OS upgrade beacon for the install.
void UpdateOsUpgradeBeacon(bool system_install,
                           BrowserDistribution* distribution);

namespace installer_util {

class Beacon;

// Returns a Beacon representing the last time the machine's OS was ugpraded.
scoped_ptr<Beacon> MakeLastOsUpgradeBeacon(
    bool system_install,
    const AppRegistrationData& registration_data);

// Returns a Beacon representing the last time Chrome was the user's default
// browser.
scoped_ptr<Beacon> MakeLastWasDefaultBeacon(
    bool system_install,
    const AppRegistrationData& registration_data);

// Returns a Beacon representing the first time Chrome was not the user's
// default browser.
scoped_ptr<Beacon> MakeFirstNotDefaultBeacon(
    bool system_install,
    const AppRegistrationData& registration_data);

// 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,
  };

  // Creates a beacon named |name| for the product identified by
  // |registration_data| installed as either a per-user or a per-machine app
  // according to |system_install|.
  Beacon(base::StringPiece16 name,
         BeaconType type,
         BeaconScope scope,
         bool system_install,
         const AppRegistrationData& registration_data);
  ~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(base::StringPiece16 name,
                  bool system_install,
                  const AppRegistrationData& registration_data);

  // 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.
  base::string16 key_path_;

  // The name of the registry value holding the beacon.
  base::string16 value_name_;

  DISALLOW_COPY_AND_ASSIGN(Beacon);
};

}  // namespace installer_util

#endif  // CHROME_INSTALLER_UTIL_BEACONS_H_