[go: nahoru, domu]

Don't use ::GetFileVersionInfo() in CreateFileVersionInfoForModule()

Currently, base::FileVersionInfo::CreateFileVersionInfoForModule()
calls ::GetModuleFileName and ::GetFileVersionInfo, grabs the loader
lock and potentially touches the disk to obtain the VS_VERSION_INFO
of the module. This is gratuitous for a module that is already loaded.

With this CL, base::FileVersionInfo::CreateFileVersionInfoForModule()
uses base::win::GetResourceFromModule() to get the VS_VERSION_INFO
resource from memory.

First version of this CL: https://codereview.chromium.org/2046583002/

TBR=thestig@chromium.org
BUG=609709

Review-Url: https://codereview.chromium.org/2111613002
Cr-Commit-Position: refs/heads/master@{#402985}
diff --git a/base/file_version_info_win.h b/base/file_version_info_win.h
index 1e152a8..d91b67f 100644
--- a/base/file_version_info_win.h
+++ b/base/file_version_info_win.h
@@ -5,20 +5,23 @@
 #ifndef BASE_FILE_VERSION_INFO_WIN_H_
 #define BASE_FILE_VERSION_INFO_WIN_H_
 
+#include <windows.h>
+
+#include <stdint.h>
+
 #include <memory>
 #include <string>
+#include <vector>
 
 #include "base/base_export.h"
 #include "base/file_version_info.h"
 #include "base/macros.h"
-#include "base/memory/free_deleter.h"
 
 struct tagVS_FIXEDFILEINFO;
 typedef tagVS_FIXEDFILEINFO VS_FIXEDFILEINFO;
 
 class BASE_EXPORT FileVersionInfoWin : public FileVersionInfo {
  public:
-  FileVersionInfoWin(void* data, WORD language, WORD code_page);
   ~FileVersionInfoWin() override;
 
   // Accessors to the different version properties.
@@ -48,14 +51,25 @@
   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_; }
+  const VS_FIXEDFILEINFO* fixed_file_info() const { return fixed_file_info_; }
 
  private:
-  std::unique_ptr<char, base::FreeDeleter> data_;
-  WORD language_;
-  WORD code_page_;
-  // This is a pointer into the data_ if it exists. Otherwise NULL.
-  VS_FIXEDFILEINFO* fixed_file_info_;
+  friend FileVersionInfo;
+
+  // |data| is a VS_VERSION_INFO resource. |language| and |code_page| are
+  // extracted from the \VarFileInfo\Translation value of |data|.
+  FileVersionInfoWin(std::vector<uint8_t>&& data,
+                     WORD language,
+                     WORD code_page);
+  FileVersionInfoWin(void* data, WORD language, WORD code_page);
+
+  const std::vector<uint8_t> owned_data_;
+  const void* const data_;
+  const WORD language_;
+  const WORD code_page_;
+
+  // This is a pointer into |data_| if it exists. Otherwise nullptr.
+  const VS_FIXEDFILEINFO* const fixed_file_info_;
 
   DISALLOW_COPY_AND_ASSIGN(FileVersionInfoWin);
 };