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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/common/chrome_constants_win_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/app/main_dll_loader_win.cc
diff --git a/chrome/app/main_dll_loader_win.cc b/chrome/app/main_dll_loader_win.cc
index 5ceed8fa4676fd1f6c67722cf734997190dab6f0..ef519e032342e258f514f77dd35bb0542b440d61 100644
--- a/chrome/app/main_dll_loader_win.cc
+++ b/chrome/app/main_dll_loader_win.cc
@@ -16,12 +16,14 @@
#include "base/base_switches.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/lazy_instance.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/path_service.h"
#include "base/strings/string16.h"
+#include "base/strings/string_piece.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/trace_event/trace_event.h"
@@ -40,7 +42,6 @@
#include "chrome/installer/util/google_update_constants.h"
#include "chrome/installer/util/google_update_settings.h"
#include "chrome/installer/util/install_util.h"
-#include "chrome/installer/util/module_util_win.h"
#include "chrome/installer/util/util_constants.h"
#include "content/public/app/sandbox_helper_win.h"
#include "content/public/common/content_switches.h"
@@ -73,6 +74,35 @@ bool ProcessTypeUsesMainDll(const std::string& process_type) {
return process_type.empty() || process_type == switches::kServiceProcess;
}
+// Indicates whether a file can be opened using the same flags that
+// ::LoadLibrary() uses to open modules.
+bool ModuleCanBeRead(const base::FilePath& file_path) {
+ return base::File(file_path, base::File::FLAG_OPEN | base::File::FLAG_READ)
+ .IsValid();
+}
+
+// Returns the full path to |module_name|. Both dev builds (where |module_name|
+// is in the current executable's directory) and proper installs (where
+// |module_name| is in a versioned sub-directory of the current executable's
+// directory) are suported. The identified file is not guaranteed to exist.
+base::FilePath GetModulePath(base::StringPiece16 module_name) {
+ base::FilePath exe_dir;
+ const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);
+ DCHECK(has_path);
+
+ // Look for the module in the current executable's directory and return the
+ // path if it can be read. This is the expected location of modules for dev
+ // builds.
+ const base::FilePath module_path = exe_dir.Append(module_name);
+ if (ModuleCanBeRead(module_path))
+ return module_path;
+
+ // Othwerwise, return the path to the module in a versioned sub-directory of
+ // the current executable's directory. This is the expected location of
+ // modules for proper installs.
+ return exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);
+}
+
} // namespace
//=============================================================================
@@ -98,7 +128,7 @@ HMODULE MainDllLoader::Load(base::FilePath* module) {
#endif
}
- *module = installer::GetModulePath(dll_name);
+ *module = GetModulePath(dll_name);
if (module->empty()) {
PLOG(ERROR) << "Cannot find module " << dll_name;
return nullptr;
« 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