1 // Copyright (c) 2012 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_INSTALLATION_VALIDATOR_H_
6 #define CHROME_INSTALLER_UTIL_INSTALLATION_VALIDATOR_H_
13 #include "base/basictypes.h"
14 #include "base/compiler_specific.h"
15 #include "base/strings/string16.h"
16 #include "chrome/installer/util/browser_distribution.h"
26 class InstallationState
;
30 // A class that validates the state of an installation. Violations are logged
32 class InstallationValidator
{
36 // Bits that form the components of an installation type.
40 CHROME_FRAME_SINGLE
= 0x04,
41 CHROME_FRAME_MULTI
= 0x08,
42 CHROME_FRAME_READY_MODE
= 0x10,
43 CHROME_APP_HOST
= 0x20,
45 }; // class ProductBits
47 // Identifiers of all valid installation types.
48 enum InstallationType
{
51 ProductBits::CHROME_SINGLE
,
53 ProductBits::CHROME_MULTI
,
55 ProductBits::CHROME_FRAME_SINGLE
,
56 CHROME_FRAME_SINGLE_CHROME_SINGLE
=
57 ProductBits::CHROME_FRAME_SINGLE
| ProductBits::CHROME_SINGLE
,
58 CHROME_FRAME_SINGLE_CHROME_MULTI
=
59 ProductBits::CHROME_FRAME_SINGLE
| ProductBits::CHROME_MULTI
,
61 ProductBits::CHROME_FRAME_MULTI
,
62 CHROME_FRAME_MULTI_CHROME_MULTI
=
63 ProductBits::CHROME_FRAME_MULTI
| ProductBits::CHROME_MULTI
,
64 CHROME_FRAME_READY_MODE_CHROME_MULTI
=
65 ProductBits::CHROME_FRAME_READY_MODE
| ProductBits::CHROME_MULTI
,
67 ProductBits::CHROME_APP_HOST
,
68 CHROME_APP_HOST_CHROME_FRAME_SINGLE
=
69 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_FRAME_SINGLE
,
70 CHROME_APP_HOST_CHROME_FRAME_SINGLE_CHROME_MULTI
=
71 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_FRAME_SINGLE
|
72 ProductBits::CHROME_MULTI
,
73 CHROME_APP_HOST_CHROME_FRAME_MULTI
=
74 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_FRAME_MULTI
,
75 CHROME_APP_HOST_CHROME_FRAME_MULTI_CHROME_MULTI
=
76 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_FRAME_MULTI
|
77 ProductBits::CHROME_MULTI
,
78 CHROME_APP_HOST_CHROME_MULTI
=
79 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_MULTI
,
80 CHROME_APP_HOST_CHROME_MULTI_CHROME_FRAME_READY_MODE
=
81 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_MULTI
|
82 ProductBits::CHROME_FRAME_READY_MODE
,
85 // Validates |machine_state| at user or system level, returning true if valid.
86 // |type| is populated in either case, although it is a best-guess when the
87 // method returns false.
88 static bool ValidateInstallationTypeForState(
89 const InstallationState
& machine_state
,
91 InstallationType
* type
);
93 // Validates the machine's current installation at user or system level,
94 // returning true and populating |type| if valid.
95 static bool ValidateInstallationType(bool system_level
,
96 InstallationType
* type
);
99 struct ProductContext
;
100 typedef std::vector
<std::pair
<std::string
, bool> > SwitchExpectations
;
101 typedef void (*CommandValidatorFn
)(const ProductContext
& ctx
,
102 const AppCommand
& app_cmd
,
104 typedef std::map
<string16
, CommandValidatorFn
> CommandExpectations
;
106 // An interface to product-specific validation rules.
109 virtual ~ProductRules() { }
110 virtual BrowserDistribution::Type
distribution_type() const = 0;
111 virtual void AddUninstallSwitchExpectations(
112 const ProductContext
& ctx
,
113 SwitchExpectations
* expectations
) const = 0;
114 virtual void AddRenameSwitchExpectations(
115 const ProductContext
& ctx
,
116 SwitchExpectations
* expectations
) const = 0;
117 // Return true if the rules allow usagestats setting.
118 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const = 0;
121 // Validation rules for the Chrome browser.
122 class ChromeRules
: public ProductRules
{
124 virtual BrowserDistribution::Type
distribution_type() const OVERRIDE
;
125 virtual void AddUninstallSwitchExpectations(
126 const ProductContext
& ctx
,
127 SwitchExpectations
* expectations
) const OVERRIDE
;
128 virtual void AddRenameSwitchExpectations(
129 const ProductContext
& ctx
,
130 SwitchExpectations
* expectations
) const OVERRIDE
;
131 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const OVERRIDE
;
134 // Validation rules for Chrome Frame.
135 class ChromeFrameRules
: public ProductRules
{
137 virtual BrowserDistribution::Type
distribution_type() const OVERRIDE
;
138 virtual void AddUninstallSwitchExpectations(
139 const ProductContext
& ctx
,
140 SwitchExpectations
* expectations
) const OVERRIDE
;
141 virtual void AddRenameSwitchExpectations(
142 const ProductContext
& ctx
,
143 SwitchExpectations
* expectations
) const OVERRIDE
;
144 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const OVERRIDE
;
147 // Validation rules for Chrome App Host.
148 class ChromeAppHostRules
: public ProductRules
{
150 virtual BrowserDistribution::Type
distribution_type() const OVERRIDE
;
151 virtual void AddUninstallSwitchExpectations(
152 const ProductContext
& ctx
,
153 SwitchExpectations
* expectations
) const OVERRIDE
;
154 virtual void AddRenameSwitchExpectations(
155 const ProductContext
& ctx
,
156 SwitchExpectations
* expectations
) const OVERRIDE
;
157 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const OVERRIDE
;
160 // Validation rules for the multi-install Chrome binaries.
161 class ChromeBinariesRules
: public ProductRules
{
163 virtual BrowserDistribution::Type
distribution_type() const OVERRIDE
;
164 virtual void AddUninstallSwitchExpectations(
165 const ProductContext
& ctx
,
166 SwitchExpectations
* expectations
) const OVERRIDE
;
167 virtual void AddRenameSwitchExpectations(
168 const ProductContext
& ctx
,
169 SwitchExpectations
* expectations
) const OVERRIDE
;
170 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const OVERRIDE
;
173 struct ProductContext
{
174 ProductContext(const InstallationState
& machine_state_in
,
175 bool system_install_in
,
176 const ProductState
& state_in
,
177 const ProductRules
& rules_in
)
178 : machine_state(machine_state_in
),
179 system_install(system_install_in
),
180 dist(BrowserDistribution::GetSpecificDistribution(
181 rules_in
.distribution_type())),
186 const InstallationState
& machine_state
;
188 BrowserDistribution
* dist
;
189 const ProductState
& state
;
190 const ProductRules
& rules
;
193 // Helper to validate the values of bool elements in AppCommand, and to output
194 // error messages. |flag_expect| is a bit mask specifying the expected
195 // presence/absence of bool variables.
196 static void ValidateAppCommandFlags(const ProductContext
& ctx
,
197 const AppCommand
& app_cmd
,
198 const std::set
<string16
>& flags_expected
,
199 const string16
& name
,
201 static void ValidateInstallCommand(const ProductContext
& ctx
,
202 const AppCommand
& app_cmd
,
203 const wchar_t* expected_command
,
204 const wchar_t* expected_app_name
,
205 const char* expected_switch
,
207 static void ValidateInstallAppCommand(const ProductContext
& ctx
,
208 const AppCommand
& app_cmd
,
210 static void ValidateInstallExtensionCommand(const ProductContext
& ctx
,
211 const AppCommand
& app_cmd
,
213 static void ValidateOnOsUpgradeCommand(const ProductContext
& ctx
,
214 const AppCommand
& app_cmd
,
216 static void ValidateQueryEULAAcceptanceCommand(const ProductContext
& ctx
,
217 const AppCommand
& app_cmd
,
219 static void ValidateQuickEnableCfCommand(const ProductContext
& ctx
,
220 const AppCommand
& app_cmd
,
222 static void ValidateQuickEnableApplicationHostCommand(
223 const ProductContext
& ctx
,
224 const AppCommand
& app_cmd
,
227 static void ValidateAppCommandExpectations(
228 const ProductContext
& ctx
,
229 const CommandExpectations
& expectations
,
231 static void ValidateBinariesCommands(const ProductContext
& ctx
,
233 static void ValidateBinaries(const InstallationState
& machine_state
,
235 const ProductState
& binaries_state
,
237 static void ValidateSetupPath(const ProductContext
& ctx
,
238 const base::FilePath
& setup_exe
,
239 const string16
& purpose
,
241 static void ValidateCommandExpectations(const ProductContext
& ctx
,
242 const CommandLine
& command
,
243 const SwitchExpectations
& expected
,
244 const string16
& source
,
246 static void ValidateUninstallCommand(const ProductContext
& ctx
,
247 const CommandLine
& command
,
248 const string16
& source
,
250 static void ValidateRenameCommand(const ProductContext
& ctx
,
252 static void ValidateOldVersionValues(const ProductContext
& ctx
,
254 static void ValidateMultiInstallProduct(const ProductContext
& ctx
,
256 static void ValidateAppCommands(const ProductContext
& ctx
,
258 static void ValidateUsageStats(const ProductContext
& ctx
,
260 static void ValidateProduct(const InstallationState
& machine_state
,
262 const ProductState
& product_state
,
263 const ProductRules
& rules
,
266 // A collection of all valid installation types.
267 static const InstallationType kInstallationTypes
[];
270 DISALLOW_IMPLICIT_CONSTRUCTORS(InstallationValidator
);
273 } // namespace installer
275 #endif // CHROME_INSTALLER_UTIL_INSTALLATION_VALIDATOR_H_