| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 namespace { | 24 namespace { |
| 25 const char kInvalidBlobUuid[] = "Blob UUID is invalid"; | 25 const char kInvalidBlobUuid[] = "Blob UUID is invalid"; |
| 26 const char kInvalidBlobFilePath[] = "Blob file path is invalid"; | 26 const char kInvalidBlobFilePath[] = "Blob file path is invalid"; |
| 27 } // namespace | 27 } // namespace |
| 28 | 28 |
| 29 class DatabaseImpl::IDBThreadHelper { | 29 class DatabaseImpl::IDBThreadHelper { |
| 30 public: | 30 public: |
| 31 IDBThreadHelper(std::unique_ptr<IndexedDBConnection> connection, | 31 IDBThreadHelper(std::unique_ptr<IndexedDBConnection> connection, |
| 32 const url::Origin& origin, | 32 const url::Origin& origin, |
| 33 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host); | 33 scoped_refptr<IndexedDBContextImpl> indexed_db_context); |
| 34 ~IDBThreadHelper(); | 34 ~IDBThreadHelper(); |
| 35 | 35 |
| 36 void CreateObjectStore(int64_t transaction_id, | 36 void CreateObjectStore(int64_t transaction_id, |
| 37 int64_t object_store_id, | 37 int64_t object_store_id, |
| 38 const base::string16& name, | 38 const base::string16& name, |
| 39 const IndexedDBKeyPath& key_path, | 39 const IndexedDBKeyPath& key_path, |
| 40 bool auto_increment); | 40 bool auto_increment); |
| 41 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); | 41 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); |
| 42 void RenameObjectStore(int64_t transaction_id, | 42 void RenameObjectStore(int64_t transaction_id, |
| 43 int64_t object_store_id, | 43 int64_t object_store_id, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 const base::string16& new_name); | 119 const base::string16& new_name); |
| 120 void Abort(int64_t transaction_id); | 120 void Abort(int64_t transaction_id); |
| 121 void Commit(int64_t transaction_id); | 121 void Commit(int64_t transaction_id); |
| 122 void OnGotUsageAndQuotaForCommit(int64_t transaction_id, | 122 void OnGotUsageAndQuotaForCommit(int64_t transaction_id, |
| 123 storage::QuotaStatusCode status, | 123 storage::QuotaStatusCode status, |
| 124 int64_t usage, | 124 int64_t usage, |
| 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<IndexedDBContextImpl> indexed_db_context_; |
| 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 dispatcher_host->context()); |
| 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 } |
| 149 | 148 |
| 150 void DatabaseImpl::CreateObjectStore(int64_t transaction_id, | 149 void DatabaseImpl::CreateObjectStore(int64_t transaction_id, |
| 151 int64_t object_store_id, | 150 int64_t object_store_id, |
| 152 const base::string16& name, | 151 const base::string16& name, |
| 153 const IndexedDBKeyPath& key_path, | 152 const IndexedDBKeyPath& key_path, |
| (...skipping 62 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 } | 425 } |
| 427 | 426 |
| 428 void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) { | 427 void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) { |
| 429 for (const auto& uuid : uuids) | 428 for (const auto& uuid : uuids) |
| 430 dispatcher_host_->DropBlobData(uuid); | 429 dispatcher_host_->DropBlobData(uuid); |
| 431 } | 430 } |
| 432 | 431 |
| 433 DatabaseImpl::IDBThreadHelper::IDBThreadHelper( | 432 DatabaseImpl::IDBThreadHelper::IDBThreadHelper( |
| 434 std::unique_ptr<IndexedDBConnection> connection, | 433 std::unique_ptr<IndexedDBConnection> connection, |
| 435 const url::Origin& origin, | 434 const url::Origin& origin, |
| 436 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | 435 scoped_refptr<IndexedDBContextImpl> indexed_db_context) |
| 437 : dispatcher_host_(std::move(dispatcher_host)), | 436 : indexed_db_context_(indexed_db_context), |
| 438 connection_(std::move(connection)), | 437 connection_(std::move(connection)), |
| 439 origin_(origin), | 438 origin_(origin), |
| 440 weak_factory_(this) { | 439 weak_factory_(this) { |
| 441 dispatcher_host_->context()->ConnectionOpened(origin_, connection.get()); | 440 indexed_db_context_->ConnectionOpened(origin_, connection.get()); |
| 442 } | 441 } |
| 443 | 442 |
| 444 DatabaseImpl::IDBThreadHelper::~IDBThreadHelper() { | 443 DatabaseImpl::IDBThreadHelper::~IDBThreadHelper() { |
| 445 if (connection_->IsConnected()) | 444 if (connection_->IsConnected()) |
| 446 connection_->Close(); | 445 connection_->Close(); |
| 447 dispatcher_host_->context()->ConnectionClosed(origin_, connection_.get()); | 446 indexed_db_context_->ConnectionClosed(origin_, connection_.get()); |
| 448 } | 447 } |
| 449 | 448 |
| 450 void DatabaseImpl::IDBThreadHelper::CreateObjectStore( | 449 void DatabaseImpl::IDBThreadHelper::CreateObjectStore( |
| 451 int64_t transaction_id, | 450 int64_t transaction_id, |
| 452 int64_t object_store_id, | 451 int64_t object_store_id, |
| 453 const base::string16& name, | 452 const base::string16& name, |
| 454 const IndexedDBKeyPath& key_path, | 453 const IndexedDBKeyPath& key_path, |
| 455 bool auto_increment) { | 454 bool auto_increment) { |
| 456 if (!connection_->IsConnected()) | 455 if (!connection_->IsConnected()) |
| 457 return; | 456 return; |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 connection_->GetTransaction(transaction_id); | 799 connection_->GetTransaction(transaction_id); |
| 801 if (!transaction) | 800 if (!transaction) |
| 802 return; | 801 return; |
| 803 | 802 |
| 804 // Always allow empty or delete-only transactions. | 803 // Always allow empty or delete-only transactions. |
| 805 if (transaction->size() == 0) { | 804 if (transaction->size() == 0) { |
| 806 connection_->database()->Commit(transaction); | 805 connection_->database()->Commit(transaction); |
| 807 return; | 806 return; |
| 808 } | 807 } |
| 809 | 808 |
| 810 dispatcher_host_->context()->quota_manager_proxy()->GetUsageAndQuota( | 809 indexed_db_context_->quota_manager_proxy()->GetUsageAndQuota( |
| 811 dispatcher_host_->context()->TaskRunner(), origin_.GetURL(), | 810 indexed_db_context_->TaskRunner(), origin_.GetURL(), |
| 812 storage::kStorageTypeTemporary, | 811 storage::kStorageTypeTemporary, |
| 813 base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit, | 812 base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit, |
| 814 weak_factory_.GetWeakPtr(), transaction_id)); | 813 weak_factory_.GetWeakPtr(), transaction_id)); |
| 815 } | 814 } |
| 816 | 815 |
| 817 void DatabaseImpl::IDBThreadHelper::OnGotUsageAndQuotaForCommit( | 816 void DatabaseImpl::IDBThreadHelper::OnGotUsageAndQuotaForCommit( |
| 818 int64_t transaction_id, | 817 int64_t transaction_id, |
| 819 storage::QuotaStatusCode status, | 818 storage::QuotaStatusCode status, |
| 820 int64_t usage, | 819 int64_t usage, |
| 821 int64_t quota) { | 820 int64_t quota) { |
| (...skipping 10 matching lines...) Expand all 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 |