Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Unified Diff: storage/common/data_element.cc

Issue 1288373002: [BlobAsync] Patch 2: Common Constants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@async1
Patch Set: removed messages Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: storage/common/data_element.cc
diff --git a/storage/common/data_element.cc b/storage/common/data_element.cc
index f26058b7fb42875343474391d615fc11c2d546bf..c2e40c9a426643e92b12194cf74fd4bd57541a89 100644
--- a/storage/common/data_element.cc
+++ b/storage/common/data_element.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#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.
+
#include "storage/common/data_element.h"
namespace storage {
@@ -52,4 +54,46 @@ void DataElement::SetToDiskCacheEntryRange(uint64 offset, uint64 length) {
length_ = length;
}
+std::ostream& operator<<(std::ostream& os, const DataElement& x) {
+ const uint64 kMaxDataPrintLength = 40;
+ os << "<DataElement>{type: ";
+ switch (x.type()) {
+ case DataElement::TYPE_BYTES: {
+ auto flags = os.flags();
+ 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.
+ uint64 length = std::min(x.length(), kMaxDataPrintLength);
+ for (size_t i = 0; i < length; i++) {
+ os << std::setfill('0') << std::setw(2) << +(x.bytes()[i]) << ' ';
+ }
+ os.flags(flags);
+ if (length < x.length()) {
+ os << "<...truncated due to length...>";
+ }
+ os << "]";
+ break;
+ }
+ case DataElement::TYPE_FILE:
+ os << "TYPE_FILE, path: " << x.path().AsUTF8Unsafe()
+ << ", expected_modification_time: " << x.expected_modification_time();
+ break;
+ case DataElement::TYPE_BLOB:
+ os << "TYPE_BLOB, uuid: " << x.blob_uuid();
+ break;
+ case DataElement::TYPE_FILE_FILESYSTEM:
+ os << "TYPE_FILE_FILESYSTEM, filesystem_url: " << x.filesystem_url();
+ break;
+ case DataElement::TYPE_DISK_CACHE_ENTRY:
+ os << "TYPE_DISK_CACHE_ENTRY";
+ break;
+ case DataElement::TYPE_BYTES_DESCRIPTION:
+ os << "TYPE_BYTES_DESCRIPTION";
+ break;
+ case DataElement::TYPE_UNKNOWN:
+ os << "TYPE_UNKNOWN";
+ break;
+ }
+ os << ", length: " << x.length() << ", offset: " << x.offset() << "}";
+ return os;
+}
+
} // namespace storage

Powered by Google App Engine
This is Rietveld 408576698