summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 23:55:45 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-22 23:55:45 +0000
commit70910be7c6ef2377240bd3a32d1dcabc31ad0dd3 (patch)
treec8d7b8db9b973596e3cfe453900cd306d30da3fe /base
parent6b98e52b28fa37b71d4dd80556e936277a85dbc6 (diff)
downloadchromium_src-70910be7c6ef2377240bd3a32d1dcabc31ad0dd3.zip
chromium_src-70910be7c6ef2377240bd3a32d1dcabc31ad0dd3.tar.gz
chromium_src-70910be7c6ef2377240bd3a32d1dcabc31ad0dd3.tar.bz2
Base: Fix FileVersionInfo::CreateFileVersionInfoForCurrentModule so that
when base is built as a dll, the module that is inspected for the version info is the one that makes the call instead of base.dll BUG=76996 TEST=none Review URL: http://codereview.chromium.org/6897016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82754 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/file_version_info.h31
-rw-r--r--base/file_version_info_win.cc11
-rw-r--r--base/file_version_info_win.h10
3 files changed, 41 insertions, 11 deletions
diff --git a/base/file_version_info.h b/base/file_version_info.h
index dca4148..8769a14 100644
--- a/base/file_version_info.h
+++ b/base/file_version_info.h
@@ -6,11 +6,18 @@
#define BASE_FILE_VERSION_INFO_H__
#pragma once
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
+#include <windows.h>
+// http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
+extern "C" IMAGE_DOS_HEADER __ImageBase;
+#endif // OS_WIN
+
#include <string>
#include "base/base_api.h"
#include "base/string16.h"
-#include "build/build_config.h"
class FilePath;
@@ -24,19 +31,37 @@ class FilePath;
// version returns values from the Info.plist as appropriate. TODO(avi): make
// this a less-obvious Windows-ism.
-class BASE_API FileVersionInfo {
+class FileVersionInfo {
public:
virtual ~FileVersionInfo() {}
#if defined(OS_WIN) || defined(OS_MACOSX)
// Creates a FileVersionInfo for the specified path. Returns NULL if something
// goes wrong (typically the file does not exit or cannot be opened). The
// returned object should be deleted when you are done with it.
- static FileVersionInfo* CreateFileVersionInfo(const FilePath& file_path);
+ BASE_API static FileVersionInfo* CreateFileVersionInfo(
+ const FilePath& file_path);
#endif // OS_WIN || OS_MACOSX
+#if defined(OS_WIN)
+ // Creates a FileVersionInfo for the specified module. Returns NULL in case
+ // of error. The returned object should be deleted when you are done with it.
+ BASE_API static FileVersionInfo* CreateFileVersionInfoForModule(
+ HMODULE module);
+
+ // Creates a FileVersionInfo for the current module. Returns NULL in case
+ // of error. The returned object should be deleted when you are done with it.
+ // This function should be inlined so that the "current module" is evaluated
+ // correctly, instead of being the module that contains base.
+ __forceinline static FileVersionInfo*
+ CreateFileVersionInfoForCurrentModule() {
+ HMODULE module = reinterpret_cast<HMODULE>(&__ImageBase);
+ return CreateFileVersionInfoForModule(module);
+ }
+#else
// Creates a FileVersionInfo for the current module. Returns NULL in case
// of error. The returned object should be deleted when you are done with it.
static FileVersionInfo* CreateFileVersionInfoForCurrentModule();
+#endif // OS_WIN
// Accessors to the different version properties.
// Returns an empty string if the property is not found.
diff --git a/base/file_version_info_win.cc b/base/file_version_info_win.cc
index 8c6820e..6528ca3 100644
--- a/base/file_version_info_win.cc
+++ b/base/file_version_info_win.cc
@@ -31,11 +31,16 @@ typedef struct {
} LanguageAndCodePage;
// static
-FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForCurrentModule() {
- FilePath app_path;
- if (!PathService::Get(base::FILE_MODULE, &app_path))
+FileVersionInfo* FileVersionInfo::CreateFileVersionInfoForModule(
+ HMODULE module) {
+ // Note that the use of MAX_PATH is basically in line with what we do for
+ // all registered paths (PathProviderWin).
+ wchar_t system_buffer[MAX_PATH];
+ system_buffer[0] = 0;
+ if (!GetModuleFileName(module, system_buffer, MAX_PATH))
return NULL;
+ FilePath app_path(system_buffer);
return CreateFileVersionInfo(app_path);
}
diff --git a/base/file_version_info_win.h b/base/file_version_info_win.h
index 95652b0..89ac67e 100644
--- a/base/file_version_info_win.h
+++ b/base/file_version_info_win.h
@@ -16,10 +16,10 @@
struct tagVS_FIXEDFILEINFO;
typedef tagVS_FIXEDFILEINFO VS_FIXEDFILEINFO;
-class BASE_API FileVersionInfoWin : public FileVersionInfo {
+class FileVersionInfoWin : public FileVersionInfo {
public:
- FileVersionInfoWin(void* data, int language, int code_page);
- ~FileVersionInfoWin();
+ BASE_API FileVersionInfoWin(void* data, int language, int code_page);
+ BASE_API ~FileVersionInfoWin();
// Accessors to the different version properties.
// Returns an empty string if the property is not found.
@@ -41,11 +41,11 @@ class BASE_API FileVersionInfoWin : public FileVersionInfo {
virtual bool is_official_build();
// Lets you access other properties not covered above.
- bool GetValue(const wchar_t* name, std::wstring* value);
+ BASE_API bool GetValue(const wchar_t* name, std::wstring* value);
// Similar to GetValue but returns a wstring (empty string if the property
// does not exist).
- std::wstring GetStringValue(const wchar_t* name);
+ BASE_API std::wstring GetStringValue(const wchar_t* name);
// Get the fixed file info if it exists. Otherwise NULL
VS_FIXEDFILEINFO* fixed_file_info() { return fixed_file_info_; }