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

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

Issue 15255004: Refactor of BrowserDistribution. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework Created 7 years, 7 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
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>
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 app_cmd.is_auto_run_on_os_upgrade(), 206 app_cmd.is_auto_run_on_os_upgrade(),
207 "be marked to run on OS upgrade"}, 207 "be marked to run on OS upgrade"},
208 {google_update::kRegRunAsUserField, 208 {google_update::kRegRunAsUserField,
209 app_cmd.is_run_as_user(), 209 app_cmd.is_run_as_user(),
210 "be marked to run as user"}, 210 "be marked to run as user"},
211 }; 211 };
212 for (int i = 0; i < arraysize(check_list); ++i) { 212 for (int i = 0; i < arraysize(check_list); ++i) {
213 bool expected = flags_exp.find(check_list[i].exp_key) != flags_exp.end(); 213 bool expected = flags_exp.find(check_list[i].exp_key) != flags_exp.end();
214 if (check_list[i].val != expected) { 214 if (check_list[i].val != expected) {
215 *is_valid = false; 215 *is_valid = false;
216 LOG(ERROR) << ctx.dist->GetAppShortCutName() << ": " 216 LOG(ERROR) << ctx.dist->GetDisplayName() << ": "
217 << name << " command should " << (expected ? "" : "not ") 217 << name << " command should " << (expected ? "" : "not ")
218 << check_list[i].msg << "."; 218 << check_list[i].msg << ".";
219 } 219 }
220 } 220 }
221 } 221 }
222 222
223 // Validates both "install-application" and "install-extension" depending on 223 // Validates both "install-application" and "install-extension" depending on
224 // what is passed in. 224 // what is passed in.
225 void InstallationValidator::ValidateInstallCommand( 225 void InstallationValidator::ValidateInstallCommand(
226 const ProductContext& ctx, 226 const ProductContext& ctx,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 for (; cmd_iterators.first != cmd_iterators.second; ++cmd_iterators.first) { 410 for (; cmd_iterators.first != cmd_iterators.second; ++cmd_iterators.first) {
411 const string16& cmd_id = cmd_iterators.first->first; 411 const string16& cmd_id = cmd_iterators.first->first;
412 // Do we have an expectation for this command? 412 // Do we have an expectation for this command?
413 expectation = the_expectations.find(cmd_id); 413 expectation = the_expectations.find(cmd_id);
414 if (expectation != the_expectations.end()) { 414 if (expectation != the_expectations.end()) {
415 (expectation->second)(ctx, cmd_iterators.first->second, is_valid); 415 (expectation->second)(ctx, cmd_iterators.first->second, is_valid);
416 // Remove this command from the set of expectations since we found it. 416 // Remove this command from the set of expectations since we found it.
417 the_expectations.erase(expectation); 417 the_expectations.erase(expectation);
418 } else { 418 } else {
419 *is_valid = false; 419 *is_valid = false;
420 LOG(ERROR) << ctx.dist->GetAppShortCutName() 420 LOG(ERROR) << ctx.dist->GetDisplayName()
421 << " has an unexpected Google Update product command named \"" 421 << " has an unexpected Google Update product command named \""
422 << cmd_id << "\"."; 422 << cmd_id << "\".";
423 } 423 }
424 } 424 }
425 425
426 // Report on any expected commands that weren't present. 426 // Report on any expected commands that weren't present.
427 CommandExpectations::const_iterator scan(the_expectations.begin()); 427 CommandExpectations::const_iterator scan(the_expectations.begin());
428 CommandExpectations::const_iterator end(the_expectations.end()); 428 CommandExpectations::const_iterator end(the_expectations.end());
429 for (; scan != end; ++scan) { 429 for (; scan != end; ++scan) {
430 *is_valid = false; 430 *is_valid = false;
431 LOG(ERROR) << ctx.dist->GetAppShortCutName() 431 LOG(ERROR) << ctx.dist->GetDisplayName()
432 << " is missing the Google Update product command named \"" 432 << " is missing the Google Update product command named \""
433 << scan->first << "\"."; 433 << scan->first << "\".";
434 } 434 }
435 } 435 }
436 436
437 // Validates the multi-install binaries' Google Update commands. 437 // Validates the multi-install binaries' Google Update commands.
438 void InstallationValidator::ValidateBinariesCommands( 438 void InstallationValidator::ValidateBinariesCommands(
439 const ProductContext& ctx, 439 const ProductContext& ctx,
440 bool* is_valid) { 440 bool* is_valid) {
441 DCHECK(is_valid); 441 DCHECK(is_valid);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 590
591 base::FilePath expected_path = installer::GetChromeInstallPath( 591 base::FilePath expected_path = installer::GetChromeInstallPath(
592 ctx.system_install, bins_dist); 592 ctx.system_install, bins_dist);
593 expected_path = expected_path 593 expected_path = expected_path
594 .AppendASCII(ctx.state.version().GetString()) 594 .AppendASCII(ctx.state.version().GetString())
595 .Append(installer::kInstallerDir) 595 .Append(installer::kInstallerDir)
596 .Append(installer::kSetupExe); 596 .Append(installer::kSetupExe);
597 if (!base::FilePath::CompareEqualIgnoreCase(expected_path.value(), 597 if (!base::FilePath::CompareEqualIgnoreCase(expected_path.value(),
598 setup_exe.value())) { 598 setup_exe.value())) {
599 *is_valid = false; 599 *is_valid = false;
600 LOG(ERROR) << ctx.dist->GetAppShortCutName() << " path to " << purpose 600 LOG(ERROR) << ctx.dist->GetDisplayName() << " path to " << purpose
601 << " is not " << expected_path.value() << ": " 601 << " is not " << expected_path.value() << ": "
602 << setup_exe.value(); 602 << setup_exe.value();
603 } 603 }
604 } 604 }
605 605
606 // Validates that |command| meets the expectations described in |expected|. 606 // Validates that |command| meets the expectations described in |expected|.
607 void InstallationValidator::ValidateCommandExpectations( 607 void InstallationValidator::ValidateCommandExpectations(
608 const ProductContext& ctx, 608 const ProductContext& ctx,
609 const CommandLine& command, 609 const CommandLine& command,
610 const SwitchExpectations& expected, 610 const SwitchExpectations& expected,
611 const string16& source, 611 const string16& source,
612 bool* is_valid) { 612 bool* is_valid) {
613 for (SwitchExpectations::size_type i = 0, size = expected.size(); i < size; 613 for (SwitchExpectations::size_type i = 0, size = expected.size(); i < size;
614 ++i) { 614 ++i) {
615 const SwitchExpectations::value_type& expectation = expected[i]; 615 const SwitchExpectations::value_type& expectation = expected[i];
616 if (command.HasSwitch(expectation.first) != expectation.second) { 616 if (command.HasSwitch(expectation.first) != expectation.second) {
617 *is_valid = false; 617 *is_valid = false;
618 LOG(ERROR) << ctx.dist->GetAppShortCutName() << " " << source 618 LOG(ERROR) << ctx.dist->GetDisplayName() << " " << source
619 << (expectation.second ? " is missing" : " has") << " \"" 619 << (expectation.second ? " is missing" : " has") << " \""
620 << expectation.first << "\"" 620 << expectation.first << "\""
621 << (expectation.second ? "" : " but shouldn't") << ": " 621 << (expectation.second ? "" : " but shouldn't") << ": "
622 << command.GetCommandLineString(); 622 << command.GetCommandLineString();
623 } 623 }
624 } 624 }
625 } 625 }
626 626
627 // Validates that |command|, originating from |source|, is formed properly for 627 // Validates that |command|, originating from |source|, is formed properly for
628 // the product described by |ctx| 628 // the product described by |ctx|
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 // Validates the "opv" and "cmd" values for the product described in |ctx|. 675 // Validates the "opv" and "cmd" values for the product described in |ctx|.
676 void InstallationValidator::ValidateOldVersionValues( 676 void InstallationValidator::ValidateOldVersionValues(
677 const ProductContext& ctx, 677 const ProductContext& ctx,
678 bool* is_valid) { 678 bool* is_valid) {
679 DCHECK(is_valid); 679 DCHECK(is_valid);
680 680
681 // opv and cmd must both be present or both absent 681 // opv and cmd must both be present or both absent
682 if (ctx.state.old_version() == NULL) { 682 if (ctx.state.old_version() == NULL) {
683 if (!ctx.state.rename_cmd().empty()) { 683 if (!ctx.state.rename_cmd().empty()) {
684 *is_valid = false; 684 *is_valid = false;
685 LOG(ERROR) << ctx.dist->GetAppShortCutName() 685 LOG(ERROR) << ctx.dist->GetDisplayName()
686 << " has a rename command but no opv: " 686 << " has a rename command but no opv: "
687 << ctx.state.rename_cmd(); 687 << ctx.state.rename_cmd();
688 } 688 }
689 } else { 689 } else {
690 if (ctx.state.rename_cmd().empty()) { 690 if (ctx.state.rename_cmd().empty()) {
691 *is_valid = false; 691 *is_valid = false;
692 LOG(ERROR) << ctx.dist->GetAppShortCutName() 692 LOG(ERROR) << ctx.dist->GetDisplayName()
693 << " has an opv but no rename command: " 693 << " has an opv but no rename command: "
694 << ctx.state.old_version()->GetString(); 694 << ctx.state.old_version()->GetString();
695 } else { 695 } else {
696 ValidateRenameCommand(ctx, is_valid); 696 ValidateRenameCommand(ctx, is_valid);
697 } 697 }
698 } 698 }
699 } 699 }
700 700
701 // Validates the multi-install state of the product described in |ctx|. 701 // Validates the multi-install state of the product described in |ctx|.
702 void InstallationValidator::ValidateMultiInstallProduct( 702 void InstallationValidator::ValidateMultiInstallProduct(
703 const ProductContext& ctx, 703 const ProductContext& ctx,
704 bool* is_valid) { 704 bool* is_valid) {
705 DCHECK(is_valid); 705 DCHECK(is_valid);
706 706
707 const ProductState* binaries = 707 const ProductState* binaries =
708 ctx.machine_state.GetProductState(ctx.system_install, 708 ctx.machine_state.GetProductState(ctx.system_install,
709 BrowserDistribution::CHROME_BINARIES); 709 BrowserDistribution::CHROME_BINARIES);
710 if (!binaries) { 710 if (!binaries) {
711 if (ctx.dist->GetType() == BrowserDistribution::CHROME_APP_HOST) { 711 if (ctx.dist->GetType() == BrowserDistribution::CHROME_APP_HOST) {
712 if (!ctx.machine_state.GetProductState( 712 if (!ctx.machine_state.GetProductState(
713 true, // system-level 713 true, // system-level
714 BrowserDistribution::CHROME_BINARIES) && 714 BrowserDistribution::CHROME_BINARIES) &&
715 !ctx.machine_state.GetProductState( 715 !ctx.machine_state.GetProductState(
716 true, // system-level 716 true, // system-level
717 BrowserDistribution::CHROME_BROWSER)) { 717 BrowserDistribution::CHROME_BROWSER)) {
718 *is_valid = false; 718 *is_valid = false;
719 LOG(ERROR) << ctx.dist->GetAppShortCutName() 719 LOG(ERROR) << ctx.dist->GetDisplayName()
720 << " (" << ctx.state.version().GetString() << ") is " 720 << " (" << ctx.state.version().GetString() << ") is "
721 << "installed without Chrome Binaries or a system-level " 721 << "installed without Chrome Binaries or a system-level "
722 << "Chrome."; 722 << "Chrome.";
723 } 723 }
724 } else { 724 } else {
725 *is_valid = false; 725 *is_valid = false;
726 LOG(ERROR) << ctx.dist->GetAppShortCutName() 726 LOG(ERROR) << ctx.dist->GetDisplayName()
727 << " (" << ctx.state.version().GetString() << ") is installed " 727 << " (" << ctx.state.version().GetString() << ") is installed "
728 << "without Chrome Binaries."; 728 << "without Chrome Binaries.";
729 } 729 }
730 } else { 730 } else {
731 // Version must match that of binaries. 731 // Version must match that of binaries.
732 if (ctx.state.version().CompareTo(binaries->version()) != 0) { 732 if (ctx.state.version().CompareTo(binaries->version()) != 0) {
733 *is_valid = false; 733 *is_valid = false;
734 LOG(ERROR) << "Version of " << ctx.dist->GetAppShortCutName() 734 LOG(ERROR) << "Version of " << ctx.dist->GetDisplayName()
735 << " (" << ctx.state.version().GetString() << ") does not " 735 << " (" << ctx.state.version().GetString() << ") does not "
736 "match that of Chrome Binaries (" 736 "match that of Chrome Binaries ("
737 << binaries->version().GetString() << ")."; 737 << binaries->version().GetString() << ").";
738 } 738 }
739 739
740 // Channel value must match that of binaries. 740 // Channel value must match that of binaries.
741 if (!ctx.state.channel().Equals(binaries->channel())) { 741 if (!ctx.state.channel().Equals(binaries->channel())) {
742 *is_valid = false; 742 *is_valid = false;
743 LOG(ERROR) << "Channel name of " << ctx.dist->GetAppShortCutName() 743 LOG(ERROR) << "Channel name of " << ctx.dist->GetDisplayName()
744 << " (" << ctx.state.channel().value() 744 << " (" << ctx.state.channel().value()
745 << ") does not match that of Chrome Binaries (" 745 << ") does not match that of Chrome Binaries ("
746 << binaries->channel().value() << ")."; 746 << binaries->channel().value() << ").";
747 } 747 }
748 } 748 }
749 } 749 }
750 750
751 // Validates the Google Update commands for the product described in |ctx|. 751 // Validates the Google Update commands for the product described in |ctx|.
752 void InstallationValidator::ValidateAppCommands( 752 void InstallationValidator::ValidateAppCommands(
753 const ProductContext& ctx, 753 const ProductContext& ctx,
(...skipping 13 matching lines...) Expand all
767 ValidateAppCommandExpectations(ctx, expectations, is_valid); 767 ValidateAppCommandExpectations(ctx, expectations, is_valid);
768 } 768 }
769 769
770 // Validates usagestats for the product or binaries in |ctx|. 770 // Validates usagestats for the product or binaries in |ctx|.
771 void InstallationValidator::ValidateUsageStats(const ProductContext& ctx, 771 void InstallationValidator::ValidateUsageStats(const ProductContext& ctx,
772 bool* is_valid) { 772 bool* is_valid) {
773 DWORD usagestats = 0; 773 DWORD usagestats = 0;
774 if (ctx.state.GetUsageStats(&usagestats)) { 774 if (ctx.state.GetUsageStats(&usagestats)) {
775 if (!ctx.rules.UsageStatsAllowed(ctx)) { 775 if (!ctx.rules.UsageStatsAllowed(ctx)) {
776 *is_valid = false; 776 *is_valid = false;
777 LOG(ERROR) << ctx.dist->GetAppShortCutName() 777 LOG(ERROR) << ctx.dist->GetDisplayName()
778 << " has a usagestats value (" << usagestats 778 << " has a usagestats value (" << usagestats
779 << "), yet should not."; 779 << "), yet should not.";
780 } else if (usagestats != 0 && usagestats != 1) { 780 } else if (usagestats != 0 && usagestats != 1) {
781 *is_valid = false; 781 *is_valid = false;
782 LOG(ERROR) << ctx.dist->GetAppShortCutName() 782 LOG(ERROR) << ctx.dist->GetDisplayName()
783 << " has an unsupported usagestats value (" << usagestats 783 << " has an unsupported usagestats value (" << usagestats
784 << ")."; 784 << ").";
785 } 785 }
786 } 786 }
787 } 787 }
788 788
789 // Validates the product described in |product_state| according to |rules|. 789 // Validates the product described in |product_state| according to |rules|.
790 void InstallationValidator::ValidateProduct( 790 void InstallationValidator::ValidateProduct(
791 const InstallationState& machine_state, 791 const InstallationState& machine_state,
792 bool system_install, 792 bool system_install,
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 InstallationType* type) { 892 InstallationType* type) {
893 DCHECK(type); 893 DCHECK(type);
894 InstallationState machine_state; 894 InstallationState machine_state;
895 895
896 machine_state.Initialize(); 896 machine_state.Initialize();
897 897
898 return ValidateInstallationTypeForState(machine_state, system_level, type); 898 return ValidateInstallationTypeForState(machine_state, system_level, type);
899 } 899 }
900 900
901 } // namespace installer 901 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698