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

Unified Diff: snapshot/win/module_snapshot_win.cc

Issue 1472963002: win: Only call GetFileVersionInfo() once per module (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « snapshot/win/module_snapshot_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: snapshot/win/module_snapshot_win.cc
diff --git a/snapshot/win/module_snapshot_win.cc b/snapshot/win/module_snapshot_win.cc
index 194d15ac8ae915e9ce76b80038f5ff9d079d82f4..49478880f8432fa7c194c824bce3482100ff4f9a 100644
--- a/snapshot/win/module_snapshot_win.cc
+++ b/snapshot/win/module_snapshot_win.cc
@@ -33,7 +33,9 @@ ModuleSnapshotWin::ModuleSnapshotWin()
process_reader_(nullptr),
timestamp_(0),
age_(0),
- initialized_() {
+ initialized_(),
+ vs_fixed_file_info_(),
+ initialized_vs_fixed_file_info_() {
}
ModuleSnapshotWin::~ModuleSnapshotWin() {
@@ -107,12 +109,12 @@ void ModuleSnapshotWin::FileVersion(uint16_t* version_0,
uint16_t* version_2,
uint16_t* version_3) const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
- VS_FIXEDFILEINFO ffi;
- if (GetModuleVersionAndType(base::FilePath(name_), &ffi)) {
- *version_0 = ffi.dwFileVersionMS >> 16;
- *version_1 = ffi.dwFileVersionMS & 0xffff;
- *version_2 = ffi.dwFileVersionLS >> 16;
- *version_3 = ffi.dwFileVersionLS & 0xffff;
+ const VS_FIXEDFILEINFO* ffi = VSFixedFileInfo();
+ if (ffi) {
+ *version_0 = ffi->dwFileVersionMS >> 16;
+ *version_1 = ffi->dwFileVersionMS & 0xffff;
+ *version_2 = ffi->dwFileVersionLS >> 16;
+ *version_3 = ffi->dwFileVersionLS & 0xffff;
} else {
*version_0 = 0;
*version_1 = 0;
@@ -126,12 +128,12 @@ void ModuleSnapshotWin::SourceVersion(uint16_t* version_0,
uint16_t* version_2,
uint16_t* version_3) const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
- VS_FIXEDFILEINFO ffi;
- if (GetModuleVersionAndType(base::FilePath(name_), &ffi)) {
- *version_0 = ffi.dwProductVersionMS >> 16;
- *version_1 = ffi.dwProductVersionMS & 0xffff;
- *version_2 = ffi.dwProductVersionLS >> 16;
- *version_3 = ffi.dwProductVersionLS & 0xffff;
+ const VS_FIXEDFILEINFO* ffi = VSFixedFileInfo();
+ if (ffi) {
+ *version_0 = ffi->dwProductVersionMS >> 16;
+ *version_1 = ffi->dwProductVersionMS & 0xffff;
+ *version_2 = ffi->dwProductVersionLS >> 16;
+ *version_3 = ffi->dwProductVersionLS & 0xffff;
} else {
*version_0 = 0;
*version_1 = 0;
@@ -142,14 +144,17 @@ void ModuleSnapshotWin::SourceVersion(uint16_t* version_0,
ModuleSnapshot::ModuleType ModuleSnapshotWin::GetModuleType() const {
INITIALIZATION_STATE_DCHECK_VALID(initialized_);
- VS_FIXEDFILEINFO ffi;
- if (GetModuleVersionAndType(base::FilePath(name_), &ffi)) {
- if (ffi.dwFileType == VFT_APP)
- return ModuleSnapshot::kModuleTypeExecutable;
- if (ffi.dwFileType == VFT_DLL)
- return ModuleSnapshot::kModuleTypeSharedLibrary;
- if (ffi.dwFileType == VFT_DRV || ffi.dwFileType == VFT_VXD)
- return ModuleSnapshot::kModuleTypeLoadableModule;
+ const VS_FIXEDFILEINFO* ffi = VSFixedFileInfo();
+ if (ffi) {
+ switch (ffi->dwFileType) {
+ case VFT_APP:
+ return ModuleSnapshot::kModuleTypeExecutable;
+ case VFT_DLL:
+ return ModuleSnapshot::kModuleTypeSharedLibrary;
+ case VFT_DRV:
+ case VFT_VXD:
+ return ModuleSnapshot::kModuleTypeLoadableModule;
+ }
}
return ModuleSnapshot::kModuleTypeUnknown;
}
@@ -200,5 +205,19 @@ void ModuleSnapshotWin::GetCrashpadOptionsInternal(
crashpad_info.system_crash_reporter_forwarding);
}
+const VS_FIXEDFILEINFO* ModuleSnapshotWin::VSFixedFileInfo() const {
+ INITIALIZATION_STATE_DCHECK_VALID(initialized_);
+
+ if (initialized_vs_fixed_file_info_.is_uninitialized()) {
+ initialized_vs_fixed_file_info_.set_invalid();
+ if (GetModuleVersionAndType(base::FilePath(name_), &vs_fixed_file_info_)) {
+ initialized_vs_fixed_file_info_.set_valid();
+ }
+ }
+
+ return initialized_vs_fixed_file_info_.is_valid() ? &vs_fixed_file_info_
+ : nullptr;
+}
+
} // namespace internal
} // namespace crashpad
« no previous file with comments | « snapshot/win/module_snapshot_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698