| 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" |
| 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 the return value is not given to the caller. |
| 95 // ownership of the return value is not passed to the caller. | 75 Product* AddProduct(std::unique_ptr<Product> product); |
| 96 Product* AddProduct(std::unique_ptr<Product>* product); | |
| 97 | |
| 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 | 76 |
| 103 // The level (user or system) of this operation. | 77 // The level (user or system) of this operation. |
| 104 Level level() const { return level_; } | 78 Level level() const { return level_; } |
| 105 | 79 |
| 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. | 80 // An identifier of this operation. |
| 110 Operation operation() const { return operation_; } | 81 Operation operation() const { return operation_; } |
| 111 | 82 |
| 112 // A convenience method returning level() == SYSTEM_LEVEL. | 83 // A convenience method returning level() == SYSTEM_LEVEL. |
| 113 bool system_install() const; | 84 bool system_install() const; |
| 114 | 85 |
| 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. | 86 // The full path to the place where the operand resides. |
| 119 const base::FilePath& target_path() const { return target_path_; } | 87 const base::FilePath& target_path() const { return target_path_; } |
| 120 | 88 |
| 121 // Sets the value returned by target_path(). | 89 // Sets the value returned by target_path(). |
| 122 void set_target_path_for_testing(const base::FilePath& target_path) { | 90 void set_target_path_for_testing(const base::FilePath& target_path) { |
| 123 target_path_ = target_path; | 91 target_path_ = target_path; |
| 124 } | 92 } |
| 125 | 93 |
| 126 // True if the "msi" preference is set or if a product with the "msi" state | 94 // True if the "msi" preference is set or if a product with the "msi" state |
| 127 // flag is set is to be operated on. | 95 // 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_; } | 113 const base::string16& state_key() const { return state_key_; } |
| 146 | 114 |
| 147 // Convenience method to return the type of the BrowserDistribution associated | 115 // Convenience method to return the type of the BrowserDistribution associated |
| 148 // with the ClientState key we will be interacting with. | 116 // with the ClientState key we will be interacting with. |
| 149 BrowserDistribution::Type state_type() const { return state_type_; } | 117 BrowserDistribution::Type state_type() const { return state_type_; } |
| 150 | 118 |
| 151 // Returns true if this is an update of multi-install Chrome to | 119 // Returns true if this is an update of multi-install Chrome to |
| 152 // single-install. | 120 // single-install. |
| 153 bool is_migrating_to_single() const { return is_migrating_to_single_; } | 121 bool is_migrating_to_single() const { return is_migrating_to_single_; } |
| 154 | 122 |
| 155 // Returns the BrowserDistribution instance corresponding to the binaries for | 123 const Product& product() const { |
| 156 // this run if we're operating on a multi-package product. | 124 DCHECK(product_); |
| 157 BrowserDistribution* multi_package_binaries_distribution() const { | 125 return *product_; |
| 158 DCHECK(package_type_ == MULTI_PACKAGE); | |
| 159 DCHECK(multi_package_distribution_ != NULL); | |
| 160 return multi_package_distribution_; | |
| 161 } | 126 } |
| 162 | 127 |
| 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 | 128 // Returns the currently installed version in |target_path|, or NULL if no |
| 169 // products are installed. Ownership is passed to the caller. | 129 // products are installed. Ownership is passed to the caller. |
| 170 base::Version* GetCurrentVersion( | 130 base::Version* GetCurrentVersion( |
| 171 const InstallationState& machine_state) const; | 131 const InstallationState& machine_state) const; |
| 172 | 132 |
| 173 // Returns the critical update version if all of the following are true: | 133 // Returns the critical update version if all of the following are true: |
| 174 // * --critical-update-version=CUV was specified on the command-line. | 134 // * --critical-update-version=CUV was specified on the command-line. |
| 175 // * current_version == NULL or current_version < CUV. | 135 // * current_version == NULL or current_version < CUV. |
| 176 // * new_version >= CUV. | 136 // * new_version >= CUV. |
| 177 // Otherwise, returns an invalid version. | 137 // Otherwise, returns an invalid version. |
| 178 base::Version DetermineCriticalVersion( | 138 base::Version DetermineCriticalVersion( |
| 179 const base::Version* current_version, | 139 const base::Version* current_version, |
| 180 const base::Version& new_version) const; | 140 const base::Version& new_version) const; |
| 181 | 141 |
| 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 | 142 // Returns the path to the installer under Chrome version folder |
| 192 // (for example <target_path>\Google\Chrome\Application\<Version>\Installer) | 143 // (for example <target_path>\Google\Chrome\Application\<Version>\Installer) |
| 193 base::FilePath GetInstallerDirectory(const base::Version& version) const; | 144 base::FilePath GetInstallerDirectory(const base::Version& version) const; |
| 194 | 145 |
| 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 | 146 // Sets the current stage of processing. This reports a progress value to |
| 200 // Google Update for presentation to a user. | 147 // Google Update for presentation to a user. |
| 201 void SetStage(InstallerStage stage) const; | 148 void SetStage(InstallerStage stage) const; |
| 202 | 149 |
| 203 // For a MULTI_INSTALL or MULTI_UPDATE operation, updates the Google Update | 150 // Strips all evidence of multi-install from Chrome's "ap" value. |
| 204 // "ap" values for all products being operated on. | |
| 205 void UpdateChannels() const; | 151 void UpdateChannels() const; |
| 206 | 152 |
| 207 // Sets installer result information in the registry for consumption by Google | 153 // Sets installer result information in the registry for consumption by Google |
| 208 // Update. The InstallerResult value is set to 0 (SUCCESS) or 1 | 154 // Update. The InstallerResult value is set to 0 (SUCCESS) or 1 |
| 209 // (FAILED_CUSTOM_ERROR) depending on whether |status| maps to success or not. | 155 // (FAILED_CUSTOM_ERROR) depending on whether |status| maps to success or not. |
| 210 // |status| itself is written to the InstallerError value. | 156 // |status| itself is written to the InstallerError value. |
| 211 // |string_resource_id|, if non-zero, identifies a localized string written to | 157 // |string_resource_id|, if non-zero, identifies a localized string written to |
| 212 // the InstallerResultUIString value. |launch_cmd|, if non-NULL and | 158 // the InstallerResultUIString value. |launch_cmd|, if non-NULL and non-empty, |
| 213 // non-empty, is written to the InstallerSuccessLaunchCmdLine value. | 159 // is written to the InstallerSuccessLaunchCmdLine value. |
| 214 void WriteInstallerResult(InstallStatus status, | 160 void WriteInstallerResult(InstallStatus status, |
| 215 int string_resource_id, | 161 int string_resource_id, |
| 216 const base::string16* launch_cmd) const; | 162 const base::string16* launch_cmd) const; |
| 217 | 163 |
| 218 // Returns true if this install needs to register an Active Setup command. | 164 // Returns true if this install needs to register an Active Setup command. |
| 219 bool RequiresActiveSetup() const; | 165 bool RequiresActiveSetup() const; |
| 220 | 166 |
| 221 protected: | 167 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. | 168 // Clears the instance to an uninitialized state. |
| 236 void Clear(); | 169 void Clear(); |
| 237 | 170 |
| 238 // Returns true if any file corresponding to a bit in |file_bits| (from the | 171 bool CanAddProduct(const base::FilePath* product_dir) const; |
| 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, | |
| 244 const base::FilePath* product_dir) const; | |
| 245 Product* AddProductInDirectory(const base::FilePath* product_dir, | 172 Product* AddProductInDirectory(const base::FilePath* product_dir, |
| 246 std::unique_ptr<Product>* product); | 173 std::unique_ptr<Product> product); |
| 247 Product* AddProductFromPreferences( | 174 Product* AddProductFromPreferences( |
| 248 BrowserDistribution::Type distribution_type, | 175 BrowserDistribution::Type distribution_type, |
| 249 const MasterPreferences& prefs, | 176 const MasterPreferences& prefs, |
| 250 const InstallationState& machine_state); | 177 const InstallationState& machine_state); |
| 251 bool IsMultiInstallUpdate(const MasterPreferences& prefs, | |
| 252 const InstallationState& machine_state); | |
| 253 | 178 |
| 254 // Sets this object's level and updates the root_key_ accordingly. | 179 // Sets this object's level and updates the root_key_ accordingly. |
| 255 void set_level(Level level); | 180 void set_level(Level level); |
| 256 | 181 |
| 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_; | 182 Operation operation_; |
| 262 base::FilePath target_path_; | 183 base::FilePath target_path_; |
| 263 base::string16 state_key_; | 184 base::string16 state_key_; |
| 264 BrowserDistribution::Type state_type_; | 185 BrowserDistribution::Type state_type_; |
| 265 ScopedVector<Product> products_; | 186 std::unique_ptr<Product> product_; |
| 266 BrowserDistribution* multi_package_distribution_; | |
| 267 base::Version critical_update_version_; | 187 base::Version critical_update_version_; |
| 268 ProgressCalculator progress_calculator_; | 188 ProgressCalculator progress_calculator_; |
| 269 Level level_; | 189 Level level_; |
| 270 PackageType package_type_; | |
| 271 #if defined(OS_WIN) | 190 #if defined(OS_WIN) |
| 272 HKEY root_key_; | 191 HKEY root_key_; |
| 273 #endif | 192 #endif |
| 274 bool msi_; | 193 bool msi_; |
| 275 bool background_mode_; | 194 bool background_mode_; |
| 276 bool verbose_logging_; | 195 bool verbose_logging_; |
| 277 bool is_migrating_to_single_; | 196 bool is_migrating_to_single_; |
| 278 | 197 |
| 279 private: | 198 private: |
| 280 DISALLOW_COPY_AND_ASSIGN(InstallerState); | 199 DISALLOW_COPY_AND_ASSIGN(InstallerState); |
| 281 }; // class InstallerState | 200 }; // class InstallerState |
| 282 | 201 |
| 283 } // namespace installer | 202 } // namespace installer |
| 284 | 203 |
| 285 #endif // CHROME_INSTALLER_SETUP_INSTALLER_STATE_H_ | 204 #endif // CHROME_INSTALLER_SETUP_INSTALLER_STATE_H_ |
| OLD | NEW |