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> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 | 10 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 case DataElement::TYPE_BYTES_DESCRIPTION: | 86 case DataElement::TYPE_BYTES_DESCRIPTION: |
87 *os << "TYPE_BYTES_DESCRIPTION"; | 87 *os << "TYPE_BYTES_DESCRIPTION"; |
88 break; | 88 break; |
89 case DataElement::TYPE_UNKNOWN: | 89 case DataElement::TYPE_UNKNOWN: |
90 *os << "TYPE_UNKNOWN"; | 90 *os << "TYPE_UNKNOWN"; |
91 break; | 91 break; |
92 } | 92 } |
93 *os << ", length: " << x.length() << ", offset: " << x.offset() << "}"; | 93 *os << ", length: " << x.length() << ", offset: " << x.offset() << "}"; |
94 } | 94 } |
95 | 95 |
| 96 bool operator==(const DataElement& a, const DataElement& b) { |
| 97 if (a.type() != b.type() || a.offset() != b.offset() || |
| 98 a.length() != b.length()) |
| 99 return false; |
| 100 switch (a.type()) { |
| 101 case DataElement::TYPE_BYTES: |
| 102 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; |
| 103 case DataElement::TYPE_FILE: |
| 104 return a.path() == b.path() && |
| 105 a.expected_modification_time() == b.expected_modification_time(); |
| 106 case DataElement::TYPE_BLOB: |
| 107 return a.blob_uuid() == b.blob_uuid(); |
| 108 case DataElement::TYPE_FILE_FILESYSTEM: |
| 109 return a.filesystem_url() == b.filesystem_url(); |
| 110 case DataElement::TYPE_DISK_CACHE_ENTRY: |
| 111 // We compare only length and offset; we trust the entry itself was |
| 112 // compared at some higher level such as in BlobDataItem. |
| 113 return true; |
| 114 case DataElement::TYPE_BYTES_DESCRIPTION: |
| 115 return true; |
| 116 case DataElement::TYPE_UNKNOWN: |
| 117 NOTREACHED(); |
| 118 return false; |
| 119 } |
| 120 return false; |
| 121 } |
| 122 |
| 123 bool operator!=(const DataElement& a, const DataElement& b) { |
| 124 return !(a == b); |
| 125 } |
| 126 |
96 } // namespace storage | 127 } // namespace storage |
OLD | NEW |