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

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

Issue 1231973002: Force restoration of Chrome's shortcuts when Active Setup kicks in in response to a major OS upgrad… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@a4_use_as_workitem
Patch Set: Created 5 years, 5 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
« no previous file with comments | « chrome/installer/util/install_util.h ('k') | chrome/installer/util/install_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // 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/string_number_conversions.h"
23 #include "base/strings/string_split.h"
22 #include "base/strings/string_util.h" 24 #include "base/strings/string_util.h"
23 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
24 #include "base/sys_info.h" 26 #include "base/sys_info.h"
25 #include "base/values.h" 27 #include "base/values.h"
26 #include "base/version.h" 28 #include "base/version.h"
27 #include "base/win/metro.h" 29 #include "base/win/metro.h"
28 #include "base/win/registry.h" 30 #include "base/win/registry.h"
31 #include "base/win/win_util.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"
35 #include "chrome/installer/util/app_registration_data.h"
32 #include "chrome/installer/util/browser_distribution.h" 36 #include "chrome/installer/util/browser_distribution.h"
33 #include "chrome/installer/util/google_update_constants.h" 37 #include "chrome/installer/util/google_update_constants.h"
34 #include "chrome/installer/util/helper.h" 38 #include "chrome/installer/util/helper.h"
35 #include "chrome/installer/util/installation_state.h" 39 #include "chrome/installer/util/installation_state.h"
36 #include "chrome/installer/util/l10n_string_util.h" 40 #include "chrome/installer/util/l10n_string_util.h"
41 #include "chrome/installer/util/update_active_setup_version_work_item.h"
37 #include "chrome/installer/util/util_constants.h" 42 #include "chrome/installer/util/util_constants.h"
38 #include "chrome/installer/util/work_item_list.h" 43 #include "chrome/installer/util/work_item_list.h"
39 44
40 using base::win::RegKey; 45 using base::win::RegKey;
41 using installer::ProductState; 46 using installer::ProductState;
42 47
43 namespace { 48 namespace {
44 49
45 const wchar_t kStageBinaryPatching[] = L"binary_patching"; 50 const wchar_t kStageBinaryPatching[] = L"binary_patching";
46 const wchar_t kStageBuilding[] = L"building"; 51 const wchar_t kStageBuilding[] = L"building";
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 160
156 base::LaunchOptions launch_options; 161 base::LaunchOptions launch_options;
157 if (base::win::IsMetroProcess()) 162 if (base::win::IsMetroProcess())
158 launch_options.force_breakaway_from_job_ = true; 163 launch_options.force_breakaway_from_job_ = true;
159 base::Process process = 164 base::Process process =
160 base::LaunchProcess(cmd.GetCommandLineString(), launch_options); 165 base::LaunchProcess(cmd.GetCommandLineString(), launch_options);
161 if (!process.IsValid()) 166 if (!process.IsValid())
162 PLOG(ERROR) << cmd.GetCommandLineString(); 167 PLOG(ERROR) << cmd.GetCommandLineString();
163 } 168 }
164 169
170 bool InstallUtil::UpdateLastOSUpgradeHandledByActiveSetup(
gab 2015/07/09 20:54:44 @grt: This duplicates a bit of logic from a few pl
171 BrowserDistribution* dist) {
172 static const wchar_t kLastOSUpgradeHandledRegName[] = L"LastOSUpgradeHandled";
173
174 // FIRST: Find out the value of the last OS upgrade handled, defaults to 0 if
175 // none was ever handled.
176 DWORD last_os_upgrade_handled = 0;
177
178 base::string16 last_upgrade_handled_key_path =
179 dist->GetAppRegistrationData().GetStateMediumKey();
180 last_upgrade_handled_key_path.push_back(L'\\');
181 last_upgrade_handled_key_path.append(kLastOSUpgradeHandledRegName);
182
183 base::string16 user_specific_value;
184 // This should never fail. If it does, the beacon will be written in the key's
185 // default value, which is okay since the majority case is likely a machine
186 // with a single user.
187 if (!base::win::GetUserSidString(&user_specific_value))
188 NOTREACHED();
189
190 base::win::RegKey last_upgrade_key;
191 if (last_upgrade_key.Open(
192 HKEY_LOCAL_MACHINE, last_upgrade_handled_key_path.c_str(),
193 KEY_WOW64_32KEY | KEY_QUERY_VALUE) == ERROR_SUCCESS) {
194 last_upgrade_key.ReadValueDW(user_specific_value.c_str(),
195 &last_os_upgrade_handled);
196 }
197
198 // SECOND: Find out the value of the latest OS upgrade registered in the
199 // Active Setup version (bumped on every major OS upgrade), defaults to 0 if
200 // no OS upgrade was ever encountered by this install.
201 DWORD latest_os_upgrade = 0;
grt (UTC plus 2) 2015/07/10 18:15:24 does this method always return false without updat
gab 2015/07/13 18:19:01 Tweaked the order and made sure it only ever retur
202
203 const base::string16 active_setup_key_path(GetActiveSetupPath(dist));
204
205 base::win::RegKey active_setup_key;
206 if (active_setup_key.Open(HKEY_LOCAL_MACHINE, active_setup_key_path.c_str(),
207 KEY_QUERY_VALUE) == ERROR_SUCCESS) {
208 base::string16 existing_version;
209 if (active_setup_key.ReadValue(L"Version",
210 &existing_version) == ERROR_SUCCESS) {
211 std::vector<base::string16> version_components =
212 base::SplitString(existing_version, L",", base::TRIM_WHITESPACE,
213 base::SPLIT_WANT_NONEMPTY);
214 unsigned latest_os_upgrade_uint = 0;
215 if (version_components.size() == 4U &&
216 base::StringToUint(
217 version_components[UpdateActiveSetupVersionWorkItem::
218 VersionComponent::OS_UPGRADES],
219 &latest_os_upgrade_uint)) {
220 latest_os_upgrade = static_cast<DWORD>(latest_os_upgrade_uint);
221 } else {
222 LOG(ERROR) << "Failed to parse OS_UPGRADES component of "
223 << existing_version;
224 }
225 }
226 }
227
228 // THIRD: Figure out whether the latest OS upgrade has been handled already.
229
230 if (last_os_upgrade_handled >= latest_os_upgrade) {
231 LOG_IF(ERROR, last_os_upgrade_handled > latest_os_upgrade)
232 << "Last OS upgrade handled is somehow ahead of the latest OS upgrade?";
233 VLOG_IF(1, last_os_upgrade_handled == latest_os_upgrade)
234 << "Latest OS upgrade already handled.";
235 return false;
236 }
237
238 // At this point |last_os_upgrade_handled < latest_os_upgrade| so,
239 // FOURTH: store the fact that the latest OS upgrade has been handled and
240 // return true for the caller to act accordingly.
241
242 if (last_upgrade_key.Create(
243 HKEY_LOCAL_MACHINE, last_upgrade_handled_key_path.c_str(),
244 KEY_WOW64_32KEY | KEY_SET_VALUE) != ERROR_SUCCESS ||
245 last_upgrade_key.WriteValue(user_specific_value.c_str(),
246 latest_os_upgrade) != ERROR_SUCCESS) {
247 LOG(ERROR) << "Failed to save latest_os_upgrade value ("
248 << latest_os_upgrade << ") to " << last_upgrade_handled_key_path;
249 }
250
251 return true;
252 }
253
165 bool InstallUtil::ExecuteExeAsAdmin(const base::CommandLine& cmd, 254 bool InstallUtil::ExecuteExeAsAdmin(const base::CommandLine& cmd,
166 DWORD* exit_code) { 255 DWORD* exit_code) {
167 base::FilePath::StringType program(cmd.GetProgram().value()); 256 base::FilePath::StringType program(cmd.GetProgram().value());
168 DCHECK(!program.empty()); 257 DCHECK(!program.empty());
169 DCHECK_NE(program[0], L'\"'); 258 DCHECK_NE(program[0], L'\"');
170 259
171 base::CommandLine::StringType params(cmd.GetCommandLineString()); 260 base::CommandLine::StringType params(cmd.GetCommandLineString());
172 if (params[0] == '"') { 261 if (params[0] == '"') {
173 DCHECK_EQ('"', params[program.length() + 1]); 262 DCHECK_EQ('"', params[program.length() + 1]);
174 DCHECK_EQ(program, params.substr(1, program.length())); 263 DCHECK_EQ(program, params.substr(1, program.length()));
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 // Open the program and see if it references the expected file. 740 // Open the program and see if it references the expected file.
652 base::File file; 741 base::File file;
653 BY_HANDLE_FILE_INFORMATION info = {}; 742 BY_HANDLE_FILE_INFORMATION info = {};
654 743
655 return (OpenForInfo(path, &file) && 744 return (OpenForInfo(path, &file) &&
656 GetInfo(file, &info) && 745 GetInfo(file, &info) &&
657 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && 746 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber &&
658 info.nFileIndexHigh == file_info_.nFileIndexHigh && 747 info.nFileIndexHigh == file_info_.nFileIndexHigh &&
659 info.nFileIndexLow == file_info_.nFileIndexLow); 748 info.nFileIndexLow == file_info_.nFileIndexLow);
660 } 749 }
OLDNEW
« no previous file with comments | « chrome/installer/util/install_util.h ('k') | chrome/installer/util/install_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698