| 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 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/version.h" | 12 #include "base/version.h" |
| 13 #include "chrome/installer/util/browser_distribution.h" | 13 #include "chrome/installer/util/browser_distribution.h" |
| 14 #include "chrome/installer/util/helper.h" | 14 #include "chrome/installer/util/helper.h" |
| 15 #include "chrome/installer/util/installation_state.h" | 15 #include "chrome/installer/util/installation_state.h" |
| 16 | 16 |
| 17 namespace installer { | 17 namespace installer { |
| 18 | 18 |
| 19 BrowserDistribution::Type | 19 BrowserDistribution::Type |
| 20 InstallationValidator::ChromeRules::distribution_type() const { | 20 InstallationValidator::ChromeRules::distribution_type() const { |
| 21 return BrowserDistribution::CHROME_BROWSER; | 21 return BrowserDistribution::CHROME_BROWSER; |
| 22 } | 22 } |
| 23 | 23 |
| 24 void InstallationValidator::ChromeRules::AddUninstallSwitchExpectations( | 24 void InstallationValidator::ChromeRules::AddProductSwitchExpectations( |
| 25 const InstallationState& machine_state, | 25 const InstallationState& machine_state, |
| 26 bool system_install, | 26 bool system_install, |
| 27 const ProductState& product_state, | 27 const ProductState& product_state, |
| 28 SwitchExpectations* expectations) const { | 28 SwitchExpectations* expectations) const { |
| 29 const bool is_multi_install = | 29 const bool is_multi_install = |
| 30 product_state.uninstall_command().HasSwitch(switches::kMultiInstall); | 30 product_state.uninstall_command().HasSwitch(switches::kMultiInstall); |
| 31 | 31 |
| 32 // --chrome should be present iff --multi-install. | 32 // --chrome should be present iff --multi-install. |
| 33 expectations->push_back(std::make_pair(std::string(switches::kChrome), | 33 expectations->push_back(std::make_pair(std::string(switches::kChrome), |
| 34 is_multi_install)); | 34 is_multi_install)); |
| 35 // --chrome-frame --ready-mode should be present iff CF in ready mode. | 35 // --chrome-frame --ready-mode should be present iff CF in ready mode. |
| 36 const ProductState* cf_state = | 36 const ProductState* cf_state = |
| 37 machine_state.GetProductState(system_install, | 37 machine_state.GetProductState(system_install, |
| 38 BrowserDistribution::CHROME_FRAME); | 38 BrowserDistribution::CHROME_FRAME); |
| 39 const bool ready_mode = | 39 const bool ready_mode = |
| 40 cf_state != NULL && | 40 cf_state != NULL && |
| 41 cf_state->uninstall_command().HasSwitch(switches::kChromeFrameReadyMode); | 41 cf_state->uninstall_command().HasSwitch(switches::kChromeFrameReadyMode); |
| 42 expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), | 42 expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), |
| 43 ready_mode)); | 43 ready_mode)); |
| 44 expectations->push_back( | 44 expectations->push_back( |
| 45 std::make_pair(std::string(switches::kChromeFrameReadyMode), ready_mode)); | 45 std::make_pair(std::string(switches::kChromeFrameReadyMode), ready_mode)); |
| 46 } | 46 } |
| 47 | 47 |
| 48 BrowserDistribution::Type | 48 BrowserDistribution::Type |
| 49 InstallationValidator::ChromeFrameRules::distribution_type() const { | 49 InstallationValidator::ChromeFrameRules::distribution_type() const { |
| 50 return BrowserDistribution::CHROME_FRAME; | 50 return BrowserDistribution::CHROME_FRAME; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void InstallationValidator::ChromeFrameRules::AddUninstallSwitchExpectations( | 53 void InstallationValidator::ChromeFrameRules::AddProductSwitchExpectations( |
| 54 const InstallationState& machine_state, | 54 const InstallationState& machine_state, |
| 55 bool system_install, | 55 bool system_install, |
| 56 const ProductState& product_state, | 56 const ProductState& product_state, |
| 57 SwitchExpectations* expectations) const { | 57 SwitchExpectations* expectations) const { |
| 58 // --chrome-frame must be present. | 58 // --chrome-frame must be present. |
| 59 expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), | 59 expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), |
| 60 true)); | 60 true)); |
| 61 // --chrome must not be present. | 61 // --chrome must not be present. |
| 62 expectations->push_back(std::make_pair(std::string(switches::kChrome), | 62 expectations->push_back(std::make_pair(std::string(switches::kChrome), |
| 63 false)); | 63 false)); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 ValidateSetupPath(ctx, command.GetProgram(), "uninstaller", is_valid); | 221 ValidateSetupPath(ctx, command.GetProgram(), "uninstaller", is_valid); |
| 222 | 222 |
| 223 const bool is_multi_install = ctx.state.is_multi_install(); | 223 const bool is_multi_install = ctx.state.is_multi_install(); |
| 224 SwitchExpectations expected; | 224 SwitchExpectations expected; |
| 225 | 225 |
| 226 expected.push_back(std::make_pair(std::string(switches::kUninstall), true)); | 226 expected.push_back(std::make_pair(std::string(switches::kUninstall), true)); |
| 227 expected.push_back(std::make_pair(std::string(switches::kSystemLevel), | 227 expected.push_back(std::make_pair(std::string(switches::kSystemLevel), |
| 228 ctx.system_install)); | 228 ctx.system_install)); |
| 229 expected.push_back(std::make_pair(std::string(switches::kMultiInstall), | 229 expected.push_back(std::make_pair(std::string(switches::kMultiInstall), |
| 230 is_multi_install)); | 230 is_multi_install)); |
| 231 ctx.rules.AddUninstallSwitchExpectations(ctx.machine_state, | 231 ctx.rules.AddProductSwitchExpectations(ctx.machine_state, |
| 232 ctx.system_install, | 232 ctx.system_install, |
| 233 ctx.state, &expected); | 233 ctx.state, &expected); |
| 234 | 234 |
| 235 ValidateCommandExpectations(ctx, command, expected, source, is_valid); | 235 ValidateCommandExpectations(ctx, command, expected, source, is_valid); |
| 236 } | 236 } |
| 237 | 237 |
| 238 // Validates the rename command for the product described by |ctx|. | 238 // Validates the rename command for the product described by |ctx|. |
| 239 void InstallationValidator::ValidateRenameCommand(const ProductContext& ctx, | 239 void InstallationValidator::ValidateRenameCommand(const ProductContext& ctx, |
| 240 bool* is_valid) { | 240 bool* is_valid) { |
| 241 DCHECK(is_valid); | 241 DCHECK(is_valid); |
| 242 DCHECK(!ctx.state.rename_cmd().empty()); | 242 DCHECK(!ctx.state.rename_cmd().empty()); |
| 243 | 243 |
| 244 CommandLine command = CommandLine::FromString(ctx.state.rename_cmd()); | 244 CommandLine command = CommandLine::FromString(ctx.state.rename_cmd()); |
| 245 | 245 |
| 246 ValidateSetupPath(ctx, command.GetProgram(), "in-use renamer", is_valid); | 246 ValidateSetupPath(ctx, command.GetProgram(), "in-use renamer", is_valid); |
| 247 | 247 |
| 248 SwitchExpectations expected; | 248 SwitchExpectations expected; |
| 249 | 249 |
| 250 expected.push_back(std::make_pair(std::string(switches::kRenameChromeExe), | 250 expected.push_back(std::make_pair(std::string(switches::kRenameChromeExe), |
| 251 true)); | 251 true)); |
| 252 expected.push_back(std::make_pair(std::string(switches::kSystemLevel), | 252 expected.push_back(std::make_pair(std::string(switches::kSystemLevel), |
| 253 ctx.system_install)); | 253 ctx.system_install)); |
| 254 expected.push_back(std::make_pair(std::string(switches::kMultiInstall), | 254 expected.push_back(std::make_pair(std::string(switches::kMultiInstall), |
| 255 ctx.state.is_multi_install())); | 255 ctx.state.is_multi_install())); |
| 256 ctx.rules.AddProductSwitchExpectations(ctx.machine_state, |
| 257 ctx.system_install, |
| 258 ctx.state, &expected); |
| 256 | 259 |
| 257 ValidateCommandExpectations(ctx, command, expected, "in-use renamer", | 260 ValidateCommandExpectations(ctx, command, expected, "in-use renamer", |
| 258 is_valid); | 261 is_valid); |
| 259 } | 262 } |
| 260 | 263 |
| 261 // Validates the "opv" and "cmd" values for the product described in |ctx|. | 264 // Validates the "opv" and "cmd" values for the product described in |ctx|. |
| 262 void InstallationValidator::ValidateOldVersionValues( | 265 void InstallationValidator::ValidateOldVersionValues( |
| 263 const ProductContext& ctx, | 266 const ProductContext& ctx, |
| 264 bool* is_valid) { | 267 bool* is_valid) { |
| 265 DCHECK(is_valid); | 268 DCHECK(is_valid); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 InstallationType* type) { | 403 InstallationType* type) { |
| 401 DCHECK(type); | 404 DCHECK(type); |
| 402 InstallationState machine_state; | 405 InstallationState machine_state; |
| 403 | 406 |
| 404 machine_state.Initialize(); | 407 machine_state.Initialize(); |
| 405 | 408 |
| 406 return ValidateInstallationTypeForState(machine_state, system_level, type); | 409 return ValidateInstallationTypeForState(machine_state, system_level, type); |
| 407 } | 410 } |
| 408 | 411 |
| 409 } // namespace installer | 412 } // namespace installer |
| OLD | NEW |