| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 "chrome/common/indexed_db_param_traits.h" | |
| 6 | |
| 7 #include "chrome/common/indexed_db_key.h" | |
| 8 #include "chrome/common/serialized_script_value.h" | |
| 9 #include "ipc/ipc_message_utils.h" | |
| 10 | |
| 11 namespace IPC { | |
| 12 | |
| 13 void ParamTraits<SerializedScriptValue>::Write(Message* m, | |
| 14 const param_type& p) { | |
| 15 WriteParam(m, p.is_null()); | |
| 16 WriteParam(m, p.is_invalid()); | |
| 17 WriteParam(m, p.data()); | |
| 18 } | |
| 19 | |
| 20 bool ParamTraits<SerializedScriptValue>::Read(const Message* m, | |
| 21 void** iter, | |
| 22 param_type* r) { | |
| 23 bool is_null; | |
| 24 bool is_invalid; | |
| 25 string16 data; | |
| 26 bool ok = | |
| 27 ReadParam(m, iter, &is_null) && | |
| 28 ReadParam(m, iter, &is_invalid) && | |
| 29 ReadParam(m, iter, &data); | |
| 30 if (!ok) | |
| 31 return false; | |
| 32 r->set_is_null(is_null); | |
| 33 r->set_is_invalid(is_invalid); | |
| 34 r->set_data(data); | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 void ParamTraits<SerializedScriptValue>::Log(const param_type& p, | |
| 39 std::string* l) { | |
| 40 l->append("<SerializedScriptValue>("); | |
| 41 LogParam(p.is_null(), l); | |
| 42 l->append(", "); | |
| 43 LogParam(p.is_invalid(), l); | |
| 44 l->append(", "); | |
| 45 LogParam(p.data(), l); | |
| 46 l->append(")"); | |
| 47 } | |
| 48 | |
| 49 void ParamTraits<IndexedDBKey>::Write(Message* m, const param_type& p) { | |
| 50 WriteParam(m, int(p.type())); | |
| 51 // TODO(jorlow): Technically, we only need to pack the type being used. | |
| 52 WriteParam(m, p.string()); | |
| 53 WriteParam(m, p.date()); | |
| 54 WriteParam(m, p.number()); | |
| 55 } | |
| 56 | |
| 57 bool ParamTraits<IndexedDBKey>::Read(const Message* m, | |
| 58 void** iter, | |
| 59 param_type* r) { | |
| 60 int type; | |
| 61 string16 string; | |
| 62 double date; | |
| 63 double number; | |
| 64 bool ok = | |
| 65 ReadParam(m, iter, &type) && | |
| 66 ReadParam(m, iter, &string) && | |
| 67 ReadParam(m, iter, &date) && | |
| 68 ReadParam(m, iter, &number); | |
| 69 | |
| 70 if (!ok) | |
| 71 return false; | |
| 72 switch (type) { | |
| 73 case WebKit::WebIDBKey::NullType: | |
| 74 r->SetNull(); | |
| 75 return true; | |
| 76 case WebKit::WebIDBKey::StringType: | |
| 77 r->SetString(string); | |
| 78 return true; | |
| 79 case WebKit::WebIDBKey::DateType: | |
| 80 r->SetDate(date); | |
| 81 return true; | |
| 82 case WebKit::WebIDBKey::NumberType: | |
| 83 r->SetNumber(number); | |
| 84 return true; | |
| 85 case WebKit::WebIDBKey::InvalidType: | |
| 86 r->SetInvalid(); | |
| 87 return true; | |
| 88 } | |
| 89 NOTREACHED(); | |
| 90 return false; | |
| 91 } | |
| 92 | |
| 93 void ParamTraits<IndexedDBKey>::Log(const param_type& p, std::string* l) { | |
| 94 l->append("<IndexedDBKey>("); | |
| 95 LogParam(int(p.type()), l); | |
| 96 l->append(", "); | |
| 97 LogParam(p.string(), l); | |
| 98 l->append(", "); | |
| 99 LogParam(p.date(), l); | |
| 100 l->append(", "); | |
| 101 LogParam(p.number(), l); | |
| 102 l->append(")"); | |
| 103 } | |
| 104 | |
| 105 } // namespace IPC | |
| OLD | NEW |