| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ctx.system_install)); | 205 ctx.system_install)); |
| 244 | 206 |
| 245 ValidateCommandExpectations(ctx, cmd_line, expected, name, is_valid); | 207 ValidateCommandExpectations(ctx, cmd_line, expected, name, is_valid); |
| 246 | 208 |
| 247 std::set<base::string16> flags_exp; | 209 std::set<base::string16> flags_exp; |
| 248 flags_exp.insert(google_update::kRegWebAccessibleField); | 210 flags_exp.insert(google_update::kRegWebAccessibleField); |
| 249 flags_exp.insert(google_update::kRegRunAsUserField); | 211 flags_exp.insert(google_update::kRegRunAsUserField); |
| 250 ValidateAppCommandFlags(ctx, app_cmd, flags_exp, name, is_valid); | 212 ValidateAppCommandFlags(ctx, app_cmd, flags_exp, name, is_valid); |
| 251 } | 213 } |
| 252 | 214 |
| 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 | 215 // Validates a product's set of Google Update product commands against a |
| 286 // collection of expectations. | 216 // collection of expectations. |
| 287 void InstallationValidator::ValidateAppCommandExpectations( | 217 void InstallationValidator::ValidateAppCommandExpectations( |
| 288 const ProductContext& ctx, | 218 const ProductContext& ctx, |
| 289 const CommandExpectations& expectations, | 219 const CommandExpectations& expectations, |
| 290 bool* is_valid) { | 220 bool* is_valid) { |
| 291 DCHECK(is_valid); | 221 DCHECK(is_valid); |
| 292 | 222 |
| 293 CommandExpectations the_expectations(expectations); | 223 CommandExpectations the_expectations(expectations); |
| 294 | 224 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 const ProductContext& ctx, | 257 const ProductContext& ctx, |
| 328 bool* is_valid) { | 258 bool* is_valid) { |
| 329 DCHECK(is_valid); | 259 DCHECK(is_valid); |
| 330 | 260 |
| 331 const ProductState* binaries_state = ctx.machine_state.GetProductState( | 261 const ProductState* binaries_state = ctx.machine_state.GetProductState( |
| 332 ctx.system_install, BrowserDistribution::CHROME_BINARIES); | 262 ctx.system_install, BrowserDistribution::CHROME_BINARIES); |
| 333 | 263 |
| 334 CommandExpectations expectations; | 264 CommandExpectations expectations; |
| 335 | 265 |
| 336 if (binaries_state != NULL) { | 266 if (binaries_state != NULL) { |
| 337 expectations[kCmdQuickEnableApplicationHost] = | |
| 338 &ValidateQuickEnableApplicationHostCommand; | |
| 339 | |
| 340 expectations[kCmdQueryEULAAcceptance] = &ValidateQueryEULAAcceptanceCommand; | 267 expectations[kCmdQueryEULAAcceptance] = &ValidateQueryEULAAcceptanceCommand; |
| 341 } | 268 } |
| 342 | 269 |
| 343 ValidateAppCommandExpectations(ctx, expectations, is_valid); | 270 ValidateAppCommandExpectations(ctx, expectations, is_valid); |
| 344 } | 271 } |
| 345 | 272 |
| 346 // Validates the multi-install binaries at level |system_level|. | 273 // Validates the multi-install binaries at level |system_level|. |
| 347 void InstallationValidator::ValidateBinaries( | 274 void InstallationValidator::ValidateBinaries( |
| 348 const InstallationState& machine_state, | 275 const InstallationState& machine_state, |
| 349 bool system_install, | 276 bool system_install, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 LOG(ERROR) << "Chrome Binaries are missing \"-chromeframe\" in channel" | 309 LOG(ERROR) << "Chrome Binaries are missing \"-chromeframe\" in channel" |
| 383 " name: \"" << channel.value() << "\""; | 310 " name: \"" << channel.value() << "\""; |
| 384 } | 311 } |
| 385 } else if (channel.IsChromeFrame()) { | 312 } else if (channel.IsChromeFrame()) { |
| 386 *is_valid = false; | 313 *is_valid = false; |
| 387 LOG(ERROR) << "Chrome Binaries have \"-chromeframe\" in channel name, yet " | 314 LOG(ERROR) << "Chrome Binaries have \"-chromeframe\" in channel name, yet " |
| 388 "Chrome Frame is not installed multi: \"" << channel.value() | 315 "Chrome Frame is not installed multi: \"" << channel.value() |
| 389 << "\""; | 316 << "\""; |
| 390 } | 317 } |
| 391 | 318 |
| 392 // ap must have -applauncher iff Chrome App Launcher is installed multi | 319 // Chrome or Chrome Frame must be present |
| 393 const ProductState* app_host_state = machine_state.GetProductState( | 320 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; | 321 *is_valid = false; |
| 415 LOG(ERROR) << "Chrome Binaries are present with no other products."; | 322 LOG(ERROR) << "Chrome Binaries are present with no other products."; |
| 416 } | 323 } |
| 417 | 324 |
| 325 |
| 418 // Chrome must be multi-install if present. | 326 // Chrome must be multi-install if present. |
| 419 if (chrome_state != NULL && !chrome_state->is_multi_install()) { | 327 if (chrome_state != NULL && !chrome_state->is_multi_install()) { |
| 420 *is_valid = false; | 328 *is_valid = false; |
| 421 LOG(ERROR) | 329 LOG(ERROR) |
| 422 << "Chrome Binaries are present yet Chrome is not multi-install."; | 330 << "Chrome Binaries are present yet Chrome is not multi-install."; |
| 423 } | 331 } |
| 424 | 332 |
| 425 // Chrome Frame must be multi-install if Chrome & App Host are not present. | 333 // Chrome Frame must be multi-install if Chrome is not present. |
| 426 if (cf_state != NULL && app_host_state == NULL && chrome_state == NULL && | 334 if (cf_state != NULL && chrome_state == NULL && |
| 427 !cf_state->is_multi_install()) { | 335 !cf_state->is_multi_install()) { |
| 428 *is_valid = false; | 336 *is_valid = false; |
| 429 LOG(ERROR) << "Chrome Binaries are present without Chrome nor App Launcher " | 337 LOG(ERROR) << "Chrome Binaries are present without Chrome, yet Chrome Frame" |
| 430 << "yet Chrome Frame is not multi-install."; | 338 << " is not multi-install."; |
| 431 } | 339 } |
| 432 | 340 |
| 433 ChromeBinariesRules binaries_rules; | 341 ChromeBinariesRules binaries_rules; |
| 434 ProductContext ctx(machine_state, system_install, binaries_state, | 342 ProductContext ctx(machine_state, system_install, binaries_state, |
| 435 binaries_rules); | 343 binaries_rules); |
| 436 | 344 |
| 437 ValidateBinariesCommands(ctx, is_valid); | 345 ValidateBinariesCommands(ctx, is_valid); |
| 438 | 346 |
| 439 ValidateUsageStats(ctx, is_valid); | 347 ValidateUsageStats(ctx, is_valid); |
| 440 } | 348 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 // Validates the multi-install state of the product described in |ctx|. | 475 // Validates the multi-install state of the product described in |ctx|. |
| 568 void InstallationValidator::ValidateMultiInstallProduct( | 476 void InstallationValidator::ValidateMultiInstallProduct( |
| 569 const ProductContext& ctx, | 477 const ProductContext& ctx, |
| 570 bool* is_valid) { | 478 bool* is_valid) { |
| 571 DCHECK(is_valid); | 479 DCHECK(is_valid); |
| 572 | 480 |
| 573 const ProductState* binaries = | 481 const ProductState* binaries = |
| 574 ctx.machine_state.GetProductState(ctx.system_install, | 482 ctx.machine_state.GetProductState(ctx.system_install, |
| 575 BrowserDistribution::CHROME_BINARIES); | 483 BrowserDistribution::CHROME_BINARIES); |
| 576 if (!binaries) { | 484 if (!binaries) { |
| 577 if (ctx.dist->GetType() == BrowserDistribution::CHROME_APP_HOST) { | 485 *is_valid = false; |
| 578 if (!ctx.machine_state.GetProductState( | 486 LOG(ERROR) << ctx.dist->GetDisplayName() |
| 579 true, // system-level | 487 << " (" << ctx.state.version().GetString() << ") is installed " |
| 580 BrowserDistribution::CHROME_BINARIES) && | 488 << "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 { | 489 } else { |
| 597 // Version must match that of binaries. | 490 // Version must match that of binaries. |
| 598 if (ctx.state.version().CompareTo(binaries->version()) != 0) { | 491 if (ctx.state.version().CompareTo(binaries->version()) != 0) { |
| 599 *is_valid = false; | 492 *is_valid = false; |
| 600 LOG(ERROR) << "Version of " << ctx.dist->GetDisplayName() | 493 LOG(ERROR) << "Version of " << ctx.dist->GetDisplayName() |
| 601 << " (" << ctx.state.version().GetString() << ") does not " | 494 << " (" << ctx.state.version().GetString() << ") does not " |
| 602 "match that of Chrome Binaries (" | 495 "match that of Chrome Binaries (" |
| 603 << binaries->version().GetString() << ")."; | 496 << binaries->version().GetString() << ")."; |
| 604 } | 497 } |
| 605 | 498 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 if (product_state != NULL) { | 603 if (product_state != NULL) { |
| 711 ChromeFrameRules chrome_frame_rules; | 604 ChromeFrameRules chrome_frame_rules; |
| 712 ValidateProduct(machine_state, system_level, *product_state, | 605 ValidateProduct(machine_state, system_level, *product_state, |
| 713 chrome_frame_rules, &rock_on); | 606 chrome_frame_rules, &rock_on); |
| 714 int cf_bit = !product_state->is_multi_install() ? | 607 int cf_bit = !product_state->is_multi_install() ? |
| 715 ProductBits::CHROME_FRAME_SINGLE : | 608 ProductBits::CHROME_FRAME_SINGLE : |
| 716 ProductBits::CHROME_FRAME_MULTI; | 609 ProductBits::CHROME_FRAME_MULTI; |
| 717 *type = static_cast<InstallationType>(*type | cf_bit); | 610 *type = static_cast<InstallationType>(*type | cf_bit); |
| 718 } | 611 } |
| 719 | 612 |
| 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], | 613 DCHECK_NE(std::find(&kInstallationTypes[0], |
| 736 &kInstallationTypes[arraysize(kInstallationTypes)], | 614 &kInstallationTypes[arraysize(kInstallationTypes)], |
| 737 *type), | 615 *type), |
| 738 &kInstallationTypes[arraysize(kInstallationTypes)]) | 616 &kInstallationTypes[arraysize(kInstallationTypes)]) |
| 739 << "Invalid combination of products found on system (" << *type << ")"; | 617 << "Invalid combination of products found on system (" << *type << ")"; |
| 740 | 618 |
| 741 return rock_on; | 619 return rock_on; |
| 742 } | 620 } |
| 743 | 621 |
| 744 // static | 622 // static |
| 745 bool InstallationValidator::ValidateInstallationType(bool system_level, | 623 bool InstallationValidator::ValidateInstallationType(bool system_level, |
| 746 InstallationType* type) { | 624 InstallationType* type) { |
| 747 DCHECK(type); | 625 DCHECK(type); |
| 748 InstallationState machine_state; | 626 InstallationState machine_state; |
| 749 | 627 |
| 750 machine_state.Initialize(); | 628 machine_state.Initialize(); |
| 751 | 629 |
| 752 return ValidateInstallationTypeForState(machine_state, system_level, type); | 630 return ValidateInstallationTypeForState(machine_state, system_level, type); |
| 753 } | 631 } |
| 754 | 632 |
| 755 } // namespace installer | 633 } // namespace installer |
| OLD | NEW |