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/base_paths_win.h" |
16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
17 #include "base/environment.h" | 18 #include "base/environment.h" |
18 #include "base/files/file_util.h" | 19 #include "base/files/file_util.h" |
19 #include "base/logging.h" | 20 #include "base/logging.h" |
20 #include "base/memory/scoped_ptr.h" | 21 #include "base/memory/scoped_ptr.h" |
21 #include "base/numerics/safe_conversions.h" | 22 #include "base/numerics/safe_conversions.h" |
22 #include "base/path_service.h" | 23 #include "base/path_service.h" |
23 #include "base/process/launch.h" | 24 #include "base/process/launch.h" |
24 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
25 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 379 |
379 static const char kEnvProgramFilesPath[] = "CHROME_PROBED_PROGRAM_FILES_PATH"; | 380 static const char kEnvProgramFilesPath[] = "CHROME_PROBED_PROGRAM_FILES_PATH"; |
380 std::string env_program_files_path; | 381 std::string env_program_files_path; |
381 // Check environment variable to find program files path. | 382 // Check environment variable to find program files path. |
382 base::FilePath program_files_path; | 383 base::FilePath program_files_path; |
383 if (env->GetVar(kEnvProgramFilesPath, &env_program_files_path) && | 384 if (env->GetVar(kEnvProgramFilesPath, &env_program_files_path) && |
384 !env_program_files_path.empty()) { | 385 !env_program_files_path.empty()) { |
385 program_files_path = | 386 program_files_path = |
386 base::FilePath(base::UTF8ToWide(env_program_files_path)); | 387 base::FilePath(base::UTF8ToWide(env_program_files_path)); |
387 } else { | 388 } else { |
388 const int kProgramFilesKey = | 389 // We don't use PathService here so this can be used early in startup. |
| 390 // See http://crbug.com/564398. |
| 391 bool result = |
389 #if defined(_WIN64) | 392 #if defined(_WIN64) |
390 // TODO(wfh): Revise this when Chrome is/can be installed in the 64-bit | 393 // TODO(wfh): Revise this when Chrome is/can be installed in the 64-bit |
391 // program files directory. | 394 // program files directory. |
392 base::DIR_PROGRAM_FILESX86; | 395 GetProgramFilesX86(&program_files_path); |
393 #else | 396 #else |
394 base::DIR_PROGRAM_FILES; | 397 GetProgramFiles(&program_files_path); |
395 #endif | 398 #endif |
396 if (!PathService::Get(kProgramFilesKey, &program_files_path)) { | 399 if (!result) { |
397 NOTREACHED(); | 400 NOTREACHED(); |
398 return true; | 401 return true; |
399 } | 402 } |
400 env->SetVar(kEnvProgramFilesPath, | 403 env->SetVar(kEnvProgramFilesPath, |
401 base::WideToUTF8(program_files_path.value())); | 404 base::WideToUTF8(program_files_path.value())); |
402 } | 405 } |
403 | 406 |
404 // Return true if the program files path is not a case-insensitive prefix of | 407 // Return true if the program files path is not a case-insensitive prefix of |
405 // the exe path. | 408 // the exe path. |
406 if (exe_path.value().size() < program_files_path.value().size()) | 409 if (exe_path.value().size() < program_files_path.value().size()) |
(...skipping 14 matching lines...) Expand all Loading... |
421 } | 424 } |
422 | 425 |
423 bool CheckIsChromeSxSProcess() { | 426 bool CheckIsChromeSxSProcess() { |
424 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 427 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
425 CHECK(command_line); | 428 CHECK(command_line); |
426 | 429 |
427 if (command_line->HasSwitch(installer::switches::kChromeSxS)) | 430 if (command_line->HasSwitch(installer::switches::kChromeSxS)) |
428 return true; | 431 return true; |
429 | 432 |
430 // Also return true if we are running from Chrome SxS installed path. | 433 // Also return true if we are running from Chrome SxS installed path. |
431 base::FilePath exe_dir; | 434 // We don't use PathService here so that this can be used very early in |
432 PathService::Get(base::DIR_EXE, &exe_dir); | 435 // startup. See http://crbug.com/564398. |
| 436 base::FilePath exe_file; |
| 437 DCHECK(GetFileExe(&exe_file)); |
| 438 base::FilePath exe_dir = exe_file.DirName(); |
433 base::string16 chrome_sxs_dir(installer::kGoogleChromeInstallSubDir2); | 439 base::string16 chrome_sxs_dir(installer::kGoogleChromeInstallSubDir2); |
434 chrome_sxs_dir.append(installer::kSxSSuffix); | 440 chrome_sxs_dir.append(installer::kSxSSuffix); |
435 | 441 |
436 // This is SxS if current EXE is in or under (possibly multiple levels under) | 442 // This is SxS if current EXE is in or under (possibly multiple levels under) |
437 // |chrome_sxs_dir|\|installer::kInstallBinaryDir| | 443 // |chrome_sxs_dir|\|installer::kInstallBinaryDir| |
438 std::vector<base::FilePath::StringType> components; | 444 std::vector<base::FilePath::StringType> components; |
439 exe_dir.GetComponents(&components); | 445 exe_dir.GetComponents(&components); |
440 // We need at least 1 element in the array for the behavior of the following | 446 // We need at least 1 element in the array for the behavior of the following |
441 // loop to be defined. This should always be true, since we're splitting the | 447 // loop to be defined. This should always be true, since we're splitting the |
442 // path to our executable and one of the components will be the drive letter. | 448 // path to our executable and one of the components will be the drive letter. |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 // Open the program and see if it references the expected file. | 688 // Open the program and see if it references the expected file. |
683 base::File file; | 689 base::File file; |
684 BY_HANDLE_FILE_INFORMATION info = {}; | 690 BY_HANDLE_FILE_INFORMATION info = {}; |
685 | 691 |
686 return (OpenForInfo(path, &file) && | 692 return (OpenForInfo(path, &file) && |
687 GetInfo(file, &info) && | 693 GetInfo(file, &info) && |
688 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && | 694 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && |
689 info.nFileIndexHigh == file_info_.nFileIndexHigh && | 695 info.nFileIndexHigh == file_info_.nFileIndexHigh && |
690 info.nFileIndexLow == file_info_.nFileIndexLow); | 696 info.nFileIndexLow == file_info_.nFileIndexLow); |
691 } | 697 } |
OLD | NEW |