Chromium Code Reviews| Index: util/file/file_writer.h |
| diff --git a/util/file/file_writer.h b/util/file/file_writer.h |
| index 7b9524fc537caa22cbf057e66181993093d99029..234211159378c8e11a98603c4b0e49fc51ee0fb1 100644 |
| --- a/util/file/file_writer.h |
| +++ b/util/file/file_writer.h |
| @@ -75,6 +75,48 @@ class FileWriterInterface { |
| ~FileWriterInterface() {} |
| }; |
| +//! \brief A file writer backed by a FileHandle. |
| +//! |
| +//! Like FileWriter, this class may write to a filesystem-based file, but unlike |
| +//! FileWriter, this class is not responsible for creating or closing the file. |
| +//! Users of this class must ensure that the file handle is closed appropriately |
| +//! elsewhere. This class may also be used to write to file handles not |
| +//! associated with disk-based files, although special attention should be paid |
| +//! to the Seek() method, which may not function on file handles that do not |
| +//! refer to disk-based files. |
| +//! |
| +//! This class is expected to be used when other code is responsible for |
| +//! creating files and already provides file handles. |
| +class FileHandleFileWriter : public FileWriterInterface { |
| + public: |
| + explicit FileHandleFileWriter(FileHandle file_handle); |
| + ~FileHandleFileWriter(); |
| + |
| + // FileWriterInterface: |
| + bool Write(const void* data, size_t size) override; |
| + bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override; |
| + |
| + //! \copydoc FileWriterInterface::Seek() |
| + //! |
| + //! \note This method is only guaranteed to function on file handles referring |
| + //! to disk-based files. |
| + FileOffset Seek(FileOffset offset, int whence) override; |
| + |
| + private: |
| + void set_file_handle(FileHandle file_handle) { file_handle_ = file_handle; } |
| + |
| + FileHandle file_handle_; // weak |
| + |
| + // FileWriter uses this class as its internal implementation, and it needs to |
| + // be able to call set_file_handle(). FileWriter cannot initialize an |
| + // FileHandleFileWriter with a correct file descriptor at the time of |
|
scottmg
2015/02/04 21:14:10
extra space here
|
| + // construction because no file descriptor will be available until |
| + // FileWriter::Open() is called. |
| + friend class FileWriter; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(FileHandleFileWriter); |
| +}; |
| + |
| //! \brief A file writer implementation that wraps traditional system file |
| //! operations on files accessed through the filesystem. |
| class FileWriter : public FileWriterInterface { |
| @@ -122,6 +164,7 @@ class FileWriter : public FileWriterInterface { |
| private: |
| ScopedFileHandle file_; |
| + FileHandleFileWriter file_handle_file_writer_; |
| DISALLOW_COPY_AND_ASSIGN(FileWriter); |
| }; |