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