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

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

Issue 2476573004: Use InstallDetails in installer_util. (Closed)
Patch Set: sync to position 450321 Created 3 years, 10 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 // 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 <memory>
15 #include <string>
16 #include <vector>
17
18 #include "base/command_line.h" 14 #include "base/command_line.h"
19 #include "base/environment.h"
20 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
21 #include "base/logging.h" 16 #include "base/logging.h"
22 #include "base/macros.h" 17 #include "base/macros.h"
23 #include "base/numerics/safe_conversions.h"
24 #include "base/path_service.h" 18 #include "base/path_service.h"
25 #include "base/process/launch.h" 19 #include "base/process/launch.h"
26 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
27 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
28 #include "base/sys_info.h" 22 #include "base/sys_info.h"
29 #include "base/values.h" 23 #include "base/values.h"
30 #include "base/version.h" 24 #include "base/version.h"
31 #include "base/win/registry.h" 25 #include "base/win/registry.h"
32 #include "base/win/windows_version.h" 26 #include "base/win/windows_version.h"
33 #include "chrome/common/chrome_constants.h" 27 #include "chrome/common/chrome_constants.h"
34 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
29 #include "chrome/install_static/install_details.h"
30 #include "chrome/install_static/install_modes.h"
35 #include "chrome/installer/util/browser_distribution.h" 31 #include "chrome/installer/util/browser_distribution.h"
36 #include "chrome/installer/util/google_update_constants.h" 32 #include "chrome/installer/util/google_update_constants.h"
37 #include "chrome/installer/util/installation_state.h" 33 #include "chrome/installer/util/installation_state.h"
38 #include "chrome/installer/util/l10n_string_util.h" 34 #include "chrome/installer/util/l10n_string_util.h"
39 #include "chrome/installer/util/util_constants.h" 35 #include "chrome/installer/util/util_constants.h"
40 #include "chrome/installer/util/work_item_list.h" 36 #include "chrome/installer/util/work_item_list.h"
41 37
42 using base::win::RegKey; 38 using base::win::RegKey;
43 using installer::ProductState; 39 using installer::ProductState;
44 40
45 namespace { 41 namespace {
46 42
47 const char kEnvProgramFilesPath[] = "CHROME_PROBED_PROGRAM_FILES_PATH";
48 const wchar_t kRegDowngradeVersion[] = L"DowngradeVersion"; 43 const wchar_t kRegDowngradeVersion[] = L"DowngradeVersion";
49 44
50 // Creates a zero-sized non-decorated foreground window that doesn't appear 45 // Creates a zero-sized non-decorated foreground window that doesn't appear
51 // in the taskbar. This is used as a parent window for calls to ShellExecuteEx 46 // in the taskbar. This is used as a parent window for calls to ShellExecuteEx
52 // in order for the UAC dialog to appear in the foreground and for focus 47 // in order for the UAC dialog to appear in the foreground and for focus
53 // to be returned to this process once the UAC task is dismissed. Returns 48 // to be returned to this process once the UAC task is dismissed. Returns
54 // NULL on failure, a handle to the UAC window on success. 49 // NULL on failure, a handle to the UAC window on success.
55 HWND CreateUACForegroundWindow() { 50 HWND CreateUACForegroundWindow() {
56 HWND foreground_window = ::CreateWindowEx(WS_EX_TOOLWINDOW, 51 HWND foreground_window = ::CreateWindowEx(WS_EX_TOOLWINDOW,
57 L"STATIC", 52 L"STATIC",
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 install_list->AddSetRegValueWorkItem( 264 install_list->AddSetRegValueWorkItem(
270 root, 265 root,
271 state_key, 266 state_key,
272 KEY_WOW64_32KEY, 267 KEY_WOW64_32KEY,
273 installer::kInstallerSuccessLaunchCmdLine, 268 installer::kInstallerSuccessLaunchCmdLine,
274 *launch_cmd, 269 *launch_cmd,
275 true); 270 true);
276 } 271 }
277 } 272 }
278 273
279 bool InstallUtil::IsPerUserInstall(const base::FilePath& exe_path) { 274 bool InstallUtil::IsPerUserInstall(const base::FilePath& exe_path) {
gab 2017/02/14 16:57:56 /* exe_path */
grt (UTC plus 2) 2017/02/14 21:04:24 Done.
280 std::unique_ptr<base::Environment> env(base::Environment::Create()); 275 return !install_static::InstallDetails::Get().system_level();
281 std::string env_program_files_path;
282 // Check environment variable to find program files path.
283 base::FilePath program_files_path;
284 if (env->GetVar(kEnvProgramFilesPath, &env_program_files_path) &&
285 !env_program_files_path.empty()) {
286 program_files_path =
287 base::FilePath(base::UTF8ToWide(env_program_files_path));
288 } else {
289 const int kProgramFilesKey =
290 #if defined(_WIN64)
291 // TODO(wfh): Revise this when Chrome is/can be installed in the 64-bit
292 // program files directory.
293 base::DIR_PROGRAM_FILESX86;
294 #else
295 base::DIR_PROGRAM_FILES;
296 #endif
297 if (!PathService::Get(kProgramFilesKey, &program_files_path)) {
298 NOTREACHED();
299 return true;
300 }
301 env->SetVar(kEnvProgramFilesPath,
302 base::WideToUTF8(program_files_path.value()));
303 }
304
305 // Return true if the program files path is not a case-insensitive prefix of
306 // the exe path.
307 if (exe_path.value().size() < program_files_path.value().size())
308 return true;
309 DWORD prefix_len =
310 base::saturated_cast<DWORD>(program_files_path.value().size());
311 return ::CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
312 exe_path.value().data(), prefix_len,
313 program_files_path.value().data(), prefix_len) !=
314 CSTR_EQUAL;
315 }
316
317 void InstallUtil::ResetIsPerUserInstallForTest() {
318 std::unique_ptr<base::Environment> env(base::Environment::Create());
319 env->UnSetVar(kEnvProgramFilesPath);
320 }
321
322 bool CheckIsChromeSxSProcess() {
323 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
324 CHECK(command_line);
325
326 if (command_line->HasSwitch(installer::switches::kChromeSxS))
327 return true;
328
329 // Also return true if we are running from Chrome SxS installed path.
330 base::FilePath exe_dir;
331 PathService::Get(base::DIR_EXE, &exe_dir);
332 base::string16 chrome_sxs_dir(installer::kGoogleChromeInstallSubDir2);
333 chrome_sxs_dir.append(installer::kSxSSuffix);
334
335 // This is SxS if current EXE is in or under (possibly multiple levels under)
336 // |chrome_sxs_dir|\|installer::kInstallBinaryDir|
337 std::vector<base::FilePath::StringType> components;
338 exe_dir.GetComponents(&components);
339 // We need at least 1 element in the array for the behavior of the following
340 // loop to be defined. This should always be true, since we're splitting the
341 // path to our executable and one of the components will be the drive letter.
342 DCHECK(!components.empty());
343 typedef std::vector<base::FilePath::StringType>::const_reverse_iterator
344 ComponentsIterator;
345 for (ComponentsIterator current = components.rbegin(), parent = current + 1;
346 parent != components.rend(); current = parent++) {
347 if (base::FilePath::CompareEqualIgnoreCase(
348 *current, installer::kInstallBinaryDir) &&
349 base::FilePath::CompareEqualIgnoreCase(*parent, chrome_sxs_dir)) {
350 return true;
351 }
352 }
353
354 return false;
355 } 276 }
356 277
357 bool InstallUtil::IsChromeSxSProcess() { 278 bool InstallUtil::IsChromeSxSProcess() {
358 static bool sxs = CheckIsChromeSxSProcess(); 279 #if defined(GOOGLE_CHROME_BUILD)
359 return sxs; 280 return install_static::InstallDetails::Get().install_mode_index() ==
281 install_static::CANARY_INDEX;
282 #else
283 return false;
284 #endif
360 } 285 }
361 286
362 // static 287 // static
363 bool InstallUtil::IsFirstRunSentinelPresent() { 288 bool InstallUtil::IsFirstRunSentinelPresent() {
364 // TODO(msw): Consolidate with first_run::internal::IsFirstRunSentinelPresent. 289 // TODO(msw): Consolidate with first_run::internal::IsFirstRunSentinelPresent.
365 base::FilePath user_data_dir; 290 base::FilePath user_data_dir;
366 return !PathService::Get(chrome::DIR_USER_DATA, &user_data_dir) || 291 return !PathService::Get(chrome::DIR_USER_DATA, &user_data_dir) ||
367 base::PathExists(user_data_dir.Append(chrome::kFirstRunSentinel)); 292 base::PathExists(user_data_dir.Append(chrome::kFirstRunSentinel));
368 } 293 }
369 294
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 // Open the program and see if it references the expected file. 547 // Open the program and see if it references the expected file.
623 base::File file; 548 base::File file;
624 BY_HANDLE_FILE_INFORMATION info = {}; 549 BY_HANDLE_FILE_INFORMATION info = {};
625 550
626 return (OpenForInfo(path, &file) && 551 return (OpenForInfo(path, &file) &&
627 GetInfo(file, &info) && 552 GetInfo(file, &info) &&
628 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && 553 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber &&
629 info.nFileIndexHigh == file_info_.nFileIndexHigh && 554 info.nFileIndexHigh == file_info_.nFileIndexHigh &&
630 info.nFileIndexLow == file_info_.nFileIndexLow); 555 info.nFileIndexLow == file_info_.nFileIndexLow);
631 } 556 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698