OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_UTIL_INSTALLER_STATE_H_ | 5 #ifndef CHROME_INSTALLER_UTIL_INSTALLER_STATE_H_ |
6 #define CHROME_INSTALLER_UTIL_INSTALLER_STATE_H_ | 6 #define CHROME_INSTALLER_UTIL_INSTALLER_STATE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
10 | 11 |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/file_path.h" |
| 14 #include "base/logging.h" |
| 15 #include "base/scoped_vector.h" |
12 #include "chrome/installer/util/browser_distribution.h" | 16 #include "chrome/installer/util/browser_distribution.h" |
| 17 #include "chrome/installer/util/product.h" |
| 18 |
| 19 #if defined(OS_WIN) |
| 20 #include <windows.h> |
| 21 #endif |
| 22 |
| 23 class CommandLine; |
| 24 class Version; |
13 | 25 |
14 namespace installer { | 26 namespace installer { |
15 | 27 |
| 28 class ChannelInfo; |
16 class InstallationState; | 29 class InstallationState; |
17 class MasterPreferences; | 30 class MasterPreferences; |
18 | 31 |
| 32 class ProductState; |
| 33 |
| 34 typedef std::vector<Product*> Products; |
| 35 |
19 // Encapsulates the state of the current installation operation. Only valid | 36 // Encapsulates the state of the current installation operation. Only valid |
20 // for installs and upgrades (not for uninstalls or non-install commands) | 37 // for installs and upgrades (not for uninstalls or non-install commands). |
| 38 // TODO(grt): Rename to InstallerEngine/Conductor or somesuch? |
21 class InstallerState { | 39 class InstallerState { |
22 public: | 40 public: |
| 41 enum Level { |
| 42 UNKNOWN_LEVEL, |
| 43 USER_LEVEL, |
| 44 SYSTEM_LEVEL |
| 45 }; |
| 46 |
| 47 enum PackageType { |
| 48 UNKNOWN_PACKAGE_TYPE, |
| 49 SINGLE_PACKAGE, |
| 50 MULTI_PACKAGE |
| 51 }; |
| 52 |
23 enum Operation { | 53 enum Operation { |
24 UNINITIALIZED, | 54 UNINITIALIZED, |
25 SINGLE_INSTALL_OR_UPDATE, | 55 SINGLE_INSTALL_OR_UPDATE, |
26 MULTI_INSTALL, | 56 MULTI_INSTALL, |
27 MULTI_UPDATE, | 57 MULTI_UPDATE, |
| 58 UNINSTALL |
28 }; | 59 }; |
29 | 60 |
30 InstallerState(); | 61 InstallerState(); |
31 | 62 |
32 // Initializes |this| based on the current operation. | 63 // Initializes |this| based on the current operation. |
33 void Initialize(const MasterPreferences& prefs, | 64 void Initialize(const CommandLine& command_line, |
| 65 const MasterPreferences& prefs, |
34 const InstallationState& machine_state); | 66 const InstallationState& machine_state); |
35 | 67 |
36 // true if system-level, false if user-level. | 68 // Resets the collection of products and their associated state. |
37 bool system_install() const { return system_install_; } | 69 void ResetProducts(); |
| 70 |
| 71 // Returns the product that was added. Ownership is not passed to the caller. |
| 72 Product* AddProductFromState(BrowserDistribution::Type type, |
| 73 const ProductState& state); |
| 74 |
| 75 // Removes |product| from the set of products to be operated on. The object |
| 76 // pointed to by |product| is freed. Returns false if |product| is not |
| 77 // present in the set. |
| 78 bool RemoveProduct(const Product* product); |
| 79 |
| 80 Level level() const { return level_; } |
| 81 |
| 82 PackageType package_type() const { return package_type_; } |
| 83 |
| 84 // TODO(grt): Eradicate the bool in favor of the enum. |
| 85 bool system_install() const { return level_ == SYSTEM_LEVEL; } |
| 86 |
| 87 // TODO(grt): Eradicate the bool in favor of the enum. |
| 88 bool multi_install() const { return package_type_ == MULTI_PACKAGE; } |
| 89 |
| 90 // The full path to the place where the operand resides. |
| 91 const FilePath& target_path() const { return target_path_; } |
| 92 |
| 93 // True if the "msi" preference is set or if a product with the "msi" state |
| 94 // flag is set is to be operated on. |
| 95 bool msi() const { return msi_; } |
| 96 |
| 97 // True if the --verbose-logging command-line flag is set or if the |
| 98 // verbose_logging master preferences option is true. |
| 99 bool verbose_logging() const { return verbose_logging_; } |
| 100 |
| 101 #if defined(OS_WIN) |
| 102 HKEY root_key() const { return root_key_; } |
| 103 #endif |
38 | 104 |
39 Operation operation() const { return operation_; } | 105 Operation operation() const { return operation_; } |
40 | 106 |
41 // The ClientState key by which we interact with Google Update. | 107 // The ClientState key by which we interact with Google Update. |
42 const std::wstring& state_key() const { return state_key_; } | 108 const std::wstring& state_key() const { return state_key_; } |
43 | 109 |
| 110 // Returns the BrowserDistribution instance corresponding to the binaries for |
| 111 // this run if we're operating on a multi-package product. |
| 112 BrowserDistribution* multi_package_binaries_distribution() const { |
| 113 DCHECK(package_type_ == MULTI_PACKAGE); |
| 114 DCHECK(multi_package_distribution_ != NULL); |
| 115 return multi_package_distribution_; |
| 116 } |
| 117 |
| 118 const Products& products() const { return products_.get(); } |
| 119 |
| 120 // Returns the product of the desired type, or NULL if none found. |
| 121 const Product* FindProduct(BrowserDistribution::Type distribution_type) const; |
| 122 |
| 123 // Returns the currently installed version in |target_path|, or NULL if no |
| 124 // products are installed. Ownership is passed to the caller. |
| 125 Version* GetCurrentVersion(const InstallationState& machine_state) const; |
| 126 |
| 127 // Returns the path to the installer under Chrome version folder |
| 128 // (for example <target_path>\Google\Chrome\Application\<Version>\Installer) |
| 129 FilePath GetInstallerDirectory(const Version& version) const; |
| 130 |
| 131 void RemoveOldVersionDirectories(const Version& latest_version) const; |
| 132 |
| 133 // Adds to |com_dll_list| the list of COM DLLs that are to be registered |
| 134 // and/or unregistered. The list may be empty. |
| 135 void AddComDllList(std::vector<FilePath>* com_dll_list) const; |
| 136 |
| 137 bool SetChannelFlags(bool set, ChannelInfo* channel_info) const; |
| 138 |
44 protected: | 139 protected: |
| 140 const Product& AddProductFromPreferences( |
| 141 BrowserDistribution::Type distribution_type, |
| 142 const MasterPreferences& prefs, |
| 143 const InstallationState& machine_state); |
45 bool IsMultiInstallUpdate(const MasterPreferences& prefs, | 144 bool IsMultiInstallUpdate(const MasterPreferences& prefs, |
46 const InstallationState& machine_state); | 145 const InstallationState& machine_state); |
47 | 146 |
48 Operation operation_; | 147 Operation operation_; |
| 148 FilePath target_path_; |
49 std::wstring state_key_; | 149 std::wstring state_key_; |
50 bool system_install_; | 150 ScopedVector<Product> products_; |
| 151 BrowserDistribution* multi_package_distribution_; |
| 152 Level level_; |
| 153 PackageType package_type_; |
| 154 #if defined(OS_WIN) |
| 155 HKEY root_key_; |
| 156 #endif |
| 157 bool msi_; |
| 158 bool verbose_logging_; |
51 | 159 |
52 private: | 160 private: |
53 DISALLOW_COPY_AND_ASSIGN(InstallerState); | 161 DISALLOW_COPY_AND_ASSIGN(InstallerState); |
54 }; // class InstallerState | 162 }; // class InstallerState |
55 | 163 |
56 } // namespace installer | 164 } // namespace installer |
57 | 165 |
58 #endif // CHROME_INSTALLER_UTIL_INSTALLER_STATE_H_ | 166 #endif // CHROME_INSTALLER_UTIL_INSTALLER_STATE_H_ |
OLD | NEW |