Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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 #include "chrome/installer/util/module_util_win.h" | 5 #include "chrome/installer/util/module_util_win.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 | |
| 9 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
| 10 #include "base/file_version_info.h" | |
| 11 #include "base/files/file.h" | 8 #include "base/files/file.h" |
| 12 #include "base/logging.h" | 9 #include "base/logging.h" |
| 13 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 14 #include "base/strings/string16.h" | 11 #include "chrome/common/chrome_constants.h" |
| 15 #include "base/strings/utf_string_conversions.h" | |
| 16 #include "base/version.h" | |
| 17 #include "base/win/current_module.h" | |
| 18 | 12 |
| 19 namespace installer { | 13 namespace installer { |
| 20 | 14 |
| 21 namespace { | 15 namespace { |
| 22 | 16 |
| 23 // Returns the version in the current executable's version resource. | |
| 24 base::string16 GetCurrentExecutableVersion() { | |
| 25 std::unique_ptr<FileVersionInfo> file_version_info( | |
| 26 FileVersionInfo::CreateFileVersionInfoForModule(CURRENT_MODULE())); | |
| 27 DCHECK(file_version_info.get()); | |
| 28 base::string16 version_string(file_version_info->file_version()); | |
| 29 DCHECK(base::Version(base::UTF16ToASCII(version_string)).IsValid()); | |
| 30 return version_string; | |
| 31 } | |
| 32 | |
| 33 // Indicates whether a file can be opened using the same flags that | 17 // Indicates whether a file can be opened using the same flags that |
| 34 // ::LoadLibrary() uses to open modules. | 18 // ::LoadLibrary() uses to open modules. |
| 35 bool ModuleCanBeRead(const base::FilePath file_path) { | 19 bool ModuleCanBeRead(const base::FilePath& file_path) { |
| 36 return base::File(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ) | 20 return base::File(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ) |
| 37 .IsValid(); | 21 .IsValid(); |
| 38 } | 22 } |
| 39 | 23 |
| 40 } // namespace | 24 } // namespace |
| 41 | 25 |
| 42 base::FilePath GetModulePath(base::StringPiece16 module_name) { | 26 base::FilePath GetModulePath(base::StringPiece16 module_name) { |
| 43 base::FilePath exe_dir; | 27 base::FilePath exe_dir; |
| 44 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir); | 28 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir); |
| 45 DCHECK(has_path); | 29 DCHECK(has_path); |
| 46 | 30 |
| 47 // Look for the module in the current executable's directory and return the | 31 // Look for the module in the current executable's directory and return the |
| 48 // path if it can be read. This is the expected location of modules for dev | 32 // path if it can be read. This is the expected location of modules for dev |
| 49 // builds. | 33 // builds. |
| 50 const base::FilePath module_path = exe_dir.Append(module_name); | 34 const base::FilePath module_path = exe_dir.Append(module_name); |
| 51 if (ModuleCanBeRead(module_path)) | 35 if (ModuleCanBeRead(module_path)) |
| 52 return module_path; | 36 return module_path; |
| 53 | 37 |
| 54 // Othwerwise, return the path to the module in a versioned sub-directory of | 38 // Othwerwise, return the path to the module in a versioned sub-directory of |
| 55 // the current executable's directory. This is the expected location of | 39 // the current executable's directory. This is the expected location of |
|
grt (UTC plus 2)
2017/01/24 09:37:16
"current executable" makes this a bit tricky. look
fdoray
2017/01/31 20:47:17
Done.
| |
| 56 // modules for proper installs. | 40 // modules for proper installs. |
| 57 const base::string16 version = GetCurrentExecutableVersion(); | 41 return exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name); |
| 58 DCHECK(!version.empty()); | |
| 59 return exe_dir.Append(version).Append(module_name); | |
| 60 } | 42 } |
| 61 | 43 |
| 62 } // namespace installer | 44 } // namespace installer |
| OLD | NEW |