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 #include "components/tracing/test/fake_scattered_buffer.h" | |
| 6 | |
| 7 #include <string.h> | |
| 8 | |
| 9 #include "base/strings/string_number_conversions.h" | |
| 10 | |
| 11 namespace tracing { | |
| 12 namespace v2 { | |
| 13 | |
| 14 FakeScatteredBuffer::FakeScatteredBuffer(size_t chunk_size) | |
| 15 : chunk_size_(chunk_size) {} | |
| 16 | |
| 17 FakeScatteredBuffer::~FakeScatteredBuffer() {} | |
| 18 | |
| 19 ContiguousMemoryRange FakeScatteredBuffer::GetNewBuffer() { | |
| 20 std::unique_ptr<uint8_t[]> chunk(new uint8_t[chunk_size_]); | |
| 21 uint8_t* begin = chunk.get(); | |
| 22 memset(begin, 0, chunk_size_); | |
| 23 chunks_.push_back(std::move(chunk)); | |
| 24 return {begin, begin + chunk_size_}; | |
| 25 } | |
| 26 | |
| 27 std::string FakeScatteredBuffer::GetChunkAsString(int chunk_index) { | |
| 28 return base::HexEncode(chunks_[chunk_index].get(), chunk_size_); | |
| 29 } | |
| 30 | |
| 31 std::string FakeScatteredBuffer::GetBytesAsString(size_t start, size_t length) { | |
| 32 std::string hexstr; | |
| 33 for (size_t pos = start; pos < start + length; ++pos) { | |
| 34 const size_t chunk_idx = pos / chunk_size_; | |
| 35 const size_t chunk_off = pos % chunk_size_; | |
| 36 DCHECK_LT(chunk_idx, chunks_.size()); | |
|
petrcermak
2016/07/12 10:29:44
Given that this will only be used in tests, wouldn
Primiano Tucci (use gerrit)
2016/07/12 11:04:26
all bots these days run with DCHECK_ALWAYS_ON (so
| |
| 37 hexstr += base::HexEncode(&chunks_[chunk_idx].get()[chunk_off], 1); | |
| 38 } | |
| 39 return hexstr; | |
| 40 } | |
| 41 | |
| 42 } // namespace v2 | |
| 43 } // namespace tracing | |
| OLD | NEW |