OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <psapi.h> | 8 #include <psapi.h> |
9 #include <shellapi.h> | 9 #include <shellapi.h> |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
23 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
24 #include "base/time.h" | 24 #include "base/time.h" |
25 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
26 #include "base/win/scoped_handle.h" | 26 #include "base/win/scoped_handle.h" |
27 #include "base/win/windows_version.h" | 27 #include "base/win/windows_version.h" |
28 | 28 |
29 using base::FilePath; | 29 using base::FilePath; |
30 | 30 |
| 31 namespace base { |
| 32 |
| 33 FilePath MakeAbsoluteFilePath(const FilePath& input) { |
| 34 base::ThreadRestrictions::AssertIOAllowed(); |
| 35 wchar_t file_path[MAX_PATH]; |
| 36 if (!_wfullpath(file_path, input.value().c_str(), MAX_PATH)) |
| 37 return FilePath(); |
| 38 return FilePath(file_path); |
| 39 } |
| 40 |
| 41 } // namespace base |
| 42 |
31 namespace file_util { | 43 namespace file_util { |
32 | 44 |
33 namespace { | 45 namespace { |
34 | 46 |
35 const DWORD kFileShareAll = | 47 const DWORD kFileShareAll = |
36 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; | 48 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE; |
37 | 49 |
38 } // namespace | 50 } // namespace |
39 | 51 |
40 bool AbsolutePath(FilePath* path) { | |
41 base::ThreadRestrictions::AssertIOAllowed(); | |
42 wchar_t file_path_buf[MAX_PATH]; | |
43 if (!_wfullpath(file_path_buf, path->value().c_str(), MAX_PATH)) | |
44 return false; | |
45 *path = FilePath(file_path_buf); | |
46 return true; | |
47 } | |
48 | |
49 int CountFilesCreatedAfter(const FilePath& path, | 52 int CountFilesCreatedAfter(const FilePath& path, |
50 const base::Time& comparison_time) { | 53 const base::Time& comparison_time) { |
51 base::ThreadRestrictions::AssertIOAllowed(); | 54 base::ThreadRestrictions::AssertIOAllowed(); |
52 | 55 |
53 int file_count = 0; | 56 int file_count = 0; |
54 FILETIME comparison_filetime(comparison_time.ToFileTime()); | 57 FILETIME comparison_filetime(comparison_time.ToFileTime()); |
55 | 58 |
56 WIN32_FIND_DATA find_file_data; | 59 WIN32_FIND_DATA find_file_data; |
57 // All files in given dir | 60 // All files in given dir |
58 std::wstring filename_spec = path.Append(L"*").value(); | 61 std::wstring filename_spec = path.Append(L"*").value(); |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 | 896 |
894 // Length of |path| with path separator appended. | 897 // Length of |path| with path separator appended. |
895 size_t prefix = path.StripTrailingSeparators().value().size() + 1; | 898 size_t prefix = path.StripTrailingSeparators().value().size() + 1; |
896 // The whole path string must be shorter than MAX_PATH. That is, it must be | 899 // The whole path string must be shorter than MAX_PATH. That is, it must be |
897 // prefix + component_length < MAX_PATH (or equivalently, <= MAX_PATH - 1). | 900 // prefix + component_length < MAX_PATH (or equivalently, <= MAX_PATH - 1). |
898 int whole_path_limit = std::max(0, MAX_PATH - 1 - static_cast<int>(prefix)); | 901 int whole_path_limit = std::max(0, MAX_PATH - 1 - static_cast<int>(prefix)); |
899 return std::min(whole_path_limit, static_cast<int>(max_length)); | 902 return std::min(whole_path_limit, static_cast<int>(max_length)); |
900 } | 903 } |
901 | 904 |
902 } // namespace file_util | 905 } // namespace file_util |
OLD | NEW |