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

Side by Side Diff: services/url_response_disk_cache/url_response_disk_cache_db.cc

Issue 1358353002: * Change C++ serialization/deserialization to not be move-only operations (with the except of |Ha… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: (*it).get() to it->, and other formatting 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 unified diff | Download patch
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/url_response_disk_cache/url_response_disk_cache_db.h" 5 #include "services/url_response_disk_cache/url_response_disk_cache_db.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 10 matching lines...) Expand all
21 // character. 21 // character.
22 const char kVersionKey[] = "\1version"; 22 const char kVersionKey[] = "\1version";
23 23
24 // TODO(darin): These Serialize / Deserialize methods should not live here. 24 // TODO(darin): These Serialize / Deserialize methods should not live here.
25 // They use private details of the bindings system. Instead, we should provide 25 // They use private details of the bindings system. Instead, we should provide
26 // these as helper functions under mojo/public/cpp/bindings/. 26 // these as helper functions under mojo/public/cpp/bindings/.
27 27
28 template <typename T> 28 template <typename T>
29 void Serialize(T input, std::string* output) { 29 void Serialize(T input, std::string* output) {
30 typedef typename mojo::internal::WrapperTraits<T>::DataType DataType; 30 typedef typename mojo::internal::WrapperTraits<T>::DataType DataType;
31 size_t size = GetSerializedSize_(input); 31 size_t size = GetSerializedSize_(*input);
32 32
33 output->clear(); 33 output->clear();
34 output->resize(size); 34 output->resize(size);
35 35
36 mojo::internal::FixedBuffer buf; 36 mojo::internal::FixedBuffer buf;
37 buf.Initialize(&output->at(0), size); 37 buf.Initialize(&output->at(0), size);
38 38
39 DataType data_type; 39 DataType data_type;
40 Serialize_(input.Pass(), &buf, &data_type); 40 Serialize_(input.get(), &buf, &data_type);
41 std::vector<Handle> handles; 41 std::vector<Handle> handles;
42 data_type->EncodePointersAndHandles(&handles); 42 data_type->EncodePointersAndHandles(&handles);
43 } 43 }
44 44
45 template <typename T> 45 template <typename T>
46 bool Deserialize(void* data, size_t size, T* output) { 46 bool Deserialize(void* data, size_t size, T* output) {
47 typedef typename mojo::internal::WrapperTraits<T>::DataType DataType; 47 typedef typename mojo::internal::WrapperTraits<T>::DataType DataType;
48 mojo::internal::BoundsChecker bounds_checker(data, size, 0); 48 mojo::internal::BoundsChecker bounds_checker(data, size, 0);
49 if (!std::remove_pointer<DataType>::type::Validate(data, &bounds_checker)) { 49 if (!std::remove_pointer<DataType>::type::Validate(data, &bounds_checker)) {
50 return false; 50 return false;
51 } 51 }
52 DataType data_type = reinterpret_cast<DataType>(data); 52 DataType data_type = reinterpret_cast<DataType>(data);
53 std::vector<Handle> handles; 53 std::vector<Handle> handles;
54 data_type->DecodePointersAndHandles(&handles); 54 data_type->DecodePointersAndHandles(&handles);
55 Deserialize_(data_type, output); 55 *output = mojo::internal::RemoveStructPtr<T>::type::New();
56 Deserialize_(data_type, output->get());
56 return true; 57 return true;
57 } 58 }
58 59
59 template <typename T> 60 template <typename T>
60 bool Deserialize(std::string s, T* output) { 61 bool Deserialize(std::string s, T* output) {
61 return Deserialize(&s.at(0), s.size(), output); 62 return Deserialize(&s.at(0), s.size(), output);
62 } 63 }
63 64
64 template <typename T> 65 template <typename T>
65 bool Deserialize(const leveldb::Slice& s, T* output) { 66 bool Deserialize(const leveldb::Slice& s, T* output) {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 236 }
236 237
237 scoped_ptr<URLResponseDiskCacheDB::Iterator> 238 scoped_ptr<URLResponseDiskCacheDB::Iterator>
238 URLResponseDiskCacheDB::GetIterator() { 239 URLResponseDiskCacheDB::GetIterator() {
239 return make_scoped_ptr(new Iterator(db_)); 240 return make_scoped_ptr(new Iterator(db_));
240 } 241 }
241 242
242 URLResponseDiskCacheDB::~URLResponseDiskCacheDB() {} 243 URLResponseDiskCacheDB::~URLResponseDiskCacheDB() {}
243 244
244 } // namespace mojo 245 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/generators/cpp_templates/union_serialization_definition.tmpl ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698