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

Side by Side Diff: content/public/common/common_param_traits.h

Issue 9447084: Refactor Pickle Read methods to use higher performance PickleIterator. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile (racing with incoming CLs) Created 8 years, 9 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/ppapi_plugin/ppapi_thread.cc ('k') | content/public/common/common_param_traits.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 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 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 // This file is used to define IPC::ParamTraits<> specializations for a number 5 // This file is used to define IPC::ParamTraits<> specializations for a number
6 // of types so that they can be serialized over IPC. IPC::ParamTraits<> 6 // of types so that they can be serialized over IPC. IPC::ParamTraits<>
7 // specializations for basic types (like int and std::string) and types in the 7 // specializations for basic types (like int and std::string) and types in the
8 // 'base' project can be found in ipc/ipc_message_utils.h. This file contains 8 // 'base' project can be found in ipc/ipc_message_utils.h. This file contains
9 // specializations for types that are used by the content code, and which need 9 // specializations for types that are used by the content code, and which need
10 // manual serialization code. This is usually because they're not structs with 10 // manual serialization code. This is usually because they're not structs with
11 // public members.. 11 // public members..
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 namespace ui { 44 namespace ui {
45 class Range; 45 class Range;
46 } 46 }
47 47
48 namespace IPC { 48 namespace IPC {
49 49
50 template <> 50 template <>
51 struct CONTENT_EXPORT ParamTraits<GURL> { 51 struct CONTENT_EXPORT ParamTraits<GURL> {
52 typedef GURL param_type; 52 typedef GURL param_type;
53 static void Write(Message* m, const param_type& p); 53 static void Write(Message* m, const param_type& p);
54 static bool Read(const Message* m, void** iter, param_type* p); 54 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
55 static void Log(const param_type& p, std::string* l); 55 static void Log(const param_type& p, std::string* l);
56 }; 56 };
57 57
58 template <> 58 template <>
59 struct ParamTraits<ResourceType::Type> { 59 struct ParamTraits<ResourceType::Type> {
60 typedef ResourceType::Type param_type; 60 typedef ResourceType::Type param_type;
61 static void Write(Message* m, const param_type& p); 61 static void Write(Message* m, const param_type& p);
62 static bool Read(const Message* m, void** iter, param_type* p); 62 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
63 static void Log(const param_type& p, std::string* l); 63 static void Log(const param_type& p, std::string* l);
64 }; 64 };
65 65
66 template <> 66 template <>
67 struct CONTENT_EXPORT ParamTraits<net::URLRequestStatus> { 67 struct CONTENT_EXPORT ParamTraits<net::URLRequestStatus> {
68 typedef net::URLRequestStatus param_type; 68 typedef net::URLRequestStatus param_type;
69 static void Write(Message* m, const param_type& p); 69 static void Write(Message* m, const param_type& p);
70 static bool Read(const Message* m, void** iter, param_type* r); 70 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
71 static void Log(const param_type& p, std::string* l); 71 static void Log(const param_type& p, std::string* l);
72 }; 72 };
73 73
74 template <> 74 template <>
75 struct CONTENT_EXPORT ParamTraits<scoped_refptr<net::UploadData> > { 75 struct CONTENT_EXPORT ParamTraits<scoped_refptr<net::UploadData> > {
76 typedef scoped_refptr<net::UploadData> param_type; 76 typedef scoped_refptr<net::UploadData> param_type;
77 static void Write(Message* m, const param_type& p); 77 static void Write(Message* m, const param_type& p);
78 static bool Read(const Message* m, void** iter, param_type* r); 78 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
79 static void Log(const param_type& p, std::string* l); 79 static void Log(const param_type& p, std::string* l);
80 }; 80 };
81 81
82 template<> 82 template<>
83 struct CONTENT_EXPORT ParamTraits<net::HostPortPair> { 83 struct CONTENT_EXPORT ParamTraits<net::HostPortPair> {
84 typedef net::HostPortPair param_type; 84 typedef net::HostPortPair param_type;
85 static void Write(Message* m, const param_type& p); 85 static void Write(Message* m, const param_type& p);
86 static bool Read(const Message* m, void** iter, param_type* r); 86 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
87 static void Log(const param_type& p, std::string* l); 87 static void Log(const param_type& p, std::string* l);
88 }; 88 };
89 89
90 template <> 90 template <>
91 struct ParamTraits<scoped_refptr<net::HttpResponseHeaders> > { 91 struct ParamTraits<scoped_refptr<net::HttpResponseHeaders> > {
92 typedef scoped_refptr<net::HttpResponseHeaders> param_type; 92 typedef scoped_refptr<net::HttpResponseHeaders> param_type;
93 static void Write(Message* m, const param_type& p); 93 static void Write(Message* m, const param_type& p);
94 static bool Read(const Message* m, void** iter, param_type* r); 94 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
95 static void Log(const param_type& p, std::string* l); 95 static void Log(const param_type& p, std::string* l);
96 }; 96 };
97 97
98 template <> 98 template <>
99 struct ParamTraits<net::IPEndPoint> { 99 struct ParamTraits<net::IPEndPoint> {
100 typedef net::IPEndPoint param_type; 100 typedef net::IPEndPoint param_type;
101 static void Write(Message* m, const param_type& p); 101 static void Write(Message* m, const param_type& p);
102 static bool Read(const Message* m, void** iter, param_type* p); 102 static bool Read(const Message* m, PickleIterator* iter, param_type* p);
103 static void Log(const param_type& p, std::string* l); 103 static void Log(const param_type& p, std::string* l);
104 }; 104 };
105 105
106 template <> 106 template <>
107 struct ParamTraits<base::PlatformFileInfo> { 107 struct ParamTraits<base::PlatformFileInfo> {
108 typedef base::PlatformFileInfo param_type; 108 typedef base::PlatformFileInfo param_type;
109 static void Write(Message* m, const param_type& p); 109 static void Write(Message* m, const param_type& p);
110 static bool Read(const Message* m, void** iter, param_type* r); 110 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
111 static void Log(const param_type& p, std::string* l); 111 static void Log(const param_type& p, std::string* l);
112 }; 112 };
113 113
114 template <> 114 template <>
115 struct CONTENT_EXPORT ParamTraits<gfx::Point> { 115 struct CONTENT_EXPORT ParamTraits<gfx::Point> {
116 typedef gfx::Point param_type; 116 typedef gfx::Point param_type;
117 static void Write(Message* m, const param_type& p); 117 static void Write(Message* m, const param_type& p);
118 static bool Read(const Message* m, void** iter, param_type* r); 118 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
119 static void Log(const param_type& p, std::string* l); 119 static void Log(const param_type& p, std::string* l);
120 }; 120 };
121 121
122 template <> 122 template <>
123 struct CONTENT_EXPORT ParamTraits<gfx::Size> { 123 struct CONTENT_EXPORT ParamTraits<gfx::Size> {
124 typedef gfx::Size param_type; 124 typedef gfx::Size param_type;
125 static void Write(Message* m, const param_type& p); 125 static void Write(Message* m, const param_type& p);
126 static bool Read(const Message* m, void** iter, param_type* r); 126 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
127 static void Log(const param_type& p, std::string* l); 127 static void Log(const param_type& p, std::string* l);
128 }; 128 };
129 129
130 template <> 130 template <>
131 struct CONTENT_EXPORT ParamTraits<gfx::Rect> { 131 struct CONTENT_EXPORT ParamTraits<gfx::Rect> {
132 typedef gfx::Rect param_type; 132 typedef gfx::Rect param_type;
133 static void Write(Message* m, const param_type& p); 133 static void Write(Message* m, const param_type& p);
134 static bool Read(const Message* m, void** iter, param_type* r); 134 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
135 static void Log(const param_type& p, std::string* l); 135 static void Log(const param_type& p, std::string* l);
136 }; 136 };
137 137
138 template <> 138 template <>
139 struct ParamTraits<gfx::NativeWindow> { 139 struct ParamTraits<gfx::NativeWindow> {
140 typedef gfx::NativeWindow param_type; 140 typedef gfx::NativeWindow param_type;
141 static void Write(Message* m, const param_type& p) { 141 static void Write(Message* m, const param_type& p) {
142 #if defined(OS_WIN) 142 #if defined(OS_WIN)
143 // HWNDs are always 32 bits on Windows, even on 64 bit systems. 143 // HWNDs are always 32 bits on Windows, even on 64 bit systems.
144 m->WriteUInt32(reinterpret_cast<uint32>(p)); 144 m->WriteUInt32(reinterpret_cast<uint32>(p));
145 #else 145 #else
146 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p)); 146 m->WriteData(reinterpret_cast<const char*>(&p), sizeof(p));
147 #endif 147 #endif
148 } 148 }
149 static bool Read(const Message* m, void** iter, param_type* r) { 149 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
150 #if defined(OS_WIN) 150 #if defined(OS_WIN)
151 return m->ReadUInt32(iter, reinterpret_cast<uint32*>(r)); 151 return m->ReadUInt32(iter, reinterpret_cast<uint32*>(r));
152 #else 152 #else
153 const char *data; 153 const char *data;
154 int data_size = 0; 154 int data_size = 0;
155 bool result = m->ReadData(iter, &data, &data_size); 155 bool result = m->ReadData(iter, &data, &data_size);
156 if (result && data_size == sizeof(gfx::NativeWindow)) { 156 if (result && data_size == sizeof(gfx::NativeWindow)) {
157 memcpy(r, data, sizeof(gfx::NativeWindow)); 157 memcpy(r, data, sizeof(gfx::NativeWindow));
158 } else { 158 } else {
159 result = false; 159 result = false;
160 NOTREACHED(); 160 NOTREACHED();
161 } 161 }
162 return result; 162 return result;
163 #endif 163 #endif
164 } 164 }
165 static void Log(const param_type& p, std::string* l) { 165 static void Log(const param_type& p, std::string* l) {
166 l->append("<gfx::NativeWindow>"); 166 l->append("<gfx::NativeWindow>");
167 } 167 }
168 }; 168 };
169 169
170 template <> 170 template <>
171 struct CONTENT_EXPORT ParamTraits<ui::Range> { 171 struct CONTENT_EXPORT ParamTraits<ui::Range> {
172 typedef ui::Range param_type; 172 typedef ui::Range param_type;
173 static void Write(Message* m, const param_type& p); 173 static void Write(Message* m, const param_type& p);
174 static bool Read(const Message* m, void** iter, param_type* r); 174 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
175 static void Log(const param_type& p, std::string* l); 175 static void Log(const param_type& p, std::string* l);
176 }; 176 };
177 177
178 #if defined(OS_WIN) 178 #if defined(OS_WIN)
179 template<> 179 template<>
180 struct ParamTraits<TransportDIB::Id> { 180 struct ParamTraits<TransportDIB::Id> {
181 typedef TransportDIB::Id param_type; 181 typedef TransportDIB::Id param_type;
182 static void Write(Message* m, const param_type& p) { 182 static void Write(Message* m, const param_type& p) {
183 WriteParam(m, p.handle); 183 WriteParam(m, p.handle);
184 WriteParam(m, p.sequence_num); 184 WriteParam(m, p.sequence_num);
185 } 185 }
186 static bool Read(const Message* m, void** iter, param_type* r) { 186 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
187 return (ReadParam(m, iter, &r->handle) && 187 return (ReadParam(m, iter, &r->handle) &&
188 ReadParam(m, iter, &r->sequence_num)); 188 ReadParam(m, iter, &r->sequence_num));
189 } 189 }
190 static void Log(const param_type& p, std::string* l) { 190 static void Log(const param_type& p, std::string* l) {
191 l->append("TransportDIB("); 191 l->append("TransportDIB(");
192 LogParam(p.handle, l); 192 LogParam(p.handle, l);
193 l->append(", "); 193 l->append(", ");
194 LogParam(p.sequence_num, l); 194 LogParam(p.sequence_num, l);
195 l->append(")"); 195 l->append(")");
196 } 196 }
197 }; 197 };
198 #endif 198 #endif
199 199
200 #if defined(USE_X11) 200 #if defined(USE_X11)
201 template<> 201 template<>
202 struct ParamTraits<TransportDIB::Id> { 202 struct ParamTraits<TransportDIB::Id> {
203 typedef TransportDIB::Id param_type; 203 typedef TransportDIB::Id param_type;
204 static void Write(Message* m, const param_type& p) { 204 static void Write(Message* m, const param_type& p) {
205 WriteParam(m, p.shmkey); 205 WriteParam(m, p.shmkey);
206 } 206 }
207 static bool Read(const Message* m, void** iter, param_type* r) { 207 static bool Read(const Message* m, PickleIterator* iter, param_type* r) {
208 return ReadParam(m, iter, &r->shmkey); 208 return ReadParam(m, iter, &r->shmkey);
209 } 209 }
210 static void Log(const param_type& p, std::string* l) { 210 static void Log(const param_type& p, std::string* l) {
211 l->append("TransportDIB("); 211 l->append("TransportDIB(");
212 LogParam(p.shmkey, l); 212 LogParam(p.shmkey, l);
213 l->append(")"); 213 l->append(")");
214 } 214 }
215 }; 215 };
216 #endif 216 #endif
217 217
218 template <> 218 template <>
219 struct CONTENT_EXPORT ParamTraits<SkBitmap> { 219 struct CONTENT_EXPORT ParamTraits<SkBitmap> {
220 typedef SkBitmap param_type; 220 typedef SkBitmap param_type;
221 static void Write(Message* m, const param_type& p); 221 static void Write(Message* m, const param_type& p);
222 222
223 // Note: This function expects parameter |r| to be of type &SkBitmap since 223 // Note: This function expects parameter |r| to be of type &SkBitmap since
224 // r->SetConfig() and r->SetPixels() are called. 224 // r->SetConfig() and r->SetPixels() are called.
225 static bool Read(const Message* m, void** iter, param_type* r); 225 static bool Read(const Message* m, PickleIterator* iter, param_type* r);
226 226
227 static void Log(const param_type& p, std::string* l); 227 static void Log(const param_type& p, std::string* l);
228 }; 228 };
229 229
230 template <> 230 template <>
231 struct SimilarTypeTraits<base::PlatformFileError> { 231 struct SimilarTypeTraits<base::PlatformFileError> {
232 typedef int Type; 232 typedef int Type;
233 }; 233 };
234 234
235 template <> 235 template <>
236 struct SimilarTypeTraits<content::PageTransition> { 236 struct SimilarTypeTraits<content::PageTransition> {
237 typedef int Type; 237 typedef int Type;
238 }; 238 };
239 239
240 template <> 240 template <>
241 struct SimilarTypeTraits<content::SecurityStyle> { 241 struct SimilarTypeTraits<content::SecurityStyle> {
242 typedef int Type; 242 typedef int Type;
243 }; 243 };
244 244
245 } // namespace IPC 245 } // namespace IPC
246 246
247 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_ 247 #endif // CONTENT_PUBLIC_COMMON_COMMON_PARAM_TRAITS_H_
OLDNEW
« no previous file with comments | « content/ppapi_plugin/ppapi_thread.cc ('k') | content/public/common/common_param_traits.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698