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

Side by Side Diff: chrome/app/main_dll_loader_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 | « no previous file | chrome/common/chrome_constants_win_unittest.cc » ('j') | 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) 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 #include "chrome/app/main_dll_loader_win.h" 5 #include "chrome/app/main_dll_loader_win.h"
6 6
7 #include <windows.h> // NOLINT 7 #include <windows.h> // NOLINT
8 #include <shlwapi.h> // NOLINT 8 #include <shlwapi.h> // NOLINT
9 #include <stddef.h> 9 #include <stddef.h>
10 #include <stdint.h> 10 #include <stdint.h>
11 #include <userenv.h> // NOLINT 11 #include <userenv.h> // NOLINT
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "base/base_paths.h" 15 #include "base/base_paths.h"
16 #include "base/base_switches.h" 16 #include "base/base_switches.h"
17 #include "base/command_line.h" 17 #include "base/command_line.h"
18 #include "base/compiler_specific.h" 18 #include "base/compiler_specific.h"
19 #include "base/files/file.h"
19 #include "base/files/file_path.h" 20 #include "base/files/file_path.h"
20 #include "base/lazy_instance.h" 21 #include "base/lazy_instance.h"
21 #include "base/logging.h" 22 #include "base/logging.h"
22 #include "base/macros.h" 23 #include "base/macros.h"
23 #include "base/path_service.h" 24 #include "base/path_service.h"
24 #include "base/strings/string16.h" 25 #include "base/strings/string16.h"
26 #include "base/strings/string_piece.h"
25 #include "base/strings/string_util.h" 27 #include "base/strings/string_util.h"
26 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
27 #include "base/trace_event/trace_event.h" 29 #include "base/trace_event/trace_event.h"
28 #include "base/win/scoped_handle.h" 30 #include "base/win/scoped_handle.h"
29 #include "base/win/windows_version.h" 31 #include "base/win/windows_version.h"
30 #include "chrome/app/chrome_crash_reporter_client_win.h" 32 #include "chrome/app/chrome_crash_reporter_client_win.h"
31 #include "chrome/app/chrome_watcher_client_win.h" 33 #include "chrome/app/chrome_watcher_client_win.h"
32 #include "chrome/app/chrome_watcher_command_line_win.h" 34 #include "chrome/app/chrome_watcher_command_line_win.h"
33 #include "chrome/app/file_pre_reader_win.h" 35 #include "chrome/app/file_pre_reader_win.h"
34 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" 36 #include "chrome/chrome_watcher/chrome_watcher_main_api.h"
35 #include "chrome/common/chrome_constants.h" 37 #include "chrome/common/chrome_constants.h"
36 #include "chrome/common/chrome_paths.h" 38 #include "chrome/common/chrome_paths.h"
37 #include "chrome/common/chrome_result_codes.h" 39 #include "chrome/common/chrome_result_codes.h"
38 #include "chrome/common/chrome_switches.h" 40 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/metrics_constants_util_win.h" 41 #include "chrome/common/metrics_constants_util_win.h"
40 #include "chrome/installer/util/google_update_constants.h" 42 #include "chrome/installer/util/google_update_constants.h"
41 #include "chrome/installer/util/google_update_settings.h" 43 #include "chrome/installer/util/google_update_settings.h"
42 #include "chrome/installer/util/install_util.h" 44 #include "chrome/installer/util/install_util.h"
43 #include "chrome/installer/util/module_util_win.h"
44 #include "chrome/installer/util/util_constants.h" 45 #include "chrome/installer/util/util_constants.h"
45 #include "content/public/app/sandbox_helper_win.h" 46 #include "content/public/app/sandbox_helper_win.h"
46 #include "content/public/common/content_switches.h" 47 #include "content/public/common/content_switches.h"
47 #include "sandbox/win/src/sandbox.h" 48 #include "sandbox/win/src/sandbox.h"
48 49
49 namespace { 50 namespace {
50 // The entry point signature of chrome.dll. 51 // The entry point signature of chrome.dll.
51 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, int64_t); 52 typedef int (*DLL_MAIN)(HINSTANCE, sandbox::SandboxInterfaceInfo*, int64_t);
52 53
53 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)(); 54 typedef void (*RelaunchChromeBrowserWithNewCommandLineIfNeededFunc)();
(...skipping 12 matching lines...) Expand all
66 } 67 }
67 68
68 void ClearDidRun(const base::FilePath& dll_path) { 69 void ClearDidRun(const base::FilePath& dll_path) {
69 GoogleUpdateSettings::UpdateDidRunState(false); 70 GoogleUpdateSettings::UpdateDidRunState(false);
70 } 71 }
71 72
72 bool ProcessTypeUsesMainDll(const std::string& process_type) { 73 bool ProcessTypeUsesMainDll(const std::string& process_type) {
73 return process_type.empty() || process_type == switches::kServiceProcess; 74 return process_type.empty() || process_type == switches::kServiceProcess;
74 } 75 }
75 76
77 // Indicates whether a file can be opened using the same flags that
78 // ::LoadLibrary() uses to open modules.
79 bool ModuleCanBeRead(const base::FilePath& file_path) {
80 return base::File(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ)
81 .IsValid();
82 }
83
84 // Returns the full path to |module_name|. Both dev builds (where |module_name|
85 // is in the current executable's directory) and proper installs (where
86 // |module_name| is in a versioned sub-directory of the current executable's
87 // directory) are suported. The identified file is not guaranteed to exist.
88 base::FilePath GetModulePath(base::StringPiece16 module_name) {
89 base::FilePath exe_dir;
90 const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
91 DCHECK(has_path);
92
93 // Look for the module in the current executable's directory and return the
94 // path if it can be read. This is the expected location of modules for dev
95 // builds.
96 const base::FilePath module_path = exe_dir.Append(module_name);
97 if (ModuleCanBeRead(module_path))
98 return module_path;
99
100 // Othwerwise, return the path to the module in a versioned sub-directory of
101 // the current executable's directory. This is the expected location of
102 // modules for proper installs.
103 return exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
104 }
105
76 } // namespace 106 } // namespace
77 107
78 //============================================================================= 108 //=============================================================================
79 109
80 MainDllLoader::MainDllLoader() 110 MainDllLoader::MainDllLoader()
81 : dll_(nullptr) { 111 : dll_(nullptr) {
82 } 112 }
83 113
84 MainDllLoader::~MainDllLoader() { 114 MainDllLoader::~MainDllLoader() {
85 } 115 }
86 116
87 HMODULE MainDllLoader::Load(base::FilePath* module) { 117 HMODULE MainDllLoader::Load(base::FilePath* module) {
88 const base::char16* dll_name = nullptr; 118 const base::char16* dll_name = nullptr;
89 if (ProcessTypeUsesMainDll(process_type_)) { 119 if (ProcessTypeUsesMainDll(process_type_)) {
90 dll_name = installer::kChromeDll; 120 dll_name = installer::kChromeDll;
91 } else if (process_type_ == switches::kWatcherProcess) { 121 } else if (process_type_ == switches::kWatcherProcess) {
92 dll_name = kChromeWatcherDll; 122 dll_name = kChromeWatcherDll;
93 } else { 123 } else {
94 #if defined(CHROME_MULTIPLE_DLL) 124 #if defined(CHROME_MULTIPLE_DLL)
95 dll_name = installer::kChromeChildDll; 125 dll_name = installer::kChromeChildDll;
96 #else 126 #else
97 dll_name = installer::kChromeDll; 127 dll_name = installer::kChromeDll;
98 #endif 128 #endif
99 } 129 }
100 130
101 *module = installer::GetModulePath(dll_name); 131 *module = GetModulePath(dll_name);
102 if (module->empty()) { 132 if (module->empty()) {
103 PLOG(ERROR) << "Cannot find module " << dll_name; 133 PLOG(ERROR) << "Cannot find module " << dll_name;
104 return nullptr; 134 return nullptr;
105 } 135 }
106 HMODULE dll = LoadModuleWithDirectory(*module); 136 HMODULE dll = LoadModuleWithDirectory(*module);
107 if (!dll) { 137 if (!dll) {
108 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value(); 138 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value();
109 return nullptr; 139 return nullptr;
110 } 140 }
111 141
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } 286 }
257 }; 287 };
258 288
259 MainDllLoader* MakeMainDllLoader() { 289 MainDllLoader* MakeMainDllLoader() {
260 #if defined(GOOGLE_CHROME_BUILD) 290 #if defined(GOOGLE_CHROME_BUILD)
261 return new ChromeDllLoader(); 291 return new ChromeDllLoader();
262 #else 292 #else
263 return new ChromiumDllLoader(); 293 return new ChromiumDllLoader();
264 #endif 294 #endif
265 } 295 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/chrome_constants_win_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698