Chromium Code Reviews| Index: chrome/installer/util/install_util.cc |
| diff --git a/chrome/installer/util/install_util.cc b/chrome/installer/util/install_util.cc |
| index f7dccea263c8bc2f0c43b040dd191b70324d294e..32c794d130069d3c11b837af1f1177eb6ab875b7 100644 |
| --- a/chrome/installer/util/install_util.cc |
| +++ b/chrome/installer/util/install_util.cc |
| @@ -19,6 +19,9 @@ |
| #include "base/memory/scoped_ptr.h" |
| #include "base/path_service.h" |
| #include "base/process/launch.h" |
| +#include "base/strings/string16.h" |
| +#include "base/strings/string_number_conversions.h" |
| +#include "base/strings/string_split.h" |
| #include "base/strings/string_util.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "base/sys_info.h" |
| @@ -128,6 +131,63 @@ HWND CreateUACForegroundWindow() { |
| } // namespace |
| +base::string16 InstallUtil::GetActiveSetupVersionFromExisting( |
| + ActiveSetupVersionComponent component, |
| + ActiveSetupVersionOperation operation, |
| + int value, |
| + const base::string16& existing_version) { |
| + std::vector<base::string16> version_components = base::SplitString( |
|
grt (UTC plus 2)
2015/07/01 15:59:14
#include <vector>
gab
2015/07/02 03:50:43
Done.
|
| + existing_version, L",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| + |
| + // If |existing_version| was empty or otherwise corrupted, turn it into a |
| + // valid one. |
| + if (version_components.size() != 4U) |
| + version_components.assign(4U, L"0"); |
| + |
| + switch (operation) { |
| + case SET: |
| + version_components[component] = base::IntToString16(value); |
| + break; |
| + case BUMP: |
| + int previous_value; |
| + if (base::StringToInt(version_components[component], &previous_value)) { |
| + version_components[component] = |
| + base::IntToString16(previous_value + value); |
| + } |
| + break; |
| + } |
| + |
| + return JoinString(version_components, L','); |
| +} |
| + |
| +bool InstallUtil::UpdateActiveSetupVersion( |
| + BrowserDistribution* dist, |
| + ActiveSetupVersionComponent component, |
| + ActiveSetupVersionOperation operation, |
| + int value) { |
| + base::string16 active_setup_reg(GetActiveSetupPath(dist)); |
| + base::win::RegKey active_setup_key( |
|
grt (UTC plus 2)
2015/07/01 15:59:14
this will create the key if it doesn't exist. i do
gab
2015/07/02 03:50:43
Done.
|
| + HKEY_LOCAL_MACHINE, active_setup_reg.c_str(), |
| + KEY_QUERY_VALUE | KEY_SET_VALUE | KEY_WOW64_32KEY); |
|
grt (UTC plus 2)
2015/07/01 15:59:14
AddActiveSetupWorkItems uses kWow64Default, so rem
gab
2015/07/02 03:50:43
Done.
|
| + if (!active_setup_key.Valid()) { |
| + VLOG(1) << "Active Setup key invalid."; |
|
grt (UTC plus 2)
2015/07/01 15:59:13
LOG(ERROR) here and line 180? if not, why?
gab
2015/07/02 03:50:43
I figured the callee already logs an error if this
|
| + return false; |
| + } |
| + |
| + base::string16 existing_version; |
| + if (active_setup_key.ReadValue(L"Version", |
| + &existing_version) != ERROR_SUCCESS) { |
| + VLOG(1) << "Unable to read Active Setup key to string."; |
| + return false; |
| + } |
| + |
| + base::string16 updated_version = GetActiveSetupVersionFromExisting( |
|
grt (UTC plus 2)
2015/07/01 15:59:14
if |existing_version| is somehow malformed such th
gab
2015/07/02 03:50:43
I thought about that too, not sure how to structur
|
| + component, operation, value, existing_version); |
| + |
| + return active_setup_key.WriteValue(L"Version", updated_version.c_str()) == |
| + ERROR_SUCCESS; |
|
grt (UTC plus 2)
2015/07/01 15:59:14
is this how git cl format does it? i think this sh
gab
2015/07/02 03:50:43
Yea this is git cl format (I agree with you but th
|
| +} |
| + |
| base::string16 InstallUtil::GetActiveSetupPath(BrowserDistribution* dist) { |
| static const wchar_t kInstalledComponentsPath[] = |
| L"Software\\Microsoft\\Active Setup\\Installed Components\\"; |