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

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

Issue 2656443002: Use chrome::kChromeVersion in installer::GetModulePath(). (Closed)
Patch Set: rebase 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
« no previous file with comments | « chrome/installer/util/module_util_win.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/installer/util/module_util_win.h"
6
7 #include <memory>
8
9 #include "base/base_paths.h"
10 #include "base/file_version_info.h"
11 #include "base/files/file.h"
12 #include "base/logging.h"
13 #include "base/path_service.h"
14 #include "base/strings/string16.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "base/version.h"
17 #include "base/win/current_module.h"
18
19 namespace installer {
20
21 namespace {
22
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
34 // ::LoadLibrary() uses to open modules.
35 bool ModuleCanBeRead(const base::FilePath file_path) {
36 return base::File(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ)
37 .IsValid();
38 }
39
40 } // namespace
41
42 base::FilePath GetModulePath(base::StringPiece16 module_name) {
43 base::FilePath exe_dir;
44 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
45 DCHECK(has_path);
46
47 // 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
49 // builds.
50 const base::FilePath module_path = exe_dir.Append(module_name);
51 if (ModuleCanBeRead(module_path))
52 return module_path;
53
54 // 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
56 // modules for proper installs.
57 const base::string16 version = GetCurrentExecutableVersion();
58 DCHECK(!version.empty());
59 return exe_dir.Append(version).Append(module_name);
60 }
61
62 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/util/module_util_win.h ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698