Commit 339e4ec2 authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Remove unused DataElement logic.

In particular, remove the ability to make it use a raw data pointer.
This isn't safe if Mojo is configured to copy data for same-process
calls, and nothing is using it, anyways.

Also remove the ability to mutate stored data directly.

Also remove SetToFilePath(), which nothing is using. This does not
remove SetToFilePathRange(), which is what it calls. We do want to
remove that, too, eventually.

Bug: None
Change-Id: I0dcb291c5c2988d3e45a00d92201d0352fe03d32
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2431431
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811579}
parent 642b43e3
...@@ -20,7 +20,6 @@ const uint64_t DataElement::kUnknownSize; ...@@ -20,7 +20,6 @@ const uint64_t DataElement::kUnknownSize;
DataElement::DataElement() DataElement::DataElement()
: type_(mojom::DataElementType::kUnknown), : type_(mojom::DataElementType::kUnknown),
bytes_(nullptr),
offset_(0), offset_(0),
length_(std::numeric_limits<uint64_t>::max()) {} length_(std::numeric_limits<uint64_t>::max()) {}
......
...@@ -51,8 +51,7 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement { ...@@ -51,8 +51,7 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement {
mojom::DataElementType type() const { return type_; } mojom::DataElementType type() const { return type_; }
const char* bytes() const { const char* bytes() const {
return bytes_ ? reinterpret_cast<const char*>(bytes_) return reinterpret_cast<const char*>(buf_.data());
: reinterpret_cast<const char*>(buf_.data());
} }
const base::FilePath& path() const { return path_; } const base::FilePath& path() const { return path_; }
const std::string& blob_uuid() const { return blob_uuid_; } const std::string& blob_uuid() const { return blob_uuid_; }
...@@ -62,14 +61,9 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement { ...@@ -62,14 +61,9 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement {
return expected_modification_time_; return expected_modification_time_;
} }
// For use with SetToAllocatedBytes. Should only be used after calling
// SetToAllocatedBytes.
char* mutable_bytes() { return reinterpret_cast<char*>(&buf_[0]); }
// Sets TYPE_BYTES data. This copies the given data into the element. // Sets TYPE_BYTES data. This copies the given data into the element.
void SetToBytes(const char* bytes, int bytes_len) { void SetToBytes(const char* bytes, int bytes_len) {
type_ = mojom::DataElementType::kBytes; type_ = mojom::DataElementType::kBytes;
bytes_ = nullptr;
buf_.assign(reinterpret_cast<const uint8_t*>(bytes), buf_.assign(reinterpret_cast<const uint8_t*>(bytes),
reinterpret_cast<const uint8_t*>(bytes + bytes_len)); reinterpret_cast<const uint8_t*>(bytes + bytes_len));
length_ = buf_.size(); length_ = buf_.size();
...@@ -78,7 +72,6 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement { ...@@ -78,7 +72,6 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement {
// Sets TYPE_BYTES data. This moves the given data vector into the element. // Sets TYPE_BYTES data. This moves the given data vector into the element.
void SetToBytes(std::vector<uint8_t> bytes) { void SetToBytes(std::vector<uint8_t> bytes) {
type_ = mojom::DataElementType::kBytes; type_ = mojom::DataElementType::kBytes;
bytes_ = nullptr;
buf_ = std::move(bytes); buf_ = std::move(bytes);
length_ = buf_.size(); length_ = buf_.size();
} }
...@@ -89,7 +82,6 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement { ...@@ -89,7 +82,6 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement {
type_ = mojom::DataElementType::kBytes; type_ = mojom::DataElementType::kBytes;
buf_.clear(); buf_.clear();
length_ = 0; length_ = 0;
bytes_ = nullptr;
} }
// Copies and appends the given data into the element. SetToEmptyBytes or // Copies and appends the given data into the element. SetToEmptyBytes or
...@@ -97,37 +89,11 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement { ...@@ -97,37 +89,11 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement {
void AppendBytes(const char* bytes, int bytes_len) { void AppendBytes(const char* bytes, int bytes_len) {
DCHECK_EQ(type_, mojom::DataElementType::kBytes); DCHECK_EQ(type_, mojom::DataElementType::kBytes);
DCHECK_NE(length_, std::numeric_limits<uint64_t>::max()); DCHECK_NE(length_, std::numeric_limits<uint64_t>::max());
DCHECK(!bytes_);
buf_.insert(buf_.end(), reinterpret_cast<const uint8_t*>(bytes), buf_.insert(buf_.end(), reinterpret_cast<const uint8_t*>(bytes),
reinterpret_cast<const uint8_t*>(bytes + bytes_len)); reinterpret_cast<const uint8_t*>(bytes + bytes_len));
length_ = buf_.size(); length_ = buf_.size();
} }
// 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.
void SetToSharedBytes(const char* bytes, int bytes_len) {
type_ = mojom::DataElementType::kBytes;
bytes_ = reinterpret_cast<const uint8_t*>(bytes);
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_ = mojom::DataElementType::kBytes;
bytes_ = nullptr;
buf_.resize(bytes_len);
length_ = bytes_len;
}
// Sets TYPE_FILE data.
void SetToFilePath(const base::FilePath& path) {
SetToFilePathRange(path, 0, std::numeric_limits<uint64_t>::max(),
base::Time());
}
// Sets TYPE_BLOB data. // Sets TYPE_BLOB data.
void SetToBlob(const std::string& uuid) { void SetToBlob(const std::string& uuid) {
SetToBlobRange(uuid, 0, std::numeric_limits<uint64_t>::max()); SetToBlobRange(uuid, 0, std::numeric_limits<uint64_t>::max());
...@@ -181,8 +147,6 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement { ...@@ -181,8 +147,6 @@ class COMPONENT_EXPORT(NETWORK_CPP_BASE) DataElement {
mojom::DataElementType type_; mojom::DataElementType type_;
// For TYPE_BYTES. // For TYPE_BYTES.
std::vector<uint8_t> buf_; std::vector<uint8_t> buf_;
// For TYPE_BYTES.
const uint8_t* bytes_;
// For TYPE_FILE. // For TYPE_FILE.
base::FilePath path_; base::FilePath path_;
// For TYPE_BLOB. // For TYPE_BLOB.
......
...@@ -308,12 +308,8 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE) ...@@ -308,12 +308,8 @@ struct COMPONENT_EXPORT(NETWORK_CPP_BASE)
const network::DataElement& element) { const network::DataElement& element) {
return element.type_; return element.type_;
} }
static std::vector<uint8_t> buf(const network::DataElement& element) { static const std::vector<uint8_t>& buf(const network::DataElement& element) {
if (element.bytes_) { return element.buf_;
return std::vector<uint8_t>(element.bytes_,
element.bytes_ + element.length_);
}
return std::move(element.buf_);
} }
static const base::FilePath& path(const network::DataElement& element) { static const base::FilePath& path(const network::DataElement& element) {
return element.path_; return element.path_;
......
...@@ -55,12 +55,8 @@ struct BLINK_COMMON_EXPORT ...@@ -55,12 +55,8 @@ struct BLINK_COMMON_EXPORT
const network::DataElement& element) { const network::DataElement& element) {
return element.type_; return element.type_;
} }
static std::vector<uint8_t> buf(const network::DataElement& element) { static const std::vector<uint8_t>& buf(const network::DataElement& element) {
if (element.bytes_) { return element.buf_;
return std::vector<uint8_t>(element.bytes_,
element.bytes_ + element.length_);
}
return std::move(element.buf_);
} }
static const base::FilePath& path(const network::DataElement& element) { static const base::FilePath& path(const network::DataElement& element) {
return element.path_; return element.path_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment