Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_ | |
| 6 #define COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_ | |
| 7 | |
| 8 #include <stdint.h> | |
| 9 | |
| 10 #include "base/files/file_path.h" | |
| 11 #include "base/files/scoped_file.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/strings/string_piece.h" | |
| 14 #include "components/browser_watcher/stability_report.pb.h" | |
| 15 | |
| 16 namespace browser_watcher { | |
| 17 | |
| 18 // A class with functionality for writing minimal minidump containers to wrap | |
| 19 // postmortem stability reports. | |
| 20 // TODO(manzagop): remove this class once CrashPad takes over writing postmortem | |
| 21 // minidumps. | |
| 22 class PostmortemMinidumpWriter { | |
| 23 public: | |
| 24 using Position = uint32_t; | |
| 25 | |
| 26 PostmortemMinidumpWriter(); | |
| 27 ~PostmortemMinidumpWriter() = default; | |
| 28 | |
| 29 // Write to |minidump| a minimal minidump that wraps |report|. Returns true on | |
| 30 // success, false otherwise. | |
| 31 bool WriteDump(const base::FilePath& minidump, const StabilityReport& report); | |
| 32 | |
| 33 private: | |
| 34 // The minidump header is always located at the head. | |
| 35 static const Position kHeaderPos = 0U; | |
| 36 | |
| 37 // Allocate |size_bytes| within the minidump. On succress, |pos| contains the | |
|
scottmg
2016/08/03 22:47:06
success
manzagop (departed)
2016/08/10 15:59:51
Done.
| |
| 38 // location of the allocation. Returns true on success, false otherwise. | |
| 39 bool Allocate(size_t size_bytes, Position* pos); | |
| 40 | |
| 41 // Write to pre-allocated space. | |
| 42 template <class DataType> | |
| 43 bool Write(Position pos, const DataType& data); | |
| 44 bool WriteBytes(Position pos, size_t size_bytes, const void* data); | |
| 45 | |
| 46 // Allocate space for and write the contents of |data|. On success, |pos| | |
| 47 // contains the location of the write. Returns true on success, false | |
| 48 // otherwise. | |
| 49 template <class DataType> | |
| 50 bool Append(const DataType& data, Position* pos); | |
| 51 bool AppendBytes(base::StringPiece data, Position* pos); | |
| 52 | |
| 53 // Safely increment |cursor_| by |size_bytes|. | |
| 54 bool IncrementCursor(size_t size_bytes); | |
| 55 | |
| 56 // The next allocatable position. | |
| 57 Position cursor_; | |
| 58 | |
| 59 // The file to write to. | |
| 60 base::ScopedFILE minidump_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(PostmortemMinidumpWriter); | |
| 63 }; | |
| 64 | |
| 65 template <class DataType> | |
| 66 bool PostmortemMinidumpWriter::Write(Position pos, const DataType& data) { | |
| 67 return WriteBytes(pos, sizeof(data), &data); | |
| 68 } | |
| 69 | |
| 70 template <class DataType> | |
| 71 bool PostmortemMinidumpWriter::Append(const DataType& data, Position* pos) { | |
| 72 DCHECK(pos); | |
| 73 if (!Allocate(sizeof(data), pos)) | |
| 74 return false; | |
| 75 return Write(*pos, data); | |
| 76 } | |
| 77 | |
| 78 } // namespace browser_watcher | |
| 79 | |
| 80 #endif // COMPONENTS_BROWSER_WATCHER_POSTMORTEM_MINIDUMP_WRITER_H_ | |
| OLD | NEW |