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

Side by Side Diff: base/file_util.h

Issue 12321062: base: Move MemoryMappedFile out of file_util.h and into its own header file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix chrome_frame again Created 7 years, 10 months 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 | « base/base.gypi ('k') | 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) 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 // 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 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 base::FilePath::StringType pattern_; // Empty when we want to find 553 base::FilePath::StringType pattern_; // Empty when we want to find
554 // everything. 554 // everything.
555 555
556 // A stack that keeps track of which subdirectories we still need to 556 // A stack that keeps track of which subdirectories we still need to
557 // enumerate in the breadth-first search. 557 // enumerate in the breadth-first search.
558 std::stack<base::FilePath> pending_paths_; 558 std::stack<base::FilePath> pending_paths_;
559 559
560 DISALLOW_COPY_AND_ASSIGN(FileEnumerator); 560 DISALLOW_COPY_AND_ASSIGN(FileEnumerator);
561 }; 561 };
562 562
563 class BASE_EXPORT MemoryMappedFile {
564 public:
565 // The default constructor sets all members to invalid/null values.
566 MemoryMappedFile();
567 ~MemoryMappedFile();
568
569 // Opens an existing file and maps it into memory. Access is restricted to
570 // read only. If this object already points to a valid memory mapped file
571 // then this method will fail and return false. If it cannot open the file,
572 // the file does not exist, or the memory mapping fails, it will return false.
573 // Later we may want to allow the user to specify access.
574 bool Initialize(const base::FilePath& file_name);
575 // As above, but works with an already-opened file. MemoryMappedFile will take
576 // ownership of |file| and close it when done.
577 bool Initialize(base::PlatformFile file);
578
579 #if defined(OS_WIN)
580 // Opens an existing file and maps it as an image section. Please refer to
581 // the Initialize function above for additional information.
582 bool InitializeAsImageSection(const base::FilePath& file_name);
583 #endif // OS_WIN
584
585 const uint8* data() const { return data_; }
586 size_t length() const { return length_; }
587
588 // Is file_ a valid file handle that points to an open, memory mapped file?
589 bool IsValid() const;
590
591 private:
592 // Open the given file and pass it to MapFileToMemoryInternal().
593 bool MapFileToMemory(const base::FilePath& file_name);
594
595 // Map the file to memory, set data_ to that memory address. Return true on
596 // success, false on any kind of failure. This is a helper for Initialize().
597 bool MapFileToMemoryInternal();
598
599 // Closes all open handles. Later we may want to make this public.
600 void CloseHandles();
601
602 #if defined(OS_WIN)
603 // MapFileToMemoryInternal calls this function. It provides the ability to
604 // pass in flags which control the mapped section.
605 bool MapFileToMemoryInternalEx(int flags);
606
607 HANDLE file_mapping_;
608 #endif
609 base::PlatformFile file_;
610 uint8* data_;
611 size_t length_;
612
613 DISALLOW_COPY_AND_ASSIGN(MemoryMappedFile);
614 };
615
616 // Returns whether the file has been modified since a particular date. 563 // Returns whether the file has been modified since a particular date.
617 BASE_EXPORT bool HasFileBeenModifiedSince( 564 BASE_EXPORT bool HasFileBeenModifiedSince(
618 const FileEnumerator::FindInfo& find_info, 565 const FileEnumerator::FindInfo& find_info,
619 const base::Time& cutoff_time); 566 const base::Time& cutoff_time);
620 567
621 #if defined(OS_LINUX) 568 #if defined(OS_LINUX)
622 // Broad categories of file systems as returned by statfs() on Linux. 569 // Broad categories of file systems as returned by statfs() on Linux.
623 enum FileSystemType { 570 enum FileSystemType {
624 FILE_SYSTEM_UNKNOWN, // statfs failed. 571 FILE_SYSTEM_UNKNOWN, // statfs failed.
625 FILE_SYSTEM_0, // statfs.f_type == 0 means unknown, may indicate AFS. 572 FILE_SYSTEM_0, // statfs.f_type == 0 means unknown, may indicate AFS.
626 FILE_SYSTEM_ORDINARY, // on-disk filesystem like ext2 573 FILE_SYSTEM_ORDINARY, // on-disk filesystem like ext2
627 FILE_SYSTEM_NFS, 574 FILE_SYSTEM_NFS,
628 FILE_SYSTEM_SMB, 575 FILE_SYSTEM_SMB,
629 FILE_SYSTEM_CODA, 576 FILE_SYSTEM_CODA,
630 FILE_SYSTEM_MEMORY, // in-memory file system 577 FILE_SYSTEM_MEMORY, // in-memory file system
631 FILE_SYSTEM_CGROUP, // cgroup control. 578 FILE_SYSTEM_CGROUP, // cgroup control.
632 FILE_SYSTEM_OTHER, // any other value. 579 FILE_SYSTEM_OTHER, // any other value.
633 FILE_SYSTEM_TYPE_COUNT 580 FILE_SYSTEM_TYPE_COUNT
634 }; 581 };
635 582
636 // Attempts determine the FileSystemType for |path|. 583 // Attempts determine the FileSystemType for |path|.
637 // Returns false if |path| doesn't exist. 584 // Returns false if |path| doesn't exist.
638 BASE_EXPORT bool GetFileSystemType(const base::FilePath& path, 585 BASE_EXPORT bool GetFileSystemType(const base::FilePath& path,
639 FileSystemType* type); 586 FileSystemType* type);
640 #endif 587 #endif
641 588
642 } // namespace file_util 589 } // namespace file_util
643 590
644 #endif // BASE_FILE_UTIL_H_ 591 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698