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