Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(51)

Side by Side Diff: chrome/installer/util/installation_validator.cc

Issue 811283002: [Installer] Cleaning up dead code for App Launcher / App Host installs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removing ChannelInfo behavioral changes; removing inappropriate NULL check. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Implementation of the installation validator. 5 // Implementation of the installation validator.
6 6
7 #include "chrome/installer/util/installation_validator.h" 7 #include "chrome/installer/util/installation_validator.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 } 80 }
81 81
82 bool InstallationValidator::ChromeFrameRules::UsageStatsAllowed( 82 bool InstallationValidator::ChromeFrameRules::UsageStatsAllowed(
83 const ProductContext& ctx) const { 83 const ProductContext& ctx) const {
84 // Products must not have usagestats consent values when multi-install 84 // Products must not have usagestats consent values when multi-install
85 // (only the multi-install binaries may). 85 // (only the multi-install binaries may).
86 return !ctx.state.is_multi_install(); 86 return !ctx.state.is_multi_install();
87 } 87 }
88 88
89 BrowserDistribution::Type 89 BrowserDistribution::Type
90 InstallationValidator::ChromeAppHostRules::distribution_type() const {
91 return BrowserDistribution::CHROME_APP_HOST;
92 }
93
94 void InstallationValidator::ChromeAppHostRules::AddUninstallSwitchExpectations(
95 const ProductContext& ctx,
96 SwitchExpectations* expectations) const {
97 // --app-launcher must be present.
98 expectations->push_back(
99 std::make_pair(std::string(switches::kChromeAppLauncher), true));
100
101 // --chrome must not be present.
102 expectations->push_back(std::make_pair(std::string(switches::kChrome),
103 false));
104 // --chrome-frame must not be present.
105 expectations->push_back(std::make_pair(std::string(switches::kChromeFrame),
106 false));
107 }
108
109 void InstallationValidator::ChromeAppHostRules::AddRenameSwitchExpectations(
110 const ProductContext& ctx,
111 SwitchExpectations* expectations) const {
112 // TODO(erikwright): I guess there will be none?
113 }
114
115 bool InstallationValidator::ChromeAppHostRules::UsageStatsAllowed(
116 const ProductContext& ctx) const {
117 // App Host doesn't manage usage stats. The Chrome Binaries will.
118 return false;
119 }
120
121 BrowserDistribution::Type
122 InstallationValidator::ChromeBinariesRules::distribution_type() const { 90 InstallationValidator::ChromeBinariesRules::distribution_type() const {
123 return BrowserDistribution::CHROME_BINARIES; 91 return BrowserDistribution::CHROME_BINARIES;
124 } 92 }
125 93
126 void InstallationValidator::ChromeBinariesRules::AddUninstallSwitchExpectations( 94 void InstallationValidator::ChromeBinariesRules::AddUninstallSwitchExpectations(
127 const ProductContext& ctx, 95 const ProductContext& ctx,
128 SwitchExpectations* expectations) const { 96 SwitchExpectations* expectations) const {
129 NOTREACHED(); 97 NOTREACHED();
130 } 98 }
131 99
(...skipping 13 matching lines...) Expand all
145 const InstallationValidator::InstallationType 113 const InstallationValidator::InstallationType
146 InstallationValidator::kInstallationTypes[] = { 114 InstallationValidator::kInstallationTypes[] = {
147 NO_PRODUCTS, 115 NO_PRODUCTS,
148 CHROME_SINGLE, 116 CHROME_SINGLE,
149 CHROME_MULTI, 117 CHROME_MULTI,
150 CHROME_FRAME_SINGLE, 118 CHROME_FRAME_SINGLE,
151 CHROME_FRAME_SINGLE_CHROME_SINGLE, 119 CHROME_FRAME_SINGLE_CHROME_SINGLE,
152 CHROME_FRAME_SINGLE_CHROME_MULTI, 120 CHROME_FRAME_SINGLE_CHROME_MULTI,
153 CHROME_FRAME_MULTI, 121 CHROME_FRAME_MULTI,
154 CHROME_FRAME_MULTI_CHROME_MULTI, 122 CHROME_FRAME_MULTI_CHROME_MULTI,
155 CHROME_APP_HOST,
156 CHROME_APP_HOST_CHROME_FRAME_SINGLE,
157 CHROME_APP_HOST_CHROME_FRAME_SINGLE_CHROME_MULTI,
158 CHROME_APP_HOST_CHROME_FRAME_MULTI,
159 CHROME_APP_HOST_CHROME_FRAME_MULTI_CHROME_MULTI,
160 CHROME_APP_HOST_CHROME_MULTI,
161 }; 123 };
162 124
163 void InstallationValidator::ValidateAppCommandFlags( 125 void InstallationValidator::ValidateAppCommandFlags(
164 const ProductContext& ctx, 126 const ProductContext& ctx,
165 const AppCommand& app_cmd, 127 const AppCommand& app_cmd,
166 const std::set<base::string16>& flags_exp, 128 const std::set<base::string16>& flags_exp,
167 const base::string16& name, 129 const base::string16& name,
168 bool* is_valid) { 130 bool* is_valid) {
169 const struct { 131 const struct {
170 const base::string16 exp_key; 132 const base::string16 exp_key;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 expected.push_back(std::make_pair(std::string(switches::kChrome), 179 expected.push_back(std::make_pair(std::string(switches::kChrome),
218 ctx.state.is_multi_install())); 180 ctx.state.is_multi_install()));
219 181
220 ValidateCommandExpectations(ctx, cmd_line, expected, name, is_valid); 182 ValidateCommandExpectations(ctx, cmd_line, expected, name, is_valid);
221 183
222 std::set<base::string16> flags_exp; 184 std::set<base::string16> flags_exp;
223 flags_exp.insert(google_update::kRegAutoRunOnOSUpgradeField); 185 flags_exp.insert(google_update::kRegAutoRunOnOSUpgradeField);
224 ValidateAppCommandFlags(ctx, app_cmd, flags_exp, name, is_valid); 186 ValidateAppCommandFlags(ctx, app_cmd, flags_exp, name, is_valid);
225 } 187 }
226 188
227 // Validates the "query-eula-acceptance" Google Update product command.
228 void InstallationValidator::ValidateQueryEULAAcceptanceCommand(
229 const ProductContext& ctx,
230 const AppCommand& app_cmd,
231 bool* is_valid) {
232 DCHECK(is_valid);
233
234 CommandLine cmd_line(CommandLine::FromString(app_cmd.command_line()));
235 base::string16 name(kCmdQueryEULAAcceptance);
236
237 ValidateSetupPath(ctx, cmd_line.GetProgram(), name, is_valid);
238
239 SwitchExpectations expected;
240 expected.push_back(std::make_pair(std::string(switches::kQueryEULAAcceptance),
241 true));
242 expected.push_back(std::make_pair(std::string(switches::kSystemLevel),
243 ctx.system_install));
244
245 ValidateCommandExpectations(ctx, cmd_line, expected, name, is_valid);
246
247 std::set<base::string16> flags_exp;
248 flags_exp.insert(google_update::kRegWebAccessibleField);
249 flags_exp.insert(google_update::kRegRunAsUserField);
250 ValidateAppCommandFlags(ctx, app_cmd, flags_exp, name, is_valid);
251 }
252
253 // Validates the "quick-enable-application-host" Google Update product command.
254 void InstallationValidator::ValidateQuickEnableApplicationHostCommand(
255 const ProductContext& ctx,
256 const AppCommand& app_cmd,
257 bool* is_valid) {
258 DCHECK(is_valid);
259
260 CommandLine cmd_line(CommandLine::FromString(app_cmd.command_line()));
261 base::string16 name(kCmdQuickEnableApplicationHost);
262
263 ValidateSetupPath(ctx, cmd_line.GetProgram(), name, is_valid);
264
265 SwitchExpectations expected;
266
267 expected.push_back(std::make_pair(
268 std::string(switches::kChromeAppLauncher), true));
269 expected.push_back(std::make_pair(
270 std::string(switches::kSystemLevel), false));
271 expected.push_back(std::make_pair(
272 std::string(switches::kMultiInstall), true));
273 expected.push_back(std::make_pair(
274 std::string(switches::kEnsureGoogleUpdatePresent), true));
275
276 ValidateCommandExpectations(ctx, cmd_line, expected, name, is_valid);
277
278 std::set<base::string16> flags_exp;
279 flags_exp.insert(google_update::kRegSendsPingsField);
280 flags_exp.insert(google_update::kRegWebAccessibleField);
281 flags_exp.insert(google_update::kRegRunAsUserField);
282 ValidateAppCommandFlags(ctx, app_cmd, flags_exp, name, is_valid);
283 }
284
285 // Validates a product's set of Google Update product commands against a 189 // Validates a product's set of Google Update product commands against a
286 // collection of expectations. 190 // collection of expectations.
287 void InstallationValidator::ValidateAppCommandExpectations( 191 void InstallationValidator::ValidateAppCommandExpectations(
288 const ProductContext& ctx, 192 const ProductContext& ctx,
289 const CommandExpectations& expectations, 193 const CommandExpectations& expectations,
290 bool* is_valid) { 194 bool* is_valid) {
291 DCHECK(is_valid); 195 DCHECK(is_valid);
292 196
293 CommandExpectations the_expectations(expectations); 197 CommandExpectations the_expectations(expectations);
294 198
(...skipping 20 matching lines...) Expand all
315 CommandExpectations::const_iterator scan(the_expectations.begin()); 219 CommandExpectations::const_iterator scan(the_expectations.begin());
316 CommandExpectations::const_iterator end(the_expectations.end()); 220 CommandExpectations::const_iterator end(the_expectations.end());
317 for (; scan != end; ++scan) { 221 for (; scan != end; ++scan) {
318 *is_valid = false; 222 *is_valid = false;
319 LOG(ERROR) << ctx.dist->GetDisplayName() 223 LOG(ERROR) << ctx.dist->GetDisplayName()
320 << " is missing the Google Update product command named \"" 224 << " is missing the Google Update product command named \""
321 << scan->first << "\"."; 225 << scan->first << "\".";
322 } 226 }
323 } 227 }
324 228
325 // Validates the multi-install binaries' Google Update commands.
326 void InstallationValidator::ValidateBinariesCommands(
327 const ProductContext& ctx,
328 bool* is_valid) {
329 DCHECK(is_valid);
330
331 const ProductState* binaries_state = ctx.machine_state.GetProductState(
332 ctx.system_install, BrowserDistribution::CHROME_BINARIES);
333
334 CommandExpectations expectations;
335
336 if (binaries_state != NULL) {
337 expectations[kCmdQuickEnableApplicationHost] =
338 &ValidateQuickEnableApplicationHostCommand;
339
340 expectations[kCmdQueryEULAAcceptance] = &ValidateQueryEULAAcceptanceCommand;
341 }
342
343 ValidateAppCommandExpectations(ctx, expectations, is_valid);
344 }
345
346 // Validates the multi-install binaries at level |system_level|. 229 // Validates the multi-install binaries at level |system_level|.
347 void InstallationValidator::ValidateBinaries( 230 void InstallationValidator::ValidateBinaries(
348 const InstallationState& machine_state, 231 const InstallationState& machine_state,
349 bool system_install, 232 bool system_install,
350 const ProductState& binaries_state, 233 const ProductState& binaries_state,
351 bool* is_valid) { 234 bool* is_valid) {
352 const ChannelInfo& channel = binaries_state.channel(); 235 const ChannelInfo& channel = binaries_state.channel();
353 236
354 // ap must have -multi 237 // ap must have -multi
355 if (!channel.IsMultiInstall()) { 238 if (!channel.IsMultiInstall()) {
(...skipping 26 matching lines...) Expand all
382 LOG(ERROR) << "Chrome Binaries are missing \"-chromeframe\" in channel" 265 LOG(ERROR) << "Chrome Binaries are missing \"-chromeframe\" in channel"
383 " name: \"" << channel.value() << "\""; 266 " name: \"" << channel.value() << "\"";
384 } 267 }
385 } else if (channel.IsChromeFrame()) { 268 } else if (channel.IsChromeFrame()) {
386 *is_valid = false; 269 *is_valid = false;
387 LOG(ERROR) << "Chrome Binaries have \"-chromeframe\" in channel name, yet " 270 LOG(ERROR) << "Chrome Binaries have \"-chromeframe\" in channel name, yet "
388 "Chrome Frame is not installed multi: \"" << channel.value() 271 "Chrome Frame is not installed multi: \"" << channel.value()
389 << "\""; 272 << "\"";
390 } 273 }
391 274
392 // ap must have -applauncher iff Chrome App Launcher is installed multi 275 // Chrome or Chrome Frame must be present
393 const ProductState* app_host_state = machine_state.GetProductState( 276 if (chrome_state == NULL && cf_state == NULL) {
394 system_install, BrowserDistribution::CHROME_APP_HOST);
395 if (app_host_state != NULL) {
396 if (!app_host_state->is_multi_install()) {
397 *is_valid = false;
398 LOG(ERROR) << "Chrome App Launcher is installed in non-multi mode.";
399 }
400 if (!channel.IsAppLauncher()) {
401 *is_valid = false;
402 LOG(ERROR) << "Chrome Binaries are missing \"-applauncher\" in channel"
403 " name: \"" << channel.value() << "\"";
404 }
405 } else if (channel.IsAppLauncher()) {
406 *is_valid = false;
407 LOG(ERROR) << "Chrome Binaries have \"-applauncher\" in channel name, yet "
408 "Chrome App Launcher is not installed: \"" << channel.value()
409 << "\"";
410 }
411
412 // Chrome, Chrome Frame, or App Host must be present
413 if (chrome_state == NULL && cf_state == NULL && app_host_state == NULL) {
414 *is_valid = false; 277 *is_valid = false;
415 LOG(ERROR) << "Chrome Binaries are present with no other products."; 278 LOG(ERROR) << "Chrome Binaries are present with no other products.";
416 } 279 }
417 280
281
418 // Chrome must be multi-install if present. 282 // Chrome must be multi-install if present.
419 if (chrome_state != NULL && !chrome_state->is_multi_install()) { 283 if (chrome_state != NULL && !chrome_state->is_multi_install()) {
420 *is_valid = false; 284 *is_valid = false;
421 LOG(ERROR) 285 LOG(ERROR)
422 << "Chrome Binaries are present yet Chrome is not multi-install."; 286 << "Chrome Binaries are present yet Chrome is not multi-install.";
423 } 287 }
424 288
425 // Chrome Frame must be multi-install if Chrome & App Host are not present. 289 // Chrome Frame must be multi-install if Chrome is not present.
426 if (cf_state != NULL && app_host_state == NULL && chrome_state == NULL && 290 if (cf_state != NULL && chrome_state == NULL &&
427 !cf_state->is_multi_install()) { 291 !cf_state->is_multi_install()) {
428 *is_valid = false; 292 *is_valid = false;
429 LOG(ERROR) << "Chrome Binaries are present without Chrome nor App Launcher " 293 LOG(ERROR) << "Chrome Binaries are present without Chrome, yet Chrome Frame"
430 << "yet Chrome Frame is not multi-install."; 294 << " is not multi-install.";
431 } 295 }
432 296
433 ChromeBinariesRules binaries_rules; 297 ChromeBinariesRules binaries_rules;
434 ProductContext ctx(machine_state, system_install, binaries_state, 298 ProductContext ctx(machine_state, system_install, binaries_state,
435 binaries_rules); 299 binaries_rules);
436 300
437 ValidateBinariesCommands(ctx, is_valid);
438
439 ValidateUsageStats(ctx, is_valid); 301 ValidateUsageStats(ctx, is_valid);
440 } 302 }
441 303
442 // Validates the path to |setup_exe| for the product described by |ctx|. 304 // Validates the path to |setup_exe| for the product described by |ctx|.
443 void InstallationValidator::ValidateSetupPath(const ProductContext& ctx, 305 void InstallationValidator::ValidateSetupPath(const ProductContext& ctx,
444 const base::FilePath& setup_exe, 306 const base::FilePath& setup_exe,
445 const base::string16& purpose, 307 const base::string16& purpose,
446 bool* is_valid) { 308 bool* is_valid) {
447 DCHECK(is_valid); 309 DCHECK(is_valid);
448 310
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 // Validates the multi-install state of the product described in |ctx|. 429 // Validates the multi-install state of the product described in |ctx|.
568 void InstallationValidator::ValidateMultiInstallProduct( 430 void InstallationValidator::ValidateMultiInstallProduct(
569 const ProductContext& ctx, 431 const ProductContext& ctx,
570 bool* is_valid) { 432 bool* is_valid) {
571 DCHECK(is_valid); 433 DCHECK(is_valid);
572 434
573 const ProductState* binaries = 435 const ProductState* binaries =
574 ctx.machine_state.GetProductState(ctx.system_install, 436 ctx.machine_state.GetProductState(ctx.system_install,
575 BrowserDistribution::CHROME_BINARIES); 437 BrowserDistribution::CHROME_BINARIES);
576 if (!binaries) { 438 if (!binaries) {
577 if (ctx.dist->GetType() == BrowserDistribution::CHROME_APP_HOST) { 439 *is_valid = false;
578 if (!ctx.machine_state.GetProductState( 440 LOG(ERROR) << ctx.dist->GetDisplayName()
579 true, // system-level 441 << " (" << ctx.state.version().GetString() << ") is installed "
580 BrowserDistribution::CHROME_BINARIES) && 442 << "without Chrome Binaries.";
581 !ctx.machine_state.GetProductState(
582 true, // system-level
583 BrowserDistribution::CHROME_BROWSER)) {
584 *is_valid = false;
585 LOG(ERROR) << ctx.dist->GetDisplayName()
586 << " (" << ctx.state.version().GetString() << ") is "
587 << "installed without Chrome Binaries or a system-level "
588 << "Chrome.";
589 }
590 } else {
591 *is_valid = false;
592 LOG(ERROR) << ctx.dist->GetDisplayName()
593 << " (" << ctx.state.version().GetString() << ") is installed "
594 << "without Chrome Binaries.";
595 }
596 } else { 443 } else {
597 // Version must match that of binaries. 444 // Version must match that of binaries.
598 if (ctx.state.version().CompareTo(binaries->version()) != 0) { 445 if (ctx.state.version().CompareTo(binaries->version()) != 0) {
599 *is_valid = false; 446 *is_valid = false;
600 LOG(ERROR) << "Version of " << ctx.dist->GetDisplayName() 447 LOG(ERROR) << "Version of " << ctx.dist->GetDisplayName()
601 << " (" << ctx.state.version().GetString() << ") does not " 448 << " (" << ctx.state.version().GetString() << ") does not "
602 "match that of Chrome Binaries (" 449 "match that of Chrome Binaries ("
603 << binaries->version().GetString() << ")."; 450 << binaries->version().GetString() << ").";
604 } 451 }
605 452
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 if (product_state != NULL) { 557 if (product_state != NULL) {
711 ChromeFrameRules chrome_frame_rules; 558 ChromeFrameRules chrome_frame_rules;
712 ValidateProduct(machine_state, system_level, *product_state, 559 ValidateProduct(machine_state, system_level, *product_state,
713 chrome_frame_rules, &rock_on); 560 chrome_frame_rules, &rock_on);
714 int cf_bit = !product_state->is_multi_install() ? 561 int cf_bit = !product_state->is_multi_install() ?
715 ProductBits::CHROME_FRAME_SINGLE : 562 ProductBits::CHROME_FRAME_SINGLE :
716 ProductBits::CHROME_FRAME_MULTI; 563 ProductBits::CHROME_FRAME_MULTI;
717 *type = static_cast<InstallationType>(*type | cf_bit); 564 *type = static_cast<InstallationType>(*type | cf_bit);
718 } 565 }
719 566
720 // Is Chrome App Host installed?
721 product_state =
722 machine_state.GetProductState(system_level,
723 BrowserDistribution::CHROME_APP_HOST);
724 if (product_state != NULL) {
725 ChromeAppHostRules chrome_app_host_rules;
726 ValidateProduct(machine_state, system_level, *product_state,
727 chrome_app_host_rules, &rock_on);
728 *type = static_cast<InstallationType>(*type | ProductBits::CHROME_APP_HOST);
729 if (!product_state->is_multi_install()) {
730 LOG(ERROR) << "Chrome App Launcher must always be multi-install.";
731 rock_on = false;
732 }
733 }
734
735 DCHECK_NE(std::find(&kInstallationTypes[0], 567 DCHECK_NE(std::find(&kInstallationTypes[0],
736 &kInstallationTypes[arraysize(kInstallationTypes)], 568 &kInstallationTypes[arraysize(kInstallationTypes)],
737 *type), 569 *type),
738 &kInstallationTypes[arraysize(kInstallationTypes)]) 570 &kInstallationTypes[arraysize(kInstallationTypes)])
739 << "Invalid combination of products found on system (" << *type << ")"; 571 << "Invalid combination of products found on system (" << *type << ")";
740 572
741 return rock_on; 573 return rock_on;
742 } 574 }
743 575
744 // static 576 // static
745 bool InstallationValidator::ValidateInstallationType(bool system_level, 577 bool InstallationValidator::ValidateInstallationType(bool system_level,
746 InstallationType* type) { 578 InstallationType* type) {
747 DCHECK(type); 579 DCHECK(type);
748 InstallationState machine_state; 580 InstallationState machine_state;
749 581
750 machine_state.Initialize(); 582 machine_state.Initialize();
751 583
752 return ValidateInstallationTypeForState(machine_state, system_level, type); 584 return ValidateInstallationTypeForState(machine_state, system_level, type);
753 } 585 }
754 586
755 } // namespace installer 587 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698