OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |