Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 //! with identical semantics. | 68 //! with identical semantics. |
| 69 //! | 69 //! |
| 70 //! \return The return value of LoggingFileSeek(). `-1` on failure, | 70 //! \return The return value of LoggingFileSeek(). `-1` on failure, |
| 71 //! with an error message logged. | 71 //! with an error message logged. |
| 72 virtual FileOffset Seek(FileOffset offset, int whence) = 0; | 72 virtual FileOffset Seek(FileOffset offset, int whence) = 0; |
| 73 | 73 |
| 74 protected: | 74 protected: |
| 75 ~FileWriterInterface() {} | 75 ~FileWriterInterface() {} |
| 76 }; | 76 }; |
| 77 | 77 |
| 78 //! \brief A file writer backed by a FileHandle. | |
| 79 //! | |
| 80 //! Like FileWriter, this class may write to a filesystem-based file, but unlike | |
| 81 //! FileWriter, this class is not responsible for creating or closing the file. | |
| 82 //! Users of this class must ensure that the file handle is closed appropriately | |
| 83 //! elsewhere. This class may also be used to write to file handles not | |
| 84 //! associated with disk-based files, although special attention should be paid | |
| 85 //! to the Seek() method, which may not function on file handles that do not | |
| 86 //! refer to disk-based files. | |
| 87 //! | |
| 88 //! This class is expected to be used when other code is responsible for | |
| 89 //! creating files and already provides file handles. | |
| 90 class FileHandleFileWriter : public FileWriterInterface { | |
| 91 public: | |
| 92 explicit FileHandleFileWriter(FileHandle file_handle); | |
| 93 ~FileHandleFileWriter(); | |
| 94 | |
| 95 // FileWriterInterface: | |
| 96 bool Write(const void* data, size_t size) override; | |
| 97 bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override; | |
| 98 | |
| 99 //! \copydoc FileWriterInterface::Seek() | |
| 100 //! | |
| 101 //! \note This method is only guaranteed to function on file handles referring | |
| 102 //! to disk-based files. | |
| 103 FileOffset Seek(FileOffset offset, int whence) override; | |
| 104 | |
| 105 private: | |
| 106 void set_file_handle(FileHandle file_handle) { file_handle_ = file_handle; } | |
| 107 | |
| 108 FileHandle file_handle_; // weak | |
| 109 | |
| 110 // FileWriter uses this class as its internal implementation, and it needs to | |
| 111 // be able to call set_file_handle(). FileWriter cannot initialize an | |
| 112 // FileHandleFileWriter with a correct file descriptor at the time of | |
|
scottmg
2015/02/04 21:14:10
extra space here
| |
| 113 // construction because no file descriptor will be available until | |
| 114 // FileWriter::Open() is called. | |
| 115 friend class FileWriter; | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(FileHandleFileWriter); | |
| 118 }; | |
| 119 | |
| 78 //! \brief A file writer implementation that wraps traditional system file | 120 //! \brief A file writer implementation that wraps traditional system file |
| 79 //! operations on files accessed through the filesystem. | 121 //! operations on files accessed through the filesystem. |
| 80 class FileWriter : public FileWriterInterface { | 122 class FileWriter : public FileWriterInterface { |
| 81 public: | 123 public: |
| 82 FileWriter(); | 124 FileWriter(); |
| 83 ~FileWriter(); | 125 ~FileWriter(); |
| 84 | 126 |
| 85 //! \brief Wraps LoggingOpenFileForWrite(). | 127 //! \brief Wraps LoggingOpenFileForWrite(). |
| 86 //! | 128 //! |
| 87 //! \return `true` if the operation succeeded, `false` if it failed, with an | 129 //! \return `true` if the operation succeeded, `false` if it failed, with an |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 115 bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override; | 157 bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override; |
| 116 | 158 |
| 117 //! \copydoc FileWriterInterface::Seek() | 159 //! \copydoc FileWriterInterface::Seek() |
| 118 //! | 160 //! |
| 119 //! \note It is only valid to call this method between a successful Open() and | 161 //! \note It is only valid to call this method between a successful Open() and |
| 120 //! a Close(). | 162 //! a Close(). |
| 121 FileOffset Seek(FileOffset offset, int whence) override; | 163 FileOffset Seek(FileOffset offset, int whence) override; |
| 122 | 164 |
| 123 private: | 165 private: |
| 124 ScopedFileHandle file_; | 166 ScopedFileHandle file_; |
| 167 FileHandleFileWriter file_handle_file_writer_; | |
| 125 | 168 |
| 126 DISALLOW_COPY_AND_ASSIGN(FileWriter); | 169 DISALLOW_COPY_AND_ASSIGN(FileWriter); |
| 127 }; | 170 }; |
| 128 | 171 |
| 129 } // namespace crashpad | 172 } // namespace crashpad |
| 130 | 173 |
| 131 #endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_ | 174 #endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_ |
| OLD | NEW |