Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef IPC_IPC_MESSAGE_REPEATED_FIELD_UTILS_H_ | |
| 6 #define IPC_IPC_MESSAGE_REPEATED_FIELD_UTILS_H_ | |
| 7 | |
| 8 #include "build/build_config.h" | |
| 9 | |
| 10 #if defined(OS_NACL_NONSFI) | |
| 11 static_assert(false, | |
| 12 "ipc_message_repeated_field_utils is not able to work with " | |
| 13 "nacl_nonsfi configuration."); | |
| 14 #endif | |
| 15 | |
| 16 #include "base/pickle.h" | |
| 17 #include "ipc/ipc_param_traits.h" | |
| 18 #include "ipc/ipc_message_utils.h" | |
| 19 #include "third_party/protobuf/src/google/protobuf/repeated_field.h" | |
| 20 | |
| 21 namespace IPC { | |
| 22 | |
| 23 template <template<class> class RepeatedFieldLike, class P> | |
|
dcheng
2017/07/10 18:38:10
Is it important to include the template<class> her
Hzj_jie
2017/07/10 23:53:37
These two comments are conflict :)
If we prefer to
dcheng
2017/07/11 05:38:59
Hmm. I guess I don't really care if we Reserve().
Hzj_jie
2017/07/11 05:59:02
Why cannot we use base::Pickle::payload_size() to
| |
| 24 struct RepeatedFieldParamTraits { | |
| 25 typedef RepeatedFieldLike<P> param_type; | |
| 26 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | |
| 27 GetParamSize(sizer, p.size()); | |
| 28 for (int i = 0; i < p.size(); i++) | |
| 29 GetParamSize(sizer, p.Get(i)); | |
| 30 } | |
| 31 static void Write(base::Pickle* m, const param_type& p) { | |
| 32 WriteParam(m, p.size()); | |
| 33 for (int i = 0; i < p.size(); i++) | |
| 34 WriteParam(m, p.Get(i)); | |
| 35 } | |
| 36 static bool Read(const base::Pickle* m, | |
| 37 base::PickleIterator* iter, | |
| 38 param_type* r) { | |
| 39 int size; | |
| 40 // ReadLength() checks for < 0 itself. | |
| 41 if (!iter->ReadLength(&size)) | |
| 42 return false; | |
| 43 for (int i = 0; i < size; i++) { | |
|
dcheng
2017/07/10 18:38:10
Nit: let's keep the original logic to do bounds ch
Hzj_jie
2017/07/10 23:53:37
Done.
| |
| 44 if (!ReadParam(m, iter, r->Add())) | |
| 45 return false; | |
| 46 } | |
| 47 return true; | |
| 48 } | |
| 49 static void Log(const param_type& p, std::string* l) { | |
| 50 for (int i = 0; i < p.size(); ++i) { | |
| 51 if (i != 0) | |
| 52 l->append(" "); | |
| 53 LogParam(p.Get(i), l); | |
| 54 } | |
| 55 } | |
| 56 }; | |
| 57 | |
| 58 template <class P> | |
| 59 struct ParamTraits<google::protobuf::RepeatedField<P>> : | |
| 60 RepeatedFieldParamTraits<google::protobuf::RepeatedField, P> {}; | |
| 61 | |
| 62 template <class P> | |
| 63 struct ParamTraits<google::protobuf::RepeatedPtrField<P>> : | |
| 64 RepeatedFieldParamTraits<google::protobuf::RepeatedPtrField, P> {}; | |
| 65 | |
| 66 } // namespace IPC | |
| 67 | |
| 68 #endif // IPC_IPC_MESSAGE_REPEATED_FIELD_UTILS_H_ | |
| OLD | NEW |