OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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 // This file defines IPC::ParamTraits<> specializations for several | |
6 // input-related types that require manual serialiation code. | |
7 | |
8 #ifndef CONTENT_COMMON_INPUT_INPUT_PARAM_TRAITS_H_ | |
9 #define CONTENT_COMMON_INPUT_INPUT_PARAM_TRAITS_H_ | |
10 | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "content/common/content_param_traits_macros.h" | |
13 #include "content/common/input/input_event.h" | |
14 #include "content/common/input/web_input_event_payload.h" | |
15 | |
16 namespace IPC { | |
17 | |
18 // TODO(jdduke): There should be a common copy of this utility somewhere... | |
19 // Move or remove appropriately. | |
20 template<class P> | |
21 struct ParamTraits<scoped_ptr<P> > { | |
22 typedef scoped_ptr<P> param_type; | |
23 static void Write(Message* m, const param_type& p) { | |
24 bool valid = !!p; | |
25 WriteParam(m, valid); | |
26 if (valid) | |
27 WriteParam(m, *p); | |
28 } | |
29 static bool Read(const Message* m, PickleIterator* iter, param_type* r) { | |
30 bool valid = false; | |
31 if (!ReadParam(m, iter, &valid)) | |
32 return false; | |
33 | |
34 if (!valid) { | |
35 r->reset(); | |
36 return true; | |
37 } | |
38 | |
39 param_type temp(new P()); | |
palmer
2013/09/03 23:12:47
Just to make sure I understand: You allocate a new
jdduke (slow)
2013/09/04 17:53:24
Well, param_type* r is a pointer to any empty scop
jdduke (slow)
2013/09/05 00:01:21
Or perhaps you meant we should go ahead and assign
palmer
2013/09/05 01:20:15
No, I think you are right. I was trying to figure
jdduke (slow)
2013/09/05 19:31:48
Yeah, that crossed my mind. This operation *shoul
| |
40 if (!ReadParam(m, iter, temp.get())) | |
41 return false; | |
42 | |
43 r->swap(temp); | |
44 return true; | |
45 } | |
46 static void Log(const param_type& p, std::string* l) { | |
47 if (p) | |
48 LogParam(*p, l); | |
49 else | |
50 l->append("NULL"); | |
51 } | |
52 }; | |
53 | |
54 template <> | |
55 struct CONTENT_EXPORT ParamTraits<content::InputEvent> { | |
56 typedef content::InputEvent param_type; | |
57 static void Write(Message* m, const param_type& p); | |
58 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
59 static void Log(const param_type& p, std::string* l); | |
60 }; | |
61 | |
62 template <> | |
63 struct CONTENT_EXPORT ParamTraits<content::WebInputEventPayload> { | |
64 typedef content::WebInputEventPayload param_type; | |
65 static void Write(Message* m, const param_type& p); | |
66 static bool Read(const Message* m, PickleIterator* iter, param_type* r); | |
67 static void Log(const param_type& p, std::string* l); | |
68 }; | |
69 | |
70 } // namespace IPC | |
71 | |
72 #endif // CONTENT_COMMON_INPUT_INPUT_PARAM_TRAITS_H_ | |
OLD | NEW |