| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <shellapi.h> | 9 #include <shellapi.h> |
| 10 #include <shlobj.h> | 10 #include <shlobj.h> |
| (...skipping 787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 } | 798 } |
| 799 | 799 |
| 800 bool MemoryMappedFile::MapFileToMemoryInternal() { | 800 bool MemoryMappedFile::MapFileToMemoryInternal() { |
| 801 if (file_ == INVALID_HANDLE_VALUE) | 801 if (file_ == INVALID_HANDLE_VALUE) |
| 802 return false; | 802 return false; |
| 803 | 803 |
| 804 length_ = ::GetFileSize(file_, NULL); | 804 length_ = ::GetFileSize(file_, NULL); |
| 805 if (length_ == INVALID_FILE_SIZE) | 805 if (length_ == INVALID_FILE_SIZE) |
| 806 return false; | 806 return false; |
| 807 | 807 |
| 808 // length_ value comes from GetFileSize() above. GetFileSize() returns DWORD, |
| 809 // therefore the cast here is safe. |
| 808 file_mapping_ = ::CreateFileMapping(file_, NULL, PAGE_READONLY, | 810 file_mapping_ = ::CreateFileMapping(file_, NULL, PAGE_READONLY, |
| 809 0, length_, NULL); | 811 0, static_cast<DWORD>(length_), NULL); |
| 810 if (file_mapping_ == INVALID_HANDLE_VALUE) | 812 if (file_mapping_ == INVALID_HANDLE_VALUE) |
| 811 return false; | 813 return false; |
| 812 | 814 |
| 813 data_ = static_cast<uint8*>( | 815 data_ = static_cast<uint8*>( |
| 814 ::MapViewOfFile(file_mapping_, FILE_MAP_READ, 0, 0, length_)); | 816 ::MapViewOfFile(file_mapping_, FILE_MAP_READ, 0, 0, length_)); |
| 815 return data_ != NULL; | 817 return data_ != NULL; |
| 816 } | 818 } |
| 817 | 819 |
| 818 void MemoryMappedFile::CloseHandles() { | 820 void MemoryMappedFile::CloseHandles() { |
| 819 if (data_) | 821 if (data_) |
| 820 ::UnmapViewOfFile(data_); | 822 ::UnmapViewOfFile(data_); |
| 821 if (file_mapping_ != INVALID_HANDLE_VALUE) | 823 if (file_mapping_ != INVALID_HANDLE_VALUE) |
| 822 ::CloseHandle(file_mapping_); | 824 ::CloseHandle(file_mapping_); |
| 823 if (file_ != INVALID_HANDLE_VALUE) | 825 if (file_ != INVALID_HANDLE_VALUE) |
| 824 ::CloseHandle(file_); | 826 ::CloseHandle(file_); |
| 825 | 827 |
| 826 data_ = NULL; | 828 data_ = NULL; |
| 827 file_mapping_ = file_ = INVALID_HANDLE_VALUE; | 829 file_mapping_ = file_ = INVALID_HANDLE_VALUE; |
| 828 length_ = INVALID_FILE_SIZE; | 830 length_ = INVALID_FILE_SIZE; |
| 829 } | 831 } |
| 830 | 832 |
| 831 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, | 833 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, |
| 832 const base::Time& cutoff_time) { | 834 const base::Time& cutoff_time) { |
| 833 long result = CompareFileTime(&find_info.ftLastWriteTime, | 835 long result = CompareFileTime(&find_info.ftLastWriteTime, |
| 834 &cutoff_time.ToFileTime()); | 836 &cutoff_time.ToFileTime()); |
| 835 return result == 1 || result == 0; | 837 return result == 1 || result == 0; |
| 836 } | 838 } |
| 837 | 839 |
| 838 } // namespace file_util | 840 } // namespace file_util |
| OLD | NEW |