OLD | NEW |
1 // Copyright (c) 2008 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 // FilePath is a container for pathnames stored in a platform's native string | 5 // FilePath is a container for pathnames stored in a platform's native string |
6 // type, providing containers for manipulation in according with the | 6 // type, providing containers for manipulation in according with the |
7 // platform's conventions for pathnames. It supports the following path | 7 // platform's conventions for pathnames. It supports the following path |
8 // types: | 8 // types: |
9 // | 9 // |
10 // POSIX Windows | 10 // POSIX Windows |
11 // --------------- ---------------------------------- | 11 // --------------- ---------------------------------- |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 | 109 |
110 // Windows-style drive letter support and pathname separator characters can be | 110 // Windows-style drive letter support and pathname separator characters can be |
111 // enabled and disabled independently, to aid testing. These #defines are | 111 // enabled and disabled independently, to aid testing. These #defines are |
112 // here so that the same setting can be used in both the implementation and | 112 // here so that the same setting can be used in both the implementation and |
113 // in the unit test. | 113 // in the unit test. |
114 #if defined(OS_WIN) | 114 #if defined(OS_WIN) |
115 #define FILE_PATH_USES_DRIVE_LETTERS | 115 #define FILE_PATH_USES_DRIVE_LETTERS |
116 #define FILE_PATH_USES_WIN_SEPARATORS | 116 #define FILE_PATH_USES_WIN_SEPARATORS |
117 #endif // OS_WIN | 117 #endif // OS_WIN |
118 | 118 |
| 119 class Pickle; |
| 120 |
119 // An abstraction to isolate users from the differences between native | 121 // An abstraction to isolate users from the differences between native |
120 // pathnames on different platforms. | 122 // pathnames on different platforms. |
121 class FilePath { | 123 class FilePath { |
122 public: | 124 public: |
123 #if defined(OS_POSIX) | 125 #if defined(OS_POSIX) |
124 // On most platforms, native pathnames are char arrays, and the encoding | 126 // On most platforms, native pathnames are char arrays, and the encoding |
125 // may or may not be specified. On Mac OS X, native pathnames are encoded | 127 // may or may not be specified. On Mac OS X, native pathnames are encoded |
126 // in UTF-8. | 128 // in UTF-8. |
127 typedef std::string StringType; | 129 typedef std::string StringType; |
128 #elif defined(OS_WIN) | 130 #elif defined(OS_WIN) |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
275 // directory (i.e. has a path component that is ".." | 277 // directory (i.e. has a path component that is ".." |
276 bool ReferencesParent() const; | 278 bool ReferencesParent() const; |
277 | 279 |
278 // Older Chromium code assumes that paths are always wstrings. | 280 // Older Chromium code assumes that paths are always wstrings. |
279 // This function converts a wstring to a FilePath, and is useful to smooth | 281 // This function converts a wstring to a FilePath, and is useful to smooth |
280 // porting that old code to the FilePath API. | 282 // porting that old code to the FilePath API. |
281 // It has "Hack" in its name so people feel bad about using it. | 283 // It has "Hack" in its name so people feel bad about using it. |
282 // TODO(port): remove these functions. | 284 // TODO(port): remove these functions. |
283 static FilePath FromWStringHack(const std::wstring& wstring); | 285 static FilePath FromWStringHack(const std::wstring& wstring); |
284 | 286 |
| 287 // Static helper method to write a StringType to a pickle. |
| 288 static void WriteStringTypeToPickle(Pickle* pickle, |
| 289 const FilePath::StringType& path); |
| 290 static bool ReadStringTypeFromPickle(Pickle* pickle, void** iter, |
| 291 FilePath::StringType* path); |
| 292 |
| 293 void WriteToPickle(Pickle* pickle); |
| 294 bool ReadFromPickle(Pickle* pickle, void** iter); |
| 295 |
285 // Compare two strings in the same way the file system does. | 296 // Compare two strings in the same way the file system does. |
286 // Note that these always ignore case, even on file systems that are case- | 297 // Note that these always ignore case, even on file systems that are case- |
287 // sensitive. If case-sensitive comparison is ever needed, add corresponding | 298 // sensitive. If case-sensitive comparison is ever needed, add corresponding |
288 // methods here. | 299 // methods here. |
289 // The methods are written as a static method so that they can also be used | 300 // The methods are written as a static method so that they can also be used |
290 // on parts of a file path, e.g., just the extension. | 301 // on parts of a file path, e.g., just the extension. |
291 // CompareIgnoreCase() returns -1, 0 or 1 for less-than, equal-to and | 302 // CompareIgnoreCase() returns -1, 0 or 1 for less-than, equal-to and |
292 // greater-than respectively. | 303 // greater-than respectively. |
293 static int CompareIgnoreCase(const StringType& string1, | 304 static int CompareIgnoreCase(const StringType& string1, |
294 const StringType& string2); | 305 const StringType& string2); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 namespace stdext { | 370 namespace stdext { |
360 | 371 |
361 inline size_t hash_value(const FilePath& f) { | 372 inline size_t hash_value(const FilePath& f) { |
362 return hash_value(f.value()); | 373 return hash_value(f.value()); |
363 } | 374 } |
364 | 375 |
365 } // namespace stdext | 376 } // namespace stdext |
366 #endif // COMPILER | 377 #endif // COMPILER |
367 | 378 |
368 #endif // BASE_FILE_PATH_H_ | 379 #endif // BASE_FILE_PATH_H_ |
OLD | NEW |