Chromium Code Reviews| Index: ipc/ipc_message_utils.h |
| diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h |
| index 102992d45ec6e003bf1a516bdc9b39e002b494f8..6bfd103c6d88423cc3855eefd821c0a07416d4e1 100644 |
| --- a/ipc/ipc_message_utils.h |
| +++ b/ipc/ipc_message_utils.h |
| @@ -14,6 +14,7 @@ |
| #include "base/containers/small_map.h" |
| #include "base/files/file.h" |
| #include "base/format_macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| #include "base/memory/scoped_vector.h" |
| #include "base/strings/string16.h" |
| #include "base/strings/string_util.h" |
| @@ -706,6 +707,40 @@ struct ParamTraits<base::SmallMap<NormalMap, kArraySize, EqualKey, MapInit> > { |
| } |
| }; |
| +template <class P> |
| +struct ParamTraits<scoped_ptr<P> > { |
| + typedef scoped_ptr<P> param_type; |
| + static void Write(Message* m, const param_type& p) { |
| + bool valid = !!p; |
| + WriteParam(m, valid); |
|
piman
2014/05/19 21:51:13
What is the value of this over having 'valid' be e
jdduke (slow)
2014/05/19 22:00:21
I considered that. My only concern was the cost o
|
| + if (valid) |
| + WriteParam(m, *p); |
| + } |
| + static bool Read(const Message* m, PickleIterator* iter, param_type* r) { |
| + bool valid = false; |
| + if (!ReadParam(m, iter, &valid)) |
| + return false; |
| + |
| + if (!valid) { |
| + r->reset(); |
| + return true; |
| + } |
| + |
| + param_type temp(new P()); |
| + if (!ReadParam(m, iter, temp.get())) |
| + return false; |
| + |
| + r->swap(temp); |
| + return true; |
| + } |
| + static void Log(const param_type& p, std::string* l) { |
| + if (p) |
| + LogParam(*p, l); |
| + else |
| + l->append("NULL"); |
| + } |
| +}; |
| + |
| // IPC types ParamTraits ------------------------------------------------------- |
| // A ChannelHandle is basically a platform-inspecific wrapper around the |