| 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> |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 | 106 |
| 107 bool InstallationValidator::ChromeFrameRules::UsageStatsAllowed( | 107 bool InstallationValidator::ChromeFrameRules::UsageStatsAllowed( |
| 108 const ProductState& product_state) const { | 108 const ProductState& product_state) const { |
| 109 // Products must not have usagestats consent values when multi-install | 109 // Products must not have usagestats consent values when multi-install |
| 110 // (only the multi-install binaries may). | 110 // (only the multi-install binaries may). |
| 111 return !product_state.is_multi_install(); | 111 return !product_state.is_multi_install(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 BrowserDistribution::Type | 114 BrowserDistribution::Type |
| 115 InstallationValidator::ChromeAppHostRules::distribution_type() const { |
| 116 return BrowserDistribution::CHROME_APP_HOST; |
| 117 } |
| 118 |
| 119 void InstallationValidator::ChromeAppHostRules::AddUninstallSwitchExpectations( |
| 120 const InstallationState& machine_state, |
| 121 bool system_install, |
| 122 const ProductState& product_state, |
| 123 SwitchExpectations* expectations) const { |
| 124 DCHECK(!system_install); |
| 125 |
| 126 // --chrome-app-host must be present. |
| 127 expectations->push_back(std::make_pair(std::string(switches::kChromeAppHost), |
| 128 true)); |
| 129 // --chrome must not be present. |
| 130 expectations->push_back(std::make_pair(std::string(switches::kChrome), |
| 131 false)); |
| 132 |
| 133 // --chrome-frame must not be present. |
| 134 expectations->push_back(std::make_pair(std::string(switches::kChromeFrame), |
| 135 false)); |
| 136 } |
| 137 |
| 138 void InstallationValidator::ChromeAppHostRules::AddRenameSwitchExpectations( |
| 139 const InstallationState& machine_state, |
| 140 bool system_install, |
| 141 const ProductState& product_state, |
| 142 SwitchExpectations* expectations) const { |
| 143 // TODO(erikwright): I guess there will be none? |
| 144 } |
| 145 |
| 146 bool InstallationValidator::ChromeAppHostRules::UsageStatsAllowed( |
| 147 const ProductState& product_state) const { |
| 148 // App Host doesn't manage usage stats. The Chrome Binaries will. |
| 149 return false; |
| 150 } |
| 151 |
| 152 BrowserDistribution::Type |
| 115 InstallationValidator::ChromeBinariesRules::distribution_type() const { | 153 InstallationValidator::ChromeBinariesRules::distribution_type() const { |
| 116 return BrowserDistribution::CHROME_BINARIES; | 154 return BrowserDistribution::CHROME_BINARIES; |
| 117 } | 155 } |
| 118 | 156 |
| 119 void InstallationValidator::ChromeBinariesRules::AddUninstallSwitchExpectations( | 157 void InstallationValidator::ChromeBinariesRules::AddUninstallSwitchExpectations( |
| 120 const InstallationState& machine_state, | 158 const InstallationState& machine_state, |
| 121 bool system_install, | 159 bool system_install, |
| 122 const ProductState& product_state, | 160 const ProductState& product_state, |
| 123 SwitchExpectations* expectations) const { | 161 SwitchExpectations* expectations) const { |
| 124 NOTREACHED(); | 162 NOTREACHED(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 142 const InstallationValidator::InstallationType | 180 const InstallationValidator::InstallationType |
| 143 InstallationValidator::kInstallationTypes[] = { | 181 InstallationValidator::kInstallationTypes[] = { |
| 144 NO_PRODUCTS, | 182 NO_PRODUCTS, |
| 145 CHROME_SINGLE, | 183 CHROME_SINGLE, |
| 146 CHROME_MULTI, | 184 CHROME_MULTI, |
| 147 CHROME_FRAME_SINGLE, | 185 CHROME_FRAME_SINGLE, |
| 148 CHROME_FRAME_SINGLE_CHROME_SINGLE, | 186 CHROME_FRAME_SINGLE_CHROME_SINGLE, |
| 149 CHROME_FRAME_SINGLE_CHROME_MULTI, | 187 CHROME_FRAME_SINGLE_CHROME_MULTI, |
| 150 CHROME_FRAME_MULTI, | 188 CHROME_FRAME_MULTI, |
| 151 CHROME_FRAME_MULTI_CHROME_MULTI, | 189 CHROME_FRAME_MULTI_CHROME_MULTI, |
| 152 CHROME_FRAME_READY_MODE_CHROME_MULTI | 190 CHROME_FRAME_READY_MODE_CHROME_MULTI, |
| 191 CHROME_APP_HOST, |
| 192 CHROME_APP_HOST_CHROME_FRAME_SINGLE, |
| 193 CHROME_APP_HOST_CHROME_FRAME_SINGLE_CHROME_MULTI, |
| 194 CHROME_APP_HOST_CHROME_FRAME_MULTI, |
| 195 CHROME_APP_HOST_CHROME_FRAME_MULTI_CHROME_MULTI, |
| 196 CHROME_APP_HOST_CHROME_MULTI, |
| 197 CHROME_APP_HOST_CHROME_MULTI_CHROME_FRAME_READY_MODE, |
| 153 }; | 198 }; |
| 154 | 199 |
| 155 // Validates the "quick-enable-cf" Google Update product command. | 200 // Validates the "quick-enable-cf" Google Update product command. |
| 156 void InstallationValidator::ValidateQuickEnableCfCommand( | 201 void InstallationValidator::ValidateQuickEnableCfCommand( |
| 157 const ProductContext& ctx, | 202 const ProductContext& ctx, |
| 158 const AppCommand& command, | 203 const AppCommand& command, |
| 159 bool* is_valid) { | 204 bool* is_valid) { |
| 160 DCHECK(is_valid); | 205 DCHECK(is_valid); |
| 161 | 206 |
| 162 CommandLine the_command(CommandLine::FromString(command.command_line())); | 207 CommandLine the_command(CommandLine::FromString(command.command_line())); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 << scan->first << "\"."; | 270 << scan->first << "\"."; |
| 226 } | 271 } |
| 227 } | 272 } |
| 228 | 273 |
| 229 // Validates the multi-install binaries' Google Update commands. | 274 // Validates the multi-install binaries' Google Update commands. |
| 230 void InstallationValidator::ValidateBinariesCommands( | 275 void InstallationValidator::ValidateBinariesCommands( |
| 231 const ProductContext& ctx, | 276 const ProductContext& ctx, |
| 232 bool* is_valid) { | 277 bool* is_valid) { |
| 233 DCHECK(is_valid); | 278 DCHECK(is_valid); |
| 234 | 279 |
| 235 // The quick-enable-cf command must be present if Chrome is installed either | 280 // The quick-enable-cf command must be present if Chrome Binaries are |
| 236 // alone or with CF in ready-mode. | 281 // installed and Chrome Frame is not installed (or installed in ready mode). |
| 237 const ChannelInfo& channel = ctx.state.channel(); | 282 const ChannelInfo& channel = ctx.state.channel(); |
| 238 const ProductState* chrome_state = ctx.machine_state.GetProductState( | 283 const ProductState* binaries_state = ctx.machine_state.GetProductState( |
| 239 ctx.system_install, BrowserDistribution::CHROME_BROWSER); | 284 ctx.system_install, BrowserDistribution::CHROME_BINARIES); |
| 240 const ProductState* cf_state = ctx.machine_state.GetProductState( | 285 const ProductState* cf_state = ctx.machine_state.GetProductState( |
| 241 ctx.system_install, BrowserDistribution::CHROME_FRAME); | 286 ctx.system_install, BrowserDistribution::CHROME_FRAME); |
| 242 | 287 |
| 243 CommandExpectations expectations; | 288 CommandExpectations expectations; |
| 244 | 289 |
| 245 if (chrome_state != NULL && (cf_state == NULL || channel.IsReadyMode())) | 290 if (binaries_state != NULL && (cf_state == NULL || channel.IsReadyMode())) |
| 246 expectations[kCmdQuickEnableCf] = &ValidateQuickEnableCfCommand; | 291 expectations[kCmdQuickEnableCf] = &ValidateQuickEnableCfCommand; |
| 247 | 292 |
| 248 ValidateAppCommandExpectations(ctx, expectations, is_valid); | 293 ValidateAppCommandExpectations(ctx, expectations, is_valid); |
| 249 } | 294 } |
| 250 | 295 |
| 251 // Validates the multi-install binaries at level |system_level|. | 296 // Validates the multi-install binaries at level |system_level|. |
| 252 void InstallationValidator::ValidateBinaries( | 297 void InstallationValidator::ValidateBinaries( |
| 253 const InstallationState& machine_state, | 298 const InstallationState& machine_state, |
| 254 bool system_install, | 299 bool system_install, |
| 255 const ProductState& binaries_state, | 300 const ProductState& binaries_state, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 LOG(ERROR) << "Chrome Binaries are missing \"-readymode\" in channel" | 348 LOG(ERROR) << "Chrome Binaries are missing \"-readymode\" in channel" |
| 304 " name: \"" << channel.value() << "\""; | 349 " name: \"" << channel.value() << "\""; |
| 305 } | 350 } |
| 306 } else if (channel.IsReadyMode()) { | 351 } else if (channel.IsReadyMode()) { |
| 307 *is_valid = false; | 352 *is_valid = false; |
| 308 LOG(ERROR) << "Chrome Binaries have \"-readymode\" in channel name, yet " | 353 LOG(ERROR) << "Chrome Binaries have \"-readymode\" in channel name, yet " |
| 309 "Chrome Frame is not in ready mode: \"" << channel.value() | 354 "Chrome Frame is not in ready mode: \"" << channel.value() |
| 310 << "\""; | 355 << "\""; |
| 311 } | 356 } |
| 312 | 357 |
| 313 // Chrome or Chrome Frame must be present | 358 // ap must have -apphost iff Chrome Frame is installed multi |
| 314 if (chrome_state == NULL && cf_state == NULL) { | 359 const ProductState* app_host_state = machine_state.GetProductState( |
| 360 system_install, BrowserDistribution::CHROME_APP_HOST); |
| 361 if (app_host_state != NULL) { |
| 362 if (!app_host_state->is_multi_install()) { |
| 363 *is_valid = false; |
| 364 LOG(ERROR) << "Chrome App Host is installed in non-multi mode."; |
| 365 } |
| 366 if (!channel.IsAppHost()) { |
| 367 *is_valid = false; |
| 368 LOG(ERROR) << "Chrome Binaries are missing \"-apphost\" in channel" |
| 369 " name: \"" << channel.value() << "\""; |
| 370 } |
| 371 } else if (channel.IsAppHost()) { |
| 372 *is_valid = false; |
| 373 LOG(ERROR) << "Chrome Binaries have \"-apphost\" in channel name, yet " |
| 374 "Chrome App Host is not installed: \"" << channel.value() |
| 375 << "\""; |
| 376 } |
| 377 |
| 378 // Chrome, Chrome Frame, or App Host must be present |
| 379 if (chrome_state == NULL && cf_state == NULL && app_host_state == NULL) { |
| 315 *is_valid = false; | 380 *is_valid = false; |
| 316 LOG(ERROR) << "Chrome Binaries are present with no other products."; | 381 LOG(ERROR) << "Chrome Binaries are present with no other products."; |
| 317 } | 382 } |
| 318 | 383 |
| 319 // Chrome must be multi-install if present. | 384 // Chrome must be multi-install if present. |
| 320 if (chrome_state != NULL && !chrome_state->is_multi_install()) { | 385 if (chrome_state != NULL && !chrome_state->is_multi_install()) { |
| 321 *is_valid = false; | 386 *is_valid = false; |
| 322 LOG(ERROR) | 387 LOG(ERROR) |
| 323 << "Chrome Binaries are present yet Chrome is not multi-install."; | 388 << "Chrome Binaries are present yet Chrome is not multi-install."; |
| 324 } | 389 } |
| 325 | 390 |
| 326 // Chrome Frame must be multi-install if Chrome is not present. | 391 // Chrome Frame must be multi-install if Chrome & App Host are not present. |
| 327 if (cf_state != NULL && chrome_state == NULL && | 392 if (cf_state != NULL && app_host_state == NULL && chrome_state == NULL && |
| 328 !cf_state->is_multi_install()) { | 393 !cf_state->is_multi_install()) { |
| 329 *is_valid = false; | 394 *is_valid = false; |
| 330 LOG(ERROR) << "Chrome Binaries are present without Chrome yet Chrome Frame " | 395 LOG(ERROR) << "Chrome Binaries are present without Chrome nor App Host " |
| 331 "is not multi-install."; | 396 << "yet Chrome Frame is not multi-install."; |
| 332 } | 397 } |
| 333 | 398 |
| 334 ChromeBinariesRules binaries_rules; | 399 ChromeBinariesRules binaries_rules; |
| 335 ProductContext ctx = { | 400 ProductContext ctx = { |
| 336 machine_state, | 401 machine_state, |
| 337 system_install, | 402 system_install, |
| 338 BrowserDistribution::GetSpecificDistribution( | 403 BrowserDistribution::GetSpecificDistribution( |
| 339 BrowserDistribution::CHROME_BINARIES), | 404 BrowserDistribution::CHROME_BINARIES), |
| 340 binaries_state, | 405 binaries_state, |
| 341 binaries_rules | 406 binaries_rules |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 chrome_frame_rules, &rock_on); | 667 chrome_frame_rules, &rock_on); |
| 603 int cf_bit = !product_state->is_multi_install() ? | 668 int cf_bit = !product_state->is_multi_install() ? |
| 604 ProductBits::CHROME_FRAME_SINGLE : | 669 ProductBits::CHROME_FRAME_SINGLE : |
| 605 (product_state->uninstall_command().HasSwitch( | 670 (product_state->uninstall_command().HasSwitch( |
| 606 switches::kChromeFrameReadyMode) ? | 671 switches::kChromeFrameReadyMode) ? |
| 607 ProductBits::CHROME_FRAME_READY_MODE : | 672 ProductBits::CHROME_FRAME_READY_MODE : |
| 608 ProductBits::CHROME_FRAME_MULTI); | 673 ProductBits::CHROME_FRAME_MULTI); |
| 609 *type = static_cast<InstallationType>(*type | cf_bit); | 674 *type = static_cast<InstallationType>(*type | cf_bit); |
| 610 } | 675 } |
| 611 | 676 |
| 677 // Is Chrome App Host installed? |
| 678 product_state = |
| 679 machine_state.GetProductState(system_level, |
| 680 BrowserDistribution::CHROME_APP_HOST); |
| 681 if (product_state != NULL) { |
| 682 ChromeAppHostRules chrome_app_host_rules; |
| 683 ValidateProduct(machine_state, system_level, *product_state, |
| 684 chrome_app_host_rules, &rock_on); |
| 685 *type = static_cast<InstallationType>(*type | ProductBits::CHROME_APP_HOST); |
| 686 if (system_level) { |
| 687 LOG(ERROR) << "Chrome App Host must not be installed at system level."; |
| 688 rock_on = false; |
| 689 } |
| 690 if (!product_state->is_multi_install()) { |
| 691 LOG(ERROR) << "Chrome App Host must always be multi-install."; |
| 692 rock_on = false; |
| 693 } |
| 694 } |
| 695 |
| 612 DCHECK_NE(std::find(&kInstallationTypes[0], | 696 DCHECK_NE(std::find(&kInstallationTypes[0], |
| 613 &kInstallationTypes[arraysize(kInstallationTypes)], | 697 &kInstallationTypes[arraysize(kInstallationTypes)], |
| 614 *type), | 698 *type), |
| 615 &kInstallationTypes[arraysize(kInstallationTypes)]) | 699 &kInstallationTypes[arraysize(kInstallationTypes)]) |
| 616 << "Invalid combination of products found on system (" << *type << ")"; | 700 << "Invalid combination of products found on system (" << *type << ")"; |
| 617 | 701 |
| 618 return rock_on; | 702 return rock_on; |
| 619 } | 703 } |
| 620 | 704 |
| 621 // static | 705 // static |
| 622 bool InstallationValidator::ValidateInstallationType(bool system_level, | 706 bool InstallationValidator::ValidateInstallationType(bool system_level, |
| 623 InstallationType* type) { | 707 InstallationType* type) { |
| 624 DCHECK(type); | 708 DCHECK(type); |
| 625 InstallationState machine_state; | 709 InstallationState machine_state; |
| 626 | 710 |
| 627 machine_state.Initialize(); | 711 machine_state.Initialize(); |
| 628 | 712 |
| 629 return ValidateInstallationTypeForState(machine_state, system_level, type); | 713 return ValidateInstallationTypeForState(machine_state, system_level, type); |
| 630 } | 714 } |
| 631 | 715 |
| 632 } // namespace installer | 716 } // namespace installer |
| OLD | NEW |