OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/indexed_db/database_impl.h" | 5 #include "content/browser/indexed_db/database_impl.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.h" |
9 #include "content/browser/bad_message.h" | 9 #include "content/browser/bad_message.h" |
10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 int64_t quota); | 125 int64_t quota); |
126 void AckReceivedBlobs(const std::vector<std::string>& uuids); | 126 void AckReceivedBlobs(const std::vector<std::string>& uuids); |
127 | 127 |
128 private: | 128 private: |
129 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | 129 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; |
130 std::unique_ptr<IndexedDBConnection> connection_; | 130 std::unique_ptr<IndexedDBConnection> connection_; |
131 const url::Origin origin_; | 131 const url::Origin origin_; |
132 base::WeakPtrFactory<IDBThreadHelper> weak_factory_; | 132 base::WeakPtrFactory<IDBThreadHelper> weak_factory_; |
133 }; | 133 }; |
134 | 134 |
135 DatabaseImpl::DatabaseImpl( | 135 DatabaseImpl::DatabaseImpl(std::unique_ptr<IndexedDBConnection> connection, |
136 std::unique_ptr<IndexedDBConnection> connection, | 136 const url::Origin& origin, |
137 const url::Origin& origin, | 137 IndexedDBDispatcherHost* dispatcher_host) |
138 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | |
139 : dispatcher_host_(dispatcher_host), | 138 : dispatcher_host_(dispatcher_host), |
140 origin_(origin), | 139 origin_(origin), |
141 idb_runner_(base::ThreadTaskRunnerHandle::Get()) { | 140 idb_runner_(base::ThreadTaskRunnerHandle::Get()) { |
142 helper_ = new IDBThreadHelper(std::move(connection), origin, | 141 helper_ = new IDBThreadHelper(std::move(connection), origin, |
143 std::move(dispatcher_host)); | 142 std::move(dispatcher_host)); |
144 } | 143 } |
145 | 144 |
146 DatabaseImpl::~DatabaseImpl() { | 145 DatabaseImpl::~DatabaseImpl() { |
147 idb_runner_->DeleteSoon(FROM_HERE, helper_); | 146 idb_runner_->DeleteSoon(FROM_HERE, helper_); |
148 } | 147 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 215 } |
217 | 216 |
218 void DatabaseImpl::Get( | 217 void DatabaseImpl::Get( |
219 int64_t transaction_id, | 218 int64_t transaction_id, |
220 int64_t object_store_id, | 219 int64_t object_store_id, |
221 int64_t index_id, | 220 int64_t index_id, |
222 const IndexedDBKeyRange& key_range, | 221 const IndexedDBKeyRange& key_range, |
223 bool key_only, | 222 bool key_only, |
224 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 223 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
225 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 224 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
226 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 225 dispatcher_host_, origin_, std::move(callbacks_info))); |
227 idb_runner_->PostTask( | 226 idb_runner_->PostTask( |
228 FROM_HERE, base::Bind(&IDBThreadHelper::Get, base::Unretained(helper_), | 227 FROM_HERE, base::Bind(&IDBThreadHelper::Get, base::Unretained(helper_), |
229 transaction_id, object_store_id, index_id, | 228 transaction_id, object_store_id, index_id, |
230 key_range, key_only, base::Passed(&callbacks))); | 229 key_range, key_only, base::Passed(&callbacks))); |
231 } | 230 } |
232 | 231 |
233 void DatabaseImpl::GetAll( | 232 void DatabaseImpl::GetAll( |
234 int64_t transaction_id, | 233 int64_t transaction_id, |
235 int64_t object_store_id, | 234 int64_t object_store_id, |
236 int64_t index_id, | 235 int64_t index_id, |
237 const IndexedDBKeyRange& key_range, | 236 const IndexedDBKeyRange& key_range, |
238 bool key_only, | 237 bool key_only, |
239 int64_t max_count, | 238 int64_t max_count, |
240 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 239 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
241 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 240 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
242 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 241 dispatcher_host_, origin_, std::move(callbacks_info))); |
243 idb_runner_->PostTask( | 242 idb_runner_->PostTask( |
244 FROM_HERE, | 243 FROM_HERE, |
245 base::Bind(&IDBThreadHelper::GetAll, base::Unretained(helper_), | 244 base::Bind(&IDBThreadHelper::GetAll, base::Unretained(helper_), |
246 transaction_id, object_store_id, index_id, key_range, key_only, | 245 transaction_id, object_store_id, index_id, key_range, key_only, |
247 max_count, base::Passed(&callbacks))); | 246 max_count, base::Passed(&callbacks))); |
248 } | 247 } |
249 | 248 |
250 void DatabaseImpl::Put( | 249 void DatabaseImpl::Put( |
251 int64_t transaction_id, | 250 int64_t transaction_id, |
252 int64_t object_store_id, | 251 int64_t object_store_id, |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 if (info->size != -1) { | 284 if (info->size != -1) { |
286 blob_info[i].set_last_modified(info->file->last_modified); | 285 blob_info[i].set_last_modified(info->file->last_modified); |
287 blob_info[i].set_size(info->size); | 286 blob_info[i].set_size(info->size); |
288 } | 287 } |
289 } else { | 288 } else { |
290 blob_info[i] = IndexedDBBlobInfo(info->uuid, info->mime_type, info->size); | 289 blob_info[i] = IndexedDBBlobInfo(info->uuid, info->mime_type, info->size); |
291 } | 290 } |
292 } | 291 } |
293 | 292 |
294 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 293 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
295 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 294 dispatcher_host_, origin_, std::move(callbacks_info))); |
296 | 295 |
297 idb_runner_->PostTask( | 296 idb_runner_->PostTask( |
298 FROM_HERE, | 297 FROM_HERE, |
299 base::Bind(&IDBThreadHelper::Put, base::Unretained(helper_), | 298 base::Bind(&IDBThreadHelper::Put, base::Unretained(helper_), |
300 transaction_id, object_store_id, base::Passed(&value), | 299 transaction_id, object_store_id, base::Passed(&value), |
301 base::Passed(&handles), base::Passed(&blob_info), key, mode, | 300 base::Passed(&handles), base::Passed(&blob_info), key, mode, |
302 index_keys, base::Passed(&callbacks))); | 301 index_keys, base::Passed(&callbacks))); |
303 } | 302 } |
304 | 303 |
305 void DatabaseImpl::SetIndexKeys( | 304 void DatabaseImpl::SetIndexKeys( |
(...skipping 19 matching lines...) Expand all Loading... |
325 void DatabaseImpl::OpenCursor( | 324 void DatabaseImpl::OpenCursor( |
326 int64_t transaction_id, | 325 int64_t transaction_id, |
327 int64_t object_store_id, | 326 int64_t object_store_id, |
328 int64_t index_id, | 327 int64_t index_id, |
329 const IndexedDBKeyRange& key_range, | 328 const IndexedDBKeyRange& key_range, |
330 blink::WebIDBCursorDirection direction, | 329 blink::WebIDBCursorDirection direction, |
331 bool key_only, | 330 bool key_only, |
332 blink::WebIDBTaskType task_type, | 331 blink::WebIDBTaskType task_type, |
333 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 332 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
334 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 333 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
335 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 334 dispatcher_host_, origin_, std::move(callbacks_info))); |
336 idb_runner_->PostTask( | 335 idb_runner_->PostTask( |
337 FROM_HERE, | 336 FROM_HERE, |
338 base::Bind(&IDBThreadHelper::OpenCursor, base::Unretained(helper_), | 337 base::Bind(&IDBThreadHelper::OpenCursor, base::Unretained(helper_), |
339 transaction_id, object_store_id, index_id, key_range, | 338 transaction_id, object_store_id, index_id, key_range, |
340 direction, key_only, task_type, base::Passed(&callbacks))); | 339 direction, key_only, task_type, base::Passed(&callbacks))); |
341 } | 340 } |
342 | 341 |
343 void DatabaseImpl::Count( | 342 void DatabaseImpl::Count( |
344 int64_t transaction_id, | 343 int64_t transaction_id, |
345 int64_t object_store_id, | 344 int64_t object_store_id, |
346 int64_t index_id, | 345 int64_t index_id, |
347 const IndexedDBKeyRange& key_range, | 346 const IndexedDBKeyRange& key_range, |
348 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 347 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
349 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 348 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
350 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 349 dispatcher_host_, origin_, std::move(callbacks_info))); |
351 idb_runner_->PostTask( | 350 idb_runner_->PostTask( |
352 FROM_HERE, base::Bind(&IDBThreadHelper::Count, base::Unretained(helper_), | 351 FROM_HERE, base::Bind(&IDBThreadHelper::Count, base::Unretained(helper_), |
353 transaction_id, object_store_id, index_id, | 352 transaction_id, object_store_id, index_id, |
354 key_range, base::Passed(&callbacks))); | 353 key_range, base::Passed(&callbacks))); |
355 } | 354 } |
356 | 355 |
357 void DatabaseImpl::DeleteRange( | 356 void DatabaseImpl::DeleteRange( |
358 int64_t transaction_id, | 357 int64_t transaction_id, |
359 int64_t object_store_id, | 358 int64_t object_store_id, |
360 const IndexedDBKeyRange& key_range, | 359 const IndexedDBKeyRange& key_range, |
361 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 360 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
362 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 361 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
363 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 362 dispatcher_host_, origin_, std::move(callbacks_info))); |
364 idb_runner_->PostTask( | 363 idb_runner_->PostTask( |
365 FROM_HERE, | 364 FROM_HERE, |
366 base::Bind(&IDBThreadHelper::DeleteRange, base::Unretained(helper_), | 365 base::Bind(&IDBThreadHelper::DeleteRange, base::Unretained(helper_), |
367 transaction_id, object_store_id, key_range, | 366 transaction_id, object_store_id, key_range, |
368 base::Passed(&callbacks))); | 367 base::Passed(&callbacks))); |
369 } | 368 } |
370 | 369 |
371 void DatabaseImpl::Clear( | 370 void DatabaseImpl::Clear( |
372 int64_t transaction_id, | 371 int64_t transaction_id, |
373 int64_t object_store_id, | 372 int64_t object_store_id, |
374 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 373 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
375 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 374 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
376 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 375 dispatcher_host_, origin_, std::move(callbacks_info))); |
377 idb_runner_->PostTask( | 376 idb_runner_->PostTask( |
378 FROM_HERE, | 377 FROM_HERE, |
379 base::Bind(&IDBThreadHelper::Clear, base::Unretained(helper_), | 378 base::Bind(&IDBThreadHelper::Clear, base::Unretained(helper_), |
380 transaction_id, object_store_id, base::Passed(&callbacks))); | 379 transaction_id, object_store_id, base::Passed(&callbacks))); |
381 } | 380 } |
382 | 381 |
383 void DatabaseImpl::CreateIndex(int64_t transaction_id, | 382 void DatabaseImpl::CreateIndex(int64_t transaction_id, |
384 int64_t object_store_id, | 383 int64_t object_store_id, |
385 int64_t index_id, | 384 int64_t index_id, |
386 const base::string16& name, | 385 const base::string16& name, |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
832 usage + transaction->size() <= quota) { | 831 usage + transaction->size() <= quota) { |
833 connection_->database()->Commit(transaction); | 832 connection_->database()->Commit(transaction); |
834 } else { | 833 } else { |
835 connection_->AbortTransaction( | 834 connection_->AbortTransaction( |
836 transaction, | 835 transaction, |
837 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); | 836 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError)); |
838 } | 837 } |
839 } | 838 } |
840 | 839 |
841 } // namespace content | 840 } // namespace content |
OLD | NEW |