diff options
author | huangs@chromium.org <huangs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 19:48:51 +0000 |
---|---|---|
committer | huangs@chromium.org <huangs@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-04 19:48:51 +0000 |
commit | 9f2f88141fa58dae5e5f24045aa4a4f119c7ee32 (patch) | |
tree | 35017cc5a76f9d40a30367205956a2e76904722f /chrome/installer/setup/setup_util.cc | |
parent | 76edffaa8111da8770c31ff6537888f5b37ca519 (diff) | |
download | chromium_src-9f2f88141fa58dae5e5f24045aa4a4f119c7ee32.zip chromium_src-9f2f88141fa58dae5e5f24045aa4a4f119c7ee32.tar.gz chromium_src-9f2f88141fa58dae5e5f24045aa4a4f119c7ee32.tar.bz2 |
Refactoring: Splitting AddGenericQuickEnableWorkItems().
This is a refactoring task in preparation for adding "RunAsUser" flag in app commands [TODO: Get BUG id].
In install_util.cc,
AddGenericQuickEnableWorkItems()
was a large routine that contains common code for
(A) AddQuickEnableChromeFrameWorkItems() for "quick-enable-cf"
(B) AddQuickEnableApplicationLauncherWorkItems() for "quick-enable-application-host"
It was assumed that (A) and (B) set the same flags ("SendsPoints" and "WebAccessible"). This assumption will no longer hold once we add "RunAsUser" (for (B) only). However, the flag-setting part is buried deep inside AddGenericQuickEnableWorkItems(). The refactoring task splits the subroutine into smaller parts, and produce some duplicate glue code with acceptibly small repetition.
AddGenericQuickEnableWorkItems() is split into the following (+ glue code):
(1) WillProductBePresentAfterSetup() => moved to install_util.cc
(2) GetGenericQuickEnableCommand()
We also made (1) absorb existing code in (A). In addition,
(3) GetRegCommandKey()
is extracted to eliminate duplicate code to access App Command registry entries.
Glue codes are found in the callers (A) and (B). Moreover, code that is used in (A) only are not repeated in (B).
BUG=160293
Review URL: https://chromiumcodereview.appspot.com/12114016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180481 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer/setup/setup_util.cc')
-rw-r--r-- | chrome/installer/setup/setup_util.cc | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/chrome/installer/setup/setup_util.cc b/chrome/installer/setup/setup_util.cc index 08c9b41..126e736 100644 --- a/chrome/installer/setup/setup_util.cc +++ b/chrome/installer/setup/setup_util.cc @@ -75,6 +75,13 @@ bool LaunchAndWaitForExistingInstall(const FilePath& setup_exe, return true; } +// Returns true if product |type| cam be meaningfully installed without the +// --multi-install flag. +bool SupportsSingleInstall(BrowserDistribution::Type type) { + return (type == BrowserDistribution::CHROME_BROWSER || + type == BrowserDistribution::CHROME_FRAME); +} + } // namespace int ApplyDiffPatch(const FilePath& src, @@ -259,6 +266,53 @@ bool DeferToExistingInstall(const FilePath& setup_exe, return true; } +// There are 4 disjoint cases => return values {false,true}: +// (1) Product is being uninstalled => false. +// (2) Product is being installed => true. +// (3) Current operation ignores product, product is absent => false. +// (4) Current operation ignores product, product is present => true. +bool WillProductBePresentAfterSetup( + const installer::InstallerState& installer_state, + const installer::InstallationState& machine_state, + BrowserDistribution::Type type) { + DCHECK(SupportsSingleInstall(type) || installer_state.is_multi_install()); + + const ProductState* product_state = + machine_state.GetProductState(installer_state.system_install(), type); + + // Determine if the product is present prior to the current operation. + bool is_present = false; + if (product_state != NULL) { + if (type == BrowserDistribution::CHROME_FRAME) { + is_present = !product_state->uninstall_command().HasSwitch( + switches::kChromeFrameReadyMode); + } else { + is_present = true; + } + } + + bool is_uninstall = installer_state.operation() == InstallerState::UNINSTALL; + + // Determine if current operation affects the product. + bool is_affected = false; + const Product* product = installer_state.FindProduct(type); + if (product != NULL) { + if (type == BrowserDistribution::CHROME_FRAME) { + // If Chrome Frame is being uninstalled, we don't bother to check + // !HasOption(kOptionReadyMode) since CF would not have been installed + // in the first place. If for some odd reason it weren't, we would be + // conservative, and cause false to be retruned since CF should not be + // installed then (so is_uninstall = true and is_affected = true). + is_affected = is_uninstall || !product->HasOption(kOptionReadyMode); + } else { + is_affected = true; + } + } + + // Decide among {(1),(2),(3),(4)}. + return is_affected ? !is_uninstall : is_present; +} + ScopedTokenPrivilege::ScopedTokenPrivilege(const wchar_t* privilege_name) : is_enabled_(false) { if (!::OpenProcessToken(::GetCurrentProcess(), |