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 #include "chrome/installer/util/installation_state.h" | 5 #include "chrome/installer/util/installation_state.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/version.h" | 9 #include "base/version.h" |
10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
11 #include "chrome/installer/util/google_update_constants.h" | 11 #include "chrome/installer/util/google_update_constants.h" |
12 #include "chrome/installer/util/package_properties.h" | 12 #include "chrome/installer/util/install_util.h" |
13 | 13 |
14 namespace installer { | 14 namespace installer { |
15 | 15 |
16 ProductState::ProductState() { | 16 ProductState::ProductState() |
17 : uninstall_command_(CommandLine::NO_PROGRAM), | |
18 msi_(false), | |
19 multi_install_(false) { | |
17 } | 20 } |
18 | 21 |
19 void ProductState::Initialize(bool system_install, | 22 bool ProductState::Initialize(bool system_install, |
20 const std::wstring& version_key, | 23 BrowserDistribution::Type type) { |
21 const std::wstring& state_key) { | 24 return Initialize(system_install, |
25 BrowserDistribution::GetSpecificDistribution(type)); | |
26 } | |
27 | |
28 bool ProductState::Initialize(bool system_install, | |
29 BrowserDistribution* distribution) { | |
30 const std::wstring version_key(distribution->GetVersionKey()); | |
31 const std::wstring state_key(distribution->GetStateKey()); | |
22 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 32 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
23 base::win::RegKey key(root_key, version_key.c_str(), KEY_QUERY_VALUE); | 33 base::win::RegKey key(root_key, version_key.c_str(), KEY_QUERY_VALUE); |
24 std::wstring version_str; | 34 std::wstring version_str; |
25 if (key.ReadValue(google_update::kRegVersionField, &version_str) | 35 if (key.ReadValue(google_update::kRegVersionField, |
26 == ERROR_SUCCESS) { | 36 &version_str) == ERROR_SUCCESS) { |
27 version_.reset(Version::GetVersionFromString(WideToASCII(version_str))); | 37 version_.reset(Version::GetVersionFromString(WideToASCII(version_str))); |
28 if (version_.get() != NULL) { | 38 if (version_.get() != NULL) { |
29 // The product is installed. Check for the channel value (absent if not | 39 // The product is installed. |
30 // installed/managed by Google Update). | 40 if (key.ReadValue(google_update::kRegOldVersionField, &version_str) |
31 if ((key.Open(root_key, state_key.c_str(), KEY_QUERY_VALUE) != | 41 == ERROR_SUCCESS) { |
tommi (sloooow) - chröme
2011/01/24 19:39:39
missed this one
grt (UTC plus 2)
2011/01/25 03:09:40
Done.
| |
32 ERROR_SUCCESS) || !channel_.Initialize(key)) { | 42 old_version_.reset( |
33 channel_.set_value(std::wstring()); | 43 Version::GetVersionFromString(WideToASCII(version_str))); |
44 } else { | |
45 old_version_.reset(); | |
46 } | |
47 if (key.ReadValue(google_update::kRegRenameCmdField, | |
48 &rename_cmd_) != ERROR_SUCCESS) | |
49 rename_cmd_.clear(); | |
50 // Read from the ClientState key. | |
51 channel_.set_value(std::wstring()); | |
52 uninstall_command_ = CommandLine(CommandLine::NO_PROGRAM); | |
53 msi_ = false; | |
54 multi_install_ = false; | |
55 if (key.Open(root_key, state_key.c_str(), | |
56 KEY_QUERY_VALUE) == ERROR_SUCCESS) { | |
57 std::wstring setup_path; | |
58 std::wstring uninstall_arguments; | |
59 // "ap" will be absent if not managed by Google Update. | |
60 channel_.Initialize(key); | |
61 // "UninstallString" will be absent for the multi-installer package. | |
62 key.ReadValue(kUninstallStringField, &setup_path); | |
63 // "UninstallArguments" will be absent for the multi-installer package. | |
64 key.ReadValue(kUninstallArgumentsField, &uninstall_arguments); | |
65 InstallUtil::MakeUninstallCommand(setup_path, uninstall_arguments, | |
66 &uninstall_command_); | |
67 // "msi" may be absent, 0 or 1 | |
68 DWORD dw_value = 0; | |
69 msi_ = (key.ReadValueDW(google_update::kRegMSIField, | |
70 &dw_value) == ERROR_SUCCESS) && (dw_value != 0); | |
71 // Multi-install is implied or is derived from the command-line. | |
72 if (distribution->GetType() == BrowserDistribution::CHROME_BINARIES) { | |
73 multi_install_ = true; | |
74 } else { | |
75 multi_install_ = uninstall_command_.HasSwitch( | |
76 switches::kMultiInstall); | |
77 } | |
34 } | 78 } |
35 } | 79 } |
36 } else { | 80 } else { |
37 version_.reset(); | 81 version_.reset(); |
38 } | 82 } |
83 return version_.get() != NULL; | |
84 } | |
85 | |
86 FilePath ProductState::GetSetupPath() const { | |
87 return uninstall_command_.GetProgram(); | |
39 } | 88 } |
40 | 89 |
41 const Version& ProductState::version() const { | 90 const Version& ProductState::version() const { |
42 DCHECK(version_.get() != NULL); | 91 DCHECK(version_.get() != NULL); |
43 return *version_; | 92 return *version_; |
44 } | 93 } |
45 | 94 |
46 void ProductState::CopyFrom(const ProductState& other) { | 95 ProductState& ProductState::CopyFrom(const ProductState& other) { |
47 channel_.set_value(other.channel_.value()); | 96 channel_.set_value(other.channel_.value()); |
48 if (other.version_.get() == NULL) | 97 version_.reset(other.version_.get() == NULL ? NULL : other.version_->Clone()); |
49 version_.reset(); | 98 old_version_.reset( |
50 else | 99 other.old_version_.get() == NULL ? NULL : other.old_version_->Clone()); |
51 version_.reset(other.version_->Clone()); | 100 rename_cmd_ = other.rename_cmd_; |
101 uninstall_command_ = other.uninstall_command_; | |
102 msi_ = other.msi_; | |
103 multi_install_ = other.multi_install_; | |
104 | |
105 return *this; | |
52 } | 106 } |
53 | 107 |
54 InstallationState::InstallationState() { | 108 InstallationState::InstallationState() { |
55 } | 109 } |
56 | 110 |
57 // static | 111 // static |
58 int InstallationState::IndexFromDistType(BrowserDistribution::Type type) { | 112 int InstallationState::IndexFromDistType(BrowserDistribution::Type type) { |
59 COMPILE_ASSERT(BrowserDistribution::CHROME_BROWSER == CHROME_BROWSER_INDEX, | 113 COMPILE_ASSERT(BrowserDistribution::CHROME_BROWSER == CHROME_BROWSER_INDEX, |
60 unexpected_chrome_browser_distribution_value_); | 114 unexpected_chrome_browser_distribution_value_); |
61 COMPILE_ASSERT(BrowserDistribution::CHROME_FRAME == CHROME_FRAME_INDEX, | 115 COMPILE_ASSERT(BrowserDistribution::CHROME_FRAME == CHROME_FRAME_INDEX, |
62 unexpected_chrome_frame_distribution_value_); | 116 unexpected_chrome_frame_distribution_value_); |
117 COMPILE_ASSERT(BrowserDistribution::CHROME_BINARIES == CHROME_BINARIES_INDEX, | |
118 unexpected_chrome_frame_distribution_value_); | |
63 DCHECK(type == BrowserDistribution::CHROME_BROWSER || | 119 DCHECK(type == BrowserDistribution::CHROME_BROWSER || |
64 type == BrowserDistribution::CHROME_FRAME); | 120 type == BrowserDistribution::CHROME_FRAME || |
121 type == BrowserDistribution::CHROME_BINARIES); | |
65 return type; | 122 return type; |
66 } | 123 } |
67 | 124 |
68 void InstallationState::Initialize(const MasterPreferences& prefs) { | 125 void InstallationState::Initialize() { |
69 BrowserDistribution* distribution; | 126 BrowserDistribution* distribution; |
70 | 127 |
71 distribution = BrowserDistribution::GetSpecificDistribution( | 128 distribution = BrowserDistribution::GetSpecificDistribution( |
72 BrowserDistribution::CHROME_BROWSER, prefs); | 129 BrowserDistribution::CHROME_BROWSER); |
73 InitializeProduct(false, distribution, &user_products_[CHROME_BROWSER_INDEX]); | 130 user_products_[CHROME_BROWSER_INDEX].Initialize(false, distribution); |
74 InitializeProduct(true, distribution, | 131 system_products_[CHROME_BROWSER_INDEX].Initialize(true, distribution); |
75 &system_products_[CHROME_BROWSER_INDEX]); | |
76 | 132 |
77 distribution = BrowserDistribution::GetSpecificDistribution( | 133 distribution = BrowserDistribution::GetSpecificDistribution( |
78 BrowserDistribution::CHROME_FRAME, prefs); | 134 BrowserDistribution::CHROME_FRAME); |
79 InitializeProduct(false, distribution, &user_products_[CHROME_FRAME_INDEX]); | 135 user_products_[CHROME_FRAME_INDEX].Initialize(false, distribution); |
80 InitializeProduct(true, distribution, &system_products_[CHROME_FRAME_INDEX]); | 136 system_products_[CHROME_FRAME_INDEX].Initialize(true, distribution); |
81 | 137 |
82 ActivePackageProperties package_properties; | 138 distribution = BrowserDistribution::GetSpecificDistribution( |
83 InitializeMultiPackage(false, package_properties, | 139 BrowserDistribution::CHROME_BINARIES); |
84 &user_products_[MULTI_PACKAGE_INDEX]); | 140 user_products_[CHROME_BINARIES_INDEX].Initialize(false, distribution); |
85 InitializeMultiPackage(true, package_properties, | 141 system_products_[CHROME_BINARIES_INDEX].Initialize(true, distribution); |
86 &system_products_[MULTI_PACKAGE_INDEX]); | |
87 } | |
88 | |
89 // static | |
90 void InstallationState::InitializeProduct(bool system_install, | |
91 BrowserDistribution* distribution, | |
92 ProductState* product) { | |
93 product->Initialize(system_install, distribution->GetVersionKey(), | |
94 distribution->GetStateKey()); | |
95 } | |
96 | |
97 // static | |
98 void InstallationState::InitializeMultiPackage(bool system_install, | |
99 PackageProperties& properties, | |
100 ProductState* product) { | |
101 product->Initialize(system_install, properties.GetVersionKey(), | |
102 properties.GetStateKey()); | |
103 } | |
104 | |
105 const ProductState* InstallationState::GetMultiPackageState( | |
106 bool system_install) const { | |
107 const ProductState& product_state = | |
108 (system_install ? system_products_ : user_products_)[MULTI_PACKAGE_INDEX]; | |
109 return product_state.version_.get() == NULL ? NULL : &product_state; | |
110 } | 142 } |
111 | 143 |
112 const ProductState* InstallationState::GetProductState( | 144 const ProductState* InstallationState::GetProductState( |
113 bool system_install, | 145 bool system_install, |
114 BrowserDistribution::Type type) const { | 146 BrowserDistribution::Type type) const { |
115 const ProductState& product_state = (system_install ? system_products_ : | 147 const ProductState& product_state = (system_install ? system_products_ : |
116 user_products_)[IndexFromDistType(type)]; | 148 user_products_)[IndexFromDistType(type)]; |
117 return product_state.version_.get() == NULL ? NULL : &product_state; | 149 return product_state.version_.get() == NULL ? NULL : &product_state; |
118 } | 150 } |
119 | 151 |
120 } // namespace installer | 152 } // namespace installer |
OLD | NEW |