| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/browser/indexed_db/webidbdatabase_impl.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/basictypes.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "content/browser/indexed_db/indexed_db_callbacks_wrapper.h" | |
| 12 #include "content/browser/indexed_db/indexed_db_cursor.h" | |
| 13 #include "content/browser/indexed_db/indexed_db_database.h" | |
| 14 #include "content/browser/indexed_db/indexed_db_metadata.h" | |
| 15 #include "content/common/indexed_db/indexed_db_key_range.h" | |
| 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebData.h" | |
| 17 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBCallbacks.h" | |
| 18 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBDatabaseCallb
acks.h" | |
| 19 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBDatabaseError
.h" | |
| 20 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBKey.h" | |
| 21 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBKeyRange.h" | |
| 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebIDBMetadata.h" | |
| 23 | |
| 24 using WebKit::WebString; | |
| 25 using WebKit::WebIDBKey; | |
| 26 using WebKit::WebData; | |
| 27 using WebKit::WebIDBKeyPath; | |
| 28 using WebKit::WebIDBKeyRange; | |
| 29 using WebKit::WebIDBDatabaseCallbacks; | |
| 30 using WebKit::WebIDBCallbacks; | |
| 31 using WebKit::WebVector; | |
| 32 using WebKit::WebIDBDatabaseError; | |
| 33 | |
| 34 namespace content { | |
| 35 | |
| 36 WebIDBDatabaseImpl::WebIDBDatabaseImpl( | |
| 37 scoped_refptr<IndexedDBDatabase> database_backend, | |
| 38 scoped_refptr<IndexedDBDatabaseCallbacksWrapper> database_callbacks) | |
| 39 : database_backend_(database_backend), | |
| 40 database_callbacks_(database_callbacks) {} | |
| 41 | |
| 42 WebIDBDatabaseImpl::~WebIDBDatabaseImpl() {} | |
| 43 | |
| 44 void WebIDBDatabaseImpl::createObjectStore(long long transaction_id, | |
| 45 long long object_store_id, | |
| 46 const WebString& name, | |
| 47 const WebIDBKeyPath& key_path, | |
| 48 bool auto_increment) { | |
| 49 database_backend_->CreateObjectStore(transaction_id, | |
| 50 object_store_id, | |
| 51 name, | |
| 52 IndexedDBKeyPath(key_path), | |
| 53 auto_increment); | |
| 54 } | |
| 55 | |
| 56 void WebIDBDatabaseImpl::deleteObjectStore(long long transaction_id, | |
| 57 long long object_store_id) { | |
| 58 database_backend_->DeleteObjectStore(transaction_id, object_store_id); | |
| 59 } | |
| 60 | |
| 61 void WebIDBDatabaseImpl::createTransaction( | |
| 62 long long id, | |
| 63 WebIDBDatabaseCallbacks* /*callbacks*/, | |
| 64 const WebVector<long long>& object_store_ids, | |
| 65 unsigned short mode) { | |
| 66 if (!database_callbacks_) | |
| 67 return; | |
| 68 std::vector<int64> object_store_id_list(object_store_ids.size()); | |
| 69 for (size_t i = 0; i < object_store_ids.size(); ++i) | |
| 70 object_store_id_list[i] = object_store_ids[i]; | |
| 71 database_backend_->CreateTransaction( | |
| 72 id, database_callbacks_.get(), object_store_id_list, mode); | |
| 73 } | |
| 74 | |
| 75 void WebIDBDatabaseImpl::close() { | |
| 76 // Use the callbacks passed in to the constructor so that the backend in | |
| 77 // multi-process chromium knows which database connection is closing. | |
| 78 if (!database_callbacks_) | |
| 79 return; | |
| 80 database_backend_->Close(database_callbacks_); | |
| 81 database_callbacks_ = NULL; | |
| 82 } | |
| 83 | |
| 84 void WebIDBDatabaseImpl::forceClose() { | |
| 85 if (!database_callbacks_) | |
| 86 return; | |
| 87 database_backend_->Close(database_callbacks_); | |
| 88 database_callbacks_->OnForcedClose(); | |
| 89 database_callbacks_ = NULL; | |
| 90 } | |
| 91 | |
| 92 void WebIDBDatabaseImpl::abort(long long transaction_id) { | |
| 93 if (database_backend_) | |
| 94 database_backend_->Abort(transaction_id); | |
| 95 } | |
| 96 | |
| 97 void WebIDBDatabaseImpl::abort(long long transaction_id, | |
| 98 const WebIDBDatabaseError& error) { | |
| 99 if (database_backend_) | |
| 100 database_backend_->Abort(transaction_id, | |
| 101 IndexedDBDatabaseError::Create(error)); | |
| 102 } | |
| 103 | |
| 104 void WebIDBDatabaseImpl::commit(long long transaction_id) { | |
| 105 if (database_backend_) | |
| 106 database_backend_->Commit(transaction_id); | |
| 107 } | |
| 108 | |
| 109 void WebIDBDatabaseImpl::openCursor(long long transaction_id, | |
| 110 long long object_store_id, | |
| 111 long long index_id, | |
| 112 const WebIDBKeyRange& key_range, | |
| 113 unsigned short direction, | |
| 114 bool key_only, | |
| 115 TaskType task_type, | |
| 116 WebIDBCallbacks* callbacks) { | |
| 117 if (database_backend_) | |
| 118 database_backend_->OpenCursor( | |
| 119 transaction_id, | |
| 120 object_store_id, | |
| 121 index_id, | |
| 122 make_scoped_ptr(new IndexedDBKeyRange(key_range)), | |
| 123 static_cast<indexed_db::CursorDirection>(direction), | |
| 124 key_only, | |
| 125 static_cast<IndexedDBDatabase::TaskType>(task_type), | |
| 126 IndexedDBCallbacksWrapper::Create(callbacks)); | |
| 127 } | |
| 128 | |
| 129 void WebIDBDatabaseImpl::count(long long transaction_id, | |
| 130 long long object_store_id, | |
| 131 long long index_id, | |
| 132 const WebIDBKeyRange& key_range, | |
| 133 WebIDBCallbacks* callbacks) { | |
| 134 if (database_backend_) | |
| 135 database_backend_->Count(transaction_id, | |
| 136 object_store_id, | |
| 137 index_id, | |
| 138 make_scoped_ptr(new IndexedDBKeyRange(key_range)), | |
| 139 IndexedDBCallbacksWrapper::Create(callbacks)); | |
| 140 } | |
| 141 | |
| 142 void WebIDBDatabaseImpl::get(long long transaction_id, | |
| 143 long long object_store_id, | |
| 144 long long index_id, | |
| 145 const WebIDBKeyRange& key_range, | |
| 146 bool key_only, | |
| 147 WebIDBCallbacks* callbacks) { | |
| 148 if (database_backend_) | |
| 149 database_backend_->Get(transaction_id, | |
| 150 object_store_id, | |
| 151 index_id, | |
| 152 make_scoped_ptr(new IndexedDBKeyRange(key_range)), | |
| 153 key_only, | |
| 154 IndexedDBCallbacksWrapper::Create(callbacks)); | |
| 155 } | |
| 156 | |
| 157 void WebIDBDatabaseImpl::put(long long transaction_id, | |
| 158 long long object_store_id, | |
| 159 const WebData& value, | |
| 160 const WebIDBKey& key, | |
| 161 PutMode put_mode, | |
| 162 WebIDBCallbacks* callbacks, | |
| 163 const WebVector<long long>& web_index_ids, | |
| 164 const WebVector<WebIndexKeys>& web_index_keys) { | |
| 165 if (!database_backend_) | |
| 166 return; | |
| 167 | |
| 168 DCHECK_EQ(web_index_ids.size(), web_index_keys.size()); | |
| 169 std::vector<int64> index_ids(web_index_ids.size()); | |
| 170 std::vector<IndexedDBDatabase::IndexKeys> index_keys(web_index_keys.size()); | |
| 171 | |
| 172 for (size_t i = 0; i < web_index_ids.size(); ++i) { | |
| 173 index_ids[i] = web_index_ids[i]; | |
| 174 IndexedDBKey::KeyArray index_key_list; | |
| 175 for (size_t j = 0; j < web_index_keys[i].size(); ++j) | |
| 176 index_key_list.push_back(IndexedDBKey(web_index_keys[i][j])); | |
| 177 index_keys[i] = index_key_list; | |
| 178 } | |
| 179 | |
| 180 std::vector<char> value_buffer(value.data(), value.data() + value.size()); | |
| 181 database_backend_->Put(transaction_id, | |
| 182 object_store_id, | |
| 183 &value_buffer, | |
| 184 make_scoped_ptr(new IndexedDBKey(key)), | |
| 185 static_cast<IndexedDBDatabase::PutMode>(put_mode), | |
| 186 IndexedDBCallbacksWrapper::Create(callbacks), | |
| 187 index_ids, | |
| 188 index_keys); | |
| 189 } | |
| 190 | |
| 191 void WebIDBDatabaseImpl::setIndexKeys( | |
| 192 long long transaction_id, | |
| 193 long long object_store_id, | |
| 194 const WebIDBKey& primary_key, | |
| 195 const WebVector<long long>& web_index_ids, | |
| 196 const WebVector<WebIndexKeys>& web_index_keys) { | |
| 197 if (!database_backend_) | |
| 198 return; | |
| 199 | |
| 200 DCHECK_EQ(web_index_ids.size(), web_index_keys.size()); | |
| 201 std::vector<int64> index_ids(web_index_ids.size()); | |
| 202 std::vector<IndexedDBDatabase::IndexKeys> index_keys(web_index_keys.size()); | |
| 203 | |
| 204 for (size_t i = 0; i < web_index_ids.size(); ++i) { | |
| 205 index_ids[i] = web_index_ids[i]; | |
| 206 IndexedDBKey::KeyArray index_key_list; | |
| 207 for (size_t j = 0; j < web_index_keys[i].size(); ++j) | |
| 208 index_key_list.push_back(IndexedDBKey(web_index_keys[i][j])); | |
| 209 index_keys[i] = index_key_list; | |
| 210 } | |
| 211 database_backend_->SetIndexKeys( | |
| 212 transaction_id, | |
| 213 object_store_id, | |
| 214 make_scoped_ptr(new IndexedDBKey(primary_key)), | |
| 215 index_ids, | |
| 216 index_keys); | |
| 217 } | |
| 218 | |
| 219 void WebIDBDatabaseImpl::setIndexesReady( | |
| 220 long long transaction_id, | |
| 221 long long object_store_id, | |
| 222 const WebVector<long long>& web_index_ids) { | |
| 223 if (!database_backend_) | |
| 224 return; | |
| 225 | |
| 226 std::vector<int64> index_ids(web_index_ids.size()); | |
| 227 for (size_t i = 0; i < web_index_ids.size(); ++i) | |
| 228 index_ids[i] = web_index_ids[i]; | |
| 229 database_backend_->SetIndexesReady( | |
| 230 transaction_id, object_store_id, index_ids); | |
| 231 } | |
| 232 | |
| 233 void WebIDBDatabaseImpl::deleteRange(long long transaction_id, | |
| 234 long long object_store_id, | |
| 235 const WebIDBKeyRange& key_range, | |
| 236 WebIDBCallbacks* callbacks) { | |
| 237 if (database_backend_) | |
| 238 database_backend_->DeleteRange( | |
| 239 transaction_id, | |
| 240 object_store_id, | |
| 241 make_scoped_ptr(new IndexedDBKeyRange(key_range)), | |
| 242 IndexedDBCallbacksWrapper::Create(callbacks)); | |
| 243 } | |
| 244 | |
| 245 void WebIDBDatabaseImpl::clear(long long transaction_id, | |
| 246 long long object_store_id, | |
| 247 WebIDBCallbacks* callbacks) { | |
| 248 if (database_backend_) | |
| 249 database_backend_->Clear(transaction_id, | |
| 250 object_store_id, | |
| 251 IndexedDBCallbacksWrapper::Create(callbacks)); | |
| 252 } | |
| 253 | |
| 254 void WebIDBDatabaseImpl::createIndex(long long transaction_id, | |
| 255 long long object_store_id, | |
| 256 long long index_id, | |
| 257 const WebString& name, | |
| 258 const WebIDBKeyPath& key_path, | |
| 259 bool unique, | |
| 260 bool multi_entry) { | |
| 261 if (database_backend_) | |
| 262 database_backend_->CreateIndex(transaction_id, | |
| 263 object_store_id, | |
| 264 index_id, | |
| 265 name, | |
| 266 IndexedDBKeyPath(key_path), | |
| 267 unique, | |
| 268 multi_entry); | |
| 269 } | |
| 270 | |
| 271 void WebIDBDatabaseImpl::deleteIndex(long long transaction_id, | |
| 272 long long object_store_id, | |
| 273 long long index_id) { | |
| 274 if (database_backend_) | |
| 275 database_backend_->DeleteIndex(transaction_id, object_store_id, index_id); | |
| 276 } | |
| 277 | |
| 278 } // namespace WebKit | |
| OLD | NEW |