Chromium Code Reviews| 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 // See the corresponding header file for description of the functions in this | 5 // See the corresponding header file for description of the functions in this |
| 6 // file. | 6 // file. |
| 7 | 7 |
| 8 #include "chrome/installer/util/install_util.h" | 8 #include "chrome/installer/util/install_util.h" |
| 9 | 9 |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| 11 #include <shlobj.h> | 11 #include <shlobj.h> |
| 12 #include <shlwapi.h> | 12 #include <shlwapi.h> |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 | 15 |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/files/file_util.h" | 17 #include "base/files/file_util.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
| 20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 21 #include "base/process/launch.h" | 21 #include "base/process/launch.h" |
| 22 #include "base/strings/string16.h" | |
| 23 #include "base/strings/string_number_conversions.h" | |
| 24 #include "base/strings/string_split.h" | |
| 22 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 23 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 24 #include "base/sys_info.h" | 27 #include "base/sys_info.h" |
| 25 #include "base/values.h" | 28 #include "base/values.h" |
| 26 #include "base/version.h" | 29 #include "base/version.h" |
| 27 #include "base/win/metro.h" | 30 #include "base/win/metro.h" |
| 28 #include "base/win/registry.h" | 31 #include "base/win/registry.h" |
| 29 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
| 30 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 } else { | 124 } else { |
| 122 NOTREACHED() << "Unable to get default monitor"; | 125 NOTREACHED() << "Unable to get default monitor"; |
| 123 } | 126 } |
| 124 ::SetForegroundWindow(foreground_window); | 127 ::SetForegroundWindow(foreground_window); |
| 125 } | 128 } |
| 126 return foreground_window; | 129 return foreground_window; |
| 127 } | 130 } |
| 128 | 131 |
| 129 } // namespace | 132 } // namespace |
| 130 | 133 |
| 134 base::string16 InstallUtil::GetActiveSetupVersionFromExisting( | |
| 135 ActiveSetupVersionComponent component, | |
| 136 ActiveSetupVersionOperation operation, | |
| 137 int value, | |
| 138 const base::string16& existing_version) { | |
| 139 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.
| |
| 140 existing_version, L",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | |
| 141 | |
| 142 // If |existing_version| was empty or otherwise corrupted, turn it into a | |
| 143 // valid one. | |
| 144 if (version_components.size() != 4U) | |
| 145 version_components.assign(4U, L"0"); | |
| 146 | |
| 147 switch (operation) { | |
| 148 case SET: | |
| 149 version_components[component] = base::IntToString16(value); | |
| 150 break; | |
| 151 case BUMP: | |
| 152 int previous_value; | |
| 153 if (base::StringToInt(version_components[component], &previous_value)) { | |
| 154 version_components[component] = | |
| 155 base::IntToString16(previous_value + value); | |
| 156 } | |
| 157 break; | |
| 158 } | |
| 159 | |
| 160 return JoinString(version_components, L','); | |
| 161 } | |
| 162 | |
| 163 bool InstallUtil::UpdateActiveSetupVersion( | |
| 164 BrowserDistribution* dist, | |
| 165 ActiveSetupVersionComponent component, | |
| 166 ActiveSetupVersionOperation operation, | |
| 167 int value) { | |
| 168 base::string16 active_setup_reg(GetActiveSetupPath(dist)); | |
| 169 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.
| |
| 170 HKEY_LOCAL_MACHINE, active_setup_reg.c_str(), | |
| 171 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.
| |
| 172 if (!active_setup_key.Valid()) { | |
| 173 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
| |
| 174 return false; | |
| 175 } | |
| 176 | |
| 177 base::string16 existing_version; | |
| 178 if (active_setup_key.ReadValue(L"Version", | |
| 179 &existing_version) != ERROR_SUCCESS) { | |
| 180 VLOG(1) << "Unable to read Active Setup key to string."; | |
| 181 return false; | |
| 182 } | |
| 183 | |
| 184 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
| |
| 185 component, operation, value, existing_version); | |
| 186 | |
| 187 return active_setup_key.WriteValue(L"Version", updated_version.c_str()) == | |
| 188 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
| |
| 189 } | |
| 190 | |
| 131 base::string16 InstallUtil::GetActiveSetupPath(BrowserDistribution* dist) { | 191 base::string16 InstallUtil::GetActiveSetupPath(BrowserDistribution* dist) { |
| 132 static const wchar_t kInstalledComponentsPath[] = | 192 static const wchar_t kInstalledComponentsPath[] = |
| 133 L"Software\\Microsoft\\Active Setup\\Installed Components\\"; | 193 L"Software\\Microsoft\\Active Setup\\Installed Components\\"; |
| 134 return kInstalledComponentsPath + dist->GetActiveSetupGuid(); | 194 return kInstalledComponentsPath + dist->GetActiveSetupGuid(); |
| 135 } | 195 } |
| 136 | 196 |
| 137 void InstallUtil::TriggerActiveSetupCommand() { | 197 void InstallUtil::TriggerActiveSetupCommand() { |
| 138 base::string16 active_setup_reg( | 198 base::string16 active_setup_reg( |
| 139 GetActiveSetupPath(BrowserDistribution::GetDistribution())); | 199 GetActiveSetupPath(BrowserDistribution::GetDistribution())); |
| 140 base::win::RegKey active_setup_key( | 200 base::win::RegKey active_setup_key( |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 651 // Open the program and see if it references the expected file. | 711 // Open the program and see if it references the expected file. |
| 652 base::File file; | 712 base::File file; |
| 653 BY_HANDLE_FILE_INFORMATION info = {}; | 713 BY_HANDLE_FILE_INFORMATION info = {}; |
| 654 | 714 |
| 655 return (OpenForInfo(path, &file) && | 715 return (OpenForInfo(path, &file) && |
| 656 GetInfo(file, &info) && | 716 GetInfo(file, &info) && |
| 657 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && | 717 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && |
| 658 info.nFileIndexHigh == file_info_.nFileIndexHigh && | 718 info.nFileIndexHigh == file_info_.nFileIndexHigh && |
| 659 info.nFileIndexLow == file_info_.nFileIndexLow); | 719 info.nFileIndexLow == file_info_.nFileIndexLow); |
| 660 } | 720 } |
| OLD | NEW |