Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
| 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 16 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 17 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
| 18 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 19 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 20 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 21 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 27 | #include "public/platform/WebIDBMetadata.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 28 | |
Torne (Richard Coles) | 5267f70 | 2013-06-11 10:57:24 +0100 | [diff] [blame] | 29 | #include "public/platform/WebIDBKeyPath.h" |
| 30 | #include "public/platform/WebString.h" |
| 31 | #include "public/platform/WebVector.h" |
Torne (Richard Coles) | 53e740f | 2013-05-09 18:38:43 +0100 | [diff] [blame] | 32 | #include "modules/indexeddb/IDBMetadata.h" |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 33 | |
| 34 | using namespace WebCore; |
| 35 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 36 | namespace blink { |
Torne (Richard Coles) | 5c87bf8 | 2012-11-14 11:46:17 +0000 | [diff] [blame] | 37 | |
| 38 | WebIDBMetadata::WebIDBMetadata(const WebCore::IDBDatabaseMetadata& metadata) |
| 39 | { |
| 40 | name = metadata.name; |
| 41 | version = metadata.version; |
| 42 | intVersion = metadata.intVersion; |
| 43 | objectStores = WebVector<ObjectStore>(static_cast<size_t>(metadata.objectStores.size())); |
| 44 | maxObjectStoreId = metadata.maxObjectStoreId; |
| 45 | |
| 46 | size_t i = 0; |
| 47 | for (IDBDatabaseMetadata::ObjectStoreMap::const_iterator storeIterator = metadata.objectStores.begin(); storeIterator != metadata.objectStores.end(); ++storeIterator) { |
| 48 | const IDBObjectStoreMetadata& objectStore = storeIterator->value; |
| 49 | ObjectStore webObjectStore; |
| 50 | webObjectStore.id = objectStore.id; |
| 51 | webObjectStore.name = objectStore.name; |
| 52 | webObjectStore.keyPath = objectStore.keyPath; |
| 53 | webObjectStore.autoIncrement = objectStore.autoIncrement; |
| 54 | webObjectStore.indexes = WebVector<Index>(static_cast<size_t>(objectStore.indexes.size())); |
| 55 | webObjectStore.maxIndexId = objectStore.maxIndexId; |
| 56 | |
| 57 | size_t j = 0; |
| 58 | for (IDBObjectStoreMetadata::IndexMap::const_iterator indexIterator = objectStore.indexes.begin(); indexIterator != objectStore.indexes.end(); ++indexIterator) { |
| 59 | const IDBIndexMetadata& index = indexIterator->value; |
| 60 | Index webIndex; |
| 61 | webIndex.id = index.id; |
| 62 | webIndex.name = index.name; |
| 63 | webIndex.keyPath = index.keyPath; |
| 64 | webIndex.unique = index.unique; |
| 65 | webIndex.multiEntry = index.multiEntry; |
| 66 | webObjectStore.indexes[j++] = webIndex; |
| 67 | } |
| 68 | objectStores[i++] = webObjectStore; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | WebIDBMetadata::operator IDBDatabaseMetadata() const |
| 73 | { |
| 74 | IDBDatabaseMetadata db(name, id, version, intVersion, maxObjectStoreId); |
| 75 | for (size_t i = 0; i < objectStores.size(); ++i) { |
| 76 | const ObjectStore webObjectStore = objectStores[i]; |
| 77 | IDBObjectStoreMetadata objectStore(webObjectStore.name, webObjectStore.id, webObjectStore.keyPath, webObjectStore.autoIncrement, webObjectStore.maxIndexId); |
| 78 | |
| 79 | for (size_t j = 0; j < webObjectStore.indexes.size(); ++j) { |
| 80 | const Index webIndex = webObjectStore.indexes[j]; |
| 81 | IDBIndexMetadata index(webIndex.name, webIndex.id, webIndex.keyPath, webIndex.unique, webIndex.multiEntry); |
| 82 | objectStore.indexes.set(index.id, index); |
| 83 | } |
| 84 | db.objectStores.set(objectStore.id, objectStore); |
| 85 | } |
| 86 | return db; |
| 87 | } |
| 88 | |
Torne (Richard Coles) | 51b2906 | 2013-11-28 11:56:03 +0000 | [diff] [blame] | 89 | } // namespace blink |