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
3 // found in the LICENSE file.
5 // This file declares util functions for setup project. It also declares a
6 // few functions that the Chrome component updater uses for patching binary
9 #ifndef CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
10 #define CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
16 #include "base/basictypes.h"
17 #include "base/strings/string16.h"
18 #include "base/win/scoped_handle.h"
19 #include "chrome/installer/util/browser_distribution.h"
20 #include "chrome/installer/util/util_constants.h"
22 class AppRegistrationData
;
32 class InstallationState
;
36 // Applies a patch file to source file using Courgette. Returns 0 in case of
37 // success. In case of errors, it returns kCourgetteErrorOffset + a Courgette
38 // status code, as defined in courgette/courgette.h
39 int CourgettePatchFiles(const base::FilePath
& src
,
40 const base::FilePath
& patch
,
41 const base::FilePath
& dest
);
43 // Applies a patch file to source file using bsdiff. This function uses
44 // Courgette's flavor of bsdiff. Returns 0 in case of success, or
45 // kBsdiffErrorOffset + a bsdiff status code in case of errors.
46 // See courgette/third_party/bsdiff.h for details.
47 int BsdiffPatchFiles(const base::FilePath
& src
,
48 const base::FilePath
& patch
,
49 const base::FilePath
& dest
);
51 // Find the version of Chrome from an install source directory.
52 // Chrome_path should contain at least one version folder.
53 // Returns the maximum version found or NULL if no version is found.
54 Version
* GetMaxVersionFromArchiveDir(const base::FilePath
& chrome_path
);
56 // Returns the uncompressed archive of the installed version that serves as the
57 // source for patching. If |desired_version| is valid, only the path to that
58 // version will be returned, or empty if it doesn't exist.
59 base::FilePath
FindArchiveToPatch(const InstallationState
& original_state
,
60 const InstallerState
& installer_state
,
61 const base::Version
& desired_version
);
63 // Spawns a new process that waits for a specified amount of time before
64 // attempting to delete |path|. This is useful for setup to delete the
65 // currently running executable or a file that we cannot close right away but
66 // estimate that it will be possible after some period of time.
67 // Returns true if a new process was started, false otherwise. Note that
68 // given the nature of this function, it is not possible to know if the
69 // delete operation itself succeeded.
70 bool DeleteFileFromTempProcess(const base::FilePath
& path
,
71 uint32 delay_before_delete_ms
);
73 // Returns true and populates |setup_exe| with the path to an existing product
74 // installer if one is found that is newer than the currently running installer
75 // (|installer_version|).
76 bool GetExistingHigherInstaller(const InstallationState
& original_state
,
78 const base::Version
& installer_version
,
79 base::FilePath
* setup_exe
);
81 // Invokes the pre-existing |setup_exe| to handle the current operation (as
82 // dictated by |command_line|). An installerdata file, if specified, is first
83 // unconditionally copied into place so that it will be in effect in case the
84 // invoked |setup_exe| runs the newly installed product prior to exiting.
85 // Returns true if |setup_exe| was launched, false otherwise.
86 bool DeferToExistingInstall(const base::FilePath
& setup_exe
,
87 const base::CommandLine
& command_line
,
88 const InstallerState
& installer_state
,
89 const base::FilePath
& temp_path
,
90 InstallStatus
* install_status
);
92 // Returns true if the product |type| will be installed after the current
93 // setup.exe instance have carried out installation / uninstallation, at
94 // the level specified by |installer_state|.
95 // This function only returns meaningful results for install and update
96 // operations if called after CheckPreInstallConditions (see setup_main.cc).
97 bool WillProductBePresentAfterSetup(
98 const installer::InstallerState
& installer_state
,
99 const installer::InstallationState
& machine_state
,
100 BrowserDistribution::Type type
);
102 // Drops the process down to background processing mode on supported OSes if it
103 // was launched below the normal process priority. Returns true when background
104 // procesing mode is entered.
105 bool AdjustProcessPriority();
107 // Makes registry adjustments to migrate the Google Update state of |to_migrate|
108 // from multi-install to single-install. This includes copying the usagestats
109 // value and adjusting the ap values of all multi-install products.
110 void MigrateGoogleUpdateStateMultiToSingle(
112 BrowserDistribution::Type to_migrate
,
113 const installer::InstallationState
& machine_state
);
115 // Returns true if |install_status| represents a successful uninstall code.
116 bool IsUninstallSuccess(InstallStatus install_status
);
118 // Returns true if |cmd_line| contains unsupported (legacy) switches.
119 bool ContainsUnsupportedSwitch(const base::CommandLine
& cmd_line
);
121 // Returns true if the processor is supported by chrome.
122 bool IsProcessorSupported();
124 // Returns the "...\\Commands\\|name|" registry key for a product's |reg_data|.
125 base::string16
GetRegistrationDataCommandKey(
126 const AppRegistrationData
& reg_data
,
127 const wchar_t* name
);
129 // Deletes all values and subkeys of the key |path| under |root|, preserving
130 // the keys named in |keys_to_preserve| (each of which must be an ASCII string).
131 // The key itself is deleted if no subkeys are preserved.
132 void DeleteRegistryKeyPartial(
134 const base::string16
& path
,
135 const std::vector
<base::string16
>& keys_to_preserve
);
137 // This class will enable the privilege defined by |privilege_name| on the
138 // current process' token. The privilege will be disabled upon the
139 // ScopedTokenPrivilege's destruction (unless it was already enabled when the
140 // ScopedTokenPrivilege object was constructed).
141 // Some privileges might require admin rights to be enabled (check is_enabled()
142 // to know whether |privilege_name| was successfully enabled).
143 class ScopedTokenPrivilege
{
145 explicit ScopedTokenPrivilege(const wchar_t* privilege_name
);
146 ~ScopedTokenPrivilege();
148 // Always returns true unless the privilege could not be enabled.
149 bool is_enabled() const { return is_enabled_
; }
152 // Always true unless the privilege could not be enabled.
155 // A scoped handle to the current process' token. This will be closed
156 // preemptively should enabling the privilege fail in the constructor.
157 base::win::ScopedHandle token_
;
159 // The previous state of the privilege this object is responsible for. As set
160 // by AdjustTokenPrivileges() upon construction.
161 TOKEN_PRIVILEGES previous_privileges_
;
163 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTokenPrivilege
);
166 } // namespace installer
168 #endif // CHROME_INSTALLER_SETUP_SETUP_UTIL_H_