Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / installer / setup / setup_util.h
blob0b04b7b7812936e3aabdeb3a0195476b40b0bc08
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 // Applies a patch file to source file using Courgette. Returns 0 in case of
35 // success. In case of errors, it returns kCourgetteErrorOffset + a Courgette
36 // status code, as defined in courgette/courgette.h
37 int CourgettePatchFiles(const base::FilePath& src,
38 const base::FilePath& patch,
39 const base::FilePath& dest);
41 // Applies a patch file to source file using bsdiff. This function uses
42 // Courgette's flavor of bsdiff. Returns 0 in case of success, or
43 // kBsdiffErrorOffset + a bsdiff status code in case of errors.
44 // See courgette/third_party/bsdiff.h for details.
45 int BsdiffPatchFiles(const base::FilePath& src,
46 const base::FilePath& patch,
47 const base::FilePath& dest);
49 // Find the version of Chrome from an install source directory.
50 // Chrome_path should contain at least one version folder.
51 // Returns the maximum version found or NULL if no version is found.
52 Version* GetMaxVersionFromArchiveDir(const base::FilePath& chrome_path);
54 // Returns the uncompressed archive of the installed version that serves as the
55 // source for patching. If |desired_version| is valid, only the path to that
56 // version will be returned, or empty if it doesn't exist.
57 base::FilePath FindArchiveToPatch(const InstallationState& original_state,
58 const InstallerState& installer_state,
59 const base::Version& desired_version);
61 // Spawns a new process that waits for a specified amount of time before
62 // attempting to delete |path|. This is useful for setup to delete the
63 // currently running executable or a file that we cannot close right away but
64 // estimate that it will be possible after some period of time.
65 // Returns true if a new process was started, false otherwise. Note that
66 // given the nature of this function, it is not possible to know if the
67 // delete operation itself succeeded.
68 bool DeleteFileFromTempProcess(const base::FilePath& path,
69 uint32 delay_before_delete_ms);
71 // Returns true and populates |setup_exe| with the path to an existing product
72 // installer if one is found that is newer than the currently running installer
73 // (|installer_version|).
74 bool GetExistingHigherInstaller(const InstallationState& original_state,
75 bool system_install,
76 const base::Version& installer_version,
77 base::FilePath* setup_exe);
79 // Invokes the pre-existing |setup_exe| to handle the current operation (as
80 // dictated by |command_line|). An installerdata file, if specified, is first
81 // unconditionally copied into place so that it will be in effect in case the
82 // invoked |setup_exe| runs the newly installed product prior to exiting.
83 // Returns true if |setup_exe| was launched, false otherwise.
84 bool DeferToExistingInstall(const base::FilePath& setup_exe,
85 const base::CommandLine& command_line,
86 const InstallerState& installer_state,
87 const base::FilePath& temp_path,
88 InstallStatus* install_status);
90 // Returns true if the product |type| will be installed after the current
91 // setup.exe instance have carried out installation / uninstallation, at
92 // the level specified by |installer_state|.
93 // This function only returns meaningful results for install and update
94 // operations if called after CheckPreInstallConditions (see setup_main.cc).
95 bool WillProductBePresentAfterSetup(
96 const installer::InstallerState& installer_state,
97 const installer::InstallationState& machine_state,
98 BrowserDistribution::Type type);
100 // Drops the process down to background processing mode on supported OSes if it
101 // was launched below the normal process priority. Returns true when background
102 // procesing mode is entered.
103 bool AdjustProcessPriority();
105 // Makes registry adjustments to migrate the Google Update state of |to_migrate|
106 // from multi-install to single-install. This includes copying the usagestats
107 // value and adjusting the ap values of all multi-install products.
108 void MigrateGoogleUpdateStateMultiToSingle(
109 bool system_level,
110 BrowserDistribution::Type to_migrate,
111 const installer::InstallationState& machine_state);
113 // Returns true if |install_status| represents a successful uninstall code.
114 bool IsUninstallSuccess(InstallStatus install_status);
116 // Returns true if |cmd_line| contains unsupported (legacy) switches.
117 bool ContainsUnsupportedSwitch(const base::CommandLine& cmd_line);
119 // Returns true if the processor is supported by chrome.
120 bool IsProcessorSupported();
122 // Returns the "...\\Commands\\|name|" registry key for a product's |reg_data|.
123 base::string16 GetRegistrationDataCommandKey(
124 const AppRegistrationData& reg_data,
125 const wchar_t* name);
127 // This class will enable the privilege defined by |privilege_name| on the
128 // current process' token. The privilege will be disabled upon the
129 // ScopedTokenPrivilege's destruction (unless it was already enabled when the
130 // ScopedTokenPrivilege object was constructed).
131 // Some privileges might require admin rights to be enabled (check is_enabled()
132 // to know whether |privilege_name| was successfully enabled).
133 class ScopedTokenPrivilege {
134 public:
135 explicit ScopedTokenPrivilege(const wchar_t* privilege_name);
136 ~ScopedTokenPrivilege();
138 // Always returns true unless the privilege could not be enabled.
139 bool is_enabled() const { return is_enabled_; }
141 private:
142 // Always true unless the privilege could not be enabled.
143 bool is_enabled_;
145 // A scoped handle to the current process' token. This will be closed
146 // preemptively should enabling the privilege fail in the constructor.
147 base::win::ScopedHandle token_;
149 // The previous state of the privilege this object is responsible for. As set
150 // by AdjustTokenPrivileges() upon construction.
151 TOKEN_PRIVILEGES previous_privileges_;
153 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopedTokenPrivilege);
156 } // namespace installer
158 #endif // CHROME_INSTALLER_SETUP_SETUP_UTIL_H_