| 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/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/sequenced_task_runner.h" |
| 10 #include "base/threading/thread_checker.h" |
| 9 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 10 #include "content/browser/bad_message.h" | 12 #include "content/browser/bad_message.h" |
| 11 #include "content/browser/child_process_security_policy_impl.h" | 13 #include "content/browser/child_process_security_policy_impl.h" |
| 12 #include "content/browser/indexed_db/indexed_db_connection.h" | 14 #include "content/browser/indexed_db/indexed_db_connection.h" |
| 13 #include "content/browser/indexed_db/indexed_db_context_impl.h" | 15 #include "content/browser/indexed_db/indexed_db_context_impl.h" |
| 14 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 16 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 15 #include "content/browser/indexed_db/indexed_db_transaction.h" | 17 #include "content/browser/indexed_db/indexed_db_transaction.h" |
| 16 #include "content/browser/indexed_db/indexed_db_value.h" | 18 #include "content/browser/indexed_db/indexed_db_value.h" |
| 17 #include "storage/browser/blob/blob_storage_context.h" | 19 #include "storage/browser/blob/blob_storage_context.h" |
| 18 #include "storage/browser/quota/quota_manager_proxy.h" | 20 #include "storage/browser/quota/quota_manager_proxy.h" |
| 19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" | 21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc
eption.h" |
| 20 | 22 |
| 21 using std::swap; | 23 using std::swap; |
| 22 | 24 |
| 23 namespace content { | 25 namespace content { |
| 24 class IndexedDBDatabaseError; | 26 class IndexedDBDatabaseError; |
| 25 | 27 |
| 26 namespace { | 28 namespace { |
| 27 const char kInvalidBlobUuid[] = "Blob does not exist"; | 29 const char kInvalidBlobUuid[] = "Blob does not exist"; |
| 28 const char kInvalidBlobFilePath[] = "Blob file path is invalid"; | 30 const char kInvalidBlobFilePath[] = "Blob file path is invalid"; |
| 29 } // namespace | 31 } // namespace |
| 30 | 32 |
| 33 // Expect to be created on IO thread, and called/destroyed on IDB thread. |
| 31 class DatabaseImpl::IDBThreadHelper { | 34 class DatabaseImpl::IDBThreadHelper { |
| 32 public: | 35 public: |
| 33 IDBThreadHelper(std::unique_ptr<IndexedDBConnection> connection, | 36 IDBThreadHelper(std::unique_ptr<IndexedDBConnection> connection, |
| 34 const url::Origin& origin, | 37 const url::Origin& origin, |
| 35 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host); | 38 scoped_refptr<IndexedDBContextImpl> indexed_db_context); |
| 36 ~IDBThreadHelper(); | 39 ~IDBThreadHelper(); |
| 37 | 40 |
| 41 void ConnectionOpened(); |
| 42 |
| 38 void CreateObjectStore(int64_t transaction_id, | 43 void CreateObjectStore(int64_t transaction_id, |
| 39 int64_t object_store_id, | 44 int64_t object_store_id, |
| 40 const base::string16& name, | 45 const base::string16& name, |
| 41 const IndexedDBKeyPath& key_path, | 46 const IndexedDBKeyPath& key_path, |
| 42 bool auto_increment); | 47 bool auto_increment); |
| 43 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); | 48 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id); |
| 44 void RenameObjectStore(int64_t transaction_id, | 49 void RenameObjectStore(int64_t transaction_id, |
| 45 int64_t object_store_id, | 50 int64_t object_store_id, |
| 46 const base::string16& new_name); | 51 const base::string16& new_name); |
| 47 void CreateTransaction(int64_t transaction_id, | 52 void CreateTransaction(int64_t transaction_id, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 void AbortWithError(int64_t transaction_id, | 128 void AbortWithError(int64_t transaction_id, |
| 124 const IndexedDBDatabaseError& error); | 129 const IndexedDBDatabaseError& error); |
| 125 void Commit(int64_t transaction_id); | 130 void Commit(int64_t transaction_id); |
| 126 void OnGotUsageAndQuotaForCommit(int64_t transaction_id, | 131 void OnGotUsageAndQuotaForCommit(int64_t transaction_id, |
| 127 storage::QuotaStatusCode status, | 132 storage::QuotaStatusCode status, |
| 128 int64_t usage, | 133 int64_t usage, |
| 129 int64_t quota); | 134 int64_t quota); |
| 130 void AckReceivedBlobs(const std::vector<std::string>& uuids); | 135 void AckReceivedBlobs(const std::vector<std::string>& uuids); |
| 131 | 136 |
| 132 private: | 137 private: |
| 133 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | 138 scoped_refptr<IndexedDBContextImpl> indexed_db_context_; |
| 134 std::unique_ptr<IndexedDBConnection> connection_; | 139 std::unique_ptr<IndexedDBConnection> connection_; |
| 135 const url::Origin origin_; | 140 const url::Origin origin_; |
| 141 base::ThreadChecker idb_thread_checker_; |
| 136 base::WeakPtrFactory<IDBThreadHelper> weak_factory_; | 142 base::WeakPtrFactory<IDBThreadHelper> weak_factory_; |
| 137 }; | 143 }; |
| 138 | 144 |
| 139 DatabaseImpl::DatabaseImpl( | 145 DatabaseImpl::DatabaseImpl(std::unique_ptr<IndexedDBConnection> connection, |
| 140 std::unique_ptr<IndexedDBConnection> connection, | 146 const url::Origin& origin, |
| 141 const url::Origin& origin, | 147 IndexedDBDispatcherHost* dispatcher_host, |
| 142 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | 148 scoped_refptr<base::SequencedTaskRunner> idb_runner) |
| 143 : dispatcher_host_(dispatcher_host), | 149 : dispatcher_host_(dispatcher_host), |
| 144 origin_(origin), | 150 origin_(origin), |
| 145 idb_runner_(base::ThreadTaskRunnerHandle::Get()) { | 151 idb_runner_(std::move(idb_runner)) { |
| 152 DCHECK(connection); |
| 146 helper_ = new IDBThreadHelper(std::move(connection), origin, | 153 helper_ = new IDBThreadHelper(std::move(connection), origin, |
| 147 std::move(dispatcher_host)); | 154 dispatcher_host->context()); |
| 155 idb_runner_->PostTask(FROM_HERE, |
| 156 base::Bind(&IDBThreadHelper::ConnectionOpened, |
| 157 base::Unretained(helper_))); |
| 148 } | 158 } |
| 149 | 159 |
| 150 DatabaseImpl::~DatabaseImpl() { | 160 DatabaseImpl::~DatabaseImpl() { |
| 151 idb_runner_->DeleteSoon(FROM_HERE, helper_); | 161 idb_runner_->DeleteSoon(FROM_HERE, helper_); |
| 152 } | 162 } |
| 153 | 163 |
| 154 void DatabaseImpl::CreateObjectStore(int64_t transaction_id, | 164 void DatabaseImpl::CreateObjectStore(int64_t transaction_id, |
| 155 int64_t object_store_id, | 165 int64_t object_store_id, |
| 156 const base::string16& name, | 166 const base::string16& name, |
| 157 const IndexedDBKeyPath& key_path, | 167 const IndexedDBKeyPath& key_path, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 base::Unretained(helper_), observers)); | 229 base::Unretained(helper_), observers)); |
| 220 } | 230 } |
| 221 | 231 |
| 222 void DatabaseImpl::Get( | 232 void DatabaseImpl::Get( |
| 223 int64_t transaction_id, | 233 int64_t transaction_id, |
| 224 int64_t object_store_id, | 234 int64_t object_store_id, |
| 225 int64_t index_id, | 235 int64_t index_id, |
| 226 const IndexedDBKeyRange& key_range, | 236 const IndexedDBKeyRange& key_range, |
| 227 bool key_only, | 237 bool key_only, |
| 228 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 238 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 229 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 239 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 230 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 240 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 241 std::move(callbacks_info), idb_runner_)); |
| 231 idb_runner_->PostTask( | 242 idb_runner_->PostTask( |
| 232 FROM_HERE, base::Bind(&IDBThreadHelper::Get, base::Unretained(helper_), | 243 FROM_HERE, base::Bind(&IDBThreadHelper::Get, base::Unretained(helper_), |
| 233 transaction_id, object_store_id, index_id, | 244 transaction_id, object_store_id, index_id, |
| 234 key_range, key_only, base::Passed(&callbacks))); | 245 key_range, key_only, base::Passed(&callbacks))); |
| 235 } | 246 } |
| 236 | 247 |
| 237 void DatabaseImpl::GetAll( | 248 void DatabaseImpl::GetAll( |
| 238 int64_t transaction_id, | 249 int64_t transaction_id, |
| 239 int64_t object_store_id, | 250 int64_t object_store_id, |
| 240 int64_t index_id, | 251 int64_t index_id, |
| 241 const IndexedDBKeyRange& key_range, | 252 const IndexedDBKeyRange& key_range, |
| 242 bool key_only, | 253 bool key_only, |
| 243 int64_t max_count, | 254 int64_t max_count, |
| 244 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 255 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 245 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 256 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 246 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 257 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 258 std::move(callbacks_info), idb_runner_)); |
| 247 idb_runner_->PostTask( | 259 idb_runner_->PostTask( |
| 248 FROM_HERE, | 260 FROM_HERE, |
| 249 base::Bind(&IDBThreadHelper::GetAll, base::Unretained(helper_), | 261 base::Bind(&IDBThreadHelper::GetAll, base::Unretained(helper_), |
| 250 transaction_id, object_store_id, index_id, key_range, key_only, | 262 transaction_id, object_store_id, index_id, key_range, key_only, |
| 251 max_count, base::Passed(&callbacks))); | 263 max_count, base::Passed(&callbacks))); |
| 252 } | 264 } |
| 253 | 265 |
| 254 void DatabaseImpl::Put( | 266 void DatabaseImpl::Put( |
| 255 int64_t transaction_id, | 267 int64_t transaction_id, |
| 256 int64_t object_store_id, | 268 int64_t object_store_id, |
| 257 ::indexed_db::mojom::ValuePtr value, | 269 ::indexed_db::mojom::ValuePtr value, |
| 258 const IndexedDBKey& key, | 270 const IndexedDBKey& key, |
| 259 blink::WebIDBPutMode mode, | 271 blink::WebIDBPutMode mode, |
| 260 const std::vector<IndexedDBIndexKeys>& index_keys, | 272 const std::vector<IndexedDBIndexKeys>& index_keys, |
| 261 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 273 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 262 ChildProcessSecurityPolicyImpl* policy = | 274 ChildProcessSecurityPolicyImpl* policy = |
| 263 ChildProcessSecurityPolicyImpl::GetInstance(); | 275 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 264 | 276 |
| 265 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 277 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 266 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 278 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 279 std::move(callbacks_info), idb_runner_)); |
| 267 | 280 |
| 268 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles( | 281 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles( |
| 269 value->blob_or_file_info.size()); | 282 value->blob_or_file_info.size()); |
| 270 std::vector<IndexedDBBlobInfo> blob_info(value->blob_or_file_info.size()); | 283 std::vector<IndexedDBBlobInfo> blob_info(value->blob_or_file_info.size()); |
| 271 for (size_t i = 0; i < value->blob_or_file_info.size(); ++i) { | 284 for (size_t i = 0; i < value->blob_or_file_info.size(); ++i) { |
| 272 ::indexed_db::mojom::BlobInfoPtr& info = value->blob_or_file_info[i]; | 285 ::indexed_db::mojom::BlobInfoPtr& info = value->blob_or_file_info[i]; |
| 273 | 286 |
| 274 std::unique_ptr<storage::BlobDataHandle> handle = | 287 std::unique_ptr<storage::BlobDataHandle> handle = |
| 275 dispatcher_host_->blob_storage_context()->GetBlobDataFromUUID( | 288 dispatcher_host_->blob_storage_context()->GetBlobDataFromUUID( |
| 276 info->uuid); | 289 info->uuid); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 357 |
| 345 void DatabaseImpl::OpenCursor( | 358 void DatabaseImpl::OpenCursor( |
| 346 int64_t transaction_id, | 359 int64_t transaction_id, |
| 347 int64_t object_store_id, | 360 int64_t object_store_id, |
| 348 int64_t index_id, | 361 int64_t index_id, |
| 349 const IndexedDBKeyRange& key_range, | 362 const IndexedDBKeyRange& key_range, |
| 350 blink::WebIDBCursorDirection direction, | 363 blink::WebIDBCursorDirection direction, |
| 351 bool key_only, | 364 bool key_only, |
| 352 blink::WebIDBTaskType task_type, | 365 blink::WebIDBTaskType task_type, |
| 353 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 366 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 354 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 367 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 355 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 368 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 369 std::move(callbacks_info), idb_runner_)); |
| 356 idb_runner_->PostTask( | 370 idb_runner_->PostTask( |
| 357 FROM_HERE, | 371 FROM_HERE, |
| 358 base::Bind(&IDBThreadHelper::OpenCursor, base::Unretained(helper_), | 372 base::Bind(&IDBThreadHelper::OpenCursor, base::Unretained(helper_), |
| 359 transaction_id, object_store_id, index_id, key_range, | 373 transaction_id, object_store_id, index_id, key_range, |
| 360 direction, key_only, task_type, base::Passed(&callbacks))); | 374 direction, key_only, task_type, base::Passed(&callbacks))); |
| 361 } | 375 } |
| 362 | 376 |
| 363 void DatabaseImpl::Count( | 377 void DatabaseImpl::Count( |
| 364 int64_t transaction_id, | 378 int64_t transaction_id, |
| 365 int64_t object_store_id, | 379 int64_t object_store_id, |
| 366 int64_t index_id, | 380 int64_t index_id, |
| 367 const IndexedDBKeyRange& key_range, | 381 const IndexedDBKeyRange& key_range, |
| 368 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 382 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 369 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 383 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 370 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 384 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 385 std::move(callbacks_info), idb_runner_)); |
| 371 idb_runner_->PostTask( | 386 idb_runner_->PostTask( |
| 372 FROM_HERE, base::Bind(&IDBThreadHelper::Count, base::Unretained(helper_), | 387 FROM_HERE, base::Bind(&IDBThreadHelper::Count, base::Unretained(helper_), |
| 373 transaction_id, object_store_id, index_id, | 388 transaction_id, object_store_id, index_id, |
| 374 key_range, base::Passed(&callbacks))); | 389 key_range, base::Passed(&callbacks))); |
| 375 } | 390 } |
| 376 | 391 |
| 377 void DatabaseImpl::DeleteRange( | 392 void DatabaseImpl::DeleteRange( |
| 378 int64_t transaction_id, | 393 int64_t transaction_id, |
| 379 int64_t object_store_id, | 394 int64_t object_store_id, |
| 380 const IndexedDBKeyRange& key_range, | 395 const IndexedDBKeyRange& key_range, |
| 381 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 396 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 382 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 397 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 383 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 398 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 399 std::move(callbacks_info), idb_runner_)); |
| 384 idb_runner_->PostTask( | 400 idb_runner_->PostTask( |
| 385 FROM_HERE, | 401 FROM_HERE, |
| 386 base::Bind(&IDBThreadHelper::DeleteRange, base::Unretained(helper_), | 402 base::Bind(&IDBThreadHelper::DeleteRange, base::Unretained(helper_), |
| 387 transaction_id, object_store_id, key_range, | 403 transaction_id, object_store_id, key_range, |
| 388 base::Passed(&callbacks))); | 404 base::Passed(&callbacks))); |
| 389 } | 405 } |
| 390 | 406 |
| 391 void DatabaseImpl::Clear( | 407 void DatabaseImpl::Clear( |
| 392 int64_t transaction_id, | 408 int64_t transaction_id, |
| 393 int64_t object_store_id, | 409 int64_t object_store_id, |
| 394 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 410 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 395 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 411 scoped_refptr<IndexedDBCallbacks> callbacks( |
| 396 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 412 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, |
| 413 std::move(callbacks_info), idb_runner_)); |
| 397 idb_runner_->PostTask( | 414 idb_runner_->PostTask( |
| 398 FROM_HERE, | 415 FROM_HERE, |
| 399 base::Bind(&IDBThreadHelper::Clear, base::Unretained(helper_), | 416 base::Bind(&IDBThreadHelper::Clear, base::Unretained(helper_), |
| 400 transaction_id, object_store_id, base::Passed(&callbacks))); | 417 transaction_id, object_store_id, base::Passed(&callbacks))); |
| 401 } | 418 } |
| 402 | 419 |
| 403 void DatabaseImpl::CreateIndex(int64_t transaction_id, | 420 void DatabaseImpl::CreateIndex(int64_t transaction_id, |
| 404 int64_t object_store_id, | 421 int64_t object_store_id, |
| 405 int64_t index_id, | 422 int64_t index_id, |
| 406 const base::string16& name, | 423 const base::string16& name, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 } | 463 } |
| 447 | 464 |
| 448 void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) { | 465 void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) { |
| 449 for (const auto& uuid : uuids) | 466 for (const auto& uuid : uuids) |
| 450 dispatcher_host_->DropBlobData(uuid); | 467 dispatcher_host_->DropBlobData(uuid); |
| 451 } | 468 } |
| 452 | 469 |
| 453 DatabaseImpl::IDBThreadHelper::IDBThreadHelper( | 470 DatabaseImpl::IDBThreadHelper::IDBThreadHelper( |
| 454 std::unique_ptr<IndexedDBConnection> connection, | 471 std::unique_ptr<IndexedDBConnection> connection, |
| 455 const url::Origin& origin, | 472 const url::Origin& origin, |
| 456 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | 473 scoped_refptr<IndexedDBContextImpl> indexed_db_context) |
| 457 : dispatcher_host_(std::move(dispatcher_host)), | 474 : indexed_db_context_(indexed_db_context), |
| 458 connection_(std::move(connection)), | 475 connection_(std::move(connection)), |
| 459 origin_(origin), | 476 origin_(origin), |
| 460 weak_factory_(this) { | 477 weak_factory_(this) { |
| 461 dispatcher_host_->context()->ConnectionOpened(origin_, connection.get()); | 478 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 479 idb_thread_checker_.DetachFromThread(); |
| 462 } | 480 } |
| 463 | 481 |
| 464 DatabaseImpl::IDBThreadHelper::~IDBThreadHelper() { | 482 DatabaseImpl::IDBThreadHelper::~IDBThreadHelper() { |
| 483 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 465 if (connection_->IsConnected()) | 484 if (connection_->IsConnected()) |
| 466 connection_->Close(); | 485 connection_->Close(); |
| 467 dispatcher_host_->context()->ConnectionClosed(origin_, connection_.get()); | 486 indexed_db_context_->ConnectionClosed(origin_, connection_.get()); |
| 487 } |
| 488 |
| 489 void DatabaseImpl::IDBThreadHelper::ConnectionOpened() { |
| 490 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 491 indexed_db_context_->ConnectionOpened(origin_, connection_.get()); |
| 468 } | 492 } |
| 469 | 493 |
| 470 void DatabaseImpl::IDBThreadHelper::CreateObjectStore( | 494 void DatabaseImpl::IDBThreadHelper::CreateObjectStore( |
| 471 int64_t transaction_id, | 495 int64_t transaction_id, |
| 472 int64_t object_store_id, | 496 int64_t object_store_id, |
| 473 const base::string16& name, | 497 const base::string16& name, |
| 474 const IndexedDBKeyPath& key_path, | 498 const IndexedDBKeyPath& key_path, |
| 475 bool auto_increment) { | 499 bool auto_increment) { |
| 500 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 476 if (!connection_->IsConnected()) | 501 if (!connection_->IsConnected()) |
| 477 return; | 502 return; |
| 478 | 503 |
| 479 IndexedDBTransaction* transaction = | 504 IndexedDBTransaction* transaction = |
| 480 connection_->GetTransaction(transaction_id); | 505 connection_->GetTransaction(transaction_id); |
| 481 if (!transaction) | 506 if (!transaction) |
| 482 return; | 507 return; |
| 483 | 508 |
| 484 connection_->database()->CreateObjectStore(transaction, object_store_id, name, | 509 connection_->database()->CreateObjectStore(transaction, object_store_id, name, |
| 485 key_path, auto_increment); | 510 key_path, auto_increment); |
| 486 } | 511 } |
| 487 | 512 |
| 488 void DatabaseImpl::IDBThreadHelper::DeleteObjectStore(int64_t transaction_id, | 513 void DatabaseImpl::IDBThreadHelper::DeleteObjectStore(int64_t transaction_id, |
| 489 int64_t object_store_id) { | 514 int64_t object_store_id) { |
| 515 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 490 if (!connection_->IsConnected()) | 516 if (!connection_->IsConnected()) |
| 491 return; | 517 return; |
| 492 | 518 |
| 493 IndexedDBTransaction* transaction = | 519 IndexedDBTransaction* transaction = |
| 494 connection_->GetTransaction(transaction_id); | 520 connection_->GetTransaction(transaction_id); |
| 495 if (!transaction) | 521 if (!transaction) |
| 496 return; | 522 return; |
| 497 | 523 |
| 498 connection_->database()->DeleteObjectStore(transaction, object_store_id); | 524 connection_->database()->DeleteObjectStore(transaction, object_store_id); |
| 499 } | 525 } |
| 500 | 526 |
| 501 void DatabaseImpl::IDBThreadHelper::RenameObjectStore( | 527 void DatabaseImpl::IDBThreadHelper::RenameObjectStore( |
| 502 int64_t transaction_id, | 528 int64_t transaction_id, |
| 503 int64_t object_store_id, | 529 int64_t object_store_id, |
| 504 const base::string16& new_name) { | 530 const base::string16& new_name) { |
| 531 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 505 if (!connection_->IsConnected()) | 532 if (!connection_->IsConnected()) |
| 506 return; | 533 return; |
| 507 | 534 |
| 508 IndexedDBTransaction* transaction = | 535 IndexedDBTransaction* transaction = |
| 509 connection_->GetTransaction(transaction_id); | 536 connection_->GetTransaction(transaction_id); |
| 510 if (!transaction) | 537 if (!transaction) |
| 511 return; | 538 return; |
| 512 | 539 |
| 513 connection_->database()->RenameObjectStore(transaction, object_store_id, | 540 connection_->database()->RenameObjectStore(transaction, object_store_id, |
| 514 new_name); | 541 new_name); |
| 515 } | 542 } |
| 516 | 543 |
| 517 void DatabaseImpl::IDBThreadHelper::CreateTransaction( | 544 void DatabaseImpl::IDBThreadHelper::CreateTransaction( |
| 518 int64_t transaction_id, | 545 int64_t transaction_id, |
| 519 const std::vector<int64_t>& object_store_ids, | 546 const std::vector<int64_t>& object_store_ids, |
| 520 blink::WebIDBTransactionMode mode) { | 547 blink::WebIDBTransactionMode mode) { |
| 548 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 521 if (!connection_->IsConnected()) | 549 if (!connection_->IsConnected()) |
| 522 return; | 550 return; |
| 523 | 551 |
| 524 connection_->database()->CreateTransaction(transaction_id, connection_.get(), | 552 connection_->database()->CreateTransaction(transaction_id, connection_.get(), |
| 525 object_store_ids, mode); | 553 object_store_ids, mode); |
| 526 } | 554 } |
| 527 | 555 |
| 528 void DatabaseImpl::IDBThreadHelper::Close() { | 556 void DatabaseImpl::IDBThreadHelper::Close() { |
| 557 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 529 if (!connection_->IsConnected()) | 558 if (!connection_->IsConnected()) |
| 530 return; | 559 return; |
| 531 | 560 |
| 532 connection_->Close(); | 561 connection_->Close(); |
| 533 } | 562 } |
| 534 | 563 |
| 535 void DatabaseImpl::IDBThreadHelper::VersionChangeIgnored() { | 564 void DatabaseImpl::IDBThreadHelper::VersionChangeIgnored() { |
| 565 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 536 if (!connection_->IsConnected()) | 566 if (!connection_->IsConnected()) |
| 537 return; | 567 return; |
| 538 | 568 |
| 539 connection_->VersionChangeIgnored(); | 569 connection_->VersionChangeIgnored(); |
| 540 } | 570 } |
| 541 | 571 |
| 542 void DatabaseImpl::IDBThreadHelper::AddObserver(int64_t transaction_id, | 572 void DatabaseImpl::IDBThreadHelper::AddObserver(int64_t transaction_id, |
| 543 int32_t observer_id, | 573 int32_t observer_id, |
| 544 bool include_transaction, | 574 bool include_transaction, |
| 545 bool no_records, | 575 bool no_records, |
| 546 bool values, | 576 bool values, |
| 547 uint16_t operation_types) { | 577 uint16_t operation_types) { |
| 578 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 548 if (!connection_->IsConnected()) | 579 if (!connection_->IsConnected()) |
| 549 return; | 580 return; |
| 550 | 581 |
| 551 IndexedDBTransaction* transaction = | 582 IndexedDBTransaction* transaction = |
| 552 connection_->GetTransaction(transaction_id); | 583 connection_->GetTransaction(transaction_id); |
| 553 if (!transaction) | 584 if (!transaction) |
| 554 return; | 585 return; |
| 555 | 586 |
| 556 IndexedDBObserver::Options options(include_transaction, no_records, values, | 587 IndexedDBObserver::Options options(include_transaction, no_records, values, |
| 557 operation_types); | 588 operation_types); |
| 558 connection_->database()->AddPendingObserver(transaction, observer_id, | 589 connection_->database()->AddPendingObserver(transaction, observer_id, |
| 559 options); | 590 options); |
| 560 } | 591 } |
| 561 | 592 |
| 562 void DatabaseImpl::IDBThreadHelper::RemoveObservers( | 593 void DatabaseImpl::IDBThreadHelper::RemoveObservers( |
| 563 const std::vector<int32_t>& observers) { | 594 const std::vector<int32_t>& observers) { |
| 595 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 564 if (!connection_->IsConnected()) | 596 if (!connection_->IsConnected()) |
| 565 return; | 597 return; |
| 566 | 598 |
| 567 connection_->RemoveObservers(observers); | 599 connection_->RemoveObservers(observers); |
| 568 } | 600 } |
| 569 | 601 |
| 570 void DatabaseImpl::IDBThreadHelper::Get( | 602 void DatabaseImpl::IDBThreadHelper::Get( |
| 571 int64_t transaction_id, | 603 int64_t transaction_id, |
| 572 int64_t object_store_id, | 604 int64_t object_store_id, |
| 573 int64_t index_id, | 605 int64_t index_id, |
| 574 const IndexedDBKeyRange& key_range, | 606 const IndexedDBKeyRange& key_range, |
| 575 bool key_only, | 607 bool key_only, |
| 576 scoped_refptr<IndexedDBCallbacks> callbacks) { | 608 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 609 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 577 if (!connection_->IsConnected()) | 610 if (!connection_->IsConnected()) |
| 578 return; | 611 return; |
| 579 | 612 |
| 580 IndexedDBTransaction* transaction = | 613 IndexedDBTransaction* transaction = |
| 581 connection_->GetTransaction(transaction_id); | 614 connection_->GetTransaction(transaction_id); |
| 582 if (!transaction) | 615 if (!transaction) |
| 583 return; | 616 return; |
| 584 | 617 |
| 585 connection_->database()->Get(transaction, object_store_id, index_id, | 618 connection_->database()->Get(transaction, object_store_id, index_id, |
| 586 base::MakeUnique<IndexedDBKeyRange>(key_range), | 619 base::MakeUnique<IndexedDBKeyRange>(key_range), |
| 587 key_only, callbacks); | 620 key_only, callbacks); |
| 588 } | 621 } |
| 589 | 622 |
| 590 void DatabaseImpl::IDBThreadHelper::GetAll( | 623 void DatabaseImpl::IDBThreadHelper::GetAll( |
| 591 int64_t transaction_id, | 624 int64_t transaction_id, |
| 592 int64_t object_store_id, | 625 int64_t object_store_id, |
| 593 int64_t index_id, | 626 int64_t index_id, |
| 594 const IndexedDBKeyRange& key_range, | 627 const IndexedDBKeyRange& key_range, |
| 595 bool key_only, | 628 bool key_only, |
| 596 int64_t max_count, | 629 int64_t max_count, |
| 597 scoped_refptr<IndexedDBCallbacks> callbacks) { | 630 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 631 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 598 if (!connection_->IsConnected()) | 632 if (!connection_->IsConnected()) |
| 599 return; | 633 return; |
| 600 | 634 |
| 601 IndexedDBTransaction* transaction = | 635 IndexedDBTransaction* transaction = |
| 602 connection_->GetTransaction(transaction_id); | 636 connection_->GetTransaction(transaction_id); |
| 603 if (!transaction) | 637 if (!transaction) |
| 604 return; | 638 return; |
| 605 | 639 |
| 606 connection_->database()->GetAll( | 640 connection_->database()->GetAll( |
| 607 transaction, object_store_id, index_id, | 641 transaction, object_store_id, index_id, |
| 608 base::MakeUnique<IndexedDBKeyRange>(key_range), key_only, max_count, | 642 base::MakeUnique<IndexedDBKeyRange>(key_range), key_only, max_count, |
| 609 std::move(callbacks)); | 643 std::move(callbacks)); |
| 610 } | 644 } |
| 611 | 645 |
| 612 void DatabaseImpl::IDBThreadHelper::Put( | 646 void DatabaseImpl::IDBThreadHelper::Put( |
| 613 int64_t transaction_id, | 647 int64_t transaction_id, |
| 614 int64_t object_store_id, | 648 int64_t object_store_id, |
| 615 ::indexed_db::mojom::ValuePtr mojo_value, | 649 ::indexed_db::mojom::ValuePtr mojo_value, |
| 616 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles, | 650 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles, |
| 617 std::vector<IndexedDBBlobInfo> blob_info, | 651 std::vector<IndexedDBBlobInfo> blob_info, |
| 618 const IndexedDBKey& key, | 652 const IndexedDBKey& key, |
| 619 blink::WebIDBPutMode mode, | 653 blink::WebIDBPutMode mode, |
| 620 const std::vector<IndexedDBIndexKeys>& index_keys, | 654 const std::vector<IndexedDBIndexKeys>& index_keys, |
| 621 scoped_refptr<IndexedDBCallbacks> callbacks) { | 655 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 656 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 622 if (!connection_->IsConnected()) | 657 if (!connection_->IsConnected()) |
| 623 return; | 658 return; |
| 624 | 659 |
| 625 IndexedDBTransaction* transaction = | 660 IndexedDBTransaction* transaction = |
| 626 connection_->GetTransaction(transaction_id); | 661 connection_->GetTransaction(transaction_id); |
| 627 if (!transaction) | 662 if (!transaction) |
| 628 return; | 663 return; |
| 629 | 664 |
| 630 uint64_t commit_size = mojo_value->bits.size(); | 665 uint64_t commit_size = mojo_value->bits.size(); |
| 631 IndexedDBValue value; | 666 IndexedDBValue value; |
| 632 swap(value.bits, mojo_value->bits); | 667 swap(value.bits, mojo_value->bits); |
| 633 swap(value.blob_info, blob_info); | 668 swap(value.blob_info, blob_info); |
| 634 connection_->database()->Put(transaction, object_store_id, &value, &handles, | 669 connection_->database()->Put(transaction, object_store_id, &value, &handles, |
| 635 base::MakeUnique<IndexedDBKey>(key), mode, | 670 base::MakeUnique<IndexedDBKey>(key), mode, |
| 636 std::move(callbacks), index_keys); | 671 std::move(callbacks), index_keys); |
| 637 | 672 |
| 638 // Size can't be big enough to overflow because it represents the | 673 // Size can't be big enough to overflow because it represents the |
| 639 // actual bytes passed through IPC. | 674 // actual bytes passed through IPC. |
| 640 transaction->set_size(transaction->size() + commit_size); | 675 transaction->set_size(transaction->size() + commit_size); |
| 641 } | 676 } |
| 642 | 677 |
| 643 void DatabaseImpl::IDBThreadHelper::SetIndexKeys( | 678 void DatabaseImpl::IDBThreadHelper::SetIndexKeys( |
| 644 int64_t transaction_id, | 679 int64_t transaction_id, |
| 645 int64_t object_store_id, | 680 int64_t object_store_id, |
| 646 const IndexedDBKey& primary_key, | 681 const IndexedDBKey& primary_key, |
| 647 const std::vector<IndexedDBIndexKeys>& index_keys) { | 682 const std::vector<IndexedDBIndexKeys>& index_keys) { |
| 683 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 648 if (!connection_->IsConnected()) | 684 if (!connection_->IsConnected()) |
| 649 return; | 685 return; |
| 650 | 686 |
| 651 IndexedDBTransaction* transaction = | 687 IndexedDBTransaction* transaction = |
| 652 connection_->GetTransaction(transaction_id); | 688 connection_->GetTransaction(transaction_id); |
| 653 if (!transaction) | 689 if (!transaction) |
| 654 return; | 690 return; |
| 655 | 691 |
| 656 connection_->database()->SetIndexKeys( | 692 connection_->database()->SetIndexKeys( |
| 657 transaction, object_store_id, base::MakeUnique<IndexedDBKey>(primary_key), | 693 transaction, object_store_id, base::MakeUnique<IndexedDBKey>(primary_key), |
| 658 index_keys); | 694 index_keys); |
| 659 } | 695 } |
| 660 | 696 |
| 661 void DatabaseImpl::IDBThreadHelper::SetIndexesReady( | 697 void DatabaseImpl::IDBThreadHelper::SetIndexesReady( |
| 662 int64_t transaction_id, | 698 int64_t transaction_id, |
| 663 int64_t object_store_id, | 699 int64_t object_store_id, |
| 664 const std::vector<int64_t>& index_ids) { | 700 const std::vector<int64_t>& index_ids) { |
| 701 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 665 if (!connection_->IsConnected()) | 702 if (!connection_->IsConnected()) |
| 666 return; | 703 return; |
| 667 | 704 |
| 668 IndexedDBTransaction* transaction = | 705 IndexedDBTransaction* transaction = |
| 669 connection_->GetTransaction(transaction_id); | 706 connection_->GetTransaction(transaction_id); |
| 670 if (!transaction) | 707 if (!transaction) |
| 671 return; | 708 return; |
| 672 | 709 |
| 673 connection_->database()->SetIndexesReady(transaction, object_store_id, | 710 connection_->database()->SetIndexesReady(transaction, object_store_id, |
| 674 index_ids); | 711 index_ids); |
| 675 } | 712 } |
| 676 | 713 |
| 677 void DatabaseImpl::IDBThreadHelper::OpenCursor( | 714 void DatabaseImpl::IDBThreadHelper::OpenCursor( |
| 678 int64_t transaction_id, | 715 int64_t transaction_id, |
| 679 int64_t object_store_id, | 716 int64_t object_store_id, |
| 680 int64_t index_id, | 717 int64_t index_id, |
| 681 const IndexedDBKeyRange& key_range, | 718 const IndexedDBKeyRange& key_range, |
| 682 blink::WebIDBCursorDirection direction, | 719 blink::WebIDBCursorDirection direction, |
| 683 bool key_only, | 720 bool key_only, |
| 684 blink::WebIDBTaskType task_type, | 721 blink::WebIDBTaskType task_type, |
| 685 scoped_refptr<IndexedDBCallbacks> callbacks) { | 722 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 723 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 686 if (!connection_->IsConnected()) | 724 if (!connection_->IsConnected()) |
| 687 return; | 725 return; |
| 688 | 726 |
| 689 IndexedDBTransaction* transaction = | 727 IndexedDBTransaction* transaction = |
| 690 connection_->GetTransaction(transaction_id); | 728 connection_->GetTransaction(transaction_id); |
| 691 if (!transaction) | 729 if (!transaction) |
| 692 return; | 730 return; |
| 693 | 731 |
| 694 connection_->database()->OpenCursor( | 732 connection_->database()->OpenCursor( |
| 695 transaction, object_store_id, index_id, | 733 transaction, object_store_id, index_id, |
| 696 base::MakeUnique<IndexedDBKeyRange>(key_range), direction, key_only, | 734 base::MakeUnique<IndexedDBKeyRange>(key_range), direction, key_only, |
| 697 task_type, std::move(callbacks)); | 735 task_type, std::move(callbacks)); |
| 698 } | 736 } |
| 699 | 737 |
| 700 void DatabaseImpl::IDBThreadHelper::Count( | 738 void DatabaseImpl::IDBThreadHelper::Count( |
| 701 int64_t transaction_id, | 739 int64_t transaction_id, |
| 702 int64_t object_store_id, | 740 int64_t object_store_id, |
| 703 int64_t index_id, | 741 int64_t index_id, |
| 704 const IndexedDBKeyRange& key_range, | 742 const IndexedDBKeyRange& key_range, |
| 705 scoped_refptr<IndexedDBCallbacks> callbacks) { | 743 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 744 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 706 if (!connection_->IsConnected()) | 745 if (!connection_->IsConnected()) |
| 707 return; | 746 return; |
| 708 | 747 |
| 709 IndexedDBTransaction* transaction = | 748 IndexedDBTransaction* transaction = |
| 710 connection_->GetTransaction(transaction_id); | 749 connection_->GetTransaction(transaction_id); |
| 711 if (!transaction) | 750 if (!transaction) |
| 712 return; | 751 return; |
| 713 | 752 |
| 714 connection_->database()->Count(transaction, object_store_id, index_id, | 753 connection_->database()->Count(transaction, object_store_id, index_id, |
| 715 base::MakeUnique<IndexedDBKeyRange>(key_range), | 754 base::MakeUnique<IndexedDBKeyRange>(key_range), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 731 | 770 |
| 732 connection_->database()->DeleteRange( | 771 connection_->database()->DeleteRange( |
| 733 transaction, object_store_id, | 772 transaction, object_store_id, |
| 734 base::MakeUnique<IndexedDBKeyRange>(key_range), std::move(callbacks)); | 773 base::MakeUnique<IndexedDBKeyRange>(key_range), std::move(callbacks)); |
| 735 } | 774 } |
| 736 | 775 |
| 737 void DatabaseImpl::IDBThreadHelper::Clear( | 776 void DatabaseImpl::IDBThreadHelper::Clear( |
| 738 int64_t transaction_id, | 777 int64_t transaction_id, |
| 739 int64_t object_store_id, | 778 int64_t object_store_id, |
| 740 scoped_refptr<IndexedDBCallbacks> callbacks) { | 779 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 780 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 741 if (!connection_->IsConnected()) | 781 if (!connection_->IsConnected()) |
| 742 return; | 782 return; |
| 743 | 783 |
| 744 IndexedDBTransaction* transaction = | 784 IndexedDBTransaction* transaction = |
| 745 connection_->GetTransaction(transaction_id); | 785 connection_->GetTransaction(transaction_id); |
| 746 if (!transaction) | 786 if (!transaction) |
| 747 return; | 787 return; |
| 748 | 788 |
| 749 connection_->database()->Clear(transaction, object_store_id, callbacks); | 789 connection_->database()->Clear(transaction, object_store_id, callbacks); |
| 750 } | 790 } |
| 751 | 791 |
| 752 void DatabaseImpl::IDBThreadHelper::CreateIndex( | 792 void DatabaseImpl::IDBThreadHelper::CreateIndex( |
| 753 int64_t transaction_id, | 793 int64_t transaction_id, |
| 754 int64_t object_store_id, | 794 int64_t object_store_id, |
| 755 int64_t index_id, | 795 int64_t index_id, |
| 756 const base::string16& name, | 796 const base::string16& name, |
| 757 const IndexedDBKeyPath& key_path, | 797 const IndexedDBKeyPath& key_path, |
| 758 bool unique, | 798 bool unique, |
| 759 bool multi_entry) { | 799 bool multi_entry) { |
| 800 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 760 if (!connection_->IsConnected()) | 801 if (!connection_->IsConnected()) |
| 761 return; | 802 return; |
| 762 | 803 |
| 763 IndexedDBTransaction* transaction = | 804 IndexedDBTransaction* transaction = |
| 764 connection_->GetTransaction(transaction_id); | 805 connection_->GetTransaction(transaction_id); |
| 765 if (!transaction) | 806 if (!transaction) |
| 766 return; | 807 return; |
| 767 | 808 |
| 768 connection_->database()->CreateIndex(transaction, object_store_id, index_id, | 809 connection_->database()->CreateIndex(transaction, object_store_id, index_id, |
| 769 name, key_path, unique, multi_entry); | 810 name, key_path, unique, multi_entry); |
| 770 } | 811 } |
| 771 | 812 |
| 772 void DatabaseImpl::IDBThreadHelper::DeleteIndex(int64_t transaction_id, | 813 void DatabaseImpl::IDBThreadHelper::DeleteIndex(int64_t transaction_id, |
| 773 int64_t object_store_id, | 814 int64_t object_store_id, |
| 774 int64_t index_id) { | 815 int64_t index_id) { |
| 816 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 775 if (!connection_->IsConnected()) | 817 if (!connection_->IsConnected()) |
| 776 return; | 818 return; |
| 777 | 819 |
| 778 IndexedDBTransaction* transaction = | 820 IndexedDBTransaction* transaction = |
| 779 connection_->GetTransaction(transaction_id); | 821 connection_->GetTransaction(transaction_id); |
| 780 if (!transaction) | 822 if (!transaction) |
| 781 return; | 823 return; |
| 782 | 824 |
| 783 connection_->database()->DeleteIndex(transaction, object_store_id, index_id); | 825 connection_->database()->DeleteIndex(transaction, object_store_id, index_id); |
| 784 } | 826 } |
| 785 | 827 |
| 786 void DatabaseImpl::IDBThreadHelper::RenameIndex( | 828 void DatabaseImpl::IDBThreadHelper::RenameIndex( |
| 787 int64_t transaction_id, | 829 int64_t transaction_id, |
| 788 int64_t object_store_id, | 830 int64_t object_store_id, |
| 789 int64_t index_id, | 831 int64_t index_id, |
| 790 const base::string16& new_name) { | 832 const base::string16& new_name) { |
| 833 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 791 if (!connection_->IsConnected()) | 834 if (!connection_->IsConnected()) |
| 792 return; | 835 return; |
| 793 | 836 |
| 794 IndexedDBTransaction* transaction = | 837 IndexedDBTransaction* transaction = |
| 795 connection_->GetTransaction(transaction_id); | 838 connection_->GetTransaction(transaction_id); |
| 796 if (!transaction) | 839 if (!transaction) |
| 797 return; | 840 return; |
| 798 | 841 |
| 799 connection_->database()->RenameIndex(transaction, object_store_id, index_id, | 842 connection_->database()->RenameIndex(transaction, object_store_id, index_id, |
| 800 new_name); | 843 new_name); |
| 801 } | 844 } |
| 802 | 845 |
| 803 void DatabaseImpl::IDBThreadHelper::Abort(int64_t transaction_id) { | 846 void DatabaseImpl::IDBThreadHelper::Abort(int64_t transaction_id) { |
| 847 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 804 if (!connection_->IsConnected()) | 848 if (!connection_->IsConnected()) |
| 805 return; | 849 return; |
| 806 | 850 |
| 807 IndexedDBTransaction* transaction = | 851 IndexedDBTransaction* transaction = |
| 808 connection_->GetTransaction(transaction_id); | 852 connection_->GetTransaction(transaction_id); |
| 809 if (!transaction) | 853 if (!transaction) |
| 810 return; | 854 return; |
| 811 | 855 |
| 812 connection_->AbortTransaction(transaction); | 856 connection_->AbortTransaction(transaction); |
| 813 } | 857 } |
| 814 | 858 |
| 815 void DatabaseImpl::IDBThreadHelper::AbortWithError( | 859 void DatabaseImpl::IDBThreadHelper::AbortWithError( |
| 816 int64_t transaction_id, | 860 int64_t transaction_id, |
| 817 const IndexedDBDatabaseError& error) { | 861 const IndexedDBDatabaseError& error) { |
| 862 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 818 if (!connection_->IsConnected()) | 863 if (!connection_->IsConnected()) |
| 819 return; | 864 return; |
| 820 | 865 |
| 821 IndexedDBTransaction* transaction = | 866 IndexedDBTransaction* transaction = |
| 822 connection_->GetTransaction(transaction_id); | 867 connection_->GetTransaction(transaction_id); |
| 823 if (!transaction) | 868 if (!transaction) |
| 824 return; | 869 return; |
| 825 | 870 |
| 826 connection_->AbortTransaction(transaction, error); | 871 connection_->AbortTransaction(transaction, error); |
| 827 } | 872 } |
| 828 | 873 |
| 829 void DatabaseImpl::IDBThreadHelper::Commit(int64_t transaction_id) { | 874 void DatabaseImpl::IDBThreadHelper::Commit(int64_t transaction_id) { |
| 875 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 830 if (!connection_->IsConnected()) | 876 if (!connection_->IsConnected()) |
| 831 return; | 877 return; |
| 832 | 878 |
| 833 IndexedDBTransaction* transaction = | 879 IndexedDBTransaction* transaction = |
| 834 connection_->GetTransaction(transaction_id); | 880 connection_->GetTransaction(transaction_id); |
| 835 if (!transaction) | 881 if (!transaction) |
| 836 return; | 882 return; |
| 837 | 883 |
| 838 // Always allow empty or delete-only transactions. | 884 // Always allow empty or delete-only transactions. |
| 839 if (transaction->size() == 0) { | 885 if (transaction->size() == 0) { |
| 840 connection_->database()->Commit(transaction); | 886 connection_->database()->Commit(transaction); |
| 841 return; | 887 return; |
| 842 } | 888 } |
| 843 | 889 |
| 844 dispatcher_host_->context()->quota_manager_proxy()->GetUsageAndQuota( | 890 indexed_db_context_->quota_manager_proxy()->GetUsageAndQuota( |
| 845 dispatcher_host_->context()->TaskRunner(), origin_.GetURL(), | 891 indexed_db_context_->TaskRunner(), origin_.GetURL(), |
| 846 storage::kStorageTypeTemporary, | 892 storage::kStorageTypeTemporary, |
| 847 base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit, | 893 base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit, |
| 848 weak_factory_.GetWeakPtr(), transaction_id)); | 894 weak_factory_.GetWeakPtr(), transaction_id)); |
| 849 } | 895 } |
| 850 | 896 |
| 851 void DatabaseImpl::IDBThreadHelper::OnGotUsageAndQuotaForCommit( | 897 void DatabaseImpl::IDBThreadHelper::OnGotUsageAndQuotaForCommit( |
| 852 int64_t transaction_id, | 898 int64_t transaction_id, |
| 853 storage::QuotaStatusCode status, | 899 storage::QuotaStatusCode status, |
| 854 int64_t usage, | 900 int64_t usage, |
| 855 int64_t quota) { | 901 int64_t quota) { |
| 902 DCHECK(idb_thread_checker_.CalledOnValidThread()); |
| 856 // May have disconnected while quota check was pending. | 903 // May have disconnected while quota check was pending. |
| 857 if (!connection_->IsConnected()) | 904 if (!connection_->IsConnected()) |
| 858 return; | 905 return; |
| 859 | 906 |
| 860 IndexedDBTransaction* transaction = | 907 IndexedDBTransaction* transaction = |
| 861 connection_->GetTransaction(transaction_id); | 908 connection_->GetTransaction(transaction_id); |
| 862 if (!transaction) | 909 if (!transaction) |
| 863 return; | 910 return; |
| 864 | 911 |
| 865 if (status == storage::kQuotaStatusOk && | 912 if (status == storage::kQuotaStatusOk && |
| 866 usage + transaction->size() <= quota) { | 913 usage + transaction->size() <= quota) { |
| 867 connection_->database()->Commit(transaction); | 914 connection_->database()->Commit(transaction); |
| 868 } else { | 915 } else { |
| 869 connection_->AbortTransaction( | 916 connection_->AbortTransaction( |
| 870 transaction, | 917 transaction, |
| 871 IndexedDBDatabaseError(blink::kWebIDBDatabaseExceptionQuotaError)); | 918 IndexedDBDatabaseError(blink::kWebIDBDatabaseExceptionQuotaError)); |
| 872 } | 919 } |
| 873 } | 920 } |
| 874 | 921 |
| 875 } // namespace content | 922 } // namespace content |
| OLD | NEW |