IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / child / indexed_db / indexed_db_key_builders.cc
blobed84ac41c2c174eabb1f2340645150b4c16d092a
1 // Copyright (c) 2013 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/child/indexed_db/indexed_db_key_builders.h"
7 #include "base/logging.h"
8 #include "third_party/WebKit/public/platform/WebVector.h"
10 using blink::WebIDBKey;
11 using blink::WebIDBKeyRange;
12 using blink::WebIDBKeyTypeArray;
13 using blink::WebIDBKeyTypeBinary;
14 using blink::WebIDBKeyTypeDate;
15 using blink::WebIDBKeyTypeInvalid;
16 using blink::WebIDBKeyTypeMin;
17 using blink::WebIDBKeyTypeNull;
18 using blink::WebIDBKeyTypeNumber;
19 using blink::WebIDBKeyTypeString;
20 using blink::WebVector;
21 using blink::WebString;
23 static content::IndexedDBKey::KeyArray CopyKeyArray(const WebIDBKey& other) {
24 content::IndexedDBKey::KeyArray result;
25 if (other.keyType() == WebIDBKeyTypeArray) {
26 const WebVector<WebIDBKey>& array = other.array();
27 for (size_t i = 0; i < array.size(); ++i)
28 result.push_back(content::IndexedDBKeyBuilder::Build(array[i]));
30 return result;
33 static std::vector<base::string16> CopyArray(
34 const WebVector<WebString>& array) {
35 std::vector<base::string16> copy(array.size());
36 for (size_t i = 0; i < array.size(); ++i)
37 copy[i] = array[i];
38 return copy;
42 namespace content {
44 IndexedDBKey IndexedDBKeyBuilder::Build(const blink::WebIDBKey& key) {
45 switch (key.keyType()) {
46 case WebIDBKeyTypeArray:
47 return IndexedDBKey(CopyKeyArray(key));
48 case WebIDBKeyTypeBinary:
49 return IndexedDBKey(
50 std::string(key.binary().data(), key.binary().size()));
51 case WebIDBKeyTypeString:
52 return IndexedDBKey(key.string());
53 case WebIDBKeyTypeDate:
54 return IndexedDBKey(key.date(), WebIDBKeyTypeDate);
55 case WebIDBKeyTypeNumber:
56 return IndexedDBKey(key.number(), WebIDBKeyTypeNumber);
57 case WebIDBKeyTypeNull:
58 case WebIDBKeyTypeInvalid:
59 return IndexedDBKey(key.keyType());
60 case WebIDBKeyTypeMin:
61 default:
62 NOTREACHED();
63 return IndexedDBKey();
65 NOTREACHED();
66 return IndexedDBKey();
69 WebIDBKey WebIDBKeyBuilder::Build(const IndexedDBKey& key) {
70 switch (key.type()) {
71 case WebIDBKeyTypeArray: {
72 const IndexedDBKey::KeyArray& array = key.array();
73 blink::WebVector<WebIDBKey> web_array(array.size());
74 for (size_t i = 0; i < array.size(); ++i) {
75 web_array[i] = Build(array[i]);
77 return WebIDBKey::createArray(web_array);
79 case WebIDBKeyTypeBinary:
80 return WebIDBKey::createBinary(key.binary());
81 case WebIDBKeyTypeString:
82 return WebIDBKey::createString(key.string());
83 case WebIDBKeyTypeDate:
84 return WebIDBKey::createDate(key.date());
85 case WebIDBKeyTypeNumber:
86 return WebIDBKey::createNumber(key.number());
87 case WebIDBKeyTypeInvalid:
88 return WebIDBKey::createInvalid();
89 case WebIDBKeyTypeNull:
90 return WebIDBKey::createNull();
91 case WebIDBKeyTypeMin:
92 default:
93 NOTREACHED();
94 return WebIDBKey::createInvalid();
96 NOTREACHED();
97 return WebIDBKey::createInvalid();
100 IndexedDBKeyRange IndexedDBKeyRangeBuilder::Build(
101 const WebIDBKeyRange& key_range) {
102 return IndexedDBKeyRange(
103 IndexedDBKeyBuilder::Build(key_range.lower()),
104 IndexedDBKeyBuilder::Build(key_range.upper()),
105 key_range.lowerOpen(),
106 key_range.upperOpen());
109 IndexedDBKeyPath IndexedDBKeyPathBuilder::Build(
110 const blink::WebIDBKeyPath& key_path) {
111 switch (key_path.keyPathType()) {
112 case blink::WebIDBKeyPathTypeString:
113 return IndexedDBKeyPath(key_path.string());
114 case blink::WebIDBKeyPathTypeArray:
115 return IndexedDBKeyPath(CopyArray(key_path.array()));
116 case blink::WebIDBKeyPathTypeNull:
117 return IndexedDBKeyPath();
119 NOTREACHED();
120 return IndexedDBKeyPath();
123 blink::WebIDBKeyPath WebIDBKeyPathBuilder::Build(
124 const IndexedDBKeyPath& key_path) {
125 switch (key_path.type()) {
126 case blink::WebIDBKeyPathTypeString:
127 return blink::WebIDBKeyPath::create(WebString(key_path.string()));
128 case blink::WebIDBKeyPathTypeArray:
129 return blink::WebIDBKeyPath::create(CopyArray(key_path.array()));
130 case blink::WebIDBKeyPathTypeNull:
131 return blink::WebIDBKeyPath::createNull();
133 NOTREACHED();
134 return blink::WebIDBKeyPath::createNull();
137 } // namespace content