Index: storage/common/data_element.h |
diff --git a/storage/common/data_element.h b/storage/common/data_element.h |
index 2eeca8e1d9513eb53e384bad97c2e2cea8d9cfc3..4ee5c6453071a03e92c85c2945b75fcc7c9a0d3d 100644 |
--- a/storage/common/data_element.h |
+++ b/storage/common/data_element.h |
@@ -5,6 +5,7 @@ |
#ifndef STORAGE_COMMON_DATA_ELEMENT_H_ |
#define STORAGE_COMMON_DATA_ELEMENT_H_ |
+#include <ostream> |
#include <string> |
#include <vector> |
@@ -24,6 +25,8 @@ class STORAGE_COMMON_EXPORT DataElement { |
enum Type { |
TYPE_UNKNOWN = -1, |
TYPE_BYTES, |
+ // Only used with BlobStorageMsg_StartBuildingBlob |
+ TYPE_BYTES_DESCRIPTION, |
TYPE_FILE, |
TYPE_BLOB, |
TYPE_FILE_FILESYSTEM, |
@@ -44,9 +47,14 @@ class STORAGE_COMMON_EXPORT DataElement { |
return expected_modification_time_; |
} |
+ // For use with SetToAllocatedBytes. Should only be used after calling |
+ // SetToAllocatedBytes. |
+ char* mutable_bytes() { return &buf_[0]; } |
michaeln
2015/08/18 03:04:41
maybe have SetToAllocatedBytes(n) return the char*
dmurph
2015/09/15 01:12:12
I had that, but unfortunately we need the bytes mu
|
+ |
// Sets TYPE_BYTES data. This copies the given data into the element. |
void SetToBytes(const char* bytes, int bytes_len) { |
type_ = TYPE_BYTES; |
+ bytes_ = nullptr; |
buf_.assign(bytes, bytes + bytes_len); |
length_ = buf_.size(); |
} |
@@ -70,6 +78,12 @@ class STORAGE_COMMON_EXPORT DataElement { |
length_ = buf_.size(); |
} |
+ void SetToBytesDescription(size_t bytes_len) { |
+ type_ = TYPE_BYTES_DESCRIPTION; |
+ bytes_ = nullptr; |
+ length_ = bytes_len; |
+ } |
+ |
// Sets TYPE_BYTES data. This does NOT copy the given data and the caller |
// should make sure the data is alive when this element is accessed. |
// You cannot use AppendBytes with this method. |
@@ -79,6 +93,16 @@ class STORAGE_COMMON_EXPORT DataElement { |
length_ = bytes_len; |
} |
+ // Sets TYPE_BYTES data. This allocates the space for the bytes in the |
+ // internal vector but does not populate it with anything. The caller can |
+ // then use the bytes() method to access this buffer and populate it. |
+ void SetToAllocatedBytes(size_t bytes_len) { |
+ type_ = TYPE_BYTES; |
+ bytes_ = nullptr; |
+ buf_.resize(bytes_len); |
+ length_ = bytes_len; |
+ } |
+ |
// Sets TYPE_FILE data. |
void SetToFilePath(const base::FilePath& path) { |
SetToFilePathRange(path, 0, kuint64max, base::Time()); |
@@ -118,6 +142,9 @@ class STORAGE_COMMON_EXPORT DataElement { |
base::Time expected_modification_time_; |
}; |
+STORAGE_COMMON_EXPORT std::ostream& operator<<(std::ostream& os, |
+ const DataElement& x); |
+ |
#if defined(UNIT_TEST) |
inline bool operator==(const DataElement& a, const DataElement& b) { |
if (a.type() != b.type() || |
@@ -138,6 +165,8 @@ inline bool operator==(const DataElement& a, const DataElement& b) { |
// We compare only length and offset; we trust the entry itself was |
// compared at some higher level such as in BlobDataItem. |
return true; |
+ case DataElement::TYPE_BYTES_DESCRIPTION: |
+ return a.length() == b.length(); |
case DataElement::TYPE_UNKNOWN: |
NOTREACHED(); |
return false; |
@@ -148,6 +177,7 @@ inline bool operator==(const DataElement& a, const DataElement& b) { |
inline bool operator!=(const DataElement& a, const DataElement& b) { |
return !(a == b); |
} |
+ |
#endif // defined(UNIT_TEST) |
} // namespace storage |