| 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 920 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 943   bool success = false; | 944   bool success = false; | 
| 944   HANDLE cp = GetCurrentProcess(); | 945   HANDLE cp = GetCurrentProcess(); | 
| 945   if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { | 946   if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { | 
| 946     *nt_path = FilePath(mapped_file_path); | 947     *nt_path = FilePath(mapped_file_path); | 
| 947     success = true; | 948     success = true; | 
| 948   } | 949   } | 
| 949   ::UnmapViewOfFile(file_view); | 950   ::UnmapViewOfFile(file_view); | 
| 950   return success; | 951   return success; | 
| 951 } | 952 } | 
| 952 | 953 | 
|  | 954 int GetMaximumPathComponentLength(const FilePath& path) { | 
|  | 955   base::ThreadRestrictions::AssertIOAllowed(); | 
|  | 956 | 
|  | 957   wchar_t volume_path[MAX_PATH]; | 
|  | 958   if (!GetVolumePathNameW(path.NormalizePathSeparators().value().c_str(), | 
|  | 959                           volume_path, | 
|  | 960                           arraysize(volume_path))) { | 
|  | 961     return -1; | 
|  | 962   } | 
|  | 963 | 
|  | 964   DWORD max_length = 0; | 
|  | 965   if (!GetVolumeInformationW(volume_path, NULL, 0, NULL, &max_length, NULL, | 
|  | 966                              NULL, 0)) { | 
|  | 967     return -1; | 
|  | 968   } | 
|  | 969 | 
|  | 970   // Length of |path| with path separator appended. | 
|  | 971   size_t prefix = path.StripTrailingSeparators().value().size() + 1; | 
|  | 972   // The whole path string must be shorter than MAX_PATH. That is, it must be | 
|  | 973   // prefix + component_length < MAX_PATH (or equivalently, <= MAX_PATH - 1). | 
|  | 974   int whole_path_limit = std::max(0, MAX_PATH - 1 - static_cast<int>(prefix)); | 
|  | 975   return std::min(whole_path_limit, static_cast<int>(max_length)); | 
|  | 976 } | 
|  | 977 | 
| 953 }  // namespace file_util | 978 }  // namespace file_util | 
| OLD | NEW | 
|---|