Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: base/file_util.h

Issue 397014: Revert 31875 to see whether it fixes reliability bot. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 12
13 #if defined(OS_WIN) 13 #if defined(OS_WIN)
14 #include <windows.h> 14 #include <windows.h>
15 #elif defined(OS_POSIX) 15 #elif defined(OS_POSIX)
16 #include <sys/stat.h> 16 #include <sys/stat.h>
17 #endif 17 #endif
18 18
19 #include <stdio.h> 19 #include <stdio.h>
20 20
21 #include <stack> 21 #include <stack>
22 #include <string> 22 #include <string>
23 #include <vector> 23 #include <vector>
24 24
25 #include "base/basictypes.h" 25 #include "base/basictypes.h"
26 #include "base/file_path.h" 26 #include "base/file_path.h"
27 #include "base/platform_file.h"
28 #include "base/scoped_ptr.h" 27 #include "base/scoped_ptr.h"
29 #include "base/string16.h" 28 #include "base/string16.h"
30 #include "base/time.h" 29 #include "base/time.h"
31 30
32 #if defined(OS_POSIX) 31 #if defined(OS_POSIX)
33 #include "base/file_descriptor_posix.h" 32 #include "base/file_descriptor_posix.h"
34 #endif 33 #endif
35 34
36 namespace base { 35 namespace base {
37 class Time; 36 class Time;
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 // The default constructor sets all members to invalid/null values. 483 // The default constructor sets all members to invalid/null values.
485 MemoryMappedFile(); 484 MemoryMappedFile();
486 ~MemoryMappedFile(); 485 ~MemoryMappedFile();
487 486
488 // Opens an existing file and maps it into memory. Access is restricted to 487 // Opens an existing file and maps it into memory. Access is restricted to
489 // read only. If this object already points to a valid memory mapped file 488 // read only. If this object already points to a valid memory mapped file
490 // then this method will fail and return false. If it cannot open the file, 489 // then this method will fail and return false. If it cannot open the file,
491 // the file does not exist, or the memory mapping fails, it will return false. 490 // the file does not exist, or the memory mapping fails, it will return false.
492 // Later we may want to allow the user to specify access. 491 // Later we may want to allow the user to specify access.
493 bool Initialize(const FilePath& file_name); 492 bool Initialize(const FilePath& file_name);
494 // As above, but works with an already-opened file. MemoryMappedFile will take 493 #if defined(OS_POSIX)
495 // ownership of |file| and close it when done. 494 // As above, but works with an alreay-opened file.
496 bool Initialize(base::PlatformFile file); 495 bool Initialize(const base::FileDescriptor& fd);
496 #endif
497 497
498 const uint8* data() const { return data_; } 498 const uint8* data() const { return data_; }
499 size_t length() const { return length_; } 499 size_t length() const { return length_; }
500 500
501 // Is file_ a valid file handle that points to an open, memory mapped file? 501 // Is file_ a valid file handle that points to an open, memory mapped file?
502 bool IsValid(); 502 bool IsValid();
503 503
504 private: 504 private:
505 // Open the given file and pass it to MapFileToMemoryInternal(). 505 // Map the file to memory, set data_ to that memory address. Return true on
506 // success, false on any kind of failure. This is a helper for Initialize().
506 bool MapFileToMemory(const FilePath& file_name); 507 bool MapFileToMemory(const FilePath& file_name);
507 508
508 // Map the file to memory, set data_ to that memory address. Return true on 509 #if defined(OS_POSIX)
509 // success, false on any kind of failure. This is a helper for Initialize().
510 bool MapFileToMemoryInternal(); 510 bool MapFileToMemoryInternal();
511 #endif
511 512
512 // Closes all open handles. Later we may want to make this public. 513 // Closes all open handles. Later we may want to make this public.
513 void CloseHandles(); 514 void CloseHandles();
514 515
515 base::PlatformFile file_;
516 #if defined(OS_WIN) 516 #if defined(OS_WIN)
517 HANDLE file_;
517 HANDLE file_mapping_; 518 HANDLE file_mapping_;
519 #elif defined(OS_POSIX)
520 // The file descriptor.
521 base::FileDescriptor file_;
518 #endif 522 #endif
519 uint8* data_; 523 uint8* data_;
520 size_t length_; 524 size_t length_;
521 525
522 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile); 526 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile);
523 }; 527 };
524 528
525 // Renames a file using the SHFileOperation API to ensure that the target file 529 // Renames a file using the SHFileOperation API to ensure that the target file
526 // gets the correct default security descriptor in the new path. 530 // gets the correct default security descriptor in the new path.
527 bool RenameFileAndResetSecurityDescriptor( 531 bool RenameFileAndResetSecurityDescriptor(
528 const FilePath& source_file_path, 532 const FilePath& source_file_path,
529 const FilePath& target_file_path); 533 const FilePath& target_file_path);
530 534
531 } // namespace file_util 535 } // namespace file_util
532 536
533 #endif // BASE_FILE_UTIL_H_ 537 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698