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

Side by Side Diff: chrome/app/main_dll_loader_win.cc

Issue 1402353011: Expose a function to get the path to a DLL. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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 <windows.h> 5 #include <windows.h>
6 #include <shlwapi.h> 6 #include <shlwapi.h>
7 7
8 #include "chrome/app/main_dll_loader_win.h"
9
8 #include "base/base_paths.h" 10 #include "base/base_paths.h"
9 #include "base/base_switches.h" 11 #include "base/base_switches.h"
10 #include "base/command_line.h" 12 #include "base/command_line.h"
11 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
12 #include "base/environment.h" 14 #include "base/environment.h"
13 #include "base/file_version_info.h"
14 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
15 #include "base/logging.h" 16 #include "base/logging.h"
16 #include "base/memory/scoped_ptr.h" 17 #include "base/memory/scoped_ptr.h"
17 #include "base/path_service.h" 18 #include "base/path_service.h"
18 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
19 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
20 #include "base/strings/stringprintf.h" 21 #include "base/strings/stringprintf.h"
21 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
22 #include "base/trace_event/trace_event.h" 23 #include "base/trace_event/trace_event.h"
23 #include "base/version.h"
24 #include "base/win/scoped_handle.h" 24 #include "base/win/scoped_handle.h"
25 #include "base/win/windows_version.h" 25 #include "base/win/windows_version.h"
26 #include "chrome/app/chrome_crash_reporter_client.h" 26 #include "chrome/app/chrome_crash_reporter_client.h"
27 #include "chrome/app/chrome_watcher_client_win.h" 27 #include "chrome/app/chrome_watcher_client_win.h"
28 #include "chrome/app/chrome_watcher_command_line_win.h" 28 #include "chrome/app/chrome_watcher_command_line_win.h"
29 #include "chrome/app/client_util.h" 29 #include "chrome/app/client_util.h"
30 #include "chrome/app/image_pre_reader_win.h" 30 #include "chrome/app/image_pre_reader_win.h"
31 #include "chrome/app/kasko_client.h" 31 #include "chrome/app/kasko_client.h"
32 #include "chrome/chrome_watcher/chrome_watcher_main_api.h" 32 #include "chrome/chrome_watcher/chrome_watcher_main_api.h"
33 #include "chrome/common/chrome_constants.h" 33 #include "chrome/common/chrome_constants.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 GoogleUpdateSettings::UpdateDidRunState(false, system_level); 82 GoogleUpdateSettings::UpdateDidRunState(false, system_level);
83 } 83 }
84 84
85 bool InMetroMode() { 85 bool InMetroMode() {
86 return (wcsstr( 86 return (wcsstr(
87 ::GetCommandLineW(), L" -ServerName:DefaultBrowserServer") != nullptr); 87 ::GetCommandLineW(), L" -ServerName:DefaultBrowserServer") != nullptr);
88 } 88 }
89 89
90 typedef int (*InitMetro)(); 90 typedef int (*InitMetro)();
91 91
92 // Returns the directory in which the currently running executable resides.
93 base::FilePath GetExecutableDir() {
94 base::char16 path[MAX_PATH];
95 ::GetModuleFileNameW(nullptr, path, MAX_PATH);
96 return base::FilePath(path).DirName();
97 }
98
99 } // namespace 92 } // namespace
100 93
101 base::string16 GetCurrentModuleVersion() {
102 scoped_ptr<FileVersionInfo> file_version_info(
103 CREATE_FILE_VERSION_INFO_FOR_CURRENT_MODULE());
104 if (file_version_info.get()) {
105 base::string16 version_string(file_version_info->file_version());
106 if (Version(base::UTF16ToASCII(version_string)).IsValid())
107 return version_string;
108 }
109 return base::string16();
110 }
111
112 //============================================================================= 94 //=============================================================================
113 95
114 MainDllLoader::MainDllLoader() 96 MainDllLoader::MainDllLoader()
115 : dll_(nullptr), metro_mode_(InMetroMode()) { 97 : dll_(nullptr), metro_mode_(InMetroMode()) {
116 } 98 }
117 99
118 MainDllLoader::~MainDllLoader() { 100 MainDllLoader::~MainDllLoader() {
119 } 101 }
120 102
121 // Loading chrome is an interesting affair. First we try loading from the 103 // Loading chrome is an interesting affair. First we try loading from the
122 // current directory to support run-what-you-compile and other development 104 // current directory to support run-what-you-compile and other development
123 // scenarios. 105 // scenarios.
124 // If that fails then we look at the version resource in the current 106 // If that fails then we look at the version resource in the current
125 // module. This is the expected path for chrome.exe browser instances in an 107 // module. This is the expected path for chrome.exe browser instances in an
126 // installed build. 108 // installed build.
127 HMODULE MainDllLoader::Load(base::string16* version, base::FilePath* module) { 109 HMODULE MainDllLoader::Load(base::string16* version, base::FilePath* module) {
128 const base::char16* dll_name = nullptr; 110 const base::char16* dll_name = nullptr;
129 if (metro_mode_) { 111 if (metro_mode_) {
130 dll_name = installer::kChromeMetroDll; 112 dll_name = installer::kChromeMetroDll;
131 } else if (process_type_ == "service" || process_type_.empty()) { 113 } else if (process_type_ == "service" || process_type_.empty()) {
132 dll_name = installer::kChromeDll; 114 dll_name = installer::kChromeDll;
133 } else if (process_type_ == "watcher") { 115 } else if (process_type_ == "watcher") {
134 dll_name = kChromeWatcherDll; 116 dll_name = kChromeWatcherDll;
135 } else { 117 } else {
136 #if defined(CHROME_MULTIPLE_DLL) 118 #if defined(CHROME_MULTIPLE_DLL)
137 dll_name = installer::kChromeChildDll; 119 dll_name = installer::kChromeChildDll;
138 #else 120 #else
139 dll_name = installer::kChromeDll; 121 dll_name = installer::kChromeDll;
140 #endif 122 #endif
141 } 123 }
142 124
125 *module = GetModulePath(dll_name, version);
126 if (module->empty()) {
127 PLOG(ERROR) << "Cannot find module " << dll_name;
128 return nullptr;
129 }
143 const bool pre_read = !metro_mode_; 130 const bool pre_read = !metro_mode_;
144 base::FilePath module_dir = GetExecutableDir();
145 *module = module_dir.Append(dll_name);
146 HMODULE dll = LoadModuleWithDirectory(*module, pre_read); 131 HMODULE dll = LoadModuleWithDirectory(*module, pre_read);
147 if (!dll) { 132 if (!dll) {
148 base::string16 version_string(GetCurrentModuleVersion()); 133 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value();
149 if (version_string.empty()) { 134 return nullptr;
150 LOG(ERROR) << "No valid Chrome version found";
151 return nullptr;
152 }
153 *version = version_string;
154 *module = module_dir.Append(version_string).Append(dll_name);
155 dll = LoadModuleWithDirectory(*module, pre_read);
156 if (!dll) {
157 PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value();
158 return nullptr;
159 }
160 } 135 }
161 136
162 DCHECK(dll); 137 DCHECK(dll);
163 return dll; 138 return dll;
164 } 139 }
165 140
166 // Launching is a matter of loading the right dll, setting the CHROME_VERSION 141 // Launching is a matter of loading the right dll, setting the CHROME_VERSION
167 // environment variable and just calling the entry point. Derived classes can 142 // environment variable and just calling the entry point. Derived classes can
168 // add custom code in the OnBeforeLaunch callback. 143 // add custom code in the OnBeforeLaunch callback.
169 int MainDllLoader::Launch(HINSTANCE instance) { 144 int MainDllLoader::Launch(HINSTANCE instance) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 } 342 }
368 }; 343 };
369 344
370 MainDllLoader* MakeMainDllLoader() { 345 MainDllLoader* MakeMainDllLoader() {
371 #if defined(GOOGLE_CHROME_BUILD) 346 #if defined(GOOGLE_CHROME_BUILD)
372 return new ChromeDllLoader(); 347 return new ChromeDllLoader();
373 #else 348 #else
374 return new ChromiumDllLoader(); 349 return new ChromiumDllLoader();
375 #endif 350 #endif
376 } 351 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698