OLD | NEW |
1 // Copyright 2017 The Crashpad Authors. All rights reserved. | 1 // Copyright 2017 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_USER_EXTENSION_STREAM_DATA_SOURCE_H_ | 15 #ifndef CRASHPAD_MINIDUMP_MINIDUMP_USER_EXTENSION_STREAM_DATA_SOURCE_H_ |
16 #define CRASHPAD_MINIDUMP_MINIDUMP_USER_EXTENSION_STREAM_DATA_SOURCE_H_ | 16 #define CRASHPAD_MINIDUMP_MINIDUMP_USER_EXTENSION_STREAM_DATA_SOURCE_H_ |
17 | 17 |
18 #include <stdint.h> | 18 #include <stdint.h> |
19 #include <sys/types.h> | 19 #include <sys/types.h> |
20 | 20 |
21 #include "base/macros.h" | 21 #include "base/macros.h" |
22 | 22 |
23 #include "minidump/minidump_extensions.h" | 23 #include "minidump/minidump_extensions.h" |
24 | 24 |
25 namespace crashpad { | 25 namespace crashpad { |
26 | 26 |
27 //! \brief Describes a user extension data stream in a minidump. | 27 //! \brief Describes a user extension data stream in a minidump. |
28 class MinidumpUserExtensionStreamDataSource { | 28 class MinidumpUserExtensionStreamDataSource { |
29 public: | 29 public: |
| 30 //! \brief An interface implemented by readers of |
| 31 //! MinidumpUserExtensionStreamDataSource. |
| 32 class Delegate { |
| 33 public: |
| 34 //! \brief Called by MinidumpUserExtensionStreamDataSource::Read() to |
| 35 //! provide data requested by a call to that method. |
| 36 //! |
| 37 //! \param[in] data A pointer to the data that was read. The callee does not |
| 38 //! take ownership of this data. This data is only valid for the |
| 39 //! duration of the call to this method. This parameter may be `nullptr` |
| 40 //! if \a size is `0`. |
| 41 //! \param[in] size The size of the data that was read. |
| 42 //! |
| 43 //! \return `true` on success, `false` on failure. |
| 44 //! MinidumpUserExtensionStreamDataSource::ReadStreamData() will use |
| 45 //! this as its own return value. |
| 46 virtual bool ExtensionStreamDataSourceRead(const void* data, |
| 47 size_t size) = 0; |
| 48 |
| 49 protected: |
| 50 ~Delegate() {} |
| 51 }; |
| 52 |
30 //! \brief Constructs a MinidumpUserExtensionStreamDataSource. | 53 //! \brief Constructs a MinidumpUserExtensionStreamDataSource. |
31 //! | 54 //! |
32 //! \param[in] stream_type The type of the user extension stream. | 55 //! \param[in] stream_type The type of the user extension stream. |
33 //! \param[in] buffer Points to the data for this stream. \a buffer is not | 56 explicit MinidumpUserExtensionStreamDataSource(uint32_t stream_type); |
34 //! owned, and must outlive the use of this object. | 57 virtual ~MinidumpUserExtensionStreamDataSource(); |
35 //! \param[in] buffer_size The length of data in \a buffer. | |
36 MinidumpUserExtensionStreamDataSource(uint32_t stream_type, | |
37 const void* buffer, | |
38 size_t buffer_size); | |
39 ~MinidumpUserExtensionStreamDataSource(); | |
40 | 58 |
41 MinidumpStreamType stream_type() const { return stream_type_; } | 59 MinidumpStreamType stream_type() const { return stream_type_; } |
42 const void* buffer() const { return buffer_; } | 60 |
43 size_t buffer_size() const { return buffer_size_; } | 61 //! \brief The size of this data stream. |
| 62 virtual size_t StreamDataSize() = 0; |
| 63 |
| 64 //! \brief Calls Delegate::UserStreamDataSourceRead(), providing it with |
| 65 //! the stream data. |
| 66 //! |
| 67 //! Implementations do not necessarily compute the stream data prior to |
| 68 //! this method being called. The stream data may be computed or loaded |
| 69 //! lazily and may be discarded after being passed to the delegate. |
| 70 //! |
| 71 //! \return `false` on failure, otherwise, the return value of |
| 72 //! Delegate::ExtensionStreamDataSourceRead(), which should be `true` on |
| 73 //! success and `false` on failure. |
| 74 virtual bool ReadStreamData(Delegate* delegate) = 0; |
44 | 75 |
45 private: | 76 private: |
46 MinidumpStreamType stream_type_; | 77 MinidumpStreamType stream_type_; |
47 const void* buffer_; // weak | |
48 size_t buffer_size_; | |
49 | 78 |
50 DISALLOW_COPY_AND_ASSIGN(MinidumpUserExtensionStreamDataSource); | 79 DISALLOW_COPY_AND_ASSIGN(MinidumpUserExtensionStreamDataSource); |
51 }; | 80 }; |
52 | 81 |
53 } // namespace crashpad | 82 } // namespace crashpad |
54 | 83 |
55 #endif // CRASHPAD_MINIDUMP_MINIDUMP_USER_EXTENSION_STREAM_DATA_SOURCE_H_ | 84 #endif // CRASHPAD_MINIDUMP_MINIDUMP_USER_EXTENSION_STREAM_DATA_SOURCE_H_ |
OLD | NEW |