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

Unified Diff: base/file_util_win.cc

Issue 9309083: Remove PreReadImage from base/file_util. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 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 | « base/file_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_win.cc
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 4723b96043bfb5806b68681b97b2d02a1a9a7f92..e5c032e5bbd6d0b3f8551a16b7359b25188b6f54 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -1111,70 +1111,4 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) {
return success;
}
-bool PreReadImage(const wchar_t* file_path, size_t size_to_read,
- size_t step_size) {
- base::ThreadRestrictions::AssertIOAllowed();
- if (base::win::GetVersion() > base::win::VERSION_XP) {
- // Vista+ branch. On these OSes, the forced reads through the DLL actually
- // slows warm starts. The solution is to sequentially read file contents
- // with an optional cap on total amount to read.
- base::win::ScopedHandle file(
- CreateFile(file_path,
- GENERIC_READ,
- FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
- NULL,
- OPEN_EXISTING,
- FILE_FLAG_SEQUENTIAL_SCAN,
- NULL));
-
- if (!file.IsValid())
- return false;
-
- // Default to 1MB sequential reads.
- const DWORD actual_step_size = std::max(static_cast<DWORD>(step_size),
- static_cast<DWORD>(1024*1024));
- LPVOID buffer = ::VirtualAlloc(NULL,
- actual_step_size,
- MEM_COMMIT,
- PAGE_READWRITE);
-
- if (buffer == NULL)
- return false;
-
- DWORD len;
- size_t total_read = 0;
- while (::ReadFile(file, buffer, actual_step_size, &len, NULL) &&
- len > 0 &&
- (size_to_read ? total_read < size_to_read : true)) {
- total_read += static_cast<size_t>(len);
- }
- ::VirtualFree(buffer, 0, MEM_RELEASE);
- } else {
- // WinXP branch. Here, reading the DLL from disk doesn't do
- // what we want so instead we pull the pages into memory by loading
- // the DLL and touching pages at a stride.
- HMODULE dll_module = ::LoadLibraryExW(
- file_path,
- NULL,
- LOAD_WITH_ALTERED_SEARCH_PATH | DONT_RESOLVE_DLL_REFERENCES);
-
- if (!dll_module)
- return false;
-
- base::win::PEImage pe_image(dll_module);
- PIMAGE_NT_HEADERS nt_headers = pe_image.GetNTHeaders();
- size_t actual_size_to_read = size_to_read ? size_to_read :
- nt_headers->OptionalHeader.SizeOfImage;
- volatile uint8* touch = reinterpret_cast<uint8*>(dll_module);
- size_t offset = 0;
- while (offset < actual_size_to_read) {
- uint8 unused = *(touch + offset);
- offset += step_size;
- }
- FreeLibrary(dll_module);
- }
-
- return true;
-}
-
} // namespace file_util
« no previous file with comments | « base/file_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698