Add ICU message format support
[chromium-blink-merge.git] / chrome / installer / setup / setup_util.h
blob4d6303a78e450ef62f08b3ecfb70768fd1e8049b
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.
4 //
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
7 // deltas.
9 #ifndef CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
10 #define CHROME_INSTALLER_SETUP_SETUP_UTIL_H_
12 #include <windows.h>
14 #include "base/basictypes.h"
15 #include "base/strings/string16.h"
16 #include "base/win/scoped_handle.h"
17 #include "chrome/installer/util/browser_distribution.h"
18 #include "chrome/installer/util/util_constants.h"
20 class AppRegistrationData;
22 namespace base {
23 class CommandLine;
24 class FilePath;
25 class Version;
28 namespace installer {
30 class InstallationState;
31 class InstallerState;
32 class ProductState;
34 // Sets a bit in the registry to note that the latest OS upgrade notification
35 // has been handled by this user. Returns true if the previous bit was
36 // different or absent (i.e., the latest OS update wasn't handled yet), in
37 // which case subsequent calls to this method will return false until the next
38 // OS upgrade. This call is only valid on system-level installs.
39 bool UpdateLastOSUpgradeHandledByActiveSetup(BrowserDistribution* dist);
41 // Applies a patch file to source file using Courgette. Returns 0 in case of
42 // success. In case of errors, it returns kCourgetteErrorOffset + a Courgette
43 // status code, as defined in courgette/courgette.h
44 int CourgettePatchFiles(const base::FilePath& src,
45 const base::FilePath& patch,
46 const base::FilePath& dest);
48 // Applies a patch file to source file using bsdiff. This function uses
49 // Courgette's flavor of bsdiff. Returns 0 in case of success, or
50 // kBsdiffErrorOffset + a bsdiff status code in case of errors.
51 // See courgette/third_party/bsdiff.h for details.
52 int BsdiffPatchFiles(const base::FilePath& src,
53 const base::FilePath& patch,
54 const base::FilePath& dest);
56 // Find the version of Chrome from an install source directory.
57 // Chrome_path should contain at least one version folder.
58 // Returns the maximum version found or NULL if no version is found.
59 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path);
61 // Returns the uncompressed archive of the installed version that serves as the
62 // source for patching. If |desired_version| is valid, only the path to that
63 // version will be returned, or empty if it doesn't exist.
64 base::FilePath FindArchiveToPatch(const InstallationState& original_state,
65 const InstallerState& installer_state,
66 const base::Version& desired_version);
68 // Spawns a new process that waits for a specified amount of time before
69 // attempting to delete |path|. This is useful for setup to delete the
70 // currently running executable or a file that we cannot close right away but
71 // estimate that it will be possible after some period of time.
72 // Returns true if a new process was started, false otherwise. Note that
73 // given the nature of this function, it is not possible to know if the
74 // delete operation itself succeeded.
75 bool DeleteFileFromTempProcess(const base::FilePath& path,
76 uint32 delay_before_delete_ms);
78 // Returns true and populates |setup_exe| with the path to an existing product
79 // installer if one is found that is newer than the currently running installer
80 // (|installer_version|).
81 bool GetExistingHigherInstaller(const InstallationState& original_state,
82 bool system_install,
83 const base::Version& installer_version,
84 base::FilePath* setup_exe);
86 // Invokes the pre-existing |setup_exe| to handle the current operation (as
87 // dictated by |command_line|). An installerdata file, if specified, is first
88 // unconditionally copied into place so that it will be in effect in case the
89 // invoked |setup_exe| runs the newly installed product prior to exiting.
90 // Returns true if |setup_exe| was launched, false otherwise.
91 bool DeferToExistingInstall(const base::FilePath& setup_exe,
92 const base::CommandLine& command_line,
93 const InstallerState& installer_state,
94 const base::FilePath& temp_path,
95 InstallStatus* install_status);
97 // Returns true if the product |type| will be installed after the current
98 // setup.exe instance have carried out installation / uninstallation, at
99 // the level specified by |installer_state|.
100 // This function only returns meaningful results for install and update
101 // operations if called after CheckPreInstallConditions (see setup_main.cc).
102 bool WillProductBePresentAfterSetup(
103 const installer::InstallerState& installer_state,
104 const installer::InstallationState& machine_state,
105 BrowserDistribution::Type type);
107 // Drops the process down to background processing mode on supported OSes if it
108 // was launched below the normal process priority. Returns true when background
109 // procesing mode is entered.
110 bool AdjustProcessPriority();
112 // Makes registry adjustments to migrate the Google Update state of |to_migrate|
113 // from multi-install to single-install. This includes copying the usagestats
114 // value and adjusting the ap values of all multi-install products.
115 void MigrateGoogleUpdateStateMultiToSingle(
116 bool system_level,
117 BrowserDistribution::Type to_migrate,
118 const installer::InstallationState& machine_state);
120 // Returns true if |install_status| represents a successful uninstall code.
121 bool IsUninstallSuccess(InstallStatus install_status);
123 // Returns true if |cmd_line| contains unsupported (legacy) switches.
124 bool ContainsUnsupportedSwitch(const base::CommandLine& cmd_line);
126 // Returns true if the processor is supported by chrome.
127 bool IsProcessorSupported();
129 // Returns the "...\\Commands\\|name|" registry key for a product's |reg_data|.
130 base::string16 GetRegistrationDataCommandKey(
131 const AppRegistrationData& reg_data,
132 const wchar_t* name);
134 // This class will enable the privilege defined by |privilege_name| on the
135 // current process' token. The privilege will be disabled upon the
136 // ScopedTokenPrivilege's destruction (unless it was already enabled when the
137 // ScopedTokenPrivilege object was constructed).
138 // Some privileges might require admin rights to be enabled (check is_enabled()
139 // to know whether |privilege_name| was successfully enabled).
140 class ScopedTokenPrivilege {
141 public:
142 explicit ScopedTokenPrivilege(const wchar_t* privilege_name);
143 ~ScopedTokenPrivilege();
145 // Always returns true unless the privilege could not be enabled.
146 bool is_enabled() const { return is_enabled_; }
148 private:
149 // Always true unless the privilege could not be enabled.
150 bool is_enabled_;
152 // A scoped handle to the current process' token. This will be closed
153 // preemptively should enabling the privilege fail in the constructor.
154 base::win::ScopedHandle token_;
156 // The previous state of the privilege this object is responsible for. As set
157 // by AdjustTokenPrivileges() upon construction.
158 TOKEN_PRIVILEGES previous_privileges_;
160 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTokenPrivilege);
163 } // namespace installer
165 #endif // CHROME_INSTALLER_SETUP_SETUP_UTIL_H_