Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(364)

Side by Side Diff: content/common/content_param_traits.cc

Issue 10980010: Cleanup the IPC param traits structure (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix android Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/common/content_param_traits.h ('k') | content/common/content_param_traits_macros.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 #include "content/common/content_param_traits.h"
6
7 #include "base/string_number_conversions.h"
8 #include "net/base/ip_endpoint.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
10 #include "webkit/glue/npruntime_util.h"
11 #include "webkit/plugins/npapi/plugin_host.h"
12 #include "ui/base/range/range.h"
13
14 NPIdentifier_Param::NPIdentifier_Param()
15 : identifier() {
16 }
17
18 NPIdentifier_Param::~NPIdentifier_Param() {
19 }
20
21 NPVariant_Param::NPVariant_Param()
22 : type(NPVARIANT_PARAM_VOID),
23 bool_value(false),
24 int_value(0),
25 double_value(0),
26 npobject_routing_id(-1) {
27 }
28
29 NPVariant_Param::~NPVariant_Param() {
30 }
31
32 namespace IPC {
33
34 void ParamTraits<net::IPEndPoint>::Write(Message* m, const param_type& p) {
35 WriteParam(m, p.address());
36 WriteParam(m, p.port());
37 }
38
39 bool ParamTraits<net::IPEndPoint>::Read(const Message* m, PickleIterator* iter,
40 param_type* p) {
41 net::IPAddressNumber address;
42 int port;
43 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port))
44 return false;
45 *p = net::IPEndPoint(address, port);
46 return true;
47 }
48
49 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) {
50 LogParam("IPEndPoint:" + p.ToString(), l);
51 }
52
53 void ParamTraits<NPVariant_Param>::Write(Message* m, const param_type& p) {
54 WriteParam(m, static_cast<int>(p.type));
55 if (p.type == NPVARIANT_PARAM_BOOL) {
56 WriteParam(m, p.bool_value);
57 } else if (p.type == NPVARIANT_PARAM_INT) {
58 WriteParam(m, p.int_value);
59 } else if (p.type == NPVARIANT_PARAM_DOUBLE) {
60 WriteParam(m, p.double_value);
61 } else if (p.type == NPVARIANT_PARAM_STRING) {
62 WriteParam(m, p.string_value);
63 } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID ||
64 p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) {
65 // This is the routing id used to connect NPObjectProxy in the other
66 // process with NPObjectStub in this process or to identify the raw
67 // npobject pointer to be used in the callee process.
68 WriteParam(m, p.npobject_routing_id);
69 } else {
70 DCHECK(p.type == NPVARIANT_PARAM_VOID || p.type == NPVARIANT_PARAM_NULL);
71 }
72 }
73
74 bool ParamTraits<NPVariant_Param>::Read(const Message* m,
75 PickleIterator* iter,
76 param_type* r) {
77 int type;
78 if (!ReadParam(m, iter, &type))
79 return false;
80
81 bool result = false;
82 r->type = static_cast<NPVariant_ParamEnum>(type);
83 if (r->type == NPVARIANT_PARAM_BOOL) {
84 result = ReadParam(m, iter, &r->bool_value);
85 } else if (r->type == NPVARIANT_PARAM_INT) {
86 result = ReadParam(m, iter, &r->int_value);
87 } else if (r->type == NPVARIANT_PARAM_DOUBLE) {
88 result = ReadParam(m, iter, &r->double_value);
89 } else if (r->type == NPVARIANT_PARAM_STRING) {
90 result = ReadParam(m, iter, &r->string_value);
91 } else if (r->type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID ||
92 r->type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) {
93 result = ReadParam(m, iter, &r->npobject_routing_id);
94 } else if ((r->type == NPVARIANT_PARAM_VOID) ||
95 (r->type == NPVARIANT_PARAM_NULL)) {
96 result = true;
97 } else {
98 NOTREACHED();
99 }
100
101 return result;
102 }
103
104 void ParamTraits<NPVariant_Param>::Log(const param_type& p, std::string* l) {
105 l->append(StringPrintf("NPVariant_Param(%d, ", static_cast<int>(p.type)));
106 if (p.type == NPVARIANT_PARAM_BOOL) {
107 LogParam(p.bool_value, l);
108 } else if (p.type == NPVARIANT_PARAM_INT) {
109 LogParam(p.int_value, l);
110 } else if (p.type == NPVARIANT_PARAM_DOUBLE) {
111 LogParam(p.double_value, l);
112 } else if (p.type == NPVARIANT_PARAM_STRING) {
113 LogParam(p.string_value, l);
114 } else if (p.type == NPVARIANT_PARAM_SENDER_OBJECT_ROUTING_ID ||
115 p.type == NPVARIANT_PARAM_RECEIVER_OBJECT_ROUTING_ID) {
116 LogParam(p.npobject_routing_id, l);
117 } else {
118 l->append("<none>");
119 }
120 l->append(")");
121 }
122
123 void ParamTraits<NPIdentifier_Param>::Write(Message* m, const param_type& p) {
124 webkit_glue::SerializeNPIdentifier(p.identifier, m);
125 }
126
127 bool ParamTraits<NPIdentifier_Param>::Read(const Message* m,
128 PickleIterator* iter,
129 param_type* r) {
130 return webkit_glue::DeserializeNPIdentifier(iter, &r->identifier);
131 }
132
133 void ParamTraits<NPIdentifier_Param>::Log(const param_type& p, std::string* l) {
134 if (WebKit::WebBindings::identifierIsString(p.identifier)) {
135 NPUTF8* str = WebKit::WebBindings::utf8FromIdentifier(p.identifier);
136 l->append(str);
137 webkit::npapi::PluginHost::Singleton()->host_functions()->memfree(str);
138 } else {
139 l->append(base::IntToString(
140 WebKit::WebBindings::intFromIdentifier(p.identifier)));
141 }
142 }
143
144 void ParamTraits<ui::Range>::Write(Message* m, const ui::Range& r) {
145 m->WriteUInt64(r.start());
146 m->WriteUInt64(r.end());
147 }
148
149 bool ParamTraits<ui::Range>::Read(const Message* m,
150 PickleIterator* iter,
151 ui::Range* r) {
152 uint64 start, end;
153 if (!m->ReadUInt64(iter, &start) || !m->ReadUInt64(iter, &end))
154 return false;
155 r->set_start(start);
156 r->set_end(end);
157 return true;
158 }
159
160 void ParamTraits<ui::Range>::Log(const ui::Range& r, std::string* l) {
161 l->append(base::StringPrintf("(%"PRIuS", %"PRIuS")", r.start(), r.end()));
162 }
163
164 } // namespace IPC
165
166 // Generate param traits write methods.
167 #include "ipc/param_traits_write_macros.h"
168 namespace IPC {
169 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
170 #include "content/common/content_param_traits_macros.h"
171 } // namespace IPC
172
173 // Generate param traits read methods.
174 #include "ipc/param_traits_read_macros.h"
175 namespace IPC {
176 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
177 #include "content/common/content_param_traits_macros.h"
178 } // namespace IPC
179
180 // Generate param traits log methods.
181 #include "ipc/param_traits_log_macros.h"
182 namespace IPC {
183 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
184 #include "content/common/content_param_traits_macros.h"
185 } // namespace IPC
OLDNEW
« no previous file with comments | « content/common/content_param_traits.h ('k') | content/common/content_param_traits_macros.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698