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

Unified Diff: third_party/crashpad/crashpad/minidump/minidump_user_stream_writer.cc

Issue 2773813002: Update Crashpad to 8e37886d418dd042c3c7bfadac99214739ee4d98 (Closed)
Patch Set: Update Crashpad to 8e37886d418dd042c3c7bfadac99214739ee4d98 Created 3 years, 9 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: third_party/crashpad/crashpad/minidump/minidump_user_stream_writer.cc
diff --git a/third_party/crashpad/crashpad/minidump/minidump_user_stream_writer.cc b/third_party/crashpad/crashpad/minidump/minidump_user_stream_writer.cc
index 7332cd014911936ddb3171f1a94aca684f3c071a..6520f0f402896fada0d404ca44527d9b51630706 100644
--- a/third_party/crashpad/crashpad/minidump/minidump_user_stream_writer.cc
+++ b/third_party/crashpad/crashpad/minidump/minidump_user_stream_writer.cc
@@ -14,13 +14,67 @@
#include "minidump/minidump_user_stream_writer.h"
+#include "base/memory/ptr_util.h"
#include "util/file/file_writer.h"
namespace crashpad {
-MinidumpUserStreamWriter::MinidumpUserStreamWriter()
- : stream_type_(0), reader_() {
-}
+class MinidumpUserStreamWriter::ContentsWriter {
+ public:
+ virtual ~ContentsWriter() {}
+ virtual bool WriteContents(FileWriterInterface* writer) = 0;
+ virtual size_t GetSize() const = 0;
+};
+
+class MinidumpUserStreamWriter::SnapshotContentsWriter final
+ : public MinidumpUserStreamWriter::ContentsWriter,
+ public MemorySnapshot::Delegate {
+ public:
+ explicit SnapshotContentsWriter(const MemorySnapshot* snapshot)
+ : snapshot_(snapshot), writer_(nullptr) {}
+
+ bool WriteContents(FileWriterInterface* writer) override {
+ DCHECK(!writer_);
+
+ writer_ = writer;
+ if (!snapshot_)
+ return true;
+
+ return snapshot_->Read(this);
+ }
+
+ size_t GetSize() const override { return snapshot_ ? snapshot_->Size() : 0; };
+
+ bool MemorySnapshotDelegateRead(void* data, size_t size) override {
+ return writer_->Write(data, size);
+ }
+
+ private:
+ const MemorySnapshot* snapshot_;
+ FileWriterInterface* writer_;
+
+ DISALLOW_COPY_AND_ASSIGN(SnapshotContentsWriter);
+};
+
+class MinidumpUserStreamWriter::BufferContentsWriter final
+ : public MinidumpUserStreamWriter::ContentsWriter {
+ public:
+ BufferContentsWriter(const void* buffer, size_t buffer_size)
+ : buffer_(buffer), buffer_size_(buffer_size) {}
+
+ bool WriteContents(FileWriterInterface* writer) override {
+ return writer->Write(buffer_, buffer_size_);
+ }
+ size_t GetSize() const override { return buffer_size_; }
+
+ private:
+ const void* buffer_;
+ size_t buffer_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(BufferContentsWriter);
+};
+
+MinidumpUserStreamWriter::MinidumpUserStreamWriter() : stream_type_() {}
MinidumpUserStreamWriter::~MinidumpUserStreamWriter() {
}
@@ -28,10 +82,23 @@ MinidumpUserStreamWriter::~MinidumpUserStreamWriter() {
void MinidumpUserStreamWriter::InitializeFromSnapshot(
const UserMinidumpStream* stream) {
DCHECK_EQ(state(), kStateMutable);
+ DCHECK(!contents_writer_.get());
+
+ stream_type_ = static_cast<MinidumpStreamType>(stream->stream_type());
+ contents_writer_ =
+ base::WrapUnique(new SnapshotContentsWriter(stream->memory()));
+}
+
+void MinidumpUserStreamWriter::InitializeFromBuffer(
+ MinidumpStreamType stream_type,
+ const void* buffer,
+ size_t buffer_size) {
+ DCHECK_EQ(state(), kStateMutable);
+ DCHECK(!contents_writer_.get());
- stream_type_ = stream->stream_type();
- if (stream->memory())
- stream->memory()->Read(&reader_);
+ stream_type_ = stream_type;
+ contents_writer_ =
+ base::WrapUnique(new BufferContentsWriter(buffer, buffer_size));
}
bool MinidumpUserStreamWriter::Freeze() {
@@ -42,7 +109,8 @@ bool MinidumpUserStreamWriter::Freeze() {
size_t MinidumpUserStreamWriter::SizeOfObject() {
DCHECK_GE(state(), kStateFrozen);
- return reader_.size();
+
+ return contents_writer_->GetSize();
}
std::vector<internal::MinidumpWritable*>
@@ -53,21 +121,12 @@ MinidumpUserStreamWriter::Children() {
bool MinidumpUserStreamWriter::WriteObject(FileWriterInterface* file_writer) {
DCHECK_EQ(state(), kStateWritable);
- return file_writer->Write(reader_.data(), reader_.size());
+
+ return contents_writer_->WriteContents(file_writer);
}
MinidumpStreamType MinidumpUserStreamWriter::StreamType() const {
return static_cast<MinidumpStreamType>(stream_type_);
}
-MinidumpUserStreamWriter::MemoryReader::~MemoryReader() {}
-
-bool MinidumpUserStreamWriter::MemoryReader::MemorySnapshotDelegateRead(
- void* data,
- size_t size) {
- data_.resize(size);
- memcpy(&data_[0], data, size);
- return true;
-}
-
} // namespace crashpad

Powered by Google App Engine
This is Rietveld 408576698