OLD | NEW |
---|---|
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 #ifndef CHROME_INSTALLER_SETUP_INSTALLER_STATE_H_ | 5 #ifndef CHROME_INSTALLER_SETUP_INSTALLER_STATE_H_ |
6 #define CHROME_INSTALLER_SETUP_INSTALLER_STATE_H_ | 6 #define CHROME_INSTALLER_SETUP_INSTALLER_STATE_H_ |
7 | 7 |
8 #include <stdint.h> | |
9 | |
10 #include <memory> | 8 #include <memory> |
11 #include <vector> | |
12 | 9 |
13 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
14 #include "base/logging.h" | 11 #include "base/logging.h" |
15 #include "base/macros.h" | 12 #include "base/macros.h" |
16 #include "base/memory/scoped_vector.h" | |
17 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
18 #include "base/version.h" | 14 #include "base/version.h" |
19 #include "build/build_config.h" | 15 #include "build/build_config.h" |
20 #include "chrome/installer/setup/progress_calculator.h" | 16 #include "chrome/installer/setup/progress_calculator.h" |
21 #include "chrome/installer/util/browser_distribution.h" | 17 #include "chrome/installer/util/browser_distribution.h" |
22 #include "chrome/installer/util/product.h" | 18 #include "chrome/installer/util/product.h" |
huangs
2017/01/03 07:26:05
Can Product be forward-declared? Not that .cc fil
| |
23 #include "chrome/installer/util/util_constants.h" | 19 #include "chrome/installer/util/util_constants.h" |
24 | 20 |
25 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
26 #include <windows.h> // NOLINT | 22 #include <windows.h> // NOLINT |
27 #endif | 23 #endif |
28 | 24 |
29 namespace base { | 25 namespace base { |
30 class CommandLine; | 26 class CommandLine; |
31 } | 27 } |
32 | 28 |
33 namespace installer { | 29 namespace installer { |
34 | 30 |
35 class InstallationState; | 31 class InstallationState; |
36 class MasterPreferences; | 32 class MasterPreferences; |
37 | 33 |
38 class ProductState; | 34 class ProductState; |
39 | 35 |
40 typedef std::vector<Product*> Products; | 36 // Encapsulates the state of the current installation operation. This class |
41 | 37 // interprets the command-line arguments and master preferences and determines |
42 // Encapsulates the state of the current installation operation. Only valid | 38 // the operations to be performed. |
43 // for installs and upgrades (not for uninstalls or non-install commands). | |
44 // This class interprets the command-line arguments and master preferences and | |
45 // determines the operations to be performed. For example, the Chrome Binaries | |
46 // are automatically added if required in multi-install mode. | |
47 // TODO(erikwright): This is now used a fair bit during uninstall, and | |
48 // InstallerState::Initialize() contains a lot of code for uninstall. The class | |
49 // comment should probably be updated. | |
50 // TODO(grt): Rename to InstallerEngine/Conductor or somesuch? | |
51 class InstallerState { | 39 class InstallerState { |
52 public: | 40 public: |
53 enum Level { | 41 enum Level { |
54 UNKNOWN_LEVEL, | 42 UNKNOWN_LEVEL, |
55 USER_LEVEL, | 43 USER_LEVEL, |
56 SYSTEM_LEVEL | 44 SYSTEM_LEVEL |
57 }; | 45 }; |
58 | 46 |
59 enum PackageType { | |
60 UNKNOWN_PACKAGE_TYPE, | |
61 SINGLE_PACKAGE, | |
62 MULTI_PACKAGE | |
63 }; | |
64 | |
65 enum Operation { | 47 enum Operation { |
66 UNINITIALIZED, | 48 UNINITIALIZED, |
67 SINGLE_INSTALL_OR_UPDATE, | 49 SINGLE_INSTALL_OR_UPDATE, |
68 MULTI_INSTALL, | |
69 MULTI_UPDATE, | |
70 UNINSTALL | 50 UNINSTALL |
71 }; | 51 }; |
72 | 52 |
73 // Constructs an uninitialized instance; see Initialize(). | 53 // Constructs an uninitialized instance; see Initialize(). |
74 InstallerState(); | 54 InstallerState(); |
75 | 55 |
76 // Constructs an initialized but empty instance. | 56 // Constructs an initialized but empty instance. |
77 explicit InstallerState(Level level); | 57 explicit InstallerState(Level level); |
78 | 58 |
79 ~InstallerState(); | 59 ~InstallerState(); |
80 | 60 |
81 // Initializes this object based on the current operation. | 61 // Initializes this object based on the current operation. |
82 void Initialize(const base::CommandLine& command_line, | 62 void Initialize(const base::CommandLine& command_line, |
83 const MasterPreferences& prefs, | 63 const MasterPreferences& prefs, |
84 const InstallationState& machine_state); | 64 const InstallationState& machine_state); |
85 | 65 |
86 // Adds a product constructed on the basis of |state|, setting this object's | 66 // Adds a product constructed on the basis of |state|, setting this object's |
87 // msi flag if |state| is msi-installed. Returns the product that was added, | 67 // msi flag if |state| is msi-installed. Returns the product that was added, |
88 // or NULL if |state| is incompatible with this object. Ownership is not | 68 // or NULL if |state| is incompatible with this object. Ownership is not |
89 // passed to the caller. | 69 // passed to the caller. |
90 Product* AddProductFromState(BrowserDistribution::Type type, | 70 Product* AddProductFromState(BrowserDistribution::Type type, |
91 const ProductState& state); | 71 const ProductState& state); |
92 | 72 |
93 // Returns the product that was added, or NULL if |product| is incompatible | 73 // Returns the product that was added, or NULL if |product| is incompatible |
94 // with this object. Ownership of |product| is taken by this object, while | 74 // with this object. Ownership of |product| is taken by this object, while |
95 // ownership of the return value is not passed to the caller. | 75 // ownership of the return value is not passed to the caller. |
96 Product* AddProduct(std::unique_ptr<Product>* product); | 76 Product* AddProduct(std::unique_ptr<Product>* product); |
97 | 77 |
98 // Removes |product| from the set of products to be operated on. The object | |
99 // pointed to by |product| is freed. Returns false if |product| is not | |
100 // present in the set. | |
101 bool RemoveProduct(const Product* product); | |
102 | |
103 // The level (user or system) of this operation. | 78 // The level (user or system) of this operation. |
104 Level level() const { return level_; } | 79 Level level() const { return level_; } |
105 | 80 |
106 // The package type (single or multi) of this operation. | |
107 PackageType package_type() const { return package_type_; } | |
108 | |
109 // An identifier of this operation. | 81 // An identifier of this operation. |
110 Operation operation() const { return operation_; } | 82 Operation operation() const { return operation_; } |
111 | 83 |
112 // A convenience method returning level() == SYSTEM_LEVEL. | 84 // A convenience method returning level() == SYSTEM_LEVEL. |
113 bool system_install() const; | 85 bool system_install() const; |
114 | 86 |
115 // A convenience method returning package_type() == MULTI_PACKAGE. | |
116 bool is_multi_install() const; | |
117 | |
118 // The full path to the place where the operand resides. | 87 // The full path to the place where the operand resides. |
119 const base::FilePath& target_path() const { return target_path_; } | 88 const base::FilePath& target_path() const { return target_path_; } |
120 | 89 |
121 // Sets the value returned by target_path(). | 90 // Sets the value returned by target_path(). |
122 void set_target_path_for_testing(const base::FilePath& target_path) { | 91 void set_target_path_for_testing(const base::FilePath& target_path) { |
123 target_path_ = target_path; | 92 target_path_ = target_path; |
124 } | 93 } |
125 | 94 |
126 // True if the "msi" preference is set or if a product with the "msi" state | 95 // True if the "msi" preference is set or if a product with the "msi" state |
127 // flag is set is to be operated on. | 96 // flag is set is to be operated on. |
(...skipping 17 matching lines...) Expand all Loading... | |
145 const base::string16& state_key() const { return state_key_; } | 114 const base::string16& state_key() const { return state_key_; } |
146 | 115 |
147 // Convenience method to return the type of the BrowserDistribution associated | 116 // Convenience method to return the type of the BrowserDistribution associated |
148 // with the ClientState key we will be interacting with. | 117 // with the ClientState key we will be interacting with. |
149 BrowserDistribution::Type state_type() const { return state_type_; } | 118 BrowserDistribution::Type state_type() const { return state_type_; } |
150 | 119 |
151 // Returns true if this is an update of multi-install Chrome to | 120 // Returns true if this is an update of multi-install Chrome to |
152 // single-install. | 121 // single-install. |
153 bool is_migrating_to_single() const { return is_migrating_to_single_; } | 122 bool is_migrating_to_single() const { return is_migrating_to_single_; } |
154 | 123 |
155 // Returns the BrowserDistribution instance corresponding to the binaries for | 124 const Product& product() const { |
156 // this run if we're operating on a multi-package product. | 125 DCHECK(product_); |
157 BrowserDistribution* multi_package_binaries_distribution() const { | 126 return *product_; |
158 DCHECK(package_type_ == MULTI_PACKAGE); | |
159 DCHECK(multi_package_distribution_ != NULL); | |
160 return multi_package_distribution_; | |
161 } | 127 } |
162 | 128 |
163 const Products& products() const { return products_.get(); } | |
164 | |
165 // Returns the product of the desired type, or NULL if none found. | |
166 const Product* FindProduct(BrowserDistribution::Type distribution_type) const; | |
167 | |
168 // Returns the currently installed version in |target_path|, or NULL if no | 129 // Returns the currently installed version in |target_path|, or NULL if no |
169 // products are installed. Ownership is passed to the caller. | 130 // products are installed. Ownership is passed to the caller. |
170 base::Version* GetCurrentVersion( | 131 base::Version* GetCurrentVersion( |
171 const InstallationState& machine_state) const; | 132 const InstallationState& machine_state) const; |
172 | 133 |
173 // Returns the critical update version if all of the following are true: | 134 // Returns the critical update version if all of the following are true: |
174 // * --critical-update-version=CUV was specified on the command-line. | 135 // * --critical-update-version=CUV was specified on the command-line. |
175 // * current_version == NULL or current_version < CUV. | 136 // * current_version == NULL or current_version < CUV. |
176 // * new_version >= CUV. | 137 // * new_version >= CUV. |
177 // Otherwise, returns an invalid version. | 138 // Otherwise, returns an invalid version. |
178 base::Version DetermineCriticalVersion( | 139 base::Version DetermineCriticalVersion( |
179 const base::Version* current_version, | 140 const base::Version* current_version, |
180 const base::Version& new_version) const; | 141 const base::Version& new_version) const; |
181 | 142 |
182 // Returns whether or not there is currently a Chrome Frame instance running. | |
183 // Note that there isn't a mechanism to lock Chrome Frame in place, so Chrome | |
184 // Frame may either exit or start up after this is called. | |
185 bool IsChromeFrameRunning(const InstallationState& machine_state) const; | |
186 | |
187 // Returns true if any of the binaries from a multi-install Chrome Frame that | |
188 // has been migrated to single-install are still in use. | |
189 bool AreBinariesInUse(const InstallationState& machine_state) const; | |
190 | |
191 // Returns the path to the installer under Chrome version folder | 143 // Returns the path to the installer under Chrome version folder |
192 // (for example <target_path>\Google\Chrome\Application\<Version>\Installer) | 144 // (for example <target_path>\Google\Chrome\Application\<Version>\Installer) |
193 base::FilePath GetInstallerDirectory(const base::Version& version) const; | 145 base::FilePath GetInstallerDirectory(const base::Version& version) const; |
194 | 146 |
195 // Adds to |com_dll_list| the list of COM DLLs that are to be registered | |
196 // and/or unregistered. The list may be empty. | |
197 void AddComDllList(std::vector<base::FilePath>* com_dll_list) const; | |
198 | |
199 // Sets the current stage of processing. This reports a progress value to | 147 // Sets the current stage of processing. This reports a progress value to |
200 // Google Update for presentation to a user. | 148 // Google Update for presentation to a user. |
201 void SetStage(InstallerStage stage) const; | 149 void SetStage(InstallerStage stage) const; |
202 | 150 |
203 // For a MULTI_INSTALL or MULTI_UPDATE operation, updates the Google Update | 151 // Strips all evidence of multi-install from Chrome's "ap" value. |
204 // "ap" values for all products being operated on. | |
205 void UpdateChannels() const; | 152 void UpdateChannels() const; |
206 | 153 |
207 // Sets installer result information in the registry for consumption by Google | 154 // Sets installer result information in the registry for consumption by Google |
208 // Update. The InstallerResult value is set to 0 (SUCCESS) or 1 | 155 // Update. The InstallerResult value is set to 0 (SUCCESS) or 1 |
209 // (FAILED_CUSTOM_ERROR) depending on whether |status| maps to success or not. | 156 // (FAILED_CUSTOM_ERROR) depending on whether |status| maps to success or not. |
210 // |status| itself is written to the InstallerError value. | 157 // |status| itself is written to the InstallerError value. |
211 // |string_resource_id|, if non-zero, identifies a localized string written to | 158 // |string_resource_id|, if non-zero, identifies a localized string written to |
212 // the InstallerResultUIString value. |launch_cmd|, if non-NULL and | 159 // the InstallerResultUIString value. |launch_cmd|, if non-NULL and |
213 // non-empty, is written to the InstallerSuccessLaunchCmdLine value. | 160 // non-empty, is written to the InstallerSuccessLaunchCmdLine value. |
214 void WriteInstallerResult(InstallStatus status, | 161 void WriteInstallerResult(InstallStatus status, |
215 int string_resource_id, | 162 int string_resource_id, |
216 const base::string16* launch_cmd) const; | 163 const base::string16* launch_cmd) const; |
217 | 164 |
218 // Returns true if this install needs to register an Active Setup command. | 165 // Returns true if this install needs to register an Active Setup command. |
219 bool RequiresActiveSetup() const; | 166 bool RequiresActiveSetup() const; |
220 | 167 |
221 protected: | 168 protected: |
222 // Bits for the |file_bits| argument of AnyExistsAndIsInUse. | |
223 enum { | |
224 CHROME_DLL = 1 << 0, | |
225 CHROME_FRAME_DLL = 1 << 1, | |
226 CHROME_FRAME_HELPER_DLL = 1 << 2, | |
227 CHROME_FRAME_HELPER_EXE = 1 << 3, | |
228 NUM_BINARIES = 4 | |
229 }; | |
230 | |
231 // Returns true if |file| exists and cannot be opened for exclusive write | |
232 // access. | |
233 static bool IsFileInUse(const base::FilePath& file); | |
234 | |
235 // Clears the instance to an uninitialized state. | 169 // Clears the instance to an uninitialized state. |
236 void Clear(); | 170 void Clear(); |
237 | 171 |
238 // Returns true if any file corresponding to a bit in |file_bits| (from the | |
239 // enum above) for the currently installed version exists and is in use. | |
240 bool AnyExistsAndIsInUse(const InstallationState& machine_state, | |
241 uint32_t file_bits) const; | |
242 base::FilePath GetDefaultProductInstallPath(BrowserDistribution* dist) const; | |
243 bool CanAddProduct(const Product& product, | 172 bool CanAddProduct(const Product& product, |
244 const base::FilePath* product_dir) const; | 173 const base::FilePath* product_dir) const; |
245 Product* AddProductInDirectory(const base::FilePath* product_dir, | 174 Product* AddProductInDirectory(const base::FilePath* product_dir, |
246 std::unique_ptr<Product>* product); | 175 std::unique_ptr<Product>* product); |
247 Product* AddProductFromPreferences( | 176 Product* AddProductFromPreferences( |
248 BrowserDistribution::Type distribution_type, | 177 BrowserDistribution::Type distribution_type, |
249 const MasterPreferences& prefs, | 178 const MasterPreferences& prefs, |
250 const InstallationState& machine_state); | 179 const InstallationState& machine_state); |
251 bool IsMultiInstallUpdate(const MasterPreferences& prefs, | |
252 const InstallationState& machine_state); | |
253 | 180 |
254 // Sets this object's level and updates the root_key_ accordingly. | 181 // Sets this object's level and updates the root_key_ accordingly. |
255 void set_level(Level level); | 182 void set_level(Level level); |
256 | 183 |
257 // Sets this object's package type and updates the multi_package_distribution_ | |
258 // accordingly. | |
259 void set_package_type(PackageType type); | |
260 | |
261 Operation operation_; | 184 Operation operation_; |
262 base::FilePath target_path_; | 185 base::FilePath target_path_; |
263 base::string16 state_key_; | 186 base::string16 state_key_; |
264 BrowserDistribution::Type state_type_; | 187 BrowserDistribution::Type state_type_; |
265 ScopedVector<Product> products_; | 188 std::unique_ptr<Product> product_; |
266 BrowserDistribution* multi_package_distribution_; | |
267 base::Version critical_update_version_; | 189 base::Version critical_update_version_; |
268 ProgressCalculator progress_calculator_; | 190 ProgressCalculator progress_calculator_; |
269 Level level_; | 191 Level level_; |
270 PackageType package_type_; | |
271 #if defined(OS_WIN) | 192 #if defined(OS_WIN) |
huangs
2017/01/03 07:26:05
This #if seems redundant; or if it serves some wei
| |
272 HKEY root_key_; | 193 HKEY root_key_; |
273 #endif | 194 #endif |
274 bool msi_; | 195 bool msi_; |
275 bool background_mode_; | 196 bool background_mode_; |
276 bool verbose_logging_; | 197 bool verbose_logging_; |
277 bool is_migrating_to_single_; | 198 bool is_migrating_to_single_; |
278 | 199 |
279 private: | 200 private: |
280 DISALLOW_COPY_AND_ASSIGN(InstallerState); | 201 DISALLOW_COPY_AND_ASSIGN(InstallerState); |
281 }; // class InstallerState | 202 }; // class InstallerState |
282 | 203 |
283 } // namespace installer | 204 } // namespace installer |
284 | 205 |
285 #endif // CHROME_INSTALLER_SETUP_INSTALLER_STATE_H_ | 206 #endif // CHROME_INSTALLER_SETUP_INSTALLER_STATE_H_ |
OLD | NEW |