| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 CHROME_PROFILING_MEMLOG_STREAM_PARSER_H_ |
| 6 #define CHROME_PROFILING_MEMLOG_STREAM_PARSER_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "chrome/profiling/memlog_receiver.h" |
| 12 #include "chrome/profiling/memlog_stream_receiver.h" |
| 13 |
| 14 namespace profiling { |
| 15 |
| 16 // Parses a memory stream. Refcounted via StreamReceiver. |
| 17 class MemlogStreamParser : public MemlogStreamReceiver { |
| 18 public: |
| 19 // Receiver must outlive this class. |
| 20 explicit MemlogStreamParser(MemlogReceiver* receiver); |
| 21 ~MemlogStreamParser(); |
| 22 |
| 23 // StreamReceiver implementation. |
| 24 void OnStreamData(std::unique_ptr<char[]> data, size_t sz) override; |
| 25 void OnStreamComplete() override; |
| 26 |
| 27 private: |
| 28 struct Block; |
| 29 |
| 30 enum ReadStatus { |
| 31 READ_OK, // Read OK. |
| 32 READ_ERROR, // Fatal error, don't send more data. |
| 33 READ_NO_DATA // Not enough data, try again when we get more |
| 34 }; |
| 35 |
| 36 // Returns true if the given number of bytes are available now. |
| 37 bool AreBytesAvailable(size_t count) const; |
| 38 |
| 39 // Returns false if not enough bytes are available. |
| 40 bool PeekBytes(size_t count, void* dest) const; |
| 41 bool ReadBytes(size_t count, void* dest); |
| 42 void ConsumeBytes(size_t count); // Bytes must be available. |
| 43 |
| 44 ReadStatus ParseHeader(); |
| 45 ReadStatus ParseAlloc(); |
| 46 ReadStatus ParseFree(); |
| 47 |
| 48 MemlogReceiver* receiver_; // Unowned. |
| 49 |
| 50 std::vector<Block> blocks_; |
| 51 |
| 52 bool received_header_ = false; |
| 53 |
| 54 // Current offset into blocks_[0] of the next packet to process. |
| 55 size_t block_zero_offset_ = 0; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(MemlogStreamParser); |
| 58 }; |
| 59 |
| 60 } // namespace profiling |
| 61 |
| 62 #endif // CHROME_PROFILING_MEMLOG_STREAM_PARSER_H_ |
| OLD | NEW |