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

Unified Diff: services/url_response_disk_cache/url_response_disk_cache_db.cc

Issue 1800753005: C++ bindings: A struct's Deserialize() now does validation before deserializing. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: fix char* - >char bug in unittest. FixedBuffer can accept sizes that aren't 8 byte multiples. Created 4 years, 9 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 | « services/authentication/accounts_db_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/url_response_disk_cache/url_response_disk_cache_db.cc
diff --git a/services/url_response_disk_cache/url_response_disk_cache_db.cc b/services/url_response_disk_cache/url_response_disk_cache_db.cc
index fc06897b487cdd23090c8de44d878ae82b3d93fd..a96b34fd7bee4fe28fc35c4b13a39f3e16139ba9 100644
--- a/services/url_response_disk_cache/url_response_disk_cache_db.cc
+++ b/services/url_response_disk_cache/url_response_disk_cache_db.cc
@@ -16,7 +16,6 @@
#include "base/time/time.h"
#include "leveldb/comparator.h"
#include "leveldb/db.h"
-#include "mojo/public/cpp/bindings/lib/fixed_buffer.h"
#include "services/url_response_disk_cache/url_response_disk_cache_entry.mojom.h"
namespace mojo {
@@ -26,40 +25,20 @@ namespace {
// character.
const char kVersionKey[] = "\1version";
-// TODO(vardhan): Rework these to use the public Serialize/Deserialize
-// functions.
+// T is a |StructPtr|.
template <typename T>
void Serialize(T input, std::string* output) {
- typedef typename mojo::internal::WrapperTraits<T>::DataType DataType;
- size_t size = GetSerializedSize_(*input);
-
+ size_t size = input->GetSerializedSize();
output->clear();
output->resize(size);
- mojo::internal::FixedBuffer buf;
- buf.Initialize(&output->at(0), size);
-
- DataType data_type;
- Serialize_(input.get(), &buf, &data_type);
- std::vector<Handle> handles;
- data_type->EncodePointersAndHandles(&handles);
+ input->Serialize(&output->at(0), size);
}
template <typename T>
bool Deserialize(void* data, size_t size, T* output) {
- typedef typename mojo::internal::WrapperTraits<T>::DataType DataType;
- mojo::internal::BoundsChecker bounds_checker(data, size, 0);
- if (std::remove_pointer<DataType>::type::Validate(data, &bounds_checker,
- nullptr) !=
- mojo::internal::ValidationError::NONE)
- return false;
-
- DataType data_type = reinterpret_cast<DataType>(data);
- std::vector<Handle> handles;
- data_type->DecodePointersAndHandles(&handles);
*output = mojo::internal::RemoveStructPtr<T>::type::New();
- Deserialize_(data_type, output->get());
- return true;
+ return (*output)->Deserialize(data, size);
}
template <typename T>
« no previous file with comments | « services/authentication/accounts_db_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698