Chromium Code Reviews| 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> |
| 11 #include <time.h> | 11 #include <time.h> |
| 12 | 12 |
| 13 #include <algorithm> | |
| 13 #include <limits> | 14 #include <limits> |
| 14 #include <string> | 15 #include <string> |
| 15 | 16 |
| 16 #include "base/file_path.h" | 17 #include "base/file_path.h" |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/metrics/histogram.h" | 19 #include "base/metrics/histogram.h" |
| 19 #include "base/process_util.h" | 20 #include "base/process_util.h" |
| 20 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 21 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
| (...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 941 bool success = false; | 942 bool success = false; |
| 942 HANDLE cp = GetCurrentProcess(); | 943 HANDLE cp = GetCurrentProcess(); |
| 943 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { | 944 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { |
| 944 *nt_path = FilePath(mapped_file_path); | 945 *nt_path = FilePath(mapped_file_path); |
| 945 success = true; | 946 success = true; |
| 946 } | 947 } |
| 947 ::UnmapViewOfFile(file_view); | 948 ::UnmapViewOfFile(file_view); |
| 948 return success; | 949 return success; |
| 949 } | 950 } |
| 950 | 951 |
| 952 int GetMaximumPathComponentLength(const FilePath& path) { | |
| 953 base::ThreadRestrictions::AssertIOAllowed(); | |
| 954 | |
| 955 wchar_t volume_path[MAX_PATH]; | |
| 956 if (!GetVolumePathNameW(path.NormalizePathSeparators().value().c_str(), | |
| 957 volume_path, | |
| 958 MAX_PATH)) { | |
|
Mark Mentovai
2013/02/15 13:49:42
arraysize(volume_path)
kinaba
2013/02/18 03:30:21
Done.
| |
| 959 return -1; | |
| 960 } | |
| 961 | |
| 962 DWORD max_length = 0; | |
| 963 if (!GetVolumeInformationW(volume_path, NULL, 0, NULL, &max_length, NULL, | |
| 964 NULL, 0)) { | |
| 965 return -1; | |
| 966 } | |
| 967 | |
| 968 // path.Append(name).value().size() must be less than MAX_PATH. | |
| 969 size_t prefix = path.StripTrailingSeparators().value().size() + 1; | |
| 970 int whole_path_limit = std::max(0, MAX_PATH - 1 - static_cast<int>(prefix)); | |
|
Mark Mentovai
2013/02/15 13:49:42
So one +1 is for the separator and one -1 is to ke
Mark Mentovai
2013/02/15 13:49:42
You might not be able to get rid of all of the sta
kinaba
2013/02/18 03:30:21
Added some comments for clarification.
kinaba
2013/02/18 03:30:21
The expression assigned to |prefix| has type size_
| |
| 971 return std::min(whole_path_limit, static_cast<int>(max_length)); | |
| 972 } | |
| 973 | |
| 951 } // namespace file_util | 974 } // namespace file_util |
| OLD | NEW |