summaryrefslogtreecommitdiffstats
path: root/chrome/common/indexed_db_param_traits.cc
blob: 70c10ffb5cf4dc0e830e445fe6f39a997cba3abb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/common/indexed_db_param_traits.h"

#include "chrome/common/indexed_db_key.h"
#include "chrome/common/serialized_script_value.h"
#include "ipc/ipc_message_utils.h"

namespace IPC {

void ParamTraits<SerializedScriptValue>::Write(Message* m,
                                               const param_type& p) {
  WriteParam(m, p.is_null());
  WriteParam(m, p.is_invalid());
  WriteParam(m, p.data());
}

bool ParamTraits<SerializedScriptValue>::Read(const Message* m,
                                              void** iter,
                                              param_type* r) {
  bool is_null;
  bool is_invalid;
  string16 data;
  bool ok =
      ReadParam(m, iter, &is_null) &&
      ReadParam(m, iter, &is_invalid) &&
      ReadParam(m, iter, &data);
  if (!ok)
  return false;
  r->set_is_null(is_null);
  r->set_is_invalid(is_invalid);
  r->set_data(data);
  return true;
}

void ParamTraits<SerializedScriptValue>::Log(const param_type& p,
                                             std::string* l) {
  l->append("<SerializedScriptValue>(");
  LogParam(p.is_null(), l);
  l->append(", ");
  LogParam(p.is_invalid(), l);
  l->append(", ");
  LogParam(p.data(), l);
  l->append(")");
}

void ParamTraits<IndexedDBKey>::Write(Message* m, const param_type& p) {
  WriteParam(m, int(p.type()));
  // TODO(jorlow): Technically, we only need to pack the type being used.
  WriteParam(m, p.string());
  WriteParam(m, p.date());
  WriteParam(m, p.number());
}

bool ParamTraits<IndexedDBKey>::Read(const Message* m,
                                     void** iter,
                                     param_type* r) {
  int type;
  string16 string;
  double date;
  double number;
  bool ok =
      ReadParam(m, iter, &type) &&
      ReadParam(m, iter, &string) &&
      ReadParam(m, iter, &date) &&
      ReadParam(m, iter, &number);

  if (!ok)
    return false;
  switch (type) {
    case WebKit::WebIDBKey::NullType:
      r->SetNull();
      return true;
    case WebKit::WebIDBKey::StringType:
      r->SetString(string);
      return true;
    case WebKit::WebIDBKey::DateType:
      r->SetDate(date);
      return true;
    case WebKit::WebIDBKey::NumberType:
      r->SetNumber(number);
      return true;
    case WebKit::WebIDBKey::InvalidType:
      r->SetInvalid();
      return true;
  }
  NOTREACHED();
  return false;
}

void ParamTraits<IndexedDBKey>::Log(const param_type& p, std::string* l) {
  l->append("<IndexedDBKey>(");
  LogParam(int(p.type()), l);
  l->append(", ");
  LogParam(p.string(), l);
  l->append(", ");
  LogParam(p.date(), l);
  l->append(", ");
  LogParam(p.number(), l);
  l->append(")");
}

}  // namespace IPC