Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 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 #ifndef IPC_IPC_MESSAGE_UTILS_H_ | 5 #ifndef IPC_IPC_MESSAGE_UTILS_H_ |
| 6 #define IPC_IPC_MESSAGE_UTILS_H_ | 6 #define IPC_IPC_MESSAGE_UTILS_H_ |
| 7 | 7 |
| 8 #include <limits.h> | 8 #include <limits.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 300 struct IPC_EXPORT ParamTraits<double> { | 300 struct IPC_EXPORT ParamTraits<double> { |
| 301 typedef double param_type; | 301 typedef double param_type; |
| 302 static void GetSize(base::PickleSizer* sizer, const param_type& p); | 302 static void GetSize(base::PickleSizer* sizer, const param_type& p); |
| 303 static void Write(base::Pickle* m, const param_type& p); | 303 static void Write(base::Pickle* m, const param_type& p); |
| 304 static bool Read(const base::Pickle* m, | 304 static bool Read(const base::Pickle* m, |
| 305 base::PickleIterator* iter, | 305 base::PickleIterator* iter, |
| 306 param_type* r); | 306 param_type* r); |
| 307 static void Log(const param_type& p, std::string* l); | 307 static void Log(const param_type& p, std::string* l); |
| 308 }; | 308 }; |
| 309 | 309 |
| 310 template <class P, size_t Size> | |
| 311 struct ParamTraits<P[Size]> { | |
| 312 using param_type = P[Size]; | |
| 313 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | |
| 314 GetParamSize(sizer, static_cast<int>(Size)); | |
|
dcheng
2017/02/08 00:13:37
Let's use strict_cast instead of static_cast throu
ericrk
2017/02/08 18:57:49
So, strict_cast seems to only consider the types b
| |
| 315 for (size_t i = 0; i < Size; i++) | |
| 316 GetParamSize(sizer, p[i]); | |
| 317 } | |
| 318 static void Write(base::Pickle* m, const param_type& p) { | |
| 319 WriteParam(m, static_cast<int>(Size)); | |
| 320 for (size_t i = 0; i < Size; i++) | |
| 321 WriteParam(m, p[i]); | |
| 322 } | |
| 323 static bool Read(const base::Pickle* m, | |
| 324 base::PickleIterator* iter, | |
| 325 param_type* r) { | |
| 326 int size; | |
| 327 // ReadLength() checks for < 0 itself. | |
| 328 if (!iter->ReadLength(&size)) | |
| 329 return false; | |
| 330 // For a fixed size array, a size mismatch should be impossible. | |
|
dcheng
2017/02/08 00:13:37
It's not impossible if the renderer sends us bad d
ericrk
2017/02/08 18:57:49
heh, true enough, updated the comment
| |
| 331 if (size != Size) | |
| 332 return false; | |
| 333 for (size_t i = 0; i < Size; i++) { | |
| 334 if (!ReadParam(m, iter, &(*r)[i])) | |
| 335 return false; | |
| 336 } | |
| 337 return true; | |
| 338 } | |
| 339 static void Log(const param_type& p, std::string* l) { | |
| 340 for (size_t i = 0; i < Size; ++i) { | |
| 341 if (i != 0) | |
| 342 l->append(" "); | |
| 343 LogParam((p[i]), l); | |
| 344 } | |
| 345 } | |
| 346 }; | |
| 347 | |
| 310 // STL ParamTraits ------------------------------------------------------------- | 348 // STL ParamTraits ------------------------------------------------------------- |
| 311 | 349 |
| 312 template <> | 350 template <> |
| 313 struct ParamTraits<std::string> { | 351 struct ParamTraits<std::string> { |
| 314 typedef std::string param_type; | 352 typedef std::string param_type; |
| 315 static void GetSize(base::PickleSizer* sizer, const param_type& p) { | 353 static void GetSize(base::PickleSizer* sizer, const param_type& p) { |
| 316 sizer->AddString(p); | 354 sizer->AddString(p); |
| 317 } | 355 } |
| 318 static void Write(base::Pickle* m, const param_type& p) { m->WriteString(p); } | 356 static void Write(base::Pickle* m, const param_type& p) { m->WriteString(p); } |
| 319 static bool Read(const base::Pickle* m, | 357 static bool Read(const base::Pickle* m, |
| (...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1139 template <class ReplyParamType> | 1177 template <class ReplyParamType> |
| 1140 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, | 1178 inline void LogReplyParamsToMessage(const ReplyParamType& reply_params, |
| 1141 const Message* msg) {} | 1179 const Message* msg) {} |
| 1142 | 1180 |
| 1143 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} | 1181 inline void ConnectMessageAndReply(const Message* msg, Message* reply) {} |
| 1144 #endif | 1182 #endif |
| 1145 | 1183 |
| 1146 } // namespace IPC | 1184 } // namespace IPC |
| 1147 | 1185 |
| 1148 #endif // IPC_IPC_MESSAGE_UTILS_H_ | 1186 #endif // IPC_IPC_MESSAGE_UTILS_H_ |
| OLD | NEW |