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 "storage/common/data_element.h" | 5 #include "storage/common/data_element.h" |
6 | 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/strings/string_number_conversions.h" |
| 10 |
7 namespace storage { | 11 namespace storage { |
8 | 12 |
9 DataElement::DataElement() | 13 DataElement::DataElement() |
10 : type_(TYPE_UNKNOWN), | 14 : type_(TYPE_UNKNOWN), |
11 bytes_(NULL), | 15 bytes_(NULL), |
12 offset_(0), | 16 offset_(0), |
13 length_(kuint64max) { | 17 length_(kuint64max) { |
14 } | 18 } |
15 | 19 |
16 DataElement::~DataElement() {} | 20 DataElement::~DataElement() {} |
(...skipping 28 matching lines...) Expand all Loading... |
45 length_ = length; | 49 length_ = length; |
46 expected_modification_time_ = expected_modification_time; | 50 expected_modification_time_ = expected_modification_time; |
47 } | 51 } |
48 | 52 |
49 void DataElement::SetToDiskCacheEntryRange(uint64 offset, uint64 length) { | 53 void DataElement::SetToDiskCacheEntryRange(uint64 offset, uint64 length) { |
50 type_ = TYPE_DISK_CACHE_ENTRY; | 54 type_ = TYPE_DISK_CACHE_ENTRY; |
51 offset_ = offset; | 55 offset_ = offset; |
52 length_ = length; | 56 length_ = length; |
53 } | 57 } |
54 | 58 |
| 59 void PrintTo(const DataElement& x, std::ostream* os) { |
| 60 const uint64 kMaxDataPrintLength = 40; |
| 61 *os << "<DataElement>{type: "; |
| 62 switch (x.type()) { |
| 63 case DataElement::TYPE_BYTES: { |
| 64 uint64 length = std::min(x.length(), kMaxDataPrintLength); |
| 65 *os << "TYPE_BYTES, data: [" |
| 66 << base::HexEncode(x.bytes(), static_cast<size_t>(length)); |
| 67 if (length < x.length()) { |
| 68 *os << "<...truncated due to length...>"; |
| 69 } |
| 70 *os << "]"; |
| 71 break; |
| 72 } |
| 73 case DataElement::TYPE_FILE: |
| 74 *os << "TYPE_FILE, path: " << x.path().AsUTF8Unsafe() |
| 75 << ", expected_modification_time: " << x.expected_modification_time(); |
| 76 break; |
| 77 case DataElement::TYPE_BLOB: |
| 78 *os << "TYPE_BLOB, uuid: " << x.blob_uuid(); |
| 79 break; |
| 80 case DataElement::TYPE_FILE_FILESYSTEM: |
| 81 *os << "TYPE_FILE_FILESYSTEM, filesystem_url: " << x.filesystem_url(); |
| 82 break; |
| 83 case DataElement::TYPE_DISK_CACHE_ENTRY: |
| 84 *os << "TYPE_DISK_CACHE_ENTRY"; |
| 85 break; |
| 86 case DataElement::TYPE_BYTES_DESCRIPTION: |
| 87 *os << "TYPE_BYTES_DESCRIPTION"; |
| 88 break; |
| 89 case DataElement::TYPE_UNKNOWN: |
| 90 *os << "TYPE_UNKNOWN"; |
| 91 break; |
| 92 } |
| 93 *os << ", length: " << x.length() << ", offset: " << x.offset() << "}"; |
| 94 } |
| 95 |
55 } // namespace storage | 96 } // namespace storage |
OLD | NEW |