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 #ifndef STORAGE_COMMON_DATA_ELEMENT_H_ | 5 #ifndef STORAGE_COMMON_DATA_ELEMENT_H_ |
6 #define STORAGE_COMMON_DATA_ELEMENT_H_ | 6 #define STORAGE_COMMON_DATA_ELEMENT_H_ |
7 | 7 |
8 #include <ostream> | 8 #include <ostream> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 std::vector<char> buf_; // For TYPE_BYTES. | 137 std::vector<char> buf_; // For TYPE_BYTES. |
138 const char* bytes_; // For TYPE_BYTES. | 138 const char* bytes_; // For TYPE_BYTES. |
139 base::FilePath path_; // For TYPE_FILE. | 139 base::FilePath path_; // For TYPE_FILE. |
140 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. | 140 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. |
141 std::string blob_uuid_; | 141 std::string blob_uuid_; |
142 uint64 offset_; | 142 uint64 offset_; |
143 uint64 length_; | 143 uint64 length_; |
144 base::Time expected_modification_time_; | 144 base::Time expected_modification_time_; |
145 }; | 145 }; |
146 | 146 |
147 #if defined(UNIT_TEST) | 147 STORAGE_COMMON_EXPORT bool operator==(const DataElement& a, |
148 inline bool operator==(const DataElement& a, const DataElement& b) { | 148 const DataElement& b); |
149 if (a.type() != b.type() || | 149 STORAGE_COMMON_EXPORT bool operator!=(const DataElement& a, |
150 a.offset() != b.offset() || | 150 const DataElement& b); |
151 a.length() != b.length()) | |
152 return false; | |
153 switch (a.type()) { | |
154 case DataElement::TYPE_BYTES: | |
155 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; | |
156 case DataElement::TYPE_FILE: | |
157 return a.path() == b.path() && | |
158 a.expected_modification_time() == b.expected_modification_time(); | |
159 case DataElement::TYPE_BLOB: | |
160 return a.blob_uuid() == b.blob_uuid(); | |
161 case DataElement::TYPE_FILE_FILESYSTEM: | |
162 return a.filesystem_url() == b.filesystem_url(); | |
163 case DataElement::TYPE_DISK_CACHE_ENTRY: | |
164 // We compare only length and offset; we trust the entry itself was | |
165 // compared at some higher level such as in BlobDataItem. | |
166 return true; | |
167 case DataElement::TYPE_BYTES_DESCRIPTION: | |
168 return true; | |
169 case DataElement::TYPE_UNKNOWN: | |
170 NOTREACHED(); | |
171 return false; | |
172 } | |
173 return false; | |
174 } | |
175 | |
176 inline bool operator!=(const DataElement& a, const DataElement& b) { | |
177 return !(a == b); | |
178 } | |
179 #endif // defined(UNIT_TEST) | |
180 | 151 |
181 } // namespace storage | 152 } // namespace storage |
182 | 153 |
183 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ | 154 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ |
OLD | NEW |