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

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: Refactoring and nits. 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>
11 #include <string>
11 12
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/version.h" 14 #include "base/version.h"
14 #include "chrome/common/chrome_switches.h" 15 #include "chrome/common/chrome_switches.h"
15 #include "chrome/installer/util/browser_distribution.h" 16 #include "chrome/installer/util/browser_distribution.h"
16 #include "chrome/installer/util/helper.h" 17 #include "chrome/installer/util/helper.h"
17 #include "chrome/installer/util/installation_state.h" 18 #include "chrome/installer/util/installation_state.h"
18 19
19 namespace installer { 20 namespace installer {
20 21
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 LOG(ERROR) << "install-application command is not configured to send " 235 LOG(ERROR) << "install-application command is not configured to send "
235 << "pings."; 236 << "pings.";
236 } 237 }
237 238
238 if (!command.is_web_accessible()) { 239 if (!command.is_web_accessible()) {
239 *is_valid = false; 240 *is_valid = false;
240 LOG(ERROR) << "install-application command is not web accessible."; 241 LOG(ERROR) << "install-application command is not web accessible.";
241 } 242 }
242 } 243 }
243 244
245 // Validates the "on-os-upgrade" Google Update internal command.
246 void InstallationValidator::ValidateOnOsUpgradeCommand(
247 const ProductContext& ctx,
248 const AppCommand& command,
249 bool* is_valid) {
250 DCHECK(is_valid);
251
252 CommandLine the_command(CommandLine::FromString(command.command_line()));
253
254 ValidateSetupPath(ctx, the_command.GetProgram(), "on os upgrade", is_valid);
255
256 SwitchExpectations expected;
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 // Expecting kChrome if and only if kMultiInstall.
263 expected.push_back(std::make_pair(std::string(switches::kChrome),
264 ctx.state.is_multi_install()));
265
266 ValidateCommandExpectations(ctx, the_command, expected, "on os upgrade",
267 is_valid);
268
269 if (!command.is_auto_run_on_os_upgrade()) {
270 *is_valid = false;
271 LOG(ERROR) << "On-os-upgrade command is not marked to run on OS upgrade.";
272 }
273
274 if (command.sends_pings()) {
275 *is_valid = false;
276 LOG(ERROR) << "On-os-upgrade command should not be able to send pings.";
277 }
278
279 if (command.is_web_accessible()) {
280 *is_valid = false;
281 LOG(ERROR) << "On-os-upgrade command should not be web accessible.";
282 }
283 }
284
244 // Validates the "quick-enable-cf" Google Update product command. 285 // Validates the "quick-enable-cf" Google Update product command.
245 void InstallationValidator::ValidateQuickEnableCfCommand( 286 void InstallationValidator::ValidateQuickEnableCfCommand(
246 const ProductContext& ctx, 287 const ProductContext& ctx,
247 const AppCommand& command, 288 const AppCommand& command,
248 bool* is_valid) { 289 bool* is_valid) {
249 DCHECK(is_valid); 290 DCHECK(is_valid);
250 291
251 CommandLine the_command(CommandLine::FromString(command.command_line())); 292 CommandLine the_command(CommandLine::FromString(command.command_line()));
252 293
253 ValidateSetupPath(ctx, the_command.GetProgram(), "quick enable cf", is_valid); 294 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, 365 const CommandExpectations& expectations,
325 bool* is_valid) { 366 bool* is_valid) {
326 DCHECK(is_valid); 367 DCHECK(is_valid);
327 368
328 CommandExpectations the_expectations(expectations); 369 CommandExpectations the_expectations(expectations);
329 370
330 AppCommands::CommandMapRange cmd_iterators( 371 AppCommands::CommandMapRange cmd_iterators(
331 ctx.state.commands().GetIterators()); 372 ctx.state.commands().GetIterators());
332 CommandExpectations::iterator expectation; 373 CommandExpectations::iterator expectation;
333 for (; cmd_iterators.first != cmd_iterators.second; ++cmd_iterators.first) { 374 for (; cmd_iterators.first != cmd_iterators.second; ++cmd_iterators.first) {
334 const std::wstring& cmd_id = cmd_iterators.first->first; 375 const string16& cmd_id = cmd_iterators.first->first;
335 // Do we have an expectation for this command? 376 // Do we have an expectation for this command?
336 expectation = the_expectations.find(cmd_id); 377 expectation = the_expectations.find(cmd_id);
337 if (expectation != the_expectations.end()) { 378 if (expectation != the_expectations.end()) {
338 (expectation->second)(ctx, cmd_iterators.first->second, is_valid); 379 (expectation->second)(ctx, cmd_iterators.first->second, is_valid);
339 // Remove this command from the set of expectations since we found it. 380 // Remove this command from the set of expectations since we found it.
340 the_expectations.erase(expectation); 381 the_expectations.erase(expectation);
341 } else { 382 } else {
342 *is_valid = false; 383 *is_valid = false;
343 LOG(ERROR) << ctx.dist->GetAppShortCutName() 384 LOG(ERROR) << ctx.dist->GetAppShortCutName()
344 << " has an unexpected Google Update product command named \"" 385 << " has an unexpected Google Update product command named \""
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 522
482 // Chrome Frame must be multi-install if Chrome & App Host are not present. 523 // 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 && 524 if (cf_state != NULL && app_host_state == NULL && chrome_state == NULL &&
484 !cf_state->is_multi_install()) { 525 !cf_state->is_multi_install()) {
485 *is_valid = false; 526 *is_valid = false;
486 LOG(ERROR) << "Chrome Binaries are present without Chrome nor App Host " 527 LOG(ERROR) << "Chrome Binaries are present without Chrome nor App Host "
487 << "yet Chrome Frame is not multi-install."; 528 << "yet Chrome Frame is not multi-install.";
488 } 529 }
489 530
490 ChromeBinariesRules binaries_rules; 531 ChromeBinariesRules binaries_rules;
491 ProductContext ctx = { 532 ProductContext ctx(machine_state, system_install, binaries_state,
492 machine_state, 533 binaries_rules);
493 system_install,
494 BrowserDistribution::GetSpecificDistribution(
495 BrowserDistribution::CHROME_BINARIES),
496 binaries_state,
497 binaries_rules
498 };
499 534
500 ValidateBinariesCommands(ctx, is_valid); 535 ValidateBinariesCommands(ctx, is_valid);
501 536
502 ValidateUsageStats(ctx, is_valid); 537 ValidateUsageStats(ctx, is_valid);
503 } 538 }
504 539
505 // Validates the path to |setup_exe| for the product described by |ctx|. 540 // Validates the path to |setup_exe| for the product described by |ctx|.
506 void InstallationValidator::ValidateSetupPath(const ProductContext& ctx, 541 void InstallationValidator::ValidateSetupPath(const ProductContext& ctx,
507 const FilePath& setup_exe, 542 const FilePath& setup_exe,
508 const char* purpose, 543 const char* purpose,
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 void InstallationValidator::ValidateAppCommands( 719 void InstallationValidator::ValidateAppCommands(
685 const ProductContext& ctx, 720 const ProductContext& ctx,
686 bool* is_valid) { 721 bool* is_valid) {
687 DCHECK(is_valid); 722 DCHECK(is_valid);
688 723
689 CommandExpectations expectations; 724 CommandExpectations expectations;
690 725
691 if (ctx.dist->GetType() == BrowserDistribution::CHROME_APP_HOST) { 726 if (ctx.dist->GetType() == BrowserDistribution::CHROME_APP_HOST) {
692 expectations[kCmdInstallApp] = &ValidateInstallAppCommand; 727 expectations[kCmdInstallApp] = &ValidateInstallAppCommand;
693 } 728 }
729 if (ctx.dist->GetType() == BrowserDistribution::CHROME_BROWSER) {
730 expectations[kCmdOnOsUpgrade] = &ValidateOnOsUpgradeCommand;
731 }
694 732
695 ValidateAppCommandExpectations(ctx, expectations, is_valid); 733 ValidateAppCommandExpectations(ctx, expectations, is_valid);
696 } 734 }
697 735
698 // Validates usagestats for the product or binaries in |ctx|. 736 // Validates usagestats for the product or binaries in |ctx|.
699 void InstallationValidator::ValidateUsageStats(const ProductContext& ctx, 737 void InstallationValidator::ValidateUsageStats(const ProductContext& ctx,
700 bool* is_valid) { 738 bool* is_valid) {
701 DWORD usagestats = 0; 739 DWORD usagestats = 0;
702 if (ctx.state.GetUsageStats(&usagestats)) { 740 if (ctx.state.GetUsageStats(&usagestats)) {
703 if (!ctx.rules.UsageStatsAllowed(ctx.state)) { 741 if (!ctx.rules.UsageStatsAllowed(ctx.state)) {
(...skipping 11 matching lines...) Expand all
715 } 753 }
716 754
717 // Validates the product described in |product_state| according to |rules|. 755 // Validates the product described in |product_state| according to |rules|.
718 void InstallationValidator::ValidateProduct( 756 void InstallationValidator::ValidateProduct(
719 const InstallationState& machine_state, 757 const InstallationState& machine_state,
720 bool system_install, 758 bool system_install,
721 const ProductState& product_state, 759 const ProductState& product_state,
722 const ProductRules& rules, 760 const ProductRules& rules,
723 bool* is_valid) { 761 bool* is_valid) {
724 DCHECK(is_valid); 762 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 763
733 ValidateUninstallCommand(ctx, product_state.uninstall_command(), 764 ProductContext ctx(machine_state, system_install, product_state, rules);
765
766 ValidateUninstallCommand(ctx, ctx.state.uninstall_command(),
734 "Google Update uninstall command", is_valid); 767 "Google Update uninstall command", is_valid);
735 768
736 ValidateOldVersionValues(ctx, is_valid); 769 ValidateOldVersionValues(ctx, is_valid);
737 770
738 if (product_state.is_multi_install()) 771 if (ctx.state.is_multi_install())
739 ValidateMultiInstallProduct(ctx, is_valid); 772 ValidateMultiInstallProduct(ctx, is_valid);
740 773
741 ValidateAppCommands(ctx, is_valid); 774 ValidateAppCommands(ctx, is_valid);
742 775
743 ValidateUsageStats(ctx, is_valid); 776 ValidateUsageStats(ctx, is_valid);
744 } 777 }
745 778
746 // static 779 // static
747 bool InstallationValidator::ValidateInstallationTypeForState( 780 bool InstallationValidator::ValidateInstallationTypeForState(
748 const InstallationState& machine_state, 781 const InstallationState& machine_state,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 InstallationType* type) { 856 InstallationType* type) {
824 DCHECK(type); 857 DCHECK(type);
825 InstallationState machine_state; 858 InstallationState machine_state;
826 859
827 machine_state.Initialize(); 860 machine_state.Initialize();
828 861
829 return ValidateInstallationTypeForState(machine_state, system_level, type); 862 return ValidateInstallationTypeForState(machine_state, system_level, type);
830 } 863 }
831 864
832 } // namespace installer 865 } // namespace installer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698