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

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

Issue 10823437: Callback flow to register Chrome and update shortcuts after OS upgrade to Windows 8 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Abandoning the use of ON_OS_UPGRADE_SUCCESSFUL installer message. Created 8 years, 3 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 | Annotate | Revision Log
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>
gab 2012/08/30 14:24:32 #include <string> since you (correctly) removed th
huangs 2012/08/30 17:13:07 Done.
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/common/chrome_switches.h" 14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/installer/util/browser_distribution.h" 15 #include "chrome/installer/util/browser_distribution.h"
16 #include "chrome/installer/util/helper.h" 16 #include "chrome/installer/util/helper.h"
17 #include "chrome/installer/util/installation_state.h" 17 #include "chrome/installer/util/installation_state.h"
18 18
19 namespace installer { 19 namespace installer {
20 20
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 LOG(ERROR) << "install-application command is not configured to send " 234 LOG(ERROR) << "install-application command is not configured to send "
235 << "pings."; 235 << "pings.";
236 } 236 }
237 237
238 if (!command.is_web_accessible()) { 238 if (!command.is_web_accessible()) {
239 *is_valid = false; 239 *is_valid = false;
240 LOG(ERROR) << "install-application command is not web accessible."; 240 LOG(ERROR) << "install-application command is not web accessible.";
241 } 241 }
242 } 242 }
243 243
244 // Validates the "on-os-upgrade" Google Update internal command.
245 void InstallationValidator::ValidateOnOsUpgradeCommand(
246 const ProductContext& ctx,
247 const AppCommand& command,
248 bool* is_valid) {
249 DCHECK(is_valid);
250
251 CommandLine the_command(CommandLine::FromString(command.command_line()));
252
253 ValidateSetupPath(ctx, the_command.GetProgram(), "on os upgrade", is_valid);
254
255 SwitchExpectations expected;
256
gab 2012/08/30 14:24:32 Remove this line (i.e. declare variable + initiali
huangs 2012/08/30 17:13:07 Done.
257 expected.push_back(std::make_pair(std::string(switches::kOnOsUpgrade), true));
258 expected.push_back(std::make_pair(std::string(switches::kSystemLevel),
259 ctx.system_install));
260 expected.push_back(std::make_pair(std::string(switches::kMultiInstall),
261 ctx.state.is_multi_install()));
262 const ProductState* product_state =
gab 2012/08/30 14:24:32 Move this before "SwitchExpectations expected;" so
huangs 2012/08/30 17:13:07 Made unnecessary by new change.
263 ctx.machine_state.GetProductState(ctx.system_install,
264 BrowserDistribution::CHROME_BROWSER);
265 expected.push_back(std::make_pair(std::string(switches::kChrome),
grt (UTC plus 2) 2012/08/30 04:15:25 --chrome is expected to only be present if --multi
huangs 2012/08/30 17:13:07 Done. And also "if", so "if and only if" => Check
266 product_state != NULL));
267
268 ValidateCommandExpectations(ctx, the_command, expected, "on os upgrade",
269 is_valid);
270
271 if (!command.is_auto_run_on_os_upgrade()) {
272 *is_valid = false;
273 LOG(ERROR) << "On-os-upgrade command is not marked to run on OS upgrade.";
274 }
275
276 if (command.sends_pings()) {
277 *is_valid = false;
278 LOG(ERROR) << "On-os-upgrade command should not be able to send pings.";
279 }
280
281 if (command.is_web_accessible()) {
282 *is_valid = false;
283 LOG(ERROR) << "On-os-upgrade command should not be web accessible.";
284 }
285 }
286
244 // Validates the "quick-enable-cf" Google Update product command. 287 // Validates the "quick-enable-cf" Google Update product command.
245 void InstallationValidator::ValidateQuickEnableCfCommand( 288 void InstallationValidator::ValidateQuickEnableCfCommand(
246 const ProductContext& ctx, 289 const ProductContext& ctx,
247 const AppCommand& command, 290 const AppCommand& command,
248 bool* is_valid) { 291 bool* is_valid) {
249 DCHECK(is_valid); 292 DCHECK(is_valid);
250 293
251 CommandLine the_command(CommandLine::FromString(command.command_line())); 294 CommandLine the_command(CommandLine::FromString(command.command_line()));
252 295
253 ValidateSetupPath(ctx, the_command.GetProgram(), "quick enable cf", is_valid); 296 ValidateSetupPath(ctx, the_command.GetProgram(), "quick enable cf", is_valid);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 const CommandExpectations& expectations, 367 const CommandExpectations& expectations,
325 bool* is_valid) { 368 bool* is_valid) {
326 DCHECK(is_valid); 369 DCHECK(is_valid);
327 370
328 CommandExpectations the_expectations(expectations); 371 CommandExpectations the_expectations(expectations);
329 372
330 AppCommands::CommandMapRange cmd_iterators( 373 AppCommands::CommandMapRange cmd_iterators(
331 ctx.state.commands().GetIterators()); 374 ctx.state.commands().GetIterators());
332 CommandExpectations::iterator expectation; 375 CommandExpectations::iterator expectation;
333 for (; cmd_iterators.first != cmd_iterators.second; ++cmd_iterators.first) { 376 for (; cmd_iterators.first != cmd_iterators.second; ++cmd_iterators.first) {
334 const std::wstring& cmd_id = cmd_iterators.first->first; 377 const string16& cmd_id = cmd_iterators.first->first;
335 // Do we have an expectation for this command? 378 // Do we have an expectation for this command?
336 expectation = the_expectations.find(cmd_id); 379 expectation = the_expectations.find(cmd_id);
337 if (expectation != the_expectations.end()) { 380 if (expectation != the_expectations.end()) {
338 (expectation->second)(ctx, cmd_iterators.first->second, is_valid); 381 (expectation->second)(ctx, cmd_iterators.first->second, is_valid);
339 // Remove this command from the set of expectations since we found it. 382 // Remove this command from the set of expectations since we found it.
340 the_expectations.erase(expectation); 383 the_expectations.erase(expectation);
341 } else { 384 } else {
342 *is_valid = false; 385 *is_valid = false;
343 LOG(ERROR) << ctx.dist->GetAppShortCutName() 386 LOG(ERROR) << ctx.dist->GetAppShortCutName()
344 << " has an unexpected Google Update product command named \"" 387 << " has an unexpected Google Update product command named \""
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 524
482 // Chrome Frame must be multi-install if Chrome & App Host are not present. 525 // Chrome Frame must be multi-install if Chrome & App Host are not present.
483 if (cf_state != NULL && app_host_state == NULL && chrome_state == NULL && 526 if (cf_state != NULL && app_host_state == NULL && chrome_state == NULL &&
484 !cf_state->is_multi_install()) { 527 !cf_state->is_multi_install()) {
485 *is_valid = false; 528 *is_valid = false;
486 LOG(ERROR) << "Chrome Binaries are present without Chrome nor App Host " 529 LOG(ERROR) << "Chrome Binaries are present without Chrome nor App Host "
487 << "yet Chrome Frame is not multi-install."; 530 << "yet Chrome Frame is not multi-install.";
488 } 531 }
489 532
490 ChromeBinariesRules binaries_rules; 533 ChromeBinariesRules binaries_rules;
491 ProductContext ctx = { 534 ProductContext ctx(machine_state, system_install, binaries_state,
492 machine_state, 535 binaries_rules);
493 system_install,
494 BrowserDistribution::GetSpecificDistribution(
495 BrowserDistribution::CHROME_BINARIES),
496 binaries_state,
497 binaries_rules
498 };
499 536
500 ValidateBinariesCommands(ctx, is_valid); 537 ValidateBinariesCommands(ctx, is_valid);
501 538
502 ValidateUsageStats(ctx, is_valid); 539 ValidateUsageStats(ctx, is_valid);
503 } 540 }
504 541
505 // Validates the path to |setup_exe| for the product described by |ctx|. 542 // Validates the path to |setup_exe| for the product described by |ctx|.
506 void InstallationValidator::ValidateSetupPath(const ProductContext& ctx, 543 void InstallationValidator::ValidateSetupPath(const ProductContext& ctx,
507 const FilePath& setup_exe, 544 const FilePath& setup_exe,
508 const char* purpose, 545 const char* purpose,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 void InstallationValidator::ValidateAppCommands( 721 void InstallationValidator::ValidateAppCommands(
685 const ProductContext& ctx, 722 const ProductContext& ctx,
686 bool* is_valid) { 723 bool* is_valid) {
687 DCHECK(is_valid); 724 DCHECK(is_valid);
688 725
689 CommandExpectations expectations; 726 CommandExpectations expectations;
690 727
691 if (ctx.dist->GetType() == BrowserDistribution::CHROME_APP_HOST) { 728 if (ctx.dist->GetType() == BrowserDistribution::CHROME_APP_HOST) {
692 expectations[kCmdInstallApp] = &ValidateInstallAppCommand; 729 expectations[kCmdInstallApp] = &ValidateInstallAppCommand;
693 } 730 }
731 if (ctx.dist->GetType() == BrowserDistribution::CHROME_BROWSER) {
732 expectations[kCmdOnOsUpgrade] = &ValidateOnOsUpgradeCommand;
733 }
694 734
695 ValidateAppCommandExpectations(ctx, expectations, is_valid); 735 ValidateAppCommandExpectations(ctx, expectations, is_valid);
696 } 736 }
697 737
698 // Validates usagestats for the product or binaries in |ctx|. 738 // Validates usagestats for the product or binaries in |ctx|.
699 void InstallationValidator::ValidateUsageStats(const ProductContext& ctx, 739 void InstallationValidator::ValidateUsageStats(const ProductContext& ctx,
700 bool* is_valid) { 740 bool* is_valid) {
701 DWORD usagestats = 0; 741 DWORD usagestats = 0;
702 if (ctx.state.GetUsageStats(&usagestats)) { 742 if (ctx.state.GetUsageStats(&usagestats)) {
703 if (!ctx.rules.UsageStatsAllowed(ctx.state)) { 743 if (!ctx.rules.UsageStatsAllowed(ctx.state)) {
704 *is_valid = false; 744 *is_valid = false;
705 LOG(ERROR) << ctx.dist->GetAppShortCutName() 745 LOG(ERROR) << ctx.dist->GetAppShortCutName()
706 << " has a usagestats value (" << usagestats 746 << " has a usagestats value (" << usagestats
707 << "), yet should not."; 747 << "), yet should not.";
708 } else if (usagestats != 0 && usagestats != 1) { 748 } else if (usagestats != 0 && usagestats != 1) {
709 *is_valid = false; 749 *is_valid = false;
710 LOG(ERROR) << ctx.dist->GetAppShortCutName() 750 LOG(ERROR) << ctx.dist->GetAppShortCutName()
711 << " has an unsupported usagestats value (" << usagestats 751 << " has an unsupported usagestats value (" << usagestats
712 << ")."; 752 << ").";
713 } 753 }
714 } 754 }
715 } 755 }
716 756
717 // Validates the product described in |product_state| according to |rules|. 757 // Validates the product described in |product_state| according to |rules|.
718 void InstallationValidator::ValidateProduct( 758 void InstallationValidator::ValidateProduct(const ProductContext& ctx,
719 const InstallationState& machine_state, 759 bool* is_valid) {
720 bool system_install,
721 const ProductState& product_state,
722 const ProductRules& rules,
723 bool* is_valid) {
724 DCHECK(is_valid); 760 DCHECK(is_valid);
725 ProductContext ctx = {
726 machine_state,
727 system_install,
728 BrowserDistribution::GetSpecificDistribution(rules.distribution_type()),
729 product_state,
730 rules
731 };
732 761
733 ValidateUninstallCommand(ctx, product_state.uninstall_command(), 762 ValidateUninstallCommand(ctx, ctx.state.uninstall_command(),
734 "Google Update uninstall command", is_valid); 763 "Google Update uninstall command", is_valid);
735 764
736 ValidateOldVersionValues(ctx, is_valid); 765 ValidateOldVersionValues(ctx, is_valid);
737 766
738 if (product_state.is_multi_install()) 767 if (ctx.state.is_multi_install())
739 ValidateMultiInstallProduct(ctx, is_valid); 768 ValidateMultiInstallProduct(ctx, is_valid);
740 769
741 ValidateAppCommands(ctx, is_valid); 770 ValidateAppCommands(ctx, is_valid);
742 771
743 ValidateUsageStats(ctx, is_valid); 772 ValidateUsageStats(ctx, is_valid);
744 } 773 }
745 774
746 // static 775 // static
747 bool InstallationValidator::ValidateInstallationTypeForState( 776 bool InstallationValidator::ValidateInstallationTypeForState(
748 const InstallationState& machine_state, 777 const InstallationState& machine_state,
749 bool system_level, 778 bool system_level,
750 InstallationType* type) { 779 InstallationType* type) {
751 DCHECK(type); 780 DCHECK(type);
752 bool rock_on = true; 781 bool rock_on = true;
753 *type = NO_PRODUCTS; 782 *type = NO_PRODUCTS;
754 783
755 // Does the system have any multi-installed products? 784 // Does the system have any multi-installed products?
756 const ProductState* multi_state = 785 const ProductState* multi_state =
757 machine_state.GetProductState(system_level, 786 machine_state.GetProductState(system_level,
758 BrowserDistribution::CHROME_BINARIES); 787 BrowserDistribution::CHROME_BINARIES);
759 if (multi_state != NULL) 788 if (multi_state != NULL)
760 ValidateBinaries(machine_state, system_level, *multi_state, &rock_on); 789 ValidateBinaries(machine_state, system_level, *multi_state, &rock_on);
761 790
762 // Is Chrome installed? 791 // Is Chrome installed?
763 const ProductState* product_state = 792 const ProductState* product_state =
764 machine_state.GetProductState(system_level, 793 machine_state.GetProductState(system_level,
765 BrowserDistribution::CHROME_BROWSER); 794 BrowserDistribution::CHROME_BROWSER);
766 if (product_state != NULL) { 795 if (product_state != NULL) {
767 ChromeRules chrome_rules; 796 ChromeRules chrome_rules;
768 ValidateProduct(machine_state, system_level, *product_state, 797 ProductContext ctx(machine_state, system_level, *product_state,
grt (UTC plus 2) 2012/08/30 04:15:25 this change appears to make ValidateProduct harder
gab 2012/08/30 14:24:32 I agree, the goal of making a struct to pass in ar
huangs 2012/08/30 17:13:07 Done.
769 chrome_rules, &rock_on); 798 chrome_rules);
799 ValidateProduct(ctx, &rock_on);
770 *type = static_cast<InstallationType>( 800 *type = static_cast<InstallationType>(
771 *type | (product_state->is_multi_install() ? 801 *type | (product_state->is_multi_install() ?
772 ProductBits::CHROME_MULTI : 802 ProductBits::CHROME_MULTI :
773 ProductBits::CHROME_SINGLE)); 803 ProductBits::CHROME_SINGLE));
774 } 804 }
775 805
776 // Is Chrome Frame installed? 806 // Is Chrome Frame installed?
777 product_state = 807 product_state =
778 machine_state.GetProductState(system_level, 808 machine_state.GetProductState(system_level,
779 BrowserDistribution::CHROME_FRAME); 809 BrowserDistribution::CHROME_FRAME);
780 if (product_state != NULL) { 810 if (product_state != NULL) {
781 ChromeFrameRules chrome_frame_rules; 811 ChromeFrameRules chrome_frame_rules;
782 ValidateProduct(machine_state, system_level, *product_state, 812 ProductContext ctx(machine_state, system_level, *product_state,
783 chrome_frame_rules, &rock_on); 813 chrome_frame_rules);
814 ValidateProduct(ctx, &rock_on);
784 int cf_bit = !product_state->is_multi_install() ? 815 int cf_bit = !product_state->is_multi_install() ?
785 ProductBits::CHROME_FRAME_SINGLE : 816 ProductBits::CHROME_FRAME_SINGLE :
786 (product_state->uninstall_command().HasSwitch( 817 (product_state->uninstall_command().HasSwitch(
787 switches::kChromeFrameReadyMode) ? 818 switches::kChromeFrameReadyMode) ?
788 ProductBits::CHROME_FRAME_READY_MODE : 819 ProductBits::CHROME_FRAME_READY_MODE :
789 ProductBits::CHROME_FRAME_MULTI); 820 ProductBits::CHROME_FRAME_MULTI);
790 *type = static_cast<InstallationType>(*type | cf_bit); 821 *type = static_cast<InstallationType>(*type | cf_bit);
791 } 822 }
792 823
793 // Is Chrome App Host installed? 824 // Is Chrome App Host installed?
794 product_state = 825 product_state =
795 machine_state.GetProductState(system_level, 826 machine_state.GetProductState(system_level,
796 BrowserDistribution::CHROME_APP_HOST); 827 BrowserDistribution::CHROME_APP_HOST);
797 if (product_state != NULL) { 828 if (product_state != NULL) {
798 ChromeAppHostRules chrome_app_host_rules; 829 ChromeAppHostRules chrome_app_host_rules;
799 ValidateProduct(machine_state, system_level, *product_state, 830 ProductContext ctx(machine_state, system_level, *product_state,
800 chrome_app_host_rules, &rock_on); 831 chrome_app_host_rules);
832 ValidateProduct(ctx, &rock_on);
801 *type = static_cast<InstallationType>(*type | ProductBits::CHROME_APP_HOST); 833 *type = static_cast<InstallationType>(*type | ProductBits::CHROME_APP_HOST);
802 if (system_level) { 834 if (system_level) {
803 LOG(ERROR) << "Chrome App Host must not be installed at system level."; 835 LOG(ERROR) << "Chrome App Host must not be installed at system level.";
804 rock_on = false; 836 rock_on = false;
805 } 837 }
806 if (!product_state->is_multi_install()) { 838 if (!product_state->is_multi_install()) {
807 LOG(ERROR) << "Chrome App Host must always be multi-install."; 839 LOG(ERROR) << "Chrome App Host must always be multi-install.";
808 rock_on = false; 840 rock_on = false;
809 } 841 }
810 } 842 }
(...skipping 12 matching lines...) Expand all
823 InstallationType* type) { 855 InstallationType* type) {
824 DCHECK(type); 856 DCHECK(type);
825 InstallationState machine_state; 857 InstallationState machine_state;
826 858
827 machine_state.Initialize(); 859 machine_state.Initialize();
828 860
829 return ValidateInstallationTypeForState(machine_state, system_level, type); 861 return ValidateInstallationTypeForState(machine_state, system_level, type);
830 } 862 }
831 863
832 } // namespace installer 864 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698