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

Unified Diff: storage/common/data_element.h

Issue 1288373002: [BlobAsync] Patch 2: Common Constants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@async1
Patch Set: comments 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
« no previous file with comments | « storage/common/blob_storage/blob_storage_constants.h ('k') | storage/common/data_element.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: storage/common/data_element.h
diff --git a/storage/common/data_element.h b/storage/common/data_element.h
index 2eeca8e1d9513eb53e384bad97c2e2cea8d9cfc3..4cd686307d4ee92005eac21b1ec4fc4935cc0c7e 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]; }
+
// 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());
@@ -107,6 +131,8 @@ class STORAGE_COMMON_EXPORT DataElement {
void SetToDiskCacheEntryRange(uint64 offset, uint64 length);
private:
+ friend STORAGE_COMMON_EXPORT void PrintTo(const DataElement& x,
+ ::std::ostream* os);
Type type_;
std::vector<char> buf_; // For TYPE_BYTES.
const char* bytes_; // For TYPE_BYTES.
@@ -138,6 +164,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 true;
case DataElement::TYPE_UNKNOWN:
NOTREACHED();
return false;
« no previous file with comments | « storage/common/blob_storage/blob_storage_constants.h ('k') | storage/common/data_element.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698