Respond with QuotaExceededError when IndexedDB has no disk space on open.
[chromium-blink-merge.git] / content / common / content_param_traits.cc
blob6b607558f927b123844cb4440a250415d74df035
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 "net/base/ip_endpoint.h"
9 #include "ui/gfx/range/range.h"
11 namespace {
13 int WebInputEventSizeForType(WebKit::WebInputEvent::Type type) {
14 if (WebKit::WebInputEvent::isMouseEventType(type))
15 return sizeof(WebKit::WebMouseEvent);
16 if (type == WebKit::WebInputEvent::MouseWheel)
17 return sizeof(WebKit::WebMouseWheelEvent);
18 if (WebKit::WebInputEvent::isKeyboardEventType(type))
19 return sizeof(WebKit::WebKeyboardEvent);
20 if (WebKit::WebInputEvent::isTouchEventType(type))
21 return sizeof(WebKit::WebTouchEvent);
22 if (WebKit::WebInputEvent::isGestureEventType(type))
23 return sizeof(WebKit::WebGestureEvent);
24 NOTREACHED() << "Unknown webkit event type " << type;
25 return 0;
28 } // namespace
30 namespace IPC {
32 void ParamTraits<net::IPEndPoint>::Write(Message* m, const param_type& p) {
33 WriteParam(m, p.address());
34 WriteParam(m, p.port());
37 bool ParamTraits<net::IPEndPoint>::Read(const Message* m, PickleIterator* iter,
38 param_type* p) {
39 net::IPAddressNumber address;
40 int port;
41 if (!ReadParam(m, iter, &address) || !ReadParam(m, iter, &port))
42 return false;
43 *p = net::IPEndPoint(address, port);
44 return true;
47 void ParamTraits<net::IPEndPoint>::Log(const param_type& p, std::string* l) {
48 LogParam("IPEndPoint:" + p.ToString(), l);
51 void ParamTraits<gfx::Range>::Write(Message* m, const gfx::Range& r) {
52 m->WriteUInt64(r.start());
53 m->WriteUInt64(r.end());
56 bool ParamTraits<gfx::Range>::Read(const Message* m,
57 PickleIterator* iter,
58 gfx::Range* r) {
59 uint64 start, end;
60 if (!m->ReadUInt64(iter, &start) || !m->ReadUInt64(iter, &end))
61 return false;
62 r->set_start(start);
63 r->set_end(end);
64 return true;
67 void ParamTraits<gfx::Range>::Log(const gfx::Range& r, std::string* l) {
68 l->append(base::StringPrintf("(%" PRIuS ", %" PRIuS ")", r.start(), r.end()));
71 void ParamTraits<WebInputEventPointer>::Write(Message* m, const param_type& p) {
72 m->WriteData(reinterpret_cast<const char*>(p), p->size);
75 bool ParamTraits<WebInputEventPointer>::Read(const Message* m,
76 PickleIterator* iter,
77 param_type* r) {
78 const char* data;
79 int data_length;
80 if (!m->ReadData(iter, &data, &data_length)) {
81 NOTREACHED();
82 return false;
84 if (data_length < static_cast<int>(sizeof(WebKit::WebInputEvent))) {
85 NOTREACHED();
86 return false;
88 param_type event = reinterpret_cast<param_type>(data);
89 // Check that the data size matches that of the event.
90 if (data_length != static_cast<int>(event->size)) {
91 NOTREACHED();
92 return false;
94 if (data_length != WebInputEventSizeForType(event->type)) {
95 NOTREACHED();
96 return false;
98 *r = event;
99 return true;
102 void ParamTraits<WebInputEventPointer>::Log(const param_type& p,
103 std::string* l) {
104 l->append("(");
105 LogParam(p->size, l);
106 l->append(", ");
107 LogParam(p->type, l);
108 l->append(", ");
109 LogParam(p->timeStampSeconds, l);
110 l->append(")");
113 } // namespace IPC
115 // Generate param traits write methods.
116 #include "ipc/param_traits_write_macros.h"
117 namespace IPC {
118 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
119 #include "content/common/content_param_traits_macros.h"
120 } // namespace IPC
122 // Generate param traits read methods.
123 #include "ipc/param_traits_read_macros.h"
124 namespace IPC {
125 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
126 #include "content/common/content_param_traits_macros.h"
127 } // namespace IPC
129 // Generate param traits log methods.
130 #include "ipc/param_traits_log_macros.h"
131 namespace IPC {
132 #undef CONTENT_COMMON_CONTENT_PARAM_TRAITS_MACROS_H_
133 #include "content/common/content_param_traits_macros.h"
134 } // namespace IPC