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

Unified Diff: util/file/file_writer.h

Issue 432003005: Introduce MinidumpWritable, its dependencies, and their tests (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: util/file/file_writer.h
diff --git a/util/file/file_writer.h b/util/file/file_writer.h
new file mode 100644
index 0000000000000000000000000000000000000000..4dd5215861ad8bbc6afb866b6406fadfadbab5ca
--- /dev/null
+++ b/util/file/file_writer.h
@@ -0,0 +1,108 @@
+// Copyright 2014 The Crashpad Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef CRASHPAD_UTIL_FILE_FILE_WRITER_H_
+#define CRASHPAD_UTIL_FILE_FILE_WRITER_H_
+
+#include <fcntl.h>
+#include <stddef.h>
+#include <sys/uio.h>
+#include <unistd.h>
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/files/scoped_file.h"
+
+namespace crashpad {
+
+//! \brief A version of `iovec` with a `const` #iov_base field.
+//!
+//! This structure is intended to be used for write operations.
+//
+// Type compatibility with iovec is tested with static assertions in the
+// implementation file.
+struct WritableIoVec {
+ //! \brief The base address of a memory region for output.
+ const void* iov_base;
+
+ //! \brief The size of the memory pointed to by #iov_base.
+ size_t iov_len;
+};
+
+//! \brief An interface to write to files and other file-like objects with POSIX
+//! semantics.
+class FileWriterInterface {
Robert Sesek 2014/08/01 14:38:04 The assumption here is that checking errno is sill
Mark Mentovai 2014/08/01 16:09:35 rsesek wrote:
+ public:
+ //! \brief Wraps `write()` or provides an alternate implementation with
+ //! identical semantics. This method will write the entire buffer,
+ //! continuing after a short write or after being interrupted.
+ //!
+ //! \return `true` if the operation succeeded, `false` if it failed, with an
+ //! error message logged.
+ virtual bool Write(const void* data, size_t size) = 0;
+
+ //! \brief Wraps `writev()` or provides an alternate implementation with
+ //! identical semantics. This method will write the entire buffer,
+ //! continuing after a short write or after being interrupted.
+ //!
+ //! \return `true` if the operation succeeded, `false` if it failed, with an
+ //! error message logged.
+ //!
+ //! \note The contents of \a iovecs are undefined when this method returns.
+ virtual bool WriteIoVec(std::vector<WritableIoVec>* iovecs) = 0;
+
+ //! \brief Wraps `lseek()` or provides an alternate implementation with
+ //! identical semantics.
+ //!
+ //! \return The return value of `lseek()`. `-1` on failure, with an error
+ //! message logged.
+ virtual off_t Seek(off_t offset, int whence) = 0;
+
+ protected:
+ ~FileWriterInterface() {}
+};
+
+//! \brief A file writer implementation that wraps traditional POSIX file
+//! operations on files accessed through the filesystem.
+class FileWriter : public FileWriterInterface {
+ public:
+ FileWriter();
+ ~FileWriter();
+
+ //! \brief Wraps `open()`.
Robert Sesek 2014/08/01 14:38:04 Probably need to mention that you can't call this
+ //!
+ //! \return `true` if the operation succeeded, `false` if it failed, with an
+ //! error message logged.
+ bool Open(const std::string& path, int oflag, mode_t mode);
Robert Sesek 2014/08/01 14:38:04 Any thought on using base::FilePath?
Mark Mentovai 2014/08/01 16:09:35 rsesek wrote:
+
+ //! \brief Wraps `close().`
+ void Close();
+
+ virtual bool Write(const void* data, size_t size) override;
Robert Sesek 2014/08/01 14:38:04 Style is typically: // FileWriterInterface: And
Mark Mentovai 2014/08/01 16:09:35 rsesek wrote:
+
+ virtual bool WriteIoVec(std::vector<WritableIoVec>* iovecs) override;
+
+ virtual off_t Seek(off_t offset, int whence) override;
+
+ private:
+ base::ScopedFD fd_;
+
+ DISALLOW_COPY_AND_ASSIGN(FileWriter);
+};
+
+} // namespace crashpad
+
+#endif // CRASHPAD_UTIL_FILE_FILE_WRITER_H_

Powered by Google App Engine
This is Rietveld 408576698