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"
25 class InstallationState
;
29 // A class that validates the state of an installation. Violations are logged
31 class InstallationValidator
{
35 // Bits that form the components of an installation type.
39 CHROME_FRAME_SINGLE
= 0x04,
40 CHROME_FRAME_MULTI
= 0x08,
41 CHROME_APP_HOST
= 0x10,
43 }; // class ProductBits
45 // Identifiers of all valid installation types.
46 enum InstallationType
{
49 ProductBits::CHROME_SINGLE
,
51 ProductBits::CHROME_MULTI
,
53 ProductBits::CHROME_FRAME_SINGLE
,
54 CHROME_FRAME_SINGLE_CHROME_SINGLE
=
55 ProductBits::CHROME_FRAME_SINGLE
| ProductBits::CHROME_SINGLE
,
56 CHROME_FRAME_SINGLE_CHROME_MULTI
=
57 ProductBits::CHROME_FRAME_SINGLE
| ProductBits::CHROME_MULTI
,
59 ProductBits::CHROME_FRAME_MULTI
,
60 CHROME_FRAME_MULTI_CHROME_MULTI
=
61 ProductBits::CHROME_FRAME_MULTI
| ProductBits::CHROME_MULTI
,
63 ProductBits::CHROME_APP_HOST
,
64 CHROME_APP_HOST_CHROME_FRAME_SINGLE
=
65 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_FRAME_SINGLE
,
66 CHROME_APP_HOST_CHROME_FRAME_SINGLE_CHROME_MULTI
=
67 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_FRAME_SINGLE
|
68 ProductBits::CHROME_MULTI
,
69 CHROME_APP_HOST_CHROME_FRAME_MULTI
=
70 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_FRAME_MULTI
,
71 CHROME_APP_HOST_CHROME_FRAME_MULTI_CHROME_MULTI
=
72 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_FRAME_MULTI
|
73 ProductBits::CHROME_MULTI
,
74 CHROME_APP_HOST_CHROME_MULTI
=
75 ProductBits::CHROME_APP_HOST
| ProductBits::CHROME_MULTI
,
78 // Validates |machine_state| at user or system level, returning true if valid.
79 // |type| is populated in either case, although it is a best-guess when the
80 // method returns false.
81 static bool ValidateInstallationTypeForState(
82 const InstallationState
& machine_state
,
84 InstallationType
* type
);
86 // Validates the machine's current installation at user or system level,
87 // returning true and populating |type| if valid.
88 static bool ValidateInstallationType(bool system_level
,
89 InstallationType
* type
);
92 struct ProductContext
;
93 typedef std::vector
<std::pair
<std::string
, bool> > SwitchExpectations
;
94 typedef void (*CommandValidatorFn
)(const ProductContext
& ctx
,
95 const AppCommand
& app_cmd
,
97 typedef std::map
<base::string16
, CommandValidatorFn
> CommandExpectations
;
99 // An interface to product-specific validation rules.
102 virtual ~ProductRules() { }
103 virtual BrowserDistribution::Type
distribution_type() const = 0;
104 virtual void AddUninstallSwitchExpectations(
105 const ProductContext
& ctx
,
106 SwitchExpectations
* expectations
) const = 0;
107 virtual void AddRenameSwitchExpectations(
108 const ProductContext
& ctx
,
109 SwitchExpectations
* expectations
) const = 0;
110 // Return true if the rules allow usagestats setting.
111 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const = 0;
114 // Validation rules for the Chrome browser.
115 class ChromeRules
: public ProductRules
{
117 virtual BrowserDistribution::Type
distribution_type() const override
;
118 virtual void AddUninstallSwitchExpectations(
119 const ProductContext
& ctx
,
120 SwitchExpectations
* expectations
) const override
;
121 virtual void AddRenameSwitchExpectations(
122 const ProductContext
& ctx
,
123 SwitchExpectations
* expectations
) const override
;
124 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const override
;
127 // Validation rules for Chrome Frame.
128 class ChromeFrameRules
: public ProductRules
{
130 virtual BrowserDistribution::Type
distribution_type() const override
;
131 virtual void AddUninstallSwitchExpectations(
132 const ProductContext
& ctx
,
133 SwitchExpectations
* expectations
) const override
;
134 virtual void AddRenameSwitchExpectations(
135 const ProductContext
& ctx
,
136 SwitchExpectations
* expectations
) const override
;
137 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const override
;
140 // Validation rules for Chrome App Host.
141 class ChromeAppHostRules
: public ProductRules
{
143 virtual BrowserDistribution::Type
distribution_type() const override
;
144 virtual void AddUninstallSwitchExpectations(
145 const ProductContext
& ctx
,
146 SwitchExpectations
* expectations
) const override
;
147 virtual void AddRenameSwitchExpectations(
148 const ProductContext
& ctx
,
149 SwitchExpectations
* expectations
) const override
;
150 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const override
;
153 // Validation rules for the multi-install Chrome binaries.
154 class ChromeBinariesRules
: public ProductRules
{
156 virtual BrowserDistribution::Type
distribution_type() const override
;
157 virtual void AddUninstallSwitchExpectations(
158 const ProductContext
& ctx
,
159 SwitchExpectations
* expectations
) const override
;
160 virtual void AddRenameSwitchExpectations(
161 const ProductContext
& ctx
,
162 SwitchExpectations
* expectations
) const override
;
163 virtual bool UsageStatsAllowed(const ProductContext
& ctx
) const override
;
166 struct ProductContext
{
167 ProductContext(const InstallationState
& machine_state_in
,
168 bool system_install_in
,
169 const ProductState
& state_in
,
170 const ProductRules
& rules_in
)
171 : machine_state(machine_state_in
),
172 system_install(system_install_in
),
173 dist(BrowserDistribution::GetSpecificDistribution(
174 rules_in
.distribution_type())),
179 const InstallationState
& machine_state
;
181 BrowserDistribution
* dist
;
182 const ProductState
& state
;
183 const ProductRules
& rules
;
186 // Helper to validate the values of bool elements in AppCommand, and to output
187 // error messages. |flag_expect| is a bit mask specifying the expected
188 // presence/absence of bool variables.
189 static void ValidateAppCommandFlags(
190 const ProductContext
& ctx
,
191 const AppCommand
& app_cmd
,
192 const std::set
<base::string16
>& flags_expected
,
193 const base::string16
& name
,
195 static void ValidateOnOsUpgradeCommand(const ProductContext
& ctx
,
196 const AppCommand
& app_cmd
,
198 static void ValidateQueryEULAAcceptanceCommand(const ProductContext
& ctx
,
199 const AppCommand
& app_cmd
,
201 static void ValidateQuickEnableApplicationHostCommand(
202 const ProductContext
& ctx
,
203 const AppCommand
& app_cmd
,
206 static void ValidateAppCommandExpectations(
207 const ProductContext
& ctx
,
208 const CommandExpectations
& expectations
,
210 static void ValidateBinariesCommands(const ProductContext
& ctx
,
212 static void ValidateBinaries(const InstallationState
& machine_state
,
214 const ProductState
& binaries_state
,
216 static void ValidateSetupPath(const ProductContext
& ctx
,
217 const base::FilePath
& setup_exe
,
218 const base::string16
& purpose
,
220 static void ValidateCommandExpectations(const ProductContext
& ctx
,
221 const base::CommandLine
& command
,
222 const SwitchExpectations
& expected
,
223 const base::string16
& source
,
225 static void ValidateUninstallCommand(const ProductContext
& ctx
,
226 const base::CommandLine
& command
,
227 const base::string16
& source
,
229 static void ValidateRenameCommand(const ProductContext
& ctx
,
231 static void ValidateOldVersionValues(const ProductContext
& ctx
,
233 static void ValidateMultiInstallProduct(const ProductContext
& ctx
,
235 static void ValidateAppCommands(const ProductContext
& ctx
,
237 static void ValidateUsageStats(const ProductContext
& ctx
,
239 static void ValidateProduct(const InstallationState
& machine_state
,
241 const ProductState
& product_state
,
242 const ProductRules
& rules
,
245 // A collection of all valid installation types.
246 static const InstallationType kInstallationTypes
[];
249 DISALLOW_IMPLICIT_CONSTRUCTORS(InstallationValidator
);
252 } // namespace installer
254 #endif // CHROME_INSTALLER_UTIL_INSTALLATION_VALIDATOR_H_