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

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

Issue 1436103005: Use PathService in installer::GetModulePath(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self-review. Created 5 years, 1 month 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 | « no previous file | no next file » | 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) 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 <windows.h>
6
7 #include "chrome/installer/util/module_util_win.h" 5 #include "chrome/installer/util/module_util_win.h"
8 6
7 #include "base/base_paths.h"
9 #include "base/file_version_info.h" 8 #include "base/file_version_info.h"
10 #include "base/files/file.h" 9 #include "base/files/file.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/path_service.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/version.h" 14 #include "base/version.h"
15 15
16 namespace installer { 16 namespace installer {
17 17
18 namespace { 18 namespace {
19 19
20 // Returns the directory in which the currently running executable resides.
21 base::FilePath GetExecutableDir() {
22 base::char16 path[MAX_PATH];
23 ::GetModuleFileNameW(nullptr, path, MAX_PATH);
24 return base::FilePath(path).DirName();
25 }
26
27 // Returns the version in the current module's version resource or the empty 20 // Returns the version in the current module's version resource or the empty
28 // string if none found. 21 // string if none found.
29 base::string16 GetCurrentModuleVersion() { 22 base::string16 GetCurrentModuleVersion() {
30 scoped_ptr<FileVersionInfo> file_version_info( 23 scoped_ptr<FileVersionInfo> file_version_info(
31 CREATE_FILE_VERSION_INFO_FOR_CURRENT_MODULE()); 24 CREATE_FILE_VERSION_INFO_FOR_CURRENT_MODULE());
32 if (file_version_info.get()) { 25 if (file_version_info.get()) {
33 base::string16 version_string(file_version_info->file_version()); 26 base::string16 version_string(file_version_info->file_version());
34 if (Version(base::UTF16ToASCII(version_string)).IsValid()) 27 if (base::Version(base::UTF16ToASCII(version_string)).IsValid())
35 return version_string; 28 return version_string;
36 } 29 }
37 return base::string16(); 30 return base::string16();
38 } 31 }
39 32
40 // Indicates whether a file can be opened using the same flags that 33 // Indicates whether a file can be opened using the same flags that
41 // ::LoadLibrary() uses to open modules. 34 // ::LoadLibrary() uses to open modules.
42 bool ModuleCanBeRead(const base::FilePath file_path) { 35 bool ModuleCanBeRead(const base::FilePath file_path) {
43 return base::File(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ) 36 return base::File(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ)
44 .IsValid(); 37 .IsValid();
45 } 38 }
46 39
47 } // namespace 40 } // namespace
48 41
49 base::FilePath GetModulePath(base::StringPiece16 module_name, 42 base::FilePath GetModulePath(base::StringPiece16 module_name,
50 base::string16* version) { 43 base::string16* version) {
51 DCHECK(version); 44 DCHECK(version);
52 45
53 base::FilePath module_dir = GetExecutableDir(); 46 base::FilePath module_dir;
47 if (!base::PathService::Get(base::DIR_EXE, &module_dir)) {
Peter Kasting 2015/11/16 21:39:00 Can this ever really fail? It seems like it shoul
fdoray 2015/11/16 22:01:36 It should never fail.
48 LOG(ERROR) << "Cannot get current executable directory.";
Peter Kasting 2015/11/16 21:39:00 We normally avoid logging statements unless you ha
fdoray 2015/11/16 22:01:36 Done.
49 return base::FilePath();
50 }
51
54 base::FilePath module = module_dir.Append(module_name); 52 base::FilePath module = module_dir.Append(module_name);
55 if (ModuleCanBeRead(module)) 53 if (ModuleCanBeRead(module))
56 return module; 54 return module;
57 55
58 base::string16 version_string(GetCurrentModuleVersion()); 56 base::string16 version_string(GetCurrentModuleVersion());
59 if (version_string.empty()) { 57 if (version_string.empty()) {
60 LOG(ERROR) << "No valid Chrome version found"; 58 LOG(ERROR) << "No valid Chrome version found";
61 return base::FilePath(); 59 return base::FilePath();
62 } 60 }
63 *version = version_string; 61 *version = version_string;
64 return module_dir.Append(version_string).Append(module_name); 62 return module_dir.Append(version_string).Append(module_name);
65 } 63 }
66 64
67 } // namespace installer 65 } // namespace installer
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698