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.get()); |
viettrungluu
2015/09/23 23:20:24
Is .get() needed?
vardhan
2015/09/25 19:33:05
Done.
| |
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 } | 214 } |
214 | 215 |
215 scoped_ptr<URLResponseDiskCacheDB::Iterator> | 216 scoped_ptr<URLResponseDiskCacheDB::Iterator> |
216 URLResponseDiskCacheDB::GetIterator() { | 217 URLResponseDiskCacheDB::GetIterator() { |
217 return make_scoped_ptr(new Iterator(db_)); | 218 return make_scoped_ptr(new Iterator(db_)); |
218 } | 219 } |
219 | 220 |
220 URLResponseDiskCacheDB::~URLResponseDiskCacheDB() {} | 221 URLResponseDiskCacheDB::~URLResponseDiskCacheDB() {} |
221 | 222 |
222 } // namespace mojo | 223 } // namespace mojo |
OLD | NEW |