Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: chrome/installer/util/installation_state.cc

Issue 2618583005: Remove support for non-browser products from InstallationState and ProductState. (Closed)
Patch Set: sync to position 442664 Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 #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/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/version.h" 10 #include "base/version.h"
11 #include "base/win/registry.h" 11 #include "base/win/registry.h"
12 #include "chrome/installer/util/browser_distribution.h"
12 #include "chrome/installer/util/google_update_constants.h" 13 #include "chrome/installer/util/google_update_constants.h"
13 #include "chrome/installer/util/install_util.h" 14 #include "chrome/installer/util/install_util.h"
14 15
15 namespace installer { 16 namespace installer {
16 17
18 namespace {
19
20 // Initializes |commands| from the "Commands" subkey of |version_key|. Returns
21 // false if there is no "Commands" subkey or on error.
22 bool InitializeCommands(const base::win::RegKey& version_key,
23 AppCommands* commands) {
24 static const DWORD kAccess =
25 KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE | KEY_WOW64_32KEY;
26 base::win::RegKey commands_key;
27
28 if (commands_key.Open(version_key.Handle(), google_update::kRegCommandsKey,
29 kAccess) == ERROR_SUCCESS) {
30 return commands->Initialize(commands_key, KEY_WOW64_32KEY);
31 }
32 return false;
33 }
34
35 } // namespace
36
17 ProductState::ProductState() 37 ProductState::ProductState()
18 : uninstall_command_(base::CommandLine::NO_PROGRAM), 38 : uninstall_command_(base::CommandLine::NO_PROGRAM),
19 eula_accepted_(0), 39 eula_accepted_(0),
20 usagestats_(0), 40 usagestats_(0),
21 msi_(false), 41 msi_(false),
22 multi_install_(false), 42 multi_install_(false),
23 has_eula_accepted_(false), 43 has_eula_accepted_(false),
24 has_oem_install_(false), 44 has_oem_install_(false),
25 has_usagestats_(false) { 45 has_usagestats_(false) {
26 } 46 }
27 47
28 ProductState::~ProductState() { 48 ProductState::~ProductState() {
29 } 49 }
30 50
31 bool ProductState::Initialize(bool system_install, 51 bool ProductState::Initialize(bool system_install) {
32 BrowserDistribution::Type type) {
33 return Initialize(system_install,
34 BrowserDistribution::GetSpecificDistribution(type));
35 }
36
37 // Initializes |commands| from the "Commands" subkey of |version_key|.
38 // Returns false if there is no "Commands" subkey or on error.
39 // static
40 bool ProductState::InitializeCommands(const base::win::RegKey& version_key,
41 AppCommands* commands) {
42 static const DWORD kAccess =
43 KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE | KEY_WOW64_32KEY;
44 base::win::RegKey commands_key;
45
46 if (commands_key.Open(version_key.Handle(), google_update::kRegCommandsKey,
47 kAccess) == ERROR_SUCCESS)
48 return commands->Initialize(commands_key, KEY_WOW64_32KEY);
49 return false;
50 }
51
52 bool ProductState::Initialize(bool system_install,
53 BrowserDistribution* distribution) {
54 static const DWORD kAccess = KEY_QUERY_VALUE | KEY_WOW64_32KEY; 52 static const DWORD kAccess = KEY_QUERY_VALUE | KEY_WOW64_32KEY;
53 const BrowserDistribution* distribution =
54 BrowserDistribution::GetDistribution();
55 const std::wstring version_key(distribution->GetVersionKey()); 55 const std::wstring version_key(distribution->GetVersionKey());
56 const std::wstring state_key(distribution->GetStateKey()); 56 const std::wstring state_key(distribution->GetStateKey());
57 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; 57 const HKEY root_key = system_install ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
58 base::win::RegKey key; 58 base::win::RegKey key;
59 59
60 // Clear the runway. 60 // Clear the runway.
61 Clear(); 61 Clear();
62 62
63 // Read from the Clients key. 63 // Read from the Clients key.
64 if (key.Open(root_key, version_key.c_str(), kAccess) == ERROR_SUCCESS) { 64 if (key.Open(root_key, version_key.c_str(), kAccess) == ERROR_SUCCESS) {
(...skipping 23 matching lines...) Expand all
88 // Read from the ClientState key. 88 // Read from the ClientState key.
89 if (key.Open(root_key, state_key.c_str(), kAccess) == ERROR_SUCCESS) { 89 if (key.Open(root_key, state_key.c_str(), kAccess) == ERROR_SUCCESS) {
90 std::wstring setup_path; 90 std::wstring setup_path;
91 std::wstring uninstall_arguments; 91 std::wstring uninstall_arguments;
92 // "ap" will be absent if not managed by Google Update. 92 // "ap" will be absent if not managed by Google Update.
93 channel_.Initialize(key); 93 channel_.Initialize(key);
94 94
95 // Read in the brand code, it may be absent 95 // Read in the brand code, it may be absent
96 key.ReadValue(google_update::kRegBrandField, &brand_); 96 key.ReadValue(google_update::kRegBrandField, &brand_);
97 97
98 // "UninstallString" will be absent for the multi-installer package.
99 key.ReadValue(kUninstallStringField, &setup_path); 98 key.ReadValue(kUninstallStringField, &setup_path);
100 // "UninstallArguments" will be absent for the multi-installer package.
101 key.ReadValue(kUninstallArgumentsField, &uninstall_arguments); 99 key.ReadValue(kUninstallArgumentsField, &uninstall_arguments);
102 InstallUtil::ComposeCommandLine(setup_path, uninstall_arguments, 100 InstallUtil::ComposeCommandLine(setup_path, uninstall_arguments,
103 &uninstall_command_); 101 &uninstall_command_);
104 102
105 // "usagestats" may be absent, 0 (false), or 1 (true). On the chance that 103 // "usagestats" may be absent, 0 (false), or 1 (true). On the chance that
106 // different values are permitted in the future, we'll simply hold whatever 104 // different values are permitted in the future, we'll simply hold whatever
107 // we find. 105 // we find.
108 has_usagestats_ = (key.ReadValueDW(google_update::kRegUsageStatsField, 106 has_usagestats_ = (key.ReadValueDW(google_update::kRegUsageStatsField,
109 &usagestats_) == ERROR_SUCCESS); 107 &usagestats_) == ERROR_SUCCESS);
110 // "oeminstall" may be present with any value or absent. 108 // "oeminstall" may be present with any value or absent.
111 has_oem_install_ = (key.ReadValue(google_update::kRegOemInstallField, 109 has_oem_install_ = (key.ReadValue(google_update::kRegOemInstallField,
112 &oem_install_) == ERROR_SUCCESS); 110 &oem_install_) == ERROR_SUCCESS);
113 // "eulaaccepted" may be absent, 0 or 1. 111 // "eulaaccepted" may be absent, 0 or 1.
114 has_eula_accepted_ = (key.ReadValueDW(google_update::kRegEULAAceptedField, 112 has_eula_accepted_ = (key.ReadValueDW(google_update::kRegEULAAceptedField,
115 &eula_accepted_) == ERROR_SUCCESS); 113 &eula_accepted_) == ERROR_SUCCESS);
116 // "msi" may be absent, 0 or 1 114 // "msi" may be absent, 0 or 1
117 DWORD dw_value = 0; 115 DWORD dw_value = 0;
118 msi_ = (key.ReadValueDW(google_update::kRegMSIField, 116 msi_ = (key.ReadValueDW(google_update::kRegMSIField,
119 &dw_value) == ERROR_SUCCESS) && (dw_value != 0); 117 &dw_value) == ERROR_SUCCESS) && (dw_value != 0);
120 // Multi-install is implied or is derived from the command-line. 118 // Multi-install is a legacy option that is read for the sole purpose of
121 if (distribution->GetType() == BrowserDistribution::CHROME_BINARIES) 119 // migrating clients away from it.
122 multi_install_ = true; 120 multi_install_ = uninstall_command_.HasSwitch(switches::kMultiInstall);
123 else
124 multi_install_ = uninstall_command_.HasSwitch(switches::kMultiInstall);
125 } 121 }
126 122
127 // Read from the ClientStateMedium key. Values here override those in 123 // Read from the ClientStateMedium key. Values here override those in
128 // ClientState. 124 // ClientState.
129 if (system_install && 125 if (system_install &&
130 key.Open(root_key, distribution->GetStateMediumKey().c_str(), kAccess) == 126 key.Open(root_key, distribution->GetStateMediumKey().c_str(), kAccess) ==
131 ERROR_SUCCESS) { 127 ERROR_SUCCESS) {
132 DWORD dword_value = 0; 128 DWORD dword_value = 0;
133 129
134 if (key.ReadValueDW(google_update::kRegUsageStatsField, 130 if (key.ReadValueDW(google_update::kRegUsageStatsField,
135 &dword_value) == ERROR_SUCCESS) { 131 &dword_value) == ERROR_SUCCESS) {
136 has_usagestats_ = true; 132 has_usagestats_ = true;
137 usagestats_ = dword_value; 133 usagestats_ = dword_value;
138 } 134 }
139 135
140 if (key.ReadValueDW(google_update::kRegEULAAceptedField, 136 if (key.ReadValueDW(google_update::kRegEULAAceptedField,
141 &dword_value) == ERROR_SUCCESS) { 137 &dword_value) == ERROR_SUCCESS) {
142 has_eula_accepted_ = true; 138 has_eula_accepted_ = true;
143 eula_accepted_ = dword_value; 139 eula_accepted_ = dword_value;
144 } 140 }
145 } 141 }
146 142
147 return version_.get() != NULL; 143 return version_.get() != nullptr;
148 } 144 }
149 145
150 base::FilePath ProductState::GetSetupPath() const { 146 base::FilePath ProductState::GetSetupPath() const {
151 return uninstall_command_.GetProgram(); 147 return uninstall_command_.GetProgram();
152 } 148 }
153 149
154 const base::Version& ProductState::version() const { 150 const base::Version& ProductState::version() const {
155 DCHECK(version_.get() != NULL); 151 DCHECK(version_);
156 return *version_; 152 return *version_;
157 } 153 }
158 154
159 ProductState& ProductState::CopyFrom(const ProductState& other) { 155 ProductState& ProductState::CopyFrom(const ProductState& other) {
160 channel_.set_value(other.channel_.value()); 156 channel_.set_value(other.channel_.value());
161 version_.reset( 157 version_.reset(other.version_.get() ? new base::Version(*other.version_)
162 other.version_.get() ? new base::Version(*other.version_) : NULL); 158 : nullptr);
163 old_version_.reset( 159 old_version_.reset(other.old_version_.get()
164 other.old_version_.get() ? new base::Version(*other.old_version_) : NULL); 160 ? new base::Version(*other.old_version_)
161 : nullptr);
165 brand_ = other.brand_; 162 brand_ = other.brand_;
166 rename_cmd_ = other.rename_cmd_; 163 rename_cmd_ = other.rename_cmd_;
167 uninstall_command_ = other.uninstall_command_; 164 uninstall_command_ = other.uninstall_command_;
168 oem_install_ = other.oem_install_; 165 oem_install_ = other.oem_install_;
169 commands_.CopyFrom(other.commands_); 166 commands_.CopyFrom(other.commands_);
170 eula_accepted_ = other.eula_accepted_; 167 eula_accepted_ = other.eula_accepted_;
171 usagestats_ = other.usagestats_; 168 usagestats_ = other.usagestats_;
172 msi_ = other.msi_; 169 msi_ = other.msi_;
173 multi_install_ = other.multi_install_; 170 multi_install_ = other.multi_install_;
174 has_eula_accepted_ = other.has_eula_accepted_; 171 has_eula_accepted_ = other.has_eula_accepted_;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 210 }
214 211
215 bool ProductState::GetUsageStats(DWORD* usagestats) const { 212 bool ProductState::GetUsageStats(DWORD* usagestats) const {
216 DCHECK(usagestats); 213 DCHECK(usagestats);
217 if (!has_usagestats_) 214 if (!has_usagestats_)
218 return false; 215 return false;
219 *usagestats = usagestats_; 216 *usagestats = usagestats_;
220 return true; 217 return true;
221 } 218 }
222 219
223 InstallationState::InstallationState() { 220 InstallationState::InstallationState() {}
221
222 void InstallationState::Initialize() {
223 user_chrome_.Initialize(false);
224 system_chrome_.Initialize(true);
224 } 225 }
225 226
226 // static 227 const ProductState* InstallationState::GetProductState(
227 int InstallationState::IndexFromDistType(BrowserDistribution::Type type) { 228 bool system_install) const {
228 static_assert(BrowserDistribution::CHROME_BROWSER == CHROME_BROWSER_INDEX, 229 const ProductState* product_state =
229 "unexpected_chrome_browser_distribution_value_"); 230 GetNonVersionedProductState(system_install);
230 static_assert(BrowserDistribution::CHROME_FRAME == CHROME_FRAME_INDEX, 231 return product_state->version_.get() ? product_state : nullptr;
231 "unexpected_chrome_frame_distribution_value_");
232 static_assert(BrowserDistribution::CHROME_BINARIES == CHROME_BINARIES_INDEX,
233 "unexpected_chrome_frame_distribution_value_");
234 DCHECK(type == BrowserDistribution::CHROME_BROWSER ||
235 type == BrowserDistribution::CHROME_FRAME ||
236 type == BrowserDistribution::CHROME_BINARIES);
237 return type;
238 }
239
240 void InstallationState::Initialize() {
241 BrowserDistribution* distribution;
242
243 distribution = BrowserDistribution::GetSpecificDistribution(
244 BrowserDistribution::CHROME_BROWSER);
245 user_products_[CHROME_BROWSER_INDEX].Initialize(false, distribution);
246 system_products_[CHROME_BROWSER_INDEX].Initialize(true, distribution);
247
248 distribution = BrowserDistribution::GetSpecificDistribution(
249 BrowserDistribution::CHROME_FRAME);
250 user_products_[CHROME_FRAME_INDEX].Initialize(false, distribution);
251 system_products_[CHROME_FRAME_INDEX].Initialize(true, distribution);
252
253 distribution = BrowserDistribution::GetSpecificDistribution(
254 BrowserDistribution::CHROME_BINARIES);
255 user_products_[CHROME_BINARIES_INDEX].Initialize(false, distribution);
256 system_products_[CHROME_BINARIES_INDEX].Initialize(true, distribution);
257 } 232 }
258 233
259 const ProductState* InstallationState::GetNonVersionedProductState( 234 const ProductState* InstallationState::GetNonVersionedProductState(
260 bool system_install, 235 bool system_install) const {
261 BrowserDistribution::Type type) const { 236 return system_install ? &system_chrome_ : &user_chrome_;
262 const ProductState& product_state = (system_install ? system_products_ :
263 user_products_)[IndexFromDistType(type)];
264 return &product_state;
265 } 237 }
266 238
267 const ProductState* InstallationState::GetProductState(
268 bool system_install,
269 BrowserDistribution::Type type) const {
270 const ProductState* product_state =
271 GetNonVersionedProductState(system_install, type);
272 return product_state->version_.get() == NULL ? NULL : product_state;
273 }
274 } // namespace installer 239 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/installation_state.h ('k') | chrome/installer/util/product_state_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698