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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Crashpad Authors. All rights reserved. 1 // Copyright 2016 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,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "minidump/minidump_user_stream_writer.h" 15 #include "minidump/minidump_user_stream_writer.h"
16 16
17 #include "base/memory/ptr_util.h"
17 #include "util/file/file_writer.h" 18 #include "util/file/file_writer.h"
18 19
19 namespace crashpad { 20 namespace crashpad {
20 21
21 MinidumpUserStreamWriter::MinidumpUserStreamWriter() 22 class MinidumpUserStreamWriter::ContentsWriter {
22 : stream_type_(0), reader_() { 23 public:
23 } 24 virtual ~ContentsWriter() {}
25 virtual bool WriteContents(FileWriterInterface* writer) = 0;
26 virtual size_t GetSize() const = 0;
27 };
28
29 class MinidumpUserStreamWriter::SnapshotContentsWriter final
30 : public MinidumpUserStreamWriter::ContentsWriter,
31 public MemorySnapshot::Delegate {
32 public:
33 explicit SnapshotContentsWriter(const MemorySnapshot* snapshot)
34 : snapshot_(snapshot), writer_(nullptr) {}
35
36 bool WriteContents(FileWriterInterface* writer) override {
37 DCHECK(!writer_);
38
39 writer_ = writer;
40 if (!snapshot_)
41 return true;
42
43 return snapshot_->Read(this);
44 }
45
46 size_t GetSize() const override { return snapshot_ ? snapshot_->Size() : 0; };
47
48 bool MemorySnapshotDelegateRead(void* data, size_t size) override {
49 return writer_->Write(data, size);
50 }
51
52 private:
53 const MemorySnapshot* snapshot_;
54 FileWriterInterface* writer_;
55
56 DISALLOW_COPY_AND_ASSIGN(SnapshotContentsWriter);
57 };
58
59 class MinidumpUserStreamWriter::BufferContentsWriter final
60 : public MinidumpUserStreamWriter::ContentsWriter {
61 public:
62 BufferContentsWriter(const void* buffer, size_t buffer_size)
63 : buffer_(buffer), buffer_size_(buffer_size) {}
64
65 bool WriteContents(FileWriterInterface* writer) override {
66 return writer->Write(buffer_, buffer_size_);
67 }
68 size_t GetSize() const override { return buffer_size_; }
69
70 private:
71 const void* buffer_;
72 size_t buffer_size_;
73
74 DISALLOW_COPY_AND_ASSIGN(BufferContentsWriter);
75 };
76
77 MinidumpUserStreamWriter::MinidumpUserStreamWriter() : stream_type_() {}
24 78
25 MinidumpUserStreamWriter::~MinidumpUserStreamWriter() { 79 MinidumpUserStreamWriter::~MinidumpUserStreamWriter() {
26 } 80 }
27 81
28 void MinidumpUserStreamWriter::InitializeFromSnapshot( 82 void MinidumpUserStreamWriter::InitializeFromSnapshot(
29 const UserMinidumpStream* stream) { 83 const UserMinidumpStream* stream) {
30 DCHECK_EQ(state(), kStateMutable); 84 DCHECK_EQ(state(), kStateMutable);
85 DCHECK(!contents_writer_.get());
31 86
32 stream_type_ = stream->stream_type(); 87 stream_type_ = static_cast<MinidumpStreamType>(stream->stream_type());
33 if (stream->memory()) 88 contents_writer_ =
34 stream->memory()->Read(&reader_); 89 base::WrapUnique(new SnapshotContentsWriter(stream->memory()));
90 }
91
92 void MinidumpUserStreamWriter::InitializeFromBuffer(
93 MinidumpStreamType stream_type,
94 const void* buffer,
95 size_t buffer_size) {
96 DCHECK_EQ(state(), kStateMutable);
97 DCHECK(!contents_writer_.get());
98
99 stream_type_ = stream_type;
100 contents_writer_ =
101 base::WrapUnique(new BufferContentsWriter(buffer, buffer_size));
35 } 102 }
36 103
37 bool MinidumpUserStreamWriter::Freeze() { 104 bool MinidumpUserStreamWriter::Freeze() {
38 DCHECK_EQ(state(), kStateMutable); 105 DCHECK_EQ(state(), kStateMutable);
39 DCHECK_NE(stream_type_, 0u); 106 DCHECK_NE(stream_type_, 0u);
40 return MinidumpStreamWriter::Freeze(); 107 return MinidumpStreamWriter::Freeze();
41 } 108 }
42 109
43 size_t MinidumpUserStreamWriter::SizeOfObject() { 110 size_t MinidumpUserStreamWriter::SizeOfObject() {
44 DCHECK_GE(state(), kStateFrozen); 111 DCHECK_GE(state(), kStateFrozen);
45 return reader_.size(); 112
113 return contents_writer_->GetSize();
46 } 114 }
47 115
48 std::vector<internal::MinidumpWritable*> 116 std::vector<internal::MinidumpWritable*>
49 MinidumpUserStreamWriter::Children() { 117 MinidumpUserStreamWriter::Children() {
50 DCHECK_GE(state(), kStateFrozen); 118 DCHECK_GE(state(), kStateFrozen);
51 return std::vector<internal::MinidumpWritable*>(); 119 return std::vector<internal::MinidumpWritable*>();
52 } 120 }
53 121
54 bool MinidumpUserStreamWriter::WriteObject(FileWriterInterface* file_writer) { 122 bool MinidumpUserStreamWriter::WriteObject(FileWriterInterface* file_writer) {
55 DCHECK_EQ(state(), kStateWritable); 123 DCHECK_EQ(state(), kStateWritable);
56 return file_writer->Write(reader_.data(), reader_.size()); 124
125 return contents_writer_->WriteContents(file_writer);
57 } 126 }
58 127
59 MinidumpStreamType MinidumpUserStreamWriter::StreamType() const { 128 MinidumpStreamType MinidumpUserStreamWriter::StreamType() const {
60 return static_cast<MinidumpStreamType>(stream_type_); 129 return static_cast<MinidumpStreamType>(stream_type_);
61 } 130 }
62 131
63 MinidumpUserStreamWriter::MemoryReader::~MemoryReader() {}
64
65 bool MinidumpUserStreamWriter::MemoryReader::MemorySnapshotDelegateRead(
66 void* data,
67 size_t size) {
68 data_.resize(size);
69 memcpy(&data_[0], data, size);
70 return true;
71 }
72
73 } // namespace crashpad 132 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698