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, |
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 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_FILE_WRITER_H_ | 15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_FILE_WRITER_H_ |
16 #define CRASHPAD_MINIDUMP_MINIDUMP_FILE_WRITER_H_ | 16 #define CRASHPAD_MINIDUMP_MINIDUMP_FILE_WRITER_H_ |
17 | 17 |
18 #include <dbghelp.h> | 18 #include <dbghelp.h> |
19 #include <sys/types.h> | 19 #include <sys/types.h> |
20 | 20 |
21 #include <set> | 21 #include <set> |
22 #include <vector> | 22 #include <vector> |
23 | 23 |
24 #include "base/basictypes.h" | 24 #include "base/basictypes.h" |
| 25 #include "base/memory/scoped_ptr.h" |
25 #include "minidump/minidump_extensions.h" | 26 #include "minidump/minidump_extensions.h" |
26 #include "minidump/minidump_stream_writer.h" | 27 #include "minidump/minidump_stream_writer.h" |
27 #include "minidump/minidump_writable.h" | 28 #include "minidump/minidump_writable.h" |
| 29 #include "util/stdlib/pointer_container.h" |
28 | 30 |
29 namespace crashpad { | 31 namespace crashpad { |
30 | 32 |
31 //! \brief The root-level object in a minidump file. | 33 //! \brief The root-level object in a minidump file. |
32 //! | 34 //! |
33 //! This object writes a MINIDUMP_HEADER and list of MINIDUMP_DIRECTORY entries | 35 //! This object writes a MINIDUMP_HEADER and list of MINIDUMP_DIRECTORY entries |
34 //! to a minidump file. | 36 //! to a minidump file. |
35 class MinidumpFileWriter final : public internal::MinidumpWritable { | 37 class MinidumpFileWriter final : public internal::MinidumpWritable { |
36 public: | 38 public: |
37 MinidumpFileWriter(); | 39 MinidumpFileWriter(); |
38 ~MinidumpFileWriter(); | 40 ~MinidumpFileWriter() override; |
39 | 41 |
40 //! \brief Sets MINIDUMP_HEADER::Timestamp. | 42 //! \brief Sets MINIDUMP_HEADER::Timestamp. |
41 //! | 43 //! |
42 //! \note Valid in #kStateMutable. | 44 //! \note Valid in #kStateMutable. |
43 void SetTimestamp(time_t timestamp); | 45 void SetTimestamp(time_t timestamp); |
44 | 46 |
45 //! \brief Adds a stream to the minidump file as a child of the object, and | 47 //! \brief Adds a stream to the minidump file and arranges for a |
46 //! arranges for a MINIDUMP_DIRECTORY entry to point to it. | 48 //! MINIDUMP_DIRECTORY entry to point to it. |
| 49 //! |
| 50 //! This object takes ownership of \a stream and becomes its parent in the |
| 51 //! overall tree of internal::MinidumpWritable objects. |
47 //! | 52 //! |
48 //! At most one object of each stream type (as obtained from | 53 //! At most one object of each stream type (as obtained from |
49 //! internal::MinidumpStreamWriter::StreamType()) may be added to a | 54 //! internal::MinidumpStreamWriter::StreamType()) may be added to a |
50 //! MinidumpFileWriter object. It is an error to attempt to add multiple | 55 //! MinidumpFileWriter object. It is an error to attempt to add multiple |
51 //! streams with the same stream type. | 56 //! streams with the same stream type. |
52 //! | 57 //! |
53 //! \note Valid in #kStateMutable. | 58 //! \note Valid in #kStateMutable. |
54 void AddStream(internal::MinidumpStreamWriter* stream); | 59 void AddStream(scoped_ptr<internal::MinidumpStreamWriter> stream); |
55 | 60 |
56 // MinidumpWritable: | 61 // MinidumpWritable: |
57 | 62 |
58 //! \copydoc internal::MinidumpWritable::WriteEverything() | 63 //! \copydoc internal::MinidumpWritable::WriteEverything() |
59 //! | 64 //! |
60 //! This method does not initially write the final value for | 65 //! This method does not initially write the final value for |
61 //! MINIDUMP_HEADER::Signature. After all child objects have been written, it | 66 //! MINIDUMP_HEADER::Signature. After all child objects have been written, it |
62 //! rewinds to the beginning of the file and writes the correct value for this | 67 //! rewinds to the beginning of the file and writes the correct value for this |
63 //! field. This prevents incompletely-written minidump files from being | 68 //! field. This prevents incompletely-written minidump files from being |
64 //! mistaken for valid ones. | 69 //! mistaken for valid ones. |
65 bool WriteEverything(FileWriterInterface* file_writer) override; | 70 bool WriteEverything(FileWriterInterface* file_writer) override; |
66 | 71 |
67 protected: | 72 protected: |
68 // MinidumpWritable: | 73 // MinidumpWritable: |
69 bool Freeze() override; | 74 bool Freeze() override; |
70 size_t SizeOfObject() override; | 75 size_t SizeOfObject() override; |
71 std::vector<MinidumpWritable*> Children() override; | 76 std::vector<MinidumpWritable*> Children() override; |
72 bool WillWriteAtOffsetImpl(off_t offset) override; | 77 bool WillWriteAtOffsetImpl(off_t offset) override; |
73 bool WriteObject(FileWriterInterface* file_writer) override; | 78 bool WriteObject(FileWriterInterface* file_writer) override; |
74 | 79 |
75 private: | 80 private: |
76 MINIDUMP_HEADER header_; | 81 MINIDUMP_HEADER header_; |
77 std::vector<internal::MinidumpStreamWriter*> streams_; // weak | 82 PointerVector<internal::MinidumpStreamWriter> streams_; |
78 | 83 |
79 // Protects against multiple streams with the same ID being added. | 84 // Protects against multiple streams with the same ID being added. |
80 std::set<MinidumpStreamType> stream_types_; | 85 std::set<MinidumpStreamType> stream_types_; |
81 | 86 |
82 DISALLOW_COPY_AND_ASSIGN(MinidumpFileWriter); | 87 DISALLOW_COPY_AND_ASSIGN(MinidumpFileWriter); |
83 }; | 88 }; |
84 | 89 |
85 } // namespace crashpad | 90 } // namespace crashpad |
86 | 91 |
87 #endif // CRASHPAD_MINIDUMP_MINIDUMP_WRITER_H_ | 92 #endif // CRASHPAD_MINIDUMP_MINIDUMP_WRITER_H_ |
OLD | NEW |