| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 "content/common/indexed_db/proxy_webidbobjectstore_impl.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "content/common/indexed_db/indexed_db_messages.h" | |
| 10 #include "content/public/common/serialized_script_value.h" | |
| 11 #include "content/common/indexed_db/indexed_db_dispatcher.h" | |
| 12 #include "content/common/indexed_db/proxy_webidbindex_impl.h" | |
| 13 #include "content/common/indexed_db/proxy_webidbtransaction_impl.h" | |
| 14 #include "content/common/child_thread.h" | |
| 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMStringList.h" | |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKey.h" | |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyPath.h" | |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBKeyRange.h" | |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIDBTransaction.h" | |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize
dScriptValue.h" | |
| 22 | |
| 23 using WebKit::WebDOMStringList; | |
| 24 using WebKit::WebExceptionCode; | |
| 25 using WebKit::WebFrame; | |
| 26 using WebKit::WebIDBCallbacks; | |
| 27 using WebKit::WebIDBKeyPath; | |
| 28 using WebKit::WebIDBKeyRange; | |
| 29 using WebKit::WebIDBIndex; | |
| 30 using WebKit::WebIDBKey; | |
| 31 using WebKit::WebIDBTransaction; | |
| 32 using WebKit::WebSerializedScriptValue; | |
| 33 using WebKit::WebString; | |
| 34 using WebKit::WebVector; | |
| 35 | |
| 36 namespace content { | |
| 37 | |
| 38 RendererWebIDBObjectStoreImpl::RendererWebIDBObjectStoreImpl( | |
| 39 int32 ipc_object_store_id) | |
| 40 : ipc_object_store_id_(ipc_object_store_id) { | |
| 41 } | |
| 42 | |
| 43 RendererWebIDBObjectStoreImpl::~RendererWebIDBObjectStoreImpl() { | |
| 44 // It's not possible for there to be pending callbacks that address this | |
| 45 // object since inside WebKit, they hold a reference to the object wich owns | |
| 46 // this object. But, if that ever changed, then we'd need to invalidate | |
| 47 // any such pointers. | |
| 48 IndexedDBDispatcher::Send( | |
| 49 new IndexedDBHostMsg_ObjectStoreDestroyed(ipc_object_store_id_)); | |
| 50 } | |
| 51 | |
| 52 void RendererWebIDBObjectStoreImpl::get( | |
| 53 const WebIDBKeyRange& key_range, | |
| 54 WebIDBCallbacks* callbacks, | |
| 55 const WebIDBTransaction& transaction, | |
| 56 WebExceptionCode& ec) { | |
| 57 IndexedDBDispatcher* dispatcher = | |
| 58 IndexedDBDispatcher::ThreadSpecificInstance(); | |
| 59 dispatcher->RequestIDBObjectStoreGet( | |
| 60 IndexedDBKeyRange(key_range), callbacks, | |
| 61 ipc_object_store_id_, transaction, &ec); | |
| 62 } | |
| 63 | |
| 64 void RendererWebIDBObjectStoreImpl::put( | |
| 65 const WebSerializedScriptValue& value, | |
| 66 const WebIDBKey& key, | |
| 67 PutMode put_mode, | |
| 68 WebIDBCallbacks* callbacks, | |
| 69 const WebIDBTransaction& transaction, | |
| 70 const WebVector<long long>& index_ids, | |
| 71 const WebVector<WebVector<WebIDBKey> >& index_keys) { | |
| 72 IndexedDBDispatcher* dispatcher = | |
| 73 IndexedDBDispatcher::ThreadSpecificInstance(); | |
| 74 dispatcher->RequestIDBObjectStorePut( | |
| 75 SerializedScriptValue(value), IndexedDBKey(key), | |
| 76 put_mode, callbacks, ipc_object_store_id_, transaction, | |
| 77 index_ids, index_keys); | |
| 78 } | |
| 79 | |
| 80 void RendererWebIDBObjectStoreImpl::setIndexKeys( | |
| 81 const WebKit::WebIDBKey& primaryKey, | |
| 82 const WebKit::WebVector<long long>& index_ids, | |
| 83 const WebKit::WebVector<WebIndexKeys>& index_keys, | |
| 84 const WebKit::WebIDBTransaction& transaction) { | |
| 85 std::vector<int64> index_ids_list(index_ids.size()); | |
| 86 for (size_t i = 0; i < index_ids.size(); ++i) { | |
| 87 index_ids_list[i] = index_ids[i]; | |
| 88 } | |
| 89 | |
| 90 std::vector<std::vector<IndexedDBKey> > | |
| 91 index_keys_list(index_keys.size()); | |
| 92 for (size_t i = 0; i < index_keys.size(); ++i) { | |
| 93 index_keys_list[i].resize(index_keys[i].size()); | |
| 94 for (size_t j = 0; j < index_keys[i].size(); ++j) { | |
| 95 index_keys_list[i][j] = IndexedDBKey(index_keys[i][j]); | |
| 96 } | |
| 97 } | |
| 98 IndexedDBDispatcher::Send(new IndexedDBHostMsg_ObjectStoreSetIndexKeys( | |
| 99 ipc_object_store_id_, | |
| 100 IndexedDBKey(primaryKey), | |
| 101 index_ids_list, | |
| 102 index_keys_list, | |
| 103 IndexedDBDispatcher::TransactionId(transaction))); | |
| 104 } | |
| 105 | |
| 106 void RendererWebIDBObjectStoreImpl::setIndexesReady( | |
| 107 const WebKit::WebVector<long long>& index_ids, | |
| 108 const WebKit::WebIDBTransaction& transaction) { | |
| 109 | |
| 110 std::vector<int64> index_id_list(index_ids.size()); | |
| 111 for (size_t i = 0; i < index_ids.size(); ++i) { | |
| 112 index_id_list[i] = index_ids[i]; | |
| 113 } | |
| 114 | |
| 115 IndexedDBDispatcher::Send(new IndexedDBHostMsg_ObjectStoreSetIndexesReady( | |
| 116 ipc_object_store_id_, | |
| 117 index_id_list, IndexedDBDispatcher::TransactionId(transaction))); | |
| 118 } | |
| 119 | |
| 120 void RendererWebIDBObjectStoreImpl::deleteFunction( | |
| 121 const WebIDBKeyRange& key_range, | |
| 122 WebIDBCallbacks* callbacks, | |
| 123 const WebIDBTransaction& transaction, | |
| 124 WebExceptionCode& ec) { | |
| 125 IndexedDBDispatcher* dispatcher = | |
| 126 IndexedDBDispatcher::ThreadSpecificInstance(); | |
| 127 dispatcher->RequestIDBObjectStoreDelete( | |
| 128 IndexedDBKeyRange(key_range), callbacks, ipc_object_store_id_, | |
| 129 transaction, &ec); | |
| 130 } | |
| 131 | |
| 132 void RendererWebIDBObjectStoreImpl::clear( | |
| 133 WebIDBCallbacks* callbacks, | |
| 134 const WebIDBTransaction& transaction, | |
| 135 WebExceptionCode& ec) { | |
| 136 IndexedDBDispatcher* dispatcher = | |
| 137 IndexedDBDispatcher::ThreadSpecificInstance(); | |
| 138 dispatcher->RequestIDBObjectStoreClear( | |
| 139 callbacks, ipc_object_store_id_, transaction, &ec); | |
| 140 } | |
| 141 | |
| 142 WebIDBIndex* RendererWebIDBObjectStoreImpl::createIndex( | |
| 143 long long id, | |
| 144 const WebString& name, | |
| 145 const WebIDBKeyPath& key_path, | |
| 146 bool unique, | |
| 147 bool multi_entry, | |
| 148 const WebIDBTransaction& transaction, | |
| 149 WebExceptionCode& ec) { | |
| 150 IndexedDBHostMsg_ObjectStoreCreateIndex_Params params; | |
| 151 params.id = id; | |
| 152 params.name = name; | |
| 153 params.key_path = IndexedDBKeyPath(key_path); | |
| 154 params.unique = unique; | |
| 155 params.multi_entry = multi_entry; | |
| 156 params.ipc_transaction_id = IndexedDBDispatcher::TransactionId(transaction); | |
| 157 params.ipc_object_store_id = ipc_object_store_id_; | |
| 158 | |
| 159 int32 ipc_index_id; | |
| 160 IndexedDBDispatcher::Send( | |
| 161 new IndexedDBHostMsg_ObjectStoreCreateIndex(params, &ipc_index_id, &ec)); | |
| 162 if (!ipc_index_id) | |
| 163 return NULL; | |
| 164 return new RendererWebIDBIndexImpl(ipc_index_id); | |
| 165 } | |
| 166 | |
| 167 WebIDBIndex* RendererWebIDBObjectStoreImpl::index( | |
| 168 const long long index_id) { | |
| 169 int32 ipc_index_id; | |
| 170 IndexedDBDispatcher::Send( | |
| 171 new IndexedDBHostMsg_ObjectStoreIndex(ipc_object_store_id_, index_id, | |
| 172 &ipc_index_id)); | |
| 173 if (!ipc_index_id) | |
| 174 return NULL; | |
| 175 return new RendererWebIDBIndexImpl(ipc_index_id); | |
| 176 } | |
| 177 | |
| 178 void RendererWebIDBObjectStoreImpl::deleteIndex( | |
| 179 long long index_id, | |
| 180 const WebIDBTransaction& transaction, | |
| 181 WebExceptionCode& ec) { | |
| 182 IndexedDBDispatcher::Send( | |
| 183 new IndexedDBHostMsg_ObjectStoreDeleteIndex( | |
| 184 ipc_object_store_id_, index_id, | |
| 185 IndexedDBDispatcher::TransactionId(transaction), &ec)); | |
| 186 } | |
| 187 | |
| 188 void RendererWebIDBObjectStoreImpl::openCursor( | |
| 189 const WebIDBKeyRange& idb_key_range, | |
| 190 WebKit::WebIDBCursor::Direction direction, WebIDBCallbacks* callbacks, | |
| 191 WebKit::WebIDBTransaction::TaskType task_type, | |
| 192 const WebIDBTransaction& transaction, | |
| 193 WebExceptionCode& ec) { | |
| 194 IndexedDBDispatcher* dispatcher = | |
| 195 IndexedDBDispatcher::ThreadSpecificInstance(); | |
| 196 dispatcher->RequestIDBObjectStoreOpenCursor( | |
| 197 idb_key_range, direction, callbacks, ipc_object_store_id_, | |
| 198 task_type, transaction, &ec); | |
| 199 } | |
| 200 | |
| 201 void RendererWebIDBObjectStoreImpl::count( | |
| 202 const WebIDBKeyRange& idb_key_range, | |
| 203 WebIDBCallbacks* callbacks, | |
| 204 const WebIDBTransaction& transaction, | |
| 205 WebExceptionCode& ec) { | |
| 206 IndexedDBDispatcher* dispatcher = | |
| 207 IndexedDBDispatcher::ThreadSpecificInstance(); | |
| 208 dispatcher->RequestIDBObjectStoreCount( | |
| 209 idb_key_range, callbacks, ipc_object_store_id_, | |
| 210 transaction, &ec); | |
| 211 } | |
| 212 | |
| 213 } // namespace content | |
| OLD | NEW |