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

Side by Side Diff: util/file/file_writer.h

Issue 871193010: Add FileHandleFileWriter (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Rename to WeakFileHandleFileWriter Created 5 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
« no previous file with comments | « util/file/file_io.h ('k') | util/file/file_writer.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 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
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 //! FileWriter requires users to provide a FilePath to open, but this class
81 //! accepts an already-open FileHandle instead. Like FileWriter, this class may
82 //! write to a filesystem-based file, but unlike FileWriter, this class is not
83 //! responsible for creating or closing the file. Users of this class must
84 //! ensure that the file handle is closed appropriately elsewhere. Objects of
85 //! this class may be used to write to file handles not associated with
86 //! filesystem-based files, although special attention should be paid to the
87 //! Seek() method, which may not function on file handles that do not refer to
88 //! disk-based files.
89 //!
90 //! This class is expected to be used when other code is responsible for
91 //! creating files and already provides file handles.
92 class WeakFileHandleFileWriter : public FileWriterInterface {
93 public:
94 explicit WeakFileHandleFileWriter(FileHandle file_handle);
95 ~WeakFileHandleFileWriter();
96
97 // FileWriterInterface:
98 bool Write(const void* data, size_t size) override;
99 bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override;
100
101 //! \copydoc FileWriterInterface::Seek()
102 //!
103 //! \note This method is only guaranteed to function on file handles referring
104 //! to disk-based files.
105 FileOffset Seek(FileOffset offset, int whence) override;
106
107 private:
108 void set_file_handle(FileHandle file_handle) { file_handle_ = file_handle; }
109
110 FileHandle file_handle_; // weak
111
112 // FileWriter uses this class as its internal implementation, and it needs to
113 // be able to call set_file_handle(). FileWriter cannot initialize an
114 // WeakFileHandleFileWriter with a correct file descriptor at the time of
115 // construction because no file descriptor will be available until
116 // FileWriter::Open() is called.
117 friend class FileWriter;
118
119 DISALLOW_COPY_AND_ASSIGN(WeakFileHandleFileWriter);
120 };
121
78 //! \brief A file writer implementation that wraps traditional system file 122 //! \brief A file writer implementation that wraps traditional system file
79 //! operations on files accessed through the filesystem. 123 //! operations on files accessed through the filesystem.
80 class FileWriter : public FileWriterInterface { 124 class FileWriter : public FileWriterInterface {
81 public: 125 public:
82 FileWriter(); 126 FileWriter();
83 ~FileWriter(); 127 ~FileWriter();
84 128
85 //! \brief Wraps LoggingOpenFileForWrite(). 129 //! \brief Wraps LoggingOpenFileForWrite().
86 //! 130 //!
87 //! \return `true` if the operation succeeded, `false` if it failed, with an 131 //! \return `true` if the operation succeeded, `false` if it failed, with an
(...skipping 27 matching lines...) Expand all
115 bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override; 159 bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override;
116 160
117 //! \copydoc FileWriterInterface::Seek() 161 //! \copydoc FileWriterInterface::Seek()
118 //! 162 //!
119 //! \note It is only valid to call this method between a successful Open() and 163 //! \note It is only valid to call this method between a successful Open() and
120 //! a Close(). 164 //! a Close().
121 FileOffset Seek(FileOffset offset, int whence) override; 165 FileOffset Seek(FileOffset offset, int whence) override;
122 166
123 private: 167 private:
124 ScopedFileHandle file_; 168 ScopedFileHandle file_;
169 WeakFileHandleFileWriter weak_file_handle_file_writer_;
125 170
126 DISALLOW_COPY_AND_ASSIGN(FileWriter); 171 DISALLOW_COPY_AND_ASSIGN(FileWriter);
127 }; 172 };
128 173
129 } // namespace crashpad 174 } // namespace crashpad
130 175
131 #endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_ 176 #endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_
OLDNEW
« no previous file with comments | « util/file/file_io.h ('k') | util/file/file_writer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698