| 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 // This file contains utility functions for dealing with the local |    5 // This file contains utility functions for dealing with the local | 
|    6 // filesystem. |    6 // filesystem. | 
|    7  |    7  | 
|    8 #ifndef BASE_FILE_UTIL_H_ |    8 #ifndef BASE_FILE_UTIL_H_ | 
|    9 #define BASE_FILE_UTIL_H_ |    9 #define BASE_FILE_UTIL_H_ | 
|   10  |   10  | 
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  407   WIN32_FIND_DATA find_data_; |  407   WIN32_FIND_DATA find_data_; | 
|  408   HANDLE find_handle_; |  408   HANDLE find_handle_; | 
|  409 #elif defined(OS_POSIX) |  409 #elif defined(OS_POSIX) | 
|  410   FTS* fts_; |  410   FTS* fts_; | 
|  411   FTSENT* fts_ent_; |  411   FTSENT* fts_ent_; | 
|  412 #endif |  412 #endif | 
|  413  |  413  | 
|  414   DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator); |  414   DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator); | 
|  415 }; |  415 }; | 
|  416  |  416  | 
|  417 // TODO(port): port this class to posix. |  | 
|  418 #if defined(OS_WIN) |  | 
|  419 class MemoryMappedFile { |  417 class MemoryMappedFile { | 
|  420  public: |  418  public: | 
|  421   // The default constructor sets all members to invalid/null values. |  419   // The default constructor sets all members to invalid/null values. | 
|  422   MemoryMappedFile(); |  420   MemoryMappedFile(); | 
|  423   ~MemoryMappedFile(); |  421   ~MemoryMappedFile(); | 
|  424  |  422  | 
|  425   // Opens an existing file and maps it into memory. Access is restricted to |  423   // Opens an existing file and maps it into memory. Access is restricted to | 
|  426   // read only. If this object already points to a valid memory mapped file |  424   // read only. If this object already points to a valid memory mapped file | 
|  427   // then this method will fail and return false. If it cannot open the file, |  425   // then this method will fail and return false. If it cannot open the file, | 
|  428   // the file does not exist, or the memory mapping fails, it will return false. |  426   // the file does not exist, or the memory mapping fails, it will return false. | 
|  429   // Later we may want to allow the user to specify access. |  427   // Later we may want to allow the user to specify access. | 
|  430   bool Initialize(const FilePath& file_name); |  428   bool Initialize(const FilePath& file_name); | 
|  431  |  429  | 
|  432   const uint8* Data() const { return data_; } |  430   const uint8* data() const { return data_; } | 
|  433   size_t Length() const { return length_; } |  431   size_t length() const { return length_; } | 
|  434  |  432  | 
|  435   // Is file_ a valid file handle that points to an open, memory mapped file? |  433   // Is file_ a valid file handle that points to an open, memory mapped file? | 
|  436   bool IsValid(); |  434   bool IsValid(); | 
|  437  |  435  | 
|  438  private: |  436  private: | 
|  439   // Map the file to memory, set data_ to that memory address. Return true on |  437   // Map the file to memory, set data_ to that memory address. Return true on | 
|  440   // success, false on any kind of failure. This is a helper for Initialize(). |  438   // success, false on any kind of failure. This is a helper for Initialize(). | 
|  441   bool MapFileToMemory(const FilePath& file_name); |  439   bool MapFileToMemory(const FilePath& file_name); | 
|  442  |  440  | 
|  443   // Closes all open handles. Later we may want to make this public. |  441   // Closes all open handles. Later we may want to make this public. | 
|  444   void CloseHandles(); |  442   void CloseHandles(); | 
|  445  |  443  | 
 |  444 #if defined(OS_WIN) | 
|  446   HANDLE file_; |  445   HANDLE file_; | 
|  447   HANDLE file_mapping_; |  446   HANDLE file_mapping_; | 
|  448   const uint8* data_; |  447 #elif defined(OS_POSIX) | 
 |  448   // The file descriptor. | 
 |  449   int file_; | 
 |  450 #endif | 
 |  451   uint8* data_; | 
|  449   size_t length_; |  452   size_t length_; | 
|  450  |  453  | 
|  451   DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); |  454   DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); | 
|  452 }; |  455 }; | 
|  453 #endif  // defined(OS_WIN) |  | 
|  454  |  456  | 
|  455 // Renames a file using the SHFileOperation API to ensure that the target file |  457 // Renames a file using the SHFileOperation API to ensure that the target file | 
|  456 // gets the correct default security descriptor in the new path. |  458 // gets the correct default security descriptor in the new path. | 
|  457 bool RenameFileAndResetSecurityDescriptor( |  459 bool RenameFileAndResetSecurityDescriptor( | 
|  458     const std::wstring& source_file_path, |  460     const std::wstring& source_file_path, | 
|  459     const std::wstring& target_file_path); |  461     const std::wstring& target_file_path); | 
|  460  |  462  | 
|  461 }  // namespace file_util |  463 }  // namespace file_util | 
|  462  |  464  | 
|  463 #endif  // BASE_FILE_UTIL_H_ |  465 #endif  // BASE_FILE_UTIL_H_ | 
| OLD | NEW |