| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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> | 
| 11 | 11 | 
| 12 #include "base/logging.h" | 12 #include "base/logging.h" | 
| 13 #include "base/version.h" | 13 #include "base/version.h" | 
| 14 #include "chrome/installer/util/browser_distribution.h" | 14 #include "chrome/installer/util/browser_distribution.h" | 
| 15 #include "chrome/installer/util/helper.h" | 15 #include "chrome/installer/util/helper.h" | 
| 16 #include "chrome/installer/util/installation_state.h" | 16 #include "chrome/installer/util/installation_state.h" | 
| 17 | 17 | 
| 18 namespace installer { | 18 namespace installer { | 
| 19 | 19 | 
| 20 BrowserDistribution::Type | 20 BrowserDistribution::Type | 
| 21     InstallationValidator::ChromeRules::distribution_type() const { | 21     InstallationValidator::ChromeRules::distribution_type() const { | 
| 22   return BrowserDistribution::CHROME_BROWSER; | 22   return BrowserDistribution::CHROME_BROWSER; | 
| 23 } | 23 } | 
| 24 | 24 | 
| 25 void InstallationValidator::ChromeRules::AddProductSwitchExpectations( | 25 void InstallationValidator::ChromeRules::AddUninstallSwitchExpectations( | 
| 26     const InstallationState& machine_state, | 26     const InstallationState& machine_state, | 
| 27     bool system_install, | 27     bool system_install, | 
| 28     const ProductState& product_state, | 28     const ProductState& product_state, | 
| 29     SwitchExpectations* expectations) const { | 29     SwitchExpectations* expectations) const { | 
| 30   const bool is_multi_install = | 30   const bool is_multi_install = | 
| 31       product_state.uninstall_command().HasSwitch(switches::kMultiInstall); | 31       product_state.uninstall_command().HasSwitch(switches::kMultiInstall); | 
| 32 | 32 | 
| 33   // --chrome should be present iff --multi-install.  This wasn't the case in | 33   // --chrome should be present for uninstall iff --multi-install.  This wasn't | 
| 34   // Chrome 10 (between r68996 and r72497), though, so consider it optional. | 34   // the case in Chrome 10 (between r68996 and r72497), though, so consider it | 
|  | 35   // optional. | 
| 35 | 36 | 
| 36   // --chrome-frame --ready-mode should be present iff CF in ready mode. | 37   // --chrome-frame --ready-mode should be present for uninstall iff CF in ready | 
|  | 38   // mode. | 
| 37   const ProductState* cf_state = | 39   const ProductState* cf_state = | 
| 38       machine_state.GetProductState(system_install, | 40       machine_state.GetProductState(system_install, | 
| 39                                     BrowserDistribution::CHROME_FRAME); | 41                                     BrowserDistribution::CHROME_FRAME); | 
| 40   const bool ready_mode = | 42   const bool ready_mode = | 
| 41       cf_state != NULL && | 43       cf_state != NULL && | 
| 42       cf_state->uninstall_command().HasSwitch(switches::kChromeFrameReadyMode); | 44       cf_state->uninstall_command().HasSwitch(switches::kChromeFrameReadyMode); | 
| 43   expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), | 45   expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), | 
| 44                                          ready_mode)); | 46                                          ready_mode)); | 
| 45   expectations->push_back( | 47   expectations->push_back( | 
| 46       std::make_pair(std::string(switches::kChromeFrameReadyMode), ready_mode)); | 48       std::make_pair(std::string(switches::kChromeFrameReadyMode), ready_mode)); | 
| 47 } | 49 } | 
| 48 | 50 | 
|  | 51 void InstallationValidator::ChromeRules::AddRenameSwitchExpectations( | 
|  | 52     const InstallationState& machine_state, | 
|  | 53     bool system_install, | 
|  | 54     const ProductState& product_state, | 
|  | 55     SwitchExpectations* expectations) const { | 
|  | 56   const bool is_multi_install = | 
|  | 57       product_state.uninstall_command().HasSwitch(switches::kMultiInstall); | 
|  | 58 | 
|  | 59   // --chrome should not be present for rename.  It was for a time, so we'll be | 
|  | 60   // lenient so that mini_installer tests pass. | 
|  | 61 | 
|  | 62   // --chrome-frame --ready-mode should never be present. | 
|  | 63   expectations->push_back( | 
|  | 64       std::make_pair(std::string(switches::kChromeFrame), false)); | 
|  | 65   expectations->push_back( | 
|  | 66       std::make_pair(std::string(switches::kChromeFrameReadyMode), false)); | 
|  | 67 } | 
|  | 68 | 
| 49 bool InstallationValidator::ChromeRules::UsageStatsAllowed( | 69 bool InstallationValidator::ChromeRules::UsageStatsAllowed( | 
| 50     const ProductState& product_state) const { | 70     const ProductState& product_state) const { | 
| 51   // Products must not have usagestats consent values when multi-install | 71   // Products must not have usagestats consent values when multi-install | 
| 52   // (only the multi-install binaries may). | 72   // (only the multi-install binaries may). | 
| 53   return !product_state.is_multi_install(); | 73   return !product_state.is_multi_install(); | 
| 54 } | 74 } | 
| 55 | 75 | 
| 56 BrowserDistribution::Type | 76 BrowserDistribution::Type | 
| 57     InstallationValidator::ChromeFrameRules::distribution_type() const { | 77     InstallationValidator::ChromeFrameRules::distribution_type() const { | 
| 58   return BrowserDistribution::CHROME_FRAME; | 78   return BrowserDistribution::CHROME_FRAME; | 
| 59 } | 79 } | 
| 60 | 80 | 
| 61 void InstallationValidator::ChromeFrameRules::AddProductSwitchExpectations( | 81 void InstallationValidator::ChromeFrameRules::AddUninstallSwitchExpectations( | 
| 62     const InstallationState& machine_state, | 82     const InstallationState& machine_state, | 
| 63     bool system_install, | 83     bool system_install, | 
| 64     const ProductState& product_state, | 84     const ProductState& product_state, | 
| 65     SwitchExpectations* expectations) const { | 85     SwitchExpectations* expectations) const { | 
| 66   // --chrome-frame must be present. | 86   // --chrome-frame must be present. | 
| 67   expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), | 87   expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), | 
| 68                                          true)); | 88                                          true)); | 
| 69   // --chrome must not be present. | 89   // --chrome must not be present. | 
| 70   expectations->push_back(std::make_pair(std::string(switches::kChrome), | 90   expectations->push_back(std::make_pair(std::string(switches::kChrome), | 
| 71                                          false)); | 91                                          false)); | 
| 72 } | 92 } | 
| 73 | 93 | 
|  | 94 void InstallationValidator::ChromeFrameRules::AddRenameSwitchExpectations( | 
|  | 95     const InstallationState& machine_state, | 
|  | 96     bool system_install, | 
|  | 97     const ProductState& product_state, | 
|  | 98     SwitchExpectations* expectations) const { | 
|  | 99   // --chrome-frame must be present for SxS rename. | 
|  | 100   expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), | 
|  | 101                                          !product_state.is_multi_install())); | 
|  | 102   // --chrome must not be present. | 
|  | 103   expectations->push_back(std::make_pair(std::string(switches::kChrome), | 
|  | 104                                          false)); | 
|  | 105 } | 
|  | 106 | 
| 74 bool InstallationValidator::ChromeFrameRules::UsageStatsAllowed( | 107 bool InstallationValidator::ChromeFrameRules::UsageStatsAllowed( | 
| 75     const ProductState& product_state) const { | 108     const ProductState& product_state) const { | 
| 76   // Products must not have usagestats consent values when multi-install | 109   // Products must not have usagestats consent values when multi-install | 
| 77   // (only the multi-install binaries may). | 110   // (only the multi-install binaries may). | 
| 78   return !product_state.is_multi_install(); | 111   return !product_state.is_multi_install(); | 
| 79 } | 112 } | 
| 80 | 113 | 
| 81 BrowserDistribution::Type | 114 BrowserDistribution::Type | 
| 82     InstallationValidator::ChromeBinariesRules::distribution_type() const { | 115     InstallationValidator::ChromeBinariesRules::distribution_type() const { | 
| 83   return BrowserDistribution::CHROME_BINARIES; | 116   return BrowserDistribution::CHROME_BINARIES; | 
| 84 } | 117 } | 
| 85 | 118 | 
| 86 void InstallationValidator::ChromeBinariesRules::AddProductSwitchExpectations( | 119 void InstallationValidator::ChromeBinariesRules::AddUninstallSwitchExpectations( | 
| 87     const InstallationState& machine_state, | 120     const InstallationState& machine_state, | 
| 88     bool system_install, | 121     bool system_install, | 
| 89     const ProductState& product_state, | 122     const ProductState& product_state, | 
| 90     SwitchExpectations* expectations) const { | 123     SwitchExpectations* expectations) const { | 
| 91   NOTREACHED(); | 124   NOTREACHED(); | 
| 92 } | 125 } | 
| 93 | 126 | 
|  | 127 void InstallationValidator::ChromeBinariesRules::AddRenameSwitchExpectations( | 
|  | 128     const InstallationState& machine_state, | 
|  | 129     bool system_install, | 
|  | 130     const ProductState& product_state, | 
|  | 131     SwitchExpectations* expectations) const { | 
|  | 132   NOTREACHED(); | 
|  | 133 } | 
|  | 134 | 
| 94 bool InstallationValidator::ChromeBinariesRules::UsageStatsAllowed( | 135 bool InstallationValidator::ChromeBinariesRules::UsageStatsAllowed( | 
| 95     const ProductState& product_state) const { | 136     const ProductState& product_state) const { | 
| 96   // UsageStats consent values are always allowed on the binaries. | 137   // UsageStats consent values are always allowed on the binaries. | 
| 97   return true; | 138   return true; | 
| 98 } | 139 } | 
| 99 | 140 | 
| 100 // static | 141 // static | 
| 101 const InstallationValidator::InstallationType | 142 const InstallationValidator::InstallationType | 
| 102     InstallationValidator::kInstallationTypes[] = { | 143     InstallationValidator::kInstallationTypes[] = { | 
| 103   NO_PRODUCTS, | 144   NO_PRODUCTS, | 
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 365   ValidateSetupPath(ctx, command.GetProgram(), "uninstaller", is_valid); | 406   ValidateSetupPath(ctx, command.GetProgram(), "uninstaller", is_valid); | 
| 366 | 407 | 
| 367   const bool is_multi_install = ctx.state.is_multi_install(); | 408   const bool is_multi_install = ctx.state.is_multi_install(); | 
| 368   SwitchExpectations expected; | 409   SwitchExpectations expected; | 
| 369 | 410 | 
| 370   expected.push_back(std::make_pair(std::string(switches::kUninstall), true)); | 411   expected.push_back(std::make_pair(std::string(switches::kUninstall), true)); | 
| 371   expected.push_back(std::make_pair(std::string(switches::kSystemLevel), | 412   expected.push_back(std::make_pair(std::string(switches::kSystemLevel), | 
| 372                                     ctx.system_install)); | 413                                     ctx.system_install)); | 
| 373   expected.push_back(std::make_pair(std::string(switches::kMultiInstall), | 414   expected.push_back(std::make_pair(std::string(switches::kMultiInstall), | 
| 374                                     is_multi_install)); | 415                                     is_multi_install)); | 
| 375   ctx.rules.AddProductSwitchExpectations(ctx.machine_state, | 416   ctx.rules.AddUninstallSwitchExpectations(ctx.machine_state, | 
| 376                                          ctx.system_install, | 417                                          ctx.system_install, | 
| 377                                          ctx.state, &expected); | 418                                          ctx.state, | 
|  | 419                                          &expected); | 
| 378 | 420 | 
| 379   ValidateCommandExpectations(ctx, command, expected, source, is_valid); | 421   ValidateCommandExpectations(ctx, command, expected, source, is_valid); | 
| 380 } | 422 } | 
| 381 | 423 | 
| 382 // Validates the rename command for the product described by |ctx|. | 424 // Validates the rename command for the product described by |ctx|. | 
| 383 void InstallationValidator::ValidateRenameCommand(const ProductContext& ctx, | 425 void InstallationValidator::ValidateRenameCommand(const ProductContext& ctx, | 
| 384                                                   bool* is_valid) { | 426                                                   bool* is_valid) { | 
| 385   DCHECK(is_valid); | 427   DCHECK(is_valid); | 
| 386   DCHECK(!ctx.state.rename_cmd().empty()); | 428   DCHECK(!ctx.state.rename_cmd().empty()); | 
| 387 | 429 | 
| 388   CommandLine command = CommandLine::FromString(ctx.state.rename_cmd()); | 430   CommandLine command = CommandLine::FromString(ctx.state.rename_cmd()); | 
| 389 | 431 | 
| 390   ValidateSetupPath(ctx, command.GetProgram(), "in-use renamer", is_valid); | 432   ValidateSetupPath(ctx, command.GetProgram(), "in-use renamer", is_valid); | 
| 391 | 433 | 
| 392   SwitchExpectations expected; | 434   SwitchExpectations expected; | 
| 393 | 435 | 
| 394   expected.push_back(std::make_pair(std::string(switches::kRenameChromeExe), | 436   expected.push_back(std::make_pair(std::string(switches::kRenameChromeExe), | 
| 395                                     true)); | 437                                     true)); | 
| 396   expected.push_back(std::make_pair(std::string(switches::kSystemLevel), | 438   expected.push_back(std::make_pair(std::string(switches::kSystemLevel), | 
| 397                                     ctx.system_install)); | 439                                     ctx.system_install)); | 
| 398   expected.push_back(std::make_pair(std::string(switches::kMultiInstall), | 440   expected.push_back(std::make_pair(std::string(switches::kMultiInstall), | 
| 399                                     ctx.state.is_multi_install())); | 441                                     ctx.state.is_multi_install())); | 
|  | 442   ctx.rules.AddRenameSwitchExpectations(ctx.machine_state, | 
|  | 443                                         ctx.system_install, | 
|  | 444                                         ctx.state, | 
|  | 445                                         &expected); | 
| 400 | 446 | 
| 401   ValidateCommandExpectations(ctx, command, expected, "in-use renamer", | 447   ValidateCommandExpectations(ctx, command, expected, "in-use renamer", | 
| 402                               is_valid); | 448                               is_valid); | 
| 403 } | 449 } | 
| 404 | 450 | 
| 405 // Validates the "opv" and "cmd" values for the product described in |ctx|. | 451 // Validates the "opv" and "cmd" values for the product described in |ctx|. | 
| 406 void InstallationValidator::ValidateOldVersionValues( | 452 void InstallationValidator::ValidateOldVersionValues( | 
| 407     const ProductContext& ctx, | 453     const ProductContext& ctx, | 
| 408     bool* is_valid) { | 454     bool* is_valid) { | 
| 409   DCHECK(is_valid); | 455   DCHECK(is_valid); | 
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 577                                                      InstallationType* type) { | 623                                                      InstallationType* type) { | 
| 578   DCHECK(type); | 624   DCHECK(type); | 
| 579   InstallationState machine_state; | 625   InstallationState machine_state; | 
| 580 | 626 | 
| 581   machine_state.Initialize(); | 627   machine_state.Initialize(); | 
| 582 | 628 | 
| 583   return ValidateInstallationTypeForState(machine_state, system_level, type); | 629   return ValidateInstallationTypeForState(machine_state, system_level, type); | 
| 584 } | 630 } | 
| 585 | 631 | 
| 586 }  // namespace installer | 632 }  // namespace installer | 
| OLD | NEW | 
|---|