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 #ifndef CHROME_COMMON_INDEXED_DB_PARAM_TRAITS_H_ |
| 6 #define CHROME_COMMON_INDEXED_DB_PARAM_TRAITS_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "chrome/common/indexed_db_key.h" |
| 10 #include "chrome/common/serialized_script_value.h" |
| 11 |
| 12 namespace IPC { |
| 13 |
| 14 // These datatypes are used by utility_messages.h and render_messages.h. |
| 15 // Unfortunately we can't move it to common: MSVC linker complains about |
| 16 // WebKit datatypes that are not linked on npchrome_frame (even though it's |
| 17 // never actually used by that target). |
| 18 |
| 19 template <> |
| 20 struct ParamTraits<SerializedScriptValue> { |
| 21 typedef SerializedScriptValue param_type; |
| 22 static void Write(Message* m, const param_type& p) { |
| 23 WriteParam(m, p.is_null()); |
| 24 WriteParam(m, p.is_invalid()); |
| 25 WriteParam(m, p.data()); |
| 26 } |
| 27 static bool Read(const Message* m, void** iter, param_type* r) { |
| 28 bool is_null; |
| 29 bool is_invalid; |
| 30 string16 data; |
| 31 bool ok = |
| 32 ReadParam(m, iter, &is_null) && |
| 33 ReadParam(m, iter, &is_invalid) && |
| 34 ReadParam(m, iter, &data); |
| 35 if (!ok) |
| 36 return false; |
| 37 r->set_is_null(is_null); |
| 38 r->set_is_invalid(is_invalid); |
| 39 r->set_data(data); |
| 40 return true; |
| 41 } |
| 42 static void Log(const param_type& p, std::wstring* l) { |
| 43 l->append(L"<SerializedScriptValue>("); |
| 44 LogParam(p.is_null(), l); |
| 45 l->append(L", "); |
| 46 LogParam(p.is_invalid(), l); |
| 47 l->append(L", "); |
| 48 LogParam(p.data(), l); |
| 49 l->append(L")"); |
| 50 } |
| 51 }; |
| 52 |
| 53 template <> |
| 54 struct ParamTraits<IndexedDBKey> { |
| 55 typedef IndexedDBKey param_type; |
| 56 static void Write(Message* m, const param_type& p) { |
| 57 WriteParam(m, int(p.type())); |
| 58 // TODO(jorlow): Technically, we only need to pack the type being used. |
| 59 WriteParam(m, p.string()); |
| 60 WriteParam(m, p.number()); |
| 61 } |
| 62 static bool Read(const Message* m, void** iter, param_type* r) { |
| 63 int type; |
| 64 string16 string; |
| 65 int32 number; |
| 66 bool ok = |
| 67 ReadParam(m, iter, &type) && |
| 68 ReadParam(m, iter, &string) && |
| 69 ReadParam(m, iter, &number); |
| 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->Set(string); |
| 78 return true; |
| 79 case WebKit::WebIDBKey::NumberType: |
| 80 r->Set(number); |
| 81 return true; |
| 82 case WebKit::WebIDBKey::InvalidType: |
| 83 r->SetInvalid(); |
| 84 return true; |
| 85 } |
| 86 NOTREACHED(); |
| 87 return false; |
| 88 } |
| 89 static void Log(const param_type& p, std::wstring* l) { |
| 90 l->append(L"<IndexedDBKey>("); |
| 91 LogParam(int(p.type()), l); |
| 92 l->append(L", "); |
| 93 LogParam(p.string(), l); |
| 94 l->append(L", "); |
| 95 LogParam(p.number(), l); |
| 96 l->append(L")"); |
| 97 } |
| 98 }; |
| 99 |
| 100 } // namespace IPC |
| 101 |
| 102 #endif // CHROME_COMMON_INDEXED_DB_PARAM_TRAITS_H_ |
OLD | NEW |