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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
// Copyright (c) 2012 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_INSTALLATION_VALIDATOR_H_
#define CHROME_INSTALLER_UTIL_INSTALLATION_VALIDATOR_H_
#include <map>
#include <set>
#include <utility>
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/strings/string16.h"
#include "chrome/installer/util/browser_distribution.h"
namespace base {
class CommandLine;
class FilePath;
}
namespace installer {
class InstallationState;
class AppCommand;
class ProductState;
// A class that validates the state of an installation. Violations are logged
// via LOG(ERROR).
class InstallationValidator {
public:
class ProductBits {
public:
// Bits that form the components of an installation type.
enum {
CHROME_SINGLE = 0x01,
CHROME_MULTI = 0x02,
CHROME_FRAME_SINGLE = 0x04,
CHROME_FRAME_MULTI = 0x08,
};
}; // class ProductBits
// Identifiers of all valid installation types.
enum InstallationType {
NO_PRODUCTS = 0,
CHROME_SINGLE =
ProductBits::CHROME_SINGLE,
CHROME_MULTI =
ProductBits::CHROME_MULTI,
CHROME_FRAME_SINGLE =
ProductBits::CHROME_FRAME_SINGLE,
CHROME_FRAME_SINGLE_CHROME_SINGLE =
ProductBits::CHROME_FRAME_SINGLE | ProductBits::CHROME_SINGLE,
CHROME_FRAME_SINGLE_CHROME_MULTI =
ProductBits::CHROME_FRAME_SINGLE | ProductBits::CHROME_MULTI,
CHROME_FRAME_MULTI =
ProductBits::CHROME_FRAME_MULTI,
CHROME_FRAME_MULTI_CHROME_MULTI =
ProductBits::CHROME_FRAME_MULTI | ProductBits::CHROME_MULTI,
};
// Validates |machine_state| at user or system level, returning true if valid.
// |type| is populated in either case, although it is a best-guess when the
// method returns false.
static bool ValidateInstallationTypeForState(
const InstallationState& machine_state,
bool system_level,
InstallationType* type);
// Validates the machine's current installation at user or system level,
// returning true and populating |type| if valid.
static bool ValidateInstallationType(bool system_level,
InstallationType* type);
protected:
struct ProductContext;
typedef std::vector<std::pair<std::string, bool> > SwitchExpectations;
typedef void (*CommandValidatorFn)(const ProductContext& ctx,
const AppCommand& app_cmd,
bool* is_valid);
typedef std::map<base::string16, CommandValidatorFn> CommandExpectations;
// An interface to product-specific validation rules.
class ProductRules {
public:
virtual ~ProductRules() { }
virtual BrowserDistribution::Type distribution_type() const = 0;
virtual void AddUninstallSwitchExpectations(
const ProductContext& ctx,
SwitchExpectations* expectations) const = 0;
virtual void AddRenameSwitchExpectations(
const ProductContext& ctx,
SwitchExpectations* expectations) const = 0;
// Return true if the rules allow usagestats setting.
virtual bool UsageStatsAllowed(const ProductContext& ctx) const = 0;
};
// Validation rules for the Chrome browser.
class ChromeRules : public ProductRules {
public:
BrowserDistribution::Type distribution_type() const override;
void AddUninstallSwitchExpectations(
const ProductContext& ctx,
SwitchExpectations* expectations) const override;
void AddRenameSwitchExpectations(
const ProductContext& ctx,
SwitchExpectations* expectations) const override;
bool UsageStatsAllowed(const ProductContext& ctx) const override;
};
// Validation rules for Chrome Frame.
class ChromeFrameRules : public ProductRules {
public:
BrowserDistribution::Type distribution_type() const override;
void AddUninstallSwitchExpectations(
const ProductContext& ctx,
SwitchExpectations* expectations) const override;
void AddRenameSwitchExpectations(
const ProductContext& ctx,
SwitchExpectations* expectations) const override;
bool UsageStatsAllowed(const ProductContext& ctx) const override;
};
// Validation rules for the multi-install Chrome binaries.
class ChromeBinariesRules : public ProductRules {
public:
BrowserDistribution::Type distribution_type() const override;
void AddUninstallSwitchExpectations(
const ProductContext& ctx,
SwitchExpectations* expectations) const override;
void AddRenameSwitchExpectations(
const ProductContext& ctx,
SwitchExpectations* expectations) const override;
bool UsageStatsAllowed(const ProductContext& ctx) const override;
};
struct ProductContext {
ProductContext(const InstallationState& machine_state_in,
bool system_install_in,
const ProductState& state_in,
const ProductRules& rules_in)
: machine_state(machine_state_in),
system_install(system_install_in),
dist(BrowserDistribution::GetSpecificDistribution(
rules_in.distribution_type())),
state(state_in),
rules(rules_in) {
}
const InstallationState& machine_state;
bool system_install;
BrowserDistribution* dist;
const ProductState& state;
const ProductRules& rules;
};
// Helper to validate the values of bool elements in AppCommand, and to output
// error messages. |flag_expect| is a bit mask specifying the expected
// presence/absence of bool variables.
static void ValidateAppCommandFlags(
const ProductContext& ctx,
const AppCommand& app_cmd,
const std::set<base::string16>& flags_expected,
const base::string16& name,
bool* is_valid);
static void ValidateOnOsUpgradeCommand(const ProductContext& ctx,
const AppCommand& app_cmd,
bool* is_valid);
static void ValidateAppCommandExpectations(
const ProductContext& ctx,
const CommandExpectations& expectations,
bool* is_valid);
static void ValidateBinaries(const InstallationState& machine_state,
bool system_install,
const ProductState& binaries_state,
bool* is_valid);
static void ValidateSetupPath(const ProductContext& ctx,
const base::FilePath& setup_exe,
const base::string16& purpose,
bool* is_valid);
static void ValidateCommandExpectations(const ProductContext& ctx,
const base::CommandLine& command,
const SwitchExpectations& expected,
const base::string16& source,
bool* is_valid);
static void ValidateUninstallCommand(const ProductContext& ctx,
const base::CommandLine& command,
const base::string16& source,
bool* is_valid);
static void ValidateRenameCommand(const ProductContext& ctx,
bool* is_valid);
static void ValidateOldVersionValues(const ProductContext& ctx,
bool* is_valid);
static void ValidateMultiInstallProduct(const ProductContext& ctx,
bool* is_valid);
static void ValidateAppCommands(const ProductContext& ctx,
bool* is_valid);
static void ValidateUsageStats(const ProductContext& ctx,
bool* is_valid);
static void ValidateProduct(const InstallationState& machine_state,
bool system_install,
const ProductState& product_state,
const ProductRules& rules,
bool* is_valid);
// A collection of all valid installation types.
static const InstallationType kInstallationTypes[];
private:
DISALLOW_IMPLICIT_CONSTRUCTORS(InstallationValidator);
};
} // namespace installer
#endif // CHROME_INSTALLER_UTIL_INSTALLATION_VALIDATOR_H_
|