Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <iomanip> | |
|
michaeln
2015/10/20 01:16:14
might not be needed if base::HexEncode is used?
dmurph
2015/10/20 18:28:27
Done.
| |
| 6 | |
| 5 #include "storage/common/data_element.h" | 7 #include "storage/common/data_element.h" |
| 6 | 8 |
| 7 namespace storage { | 9 namespace storage { |
| 8 | 10 |
| 9 DataElement::DataElement() | 11 DataElement::DataElement() |
| 10 : type_(TYPE_UNKNOWN), | 12 : type_(TYPE_UNKNOWN), |
| 11 bytes_(NULL), | 13 bytes_(NULL), |
| 12 offset_(0), | 14 offset_(0), |
| 13 length_(kuint64max) { | 15 length_(kuint64max) { |
| 14 } | 16 } |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 45 length_ = length; | 47 length_ = length; |
| 46 expected_modification_time_ = expected_modification_time; | 48 expected_modification_time_ = expected_modification_time; |
| 47 } | 49 } |
| 48 | 50 |
| 49 void DataElement::SetToDiskCacheEntryRange(uint64 offset, uint64 length) { | 51 void DataElement::SetToDiskCacheEntryRange(uint64 offset, uint64 length) { |
| 50 type_ = TYPE_DISK_CACHE_ENTRY; | 52 type_ = TYPE_DISK_CACHE_ENTRY; |
| 51 offset_ = offset; | 53 offset_ = offset; |
| 52 length_ = length; | 54 length_ = length; |
| 53 } | 55 } |
| 54 | 56 |
| 57 std::ostream& operator<<(std::ostream& os, const DataElement& x) { | |
| 58 const uint64 kMaxDataPrintLength = 40; | |
| 59 os << "<DataElement>{type: "; | |
| 60 switch (x.type()) { | |
| 61 case DataElement::TYPE_BYTES: { | |
| 62 auto flags = os.flags(); | |
| 63 os << "TYPE_BYTES, data: [" << std::hex; | |
|
michaeln
2015/10/20 01:16:14
could use << base::HexEncode(p, len) here
dmurph
2015/10/20 18:28:27
Nice catch.
| |
| 64 uint64 length = std::min(x.length(), kMaxDataPrintLength); | |
| 65 for (size_t i = 0; i < length; i++) { | |
| 66 os << std::setfill('0') << std::setw(2) << +(x.bytes()[i]) << ' '; | |
| 67 } | |
| 68 os.flags(flags); | |
| 69 if (length < x.length()) { | |
| 70 os << "<...truncated due to length...>"; | |
| 71 } | |
| 72 os << "]"; | |
| 73 break; | |
| 74 } | |
| 75 case DataElement::TYPE_FILE: | |
| 76 os << "TYPE_FILE, path: " << x.path().AsUTF8Unsafe() | |
| 77 << ", expected_modification_time: " << x.expected_modification_time(); | |
| 78 break; | |
| 79 case DataElement::TYPE_BLOB: | |
| 80 os << "TYPE_BLOB, uuid: " << x.blob_uuid(); | |
| 81 break; | |
| 82 case DataElement::TYPE_FILE_FILESYSTEM: | |
| 83 os << "TYPE_FILE_FILESYSTEM, filesystem_url: " << x.filesystem_url(); | |
| 84 break; | |
| 85 case DataElement::TYPE_DISK_CACHE_ENTRY: | |
| 86 os << "TYPE_DISK_CACHE_ENTRY"; | |
| 87 break; | |
| 88 case DataElement::TYPE_BYTES_DESCRIPTION: | |
| 89 os << "TYPE_BYTES_DESCRIPTION"; | |
| 90 break; | |
| 91 case DataElement::TYPE_UNKNOWN: | |
| 92 os << "TYPE_UNKNOWN"; | |
| 93 break; | |
| 94 } | |
| 95 os << ", length: " << x.length() << ", offset: " << x.offset() << "}"; | |
| 96 return os; | |
| 97 } | |
| 98 | |
| 55 } // namespace storage | 99 } // namespace storage |
| OLD | NEW |