OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/file_util.h" | 5 #include "base/file_util.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <propvarutil.h> | 8 #include <propvarutil.h> |
9 #include <psapi.h> | 9 #include <psapi.h> |
10 #include <shellapi.h> | 10 #include <shellapi.h> |
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 | 969 |
970 bool NormalizeFilePath(const FilePath& path, FilePath* real_path) { | 970 bool NormalizeFilePath(const FilePath& path, FilePath* real_path) { |
971 ScopedHandle path_handle( | 971 ScopedHandle path_handle( |
972 ::CreateFile(path.value().c_str(), | 972 ::CreateFile(path.value().c_str(), |
973 GENERIC_READ, | 973 GENERIC_READ, |
974 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, | 974 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
975 NULL, | 975 NULL, |
976 OPEN_EXISTING, | 976 OPEN_EXISTING, |
977 FILE_ATTRIBUTE_NORMAL, | 977 FILE_ATTRIBUTE_NORMAL, |
978 NULL)); | 978 NULL)); |
979 if (path_handle == INVALID_HANDLE_VALUE) | 979 if (!path_handle.IsValid()) |
980 return false; | 980 return false; |
981 | 981 |
982 // In Vista, GetFinalPathNameByHandle() would give us the real path | 982 // In Vista, GetFinalPathNameByHandle() would give us the real path |
983 // from a file handle. If we ever deprecate XP, consider changing the | 983 // from a file handle. If we ever deprecate XP, consider changing the |
984 // code below to a call to GetFinalPathNameByHandle(). The method this | 984 // code below to a call to GetFinalPathNameByHandle(). The method this |
985 // function uses is explained in the following msdn article: | 985 // function uses is explained in the following msdn article: |
986 // http://msdn.microsoft.com/en-us/library/aa366789(VS.85).aspx | 986 // http://msdn.microsoft.com/en-us/library/aa366789(VS.85).aspx |
987 DWORD file_size_high = 0; | 987 DWORD file_size_high = 0; |
988 DWORD file_size_low = ::GetFileSize(path_handle.Get(), &file_size_high); | 988 DWORD file_size_low = ::GetFileSize(path_handle.Get(), &file_size_high); |
989 if (file_size_low == 0 && file_size_high == 0) { | 989 if (file_size_low == 0 && file_size_high == 0) { |
990 // It is not possible to map an empty file. | 990 // It is not possible to map an empty file. |
991 LOG(ERROR) << "NormalizeFilePath failed: Empty file."; | 991 LOG(ERROR) << "NormalizeFilePath failed: Empty file."; |
992 return false; | 992 return false; |
993 } | 993 } |
994 | 994 |
995 // Create a file mapping object. Can't easily use MemoryMappedFile, because | 995 // Create a file mapping object. Can't easily use MemoryMappedFile, because |
996 // we only map the first byte, and need direct access to the handle. | 996 // we only map the first byte, and need direct access to the handle. |
997 ScopedHandle file_map_handle( | 997 ScopedHandle file_map_handle( |
998 ::CreateFileMapping(path_handle.Get(), | 998 ::CreateFileMapping(path_handle.Get(), |
999 NULL, | 999 NULL, |
1000 PAGE_READONLY, | 1000 PAGE_READONLY, |
1001 0, | 1001 0, |
1002 1, // Just one byte. No need to look at the data. | 1002 1, // Just one byte. No need to look at the data. |
1003 NULL)); | 1003 NULL)); |
1004 | 1004 |
1005 if (file_map_handle == INVALID_HANDLE_VALUE) | 1005 if (!file_map_handle.IsValid()) |
1006 return false; | 1006 return false; |
1007 | 1007 |
1008 // Use a view of the file to get the path to the file. | 1008 // Use a view of the file to get the path to the file. |
1009 void* file_view = MapViewOfFile( | 1009 void* file_view = MapViewOfFile( |
1010 file_map_handle.Get(), FILE_MAP_READ, 0, 0, 1); | 1010 file_map_handle.Get(), FILE_MAP_READ, 0, 0, 1); |
1011 if (!file_view) | 1011 if (!file_view) |
1012 return false; | 1012 return false; |
1013 | 1013 |
1014 bool success = false; | 1014 bool success = false; |
1015 | 1015 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1054 size_t offset = 0; | 1054 size_t offset = 0; |
1055 while (offset < actual_size_to_read) { | 1055 while (offset < actual_size_to_read) { |
1056 uint8 unused = *(touch + offset); | 1056 uint8 unused = *(touch + offset); |
1057 offset += step_size; | 1057 offset += step_size; |
1058 } | 1058 } |
1059 FreeLibrary(dll_module); | 1059 FreeLibrary(dll_module); |
1060 return true; | 1060 return true; |
1061 } | 1061 } |
1062 | 1062 |
1063 } // namespace file_util | 1063 } // namespace file_util |
OLD | NEW |