Blink roll 25b6bd3a7a131ffe68d809546ad1a20707915cdc:3a503f41ae42e5b79cfcd2ff10e65afde...
[chromium-blink-merge.git] / content / common / content_param_traits.cc
blob0f1ba055121f573a92e9296fd8773caf9ef95d72
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.
5 #include "content/common/content_param_traits.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "content/common/input/web_input_event_traits.h"
9 #include "net/base/ip_endpoint.h"
10 #include "ui/gfx/range/range.h"
12 namespace IPC {
14 void ParamTraits<gfx::Range>::Write(Message* m, const gfx::Range& r) {
15 m->WriteSizeT(r.start());
16 m->WriteSizeT(r.end());
19 bool ParamTraits<gfx::Range>::Read(const Message* m,
20 PickleIterator* iter,
21 gfx::Range* r) {
22 size_t start, end;
23 if (!m->ReadSizeT(iter, &start) || !m->ReadSizeT(iter, &end))
24 return false;
25 r->set_start(start);
26 r->set_end(end);
27 return true;
30 void ParamTraits<gfx::Range>::Log(const gfx::Range& r, std::string* l) {
31 l->append(base::StringPrintf("(%" PRIuS ", %" PRIuS ")", r.start(), r.end()));
34 void ParamTraits<WebInputEventPointer>::Write(Message* m, const param_type& p) {
35 m->WriteData(reinterpret_cast<const char*>(p), p->size);
38 bool ParamTraits<WebInputEventPointer>::Read(const Message* m,
39 PickleIterator* iter,
40 param_type* r) {
41 const char* data;
42 int data_length;
43 if (!m->ReadData(iter, &data, &data_length)) {
44 NOTREACHED();
45 return false;
47 if (data_length < static_cast<int>(sizeof(blink::WebInputEvent))) {
48 NOTREACHED();
49 return false;
51 param_type event = reinterpret_cast<param_type>(data);
52 // Check that the data size matches that of the event.
53 if (data_length != static_cast<int>(event->size)) {
54 NOTREACHED();
55 return false;
57 const size_t expected_size_for_type =
58 content::WebInputEventTraits::GetSize(event->type);
59 if (data_length != static_cast<int>(expected_size_for_type)) {
60 NOTREACHED();
61 return false;
63 *r = event;
64 return true;
67 void ParamTraits<WebInputEventPointer>::Log(const param_type& p,
68 std::string* l) {
69 l->append("(");
70 LogParam(p->size, l);
71 l->append(", ");
72 LogParam(p->type, l);
73 l->append(", ");
74 LogParam(p->timeStampSeconds, l);
75 l->append(")");
78 } // namespace IPC
80 // Generate param traits write methods.
81 #include "ipc/param_traits_write_macros.h"
82 namespace IPC {
83 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
84 #include "content/common/content_param_traits_macros.h"
85 } // namespace IPC
87 // Generate param traits read methods.
88 #include "ipc/param_traits_read_macros.h"
89 namespace IPC {
90 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
91 #include "content/common/content_param_traits_macros.h"
92 } // namespace IPC
94 // Generate param traits log methods.
95 #include "ipc/param_traits_log_macros.h"
96 namespace IPC {
97 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
98 #include "content/common/content_param_traits_macros.h"
99 } // namespace IPC