| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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/indexed_db_backing_store.h" | 5 #include "content/browser/indexed_db/indexed_db_backing_store.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 3223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3234 continue; | 3234 continue; |
| 3235 } | 3235 } |
| 3236 | 3236 |
| 3237 return false; | 3237 return false; |
| 3238 } | 3238 } |
| 3239 | 3239 |
| 3240 if (!HaveEnteredRange()) | 3240 if (!HaveEnteredRange()) |
| 3241 continue; | 3241 continue; |
| 3242 | 3242 |
| 3243 // The row may not load because there's a stale entry in the | 3243 // The row may not load because there's a stale entry in the |
| 3244 // index. This is not fatal. | 3244 // index. If no error then not fatal. |
| 3245 if (!LoadCurrentRow()) | 3245 if (!LoadCurrentRow(s)) { |
| 3246 if (!s->ok()) |
| 3247 return false; |
| 3246 continue; | 3248 continue; |
| 3249 } |
| 3247 | 3250 |
| 3248 if (key) { | 3251 if (key) { |
| 3249 if (forward) { | 3252 if (forward) { |
| 3250 if (primary_key && current_key_->Equals(*key) && | 3253 if (primary_key && current_key_->Equals(*key) && |
| 3251 this->primary_key().IsLessThan(*primary_key)) | 3254 this->primary_key().IsLessThan(*primary_key)) |
| 3252 continue; | 3255 continue; |
| 3253 if (!flipped && current_key_->IsLessThan(*key)) | 3256 if (!flipped && current_key_->IsLessThan(*key)) |
| 3254 continue; | 3257 continue; |
| 3255 } else { | 3258 } else { |
| 3256 if (primary_key && key->Equals(*current_key_) && | 3259 if (primary_key && key->Equals(*current_key_) && |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3345 database_id, | 3348 database_id, |
| 3346 cursor_options) {} | 3349 cursor_options) {} |
| 3347 | 3350 |
| 3348 Cursor* Clone() override { return new ObjectStoreKeyCursorImpl(this); } | 3351 Cursor* Clone() override { return new ObjectStoreKeyCursorImpl(this); } |
| 3349 | 3352 |
| 3350 // IndexedDBBackingStore::Cursor | 3353 // IndexedDBBackingStore::Cursor |
| 3351 IndexedDBValue* value() override { | 3354 IndexedDBValue* value() override { |
| 3352 NOTREACHED(); | 3355 NOTREACHED(); |
| 3353 return NULL; | 3356 return NULL; |
| 3354 } | 3357 } |
| 3355 bool LoadCurrentRow() override; | 3358 bool LoadCurrentRow(leveldb::Status* s) override; |
| 3356 | 3359 |
| 3357 protected: | 3360 protected: |
| 3358 std::string EncodeKey(const IndexedDBKey& key) override { | 3361 std::string EncodeKey(const IndexedDBKey& key) override { |
| 3359 return ObjectStoreDataKey::Encode( | 3362 return ObjectStoreDataKey::Encode( |
| 3360 cursor_options_.database_id, cursor_options_.object_store_id, key); | 3363 cursor_options_.database_id, cursor_options_.object_store_id, key); |
| 3361 } | 3364 } |
| 3362 std::string EncodeKey(const IndexedDBKey& key, | 3365 std::string EncodeKey(const IndexedDBKey& key, |
| 3363 const IndexedDBKey& primary_key) override { | 3366 const IndexedDBKey& primary_key) override { |
| 3364 NOTREACHED(); | 3367 NOTREACHED(); |
| 3365 return std::string(); | 3368 return std::string(); |
| 3366 } | 3369 } |
| 3367 | 3370 |
| 3368 private: | 3371 private: |
| 3369 explicit ObjectStoreKeyCursorImpl(const ObjectStoreKeyCursorImpl* other) | 3372 explicit ObjectStoreKeyCursorImpl(const ObjectStoreKeyCursorImpl* other) |
| 3370 : IndexedDBBackingStore::Cursor(other) {} | 3373 : IndexedDBBackingStore::Cursor(other) {} |
| 3371 | 3374 |
| 3372 DISALLOW_COPY_AND_ASSIGN(ObjectStoreKeyCursorImpl); | 3375 DISALLOW_COPY_AND_ASSIGN(ObjectStoreKeyCursorImpl); |
| 3373 }; | 3376 }; |
| 3374 | 3377 |
| 3375 bool ObjectStoreKeyCursorImpl::LoadCurrentRow() { | 3378 bool ObjectStoreKeyCursorImpl::LoadCurrentRow(leveldb::Status* s) { |
| 3376 StringPiece slice(iterator_->Key()); | 3379 StringPiece slice(iterator_->Key()); |
| 3377 ObjectStoreDataKey object_store_data_key; | 3380 ObjectStoreDataKey object_store_data_key; |
| 3378 if (!ObjectStoreDataKey::Decode(&slice, &object_store_data_key)) { | 3381 if (!ObjectStoreDataKey::Decode(&slice, &object_store_data_key)) { |
| 3379 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3382 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3383 *s = InvalidDBKeyStatus(); |
| 3380 return false; | 3384 return false; |
| 3381 } | 3385 } |
| 3382 | 3386 |
| 3383 current_key_ = object_store_data_key.user_key(); | 3387 current_key_ = object_store_data_key.user_key(); |
| 3384 | 3388 |
| 3385 int64 version; | 3389 int64 version; |
| 3386 slice = StringPiece(iterator_->Value()); | 3390 slice = StringPiece(iterator_->Value()); |
| 3387 if (!DecodeVarInt(&slice, &version)) { | 3391 if (!DecodeVarInt(&slice, &version)) { |
| 3388 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3392 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3393 *s = InternalInconsistencyStatus(); |
| 3389 return false; | 3394 return false; |
| 3390 } | 3395 } |
| 3391 | 3396 |
| 3392 // TODO(jsbell): This re-encodes what was just decoded; try and optimize. | 3397 // TODO(jsbell): This re-encodes what was just decoded; try and optimize. |
| 3393 std::string encoded_key; | 3398 std::string encoded_key; |
| 3394 EncodeIDBKey(*current_key_, &encoded_key); | 3399 EncodeIDBKey(*current_key_, &encoded_key); |
| 3395 record_identifier_.Reset(encoded_key, version); | 3400 record_identifier_.Reset(encoded_key, version); |
| 3396 | 3401 |
| 3397 return true; | 3402 return true; |
| 3398 } | 3403 } |
| 3399 | 3404 |
| 3400 class ObjectStoreCursorImpl : public IndexedDBBackingStore::Cursor { | 3405 class ObjectStoreCursorImpl : public IndexedDBBackingStore::Cursor { |
| 3401 public: | 3406 public: |
| 3402 ObjectStoreCursorImpl( | 3407 ObjectStoreCursorImpl( |
| 3403 scoped_refptr<IndexedDBBackingStore> backing_store, | 3408 scoped_refptr<IndexedDBBackingStore> backing_store, |
| 3404 IndexedDBBackingStore::Transaction* transaction, | 3409 IndexedDBBackingStore::Transaction* transaction, |
| 3405 int64 database_id, | 3410 int64 database_id, |
| 3406 const IndexedDBBackingStore::Cursor::CursorOptions& cursor_options) | 3411 const IndexedDBBackingStore::Cursor::CursorOptions& cursor_options) |
| 3407 : IndexedDBBackingStore::Cursor(backing_store, | 3412 : IndexedDBBackingStore::Cursor(backing_store, |
| 3408 transaction, | 3413 transaction, |
| 3409 database_id, | 3414 database_id, |
| 3410 cursor_options) {} | 3415 cursor_options) {} |
| 3411 | 3416 |
| 3412 Cursor* Clone() override { return new ObjectStoreCursorImpl(this); } | 3417 Cursor* Clone() override { return new ObjectStoreCursorImpl(this); } |
| 3413 | 3418 |
| 3414 // IndexedDBBackingStore::Cursor | 3419 // IndexedDBBackingStore::Cursor |
| 3415 IndexedDBValue* value() override { return ¤t_value_; } | 3420 IndexedDBValue* value() override { return ¤t_value_; } |
| 3416 bool LoadCurrentRow() override; | 3421 bool LoadCurrentRow(leveldb::Status* s) override; |
| 3417 | 3422 |
| 3418 protected: | 3423 protected: |
| 3419 std::string EncodeKey(const IndexedDBKey& key) override { | 3424 std::string EncodeKey(const IndexedDBKey& key) override { |
| 3420 return ObjectStoreDataKey::Encode( | 3425 return ObjectStoreDataKey::Encode( |
| 3421 cursor_options_.database_id, cursor_options_.object_store_id, key); | 3426 cursor_options_.database_id, cursor_options_.object_store_id, key); |
| 3422 } | 3427 } |
| 3423 std::string EncodeKey(const IndexedDBKey& key, | 3428 std::string EncodeKey(const IndexedDBKey& key, |
| 3424 const IndexedDBKey& primary_key) override { | 3429 const IndexedDBKey& primary_key) override { |
| 3425 NOTREACHED(); | 3430 NOTREACHED(); |
| 3426 return std::string(); | 3431 return std::string(); |
| 3427 } | 3432 } |
| 3428 | 3433 |
| 3429 private: | 3434 private: |
| 3430 explicit ObjectStoreCursorImpl(const ObjectStoreCursorImpl* other) | 3435 explicit ObjectStoreCursorImpl(const ObjectStoreCursorImpl* other) |
| 3431 : IndexedDBBackingStore::Cursor(other), | 3436 : IndexedDBBackingStore::Cursor(other), |
| 3432 current_value_(other->current_value_) {} | 3437 current_value_(other->current_value_) {} |
| 3433 | 3438 |
| 3434 IndexedDBValue current_value_; | 3439 IndexedDBValue current_value_; |
| 3435 | 3440 |
| 3436 DISALLOW_COPY_AND_ASSIGN(ObjectStoreCursorImpl); | 3441 DISALLOW_COPY_AND_ASSIGN(ObjectStoreCursorImpl); |
| 3437 }; | 3442 }; |
| 3438 | 3443 |
| 3439 bool ObjectStoreCursorImpl::LoadCurrentRow() { | 3444 bool ObjectStoreCursorImpl::LoadCurrentRow(leveldb::Status* s) { |
| 3440 StringPiece key_slice(iterator_->Key()); | 3445 StringPiece key_slice(iterator_->Key()); |
| 3441 ObjectStoreDataKey object_store_data_key; | 3446 ObjectStoreDataKey object_store_data_key; |
| 3442 if (!ObjectStoreDataKey::Decode(&key_slice, &object_store_data_key)) { | 3447 if (!ObjectStoreDataKey::Decode(&key_slice, &object_store_data_key)) { |
| 3443 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3448 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3449 *s = InvalidDBKeyStatus(); |
| 3444 return false; | 3450 return false; |
| 3445 } | 3451 } |
| 3446 | 3452 |
| 3447 current_key_ = object_store_data_key.user_key(); | 3453 current_key_ = object_store_data_key.user_key(); |
| 3448 | 3454 |
| 3449 int64 version; | 3455 int64 version; |
| 3450 StringPiece value_slice = StringPiece(iterator_->Value()); | 3456 StringPiece value_slice = StringPiece(iterator_->Value()); |
| 3451 if (!DecodeVarInt(&value_slice, &version)) { | 3457 if (!DecodeVarInt(&value_slice, &version)) { |
| 3452 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3458 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3459 *s = InternalInconsistencyStatus(); |
| 3453 return false; | 3460 return false; |
| 3454 } | 3461 } |
| 3455 | 3462 |
| 3456 // TODO(jsbell): This re-encodes what was just decoded; try and optimize. | 3463 // TODO(jsbell): This re-encodes what was just decoded; try and optimize. |
| 3457 std::string encoded_key; | 3464 std::string encoded_key; |
| 3458 EncodeIDBKey(*current_key_, &encoded_key); | 3465 EncodeIDBKey(*current_key_, &encoded_key); |
| 3459 record_identifier_.Reset(encoded_key, version); | 3466 record_identifier_.Reset(encoded_key, version); |
| 3460 | 3467 |
| 3461 if (!transaction_->GetBlobInfoForRecord(database_id_, | 3468 *s = transaction_->GetBlobInfoForRecord( |
| 3462 iterator_->Key().as_string(), | 3469 database_id_, iterator_->Key().as_string(), ¤t_value_); |
| 3463 ¤t_value_).ok()) { | 3470 if (!s->ok()) |
| 3464 return false; | 3471 return false; |
| 3465 } | 3472 |
| 3466 current_value_.bits = value_slice.as_string(); | 3473 current_value_.bits = value_slice.as_string(); |
| 3467 return true; | 3474 return true; |
| 3468 } | 3475 } |
| 3469 | 3476 |
| 3470 class IndexKeyCursorImpl : public IndexedDBBackingStore::Cursor { | 3477 class IndexKeyCursorImpl : public IndexedDBBackingStore::Cursor { |
| 3471 public: | 3478 public: |
| 3472 IndexKeyCursorImpl( | 3479 IndexKeyCursorImpl( |
| 3473 scoped_refptr<IndexedDBBackingStore> backing_store, | 3480 scoped_refptr<IndexedDBBackingStore> backing_store, |
| 3474 IndexedDBBackingStore::Transaction* transaction, | 3481 IndexedDBBackingStore::Transaction* transaction, |
| 3475 int64 database_id, | 3482 int64 database_id, |
| 3476 const IndexedDBBackingStore::Cursor::CursorOptions& cursor_options) | 3483 const IndexedDBBackingStore::Cursor::CursorOptions& cursor_options) |
| 3477 : IndexedDBBackingStore::Cursor(backing_store, | 3484 : IndexedDBBackingStore::Cursor(backing_store, |
| 3478 transaction, | 3485 transaction, |
| 3479 database_id, | 3486 database_id, |
| 3480 cursor_options) {} | 3487 cursor_options) {} |
| 3481 | 3488 |
| 3482 Cursor* Clone() override { return new IndexKeyCursorImpl(this); } | 3489 Cursor* Clone() override { return new IndexKeyCursorImpl(this); } |
| 3483 | 3490 |
| 3484 // IndexedDBBackingStore::Cursor | 3491 // IndexedDBBackingStore::Cursor |
| 3485 IndexedDBValue* value() override { | 3492 IndexedDBValue* value() override { |
| 3486 NOTREACHED(); | 3493 NOTREACHED(); |
| 3487 return NULL; | 3494 return NULL; |
| 3488 } | 3495 } |
| 3489 const IndexedDBKey& primary_key() const override { return *primary_key_; } | 3496 const IndexedDBKey& primary_key() const override { return *primary_key_; } |
| 3490 const IndexedDBBackingStore::RecordIdentifier& record_identifier() | 3497 const IndexedDBBackingStore::RecordIdentifier& record_identifier() |
| 3491 const override { | 3498 const override { |
| 3492 NOTREACHED(); | 3499 NOTREACHED(); |
| 3493 return record_identifier_; | 3500 return record_identifier_; |
| 3494 } | 3501 } |
| 3495 bool LoadCurrentRow() override; | 3502 bool LoadCurrentRow(leveldb::Status* s) override; |
| 3496 | 3503 |
| 3497 protected: | 3504 protected: |
| 3498 std::string EncodeKey(const IndexedDBKey& key) override { | 3505 std::string EncodeKey(const IndexedDBKey& key) override { |
| 3499 return IndexDataKey::Encode(cursor_options_.database_id, | 3506 return IndexDataKey::Encode(cursor_options_.database_id, |
| 3500 cursor_options_.object_store_id, | 3507 cursor_options_.object_store_id, |
| 3501 cursor_options_.index_id, | 3508 cursor_options_.index_id, |
| 3502 key); | 3509 key); |
| 3503 } | 3510 } |
| 3504 std::string EncodeKey(const IndexedDBKey& key, | 3511 std::string EncodeKey(const IndexedDBKey& key, |
| 3505 const IndexedDBKey& primary_key) override { | 3512 const IndexedDBKey& primary_key) override { |
| 3506 return IndexDataKey::Encode(cursor_options_.database_id, | 3513 return IndexDataKey::Encode(cursor_options_.database_id, |
| 3507 cursor_options_.object_store_id, | 3514 cursor_options_.object_store_id, |
| 3508 cursor_options_.index_id, | 3515 cursor_options_.index_id, |
| 3509 key, | 3516 key, |
| 3510 primary_key); | 3517 primary_key); |
| 3511 } | 3518 } |
| 3512 | 3519 |
| 3513 private: | 3520 private: |
| 3514 explicit IndexKeyCursorImpl(const IndexKeyCursorImpl* other) | 3521 explicit IndexKeyCursorImpl(const IndexKeyCursorImpl* other) |
| 3515 : IndexedDBBackingStore::Cursor(other), | 3522 : IndexedDBBackingStore::Cursor(other), |
| 3516 primary_key_(new IndexedDBKey(*other->primary_key_)) {} | 3523 primary_key_(new IndexedDBKey(*other->primary_key_)) {} |
| 3517 | 3524 |
| 3518 scoped_ptr<IndexedDBKey> primary_key_; | 3525 scoped_ptr<IndexedDBKey> primary_key_; |
| 3519 | 3526 |
| 3520 DISALLOW_COPY_AND_ASSIGN(IndexKeyCursorImpl); | 3527 DISALLOW_COPY_AND_ASSIGN(IndexKeyCursorImpl); |
| 3521 }; | 3528 }; |
| 3522 | 3529 |
| 3523 bool IndexKeyCursorImpl::LoadCurrentRow() { | 3530 bool IndexKeyCursorImpl::LoadCurrentRow(leveldb::Status* s) { |
| 3524 StringPiece slice(iterator_->Key()); | 3531 StringPiece slice(iterator_->Key()); |
| 3525 IndexDataKey index_data_key; | 3532 IndexDataKey index_data_key; |
| 3526 if (!IndexDataKey::Decode(&slice, &index_data_key)) { | 3533 if (!IndexDataKey::Decode(&slice, &index_data_key)) { |
| 3527 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3534 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3535 *s = InvalidDBKeyStatus(); |
| 3528 return false; | 3536 return false; |
| 3529 } | 3537 } |
| 3530 | 3538 |
| 3531 current_key_ = index_data_key.user_key(); | 3539 current_key_ = index_data_key.user_key(); |
| 3532 DCHECK(current_key_); | 3540 DCHECK(current_key_); |
| 3533 | 3541 |
| 3534 slice = StringPiece(iterator_->Value()); | 3542 slice = StringPiece(iterator_->Value()); |
| 3535 int64 index_data_version; | 3543 int64 index_data_version; |
| 3536 if (!DecodeVarInt(&slice, &index_data_version)) { | 3544 if (!DecodeVarInt(&slice, &index_data_version)) { |
| 3537 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3545 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3546 *s = InternalInconsistencyStatus(); |
| 3538 return false; | 3547 return false; |
| 3539 } | 3548 } |
| 3540 | 3549 |
| 3541 if (!DecodeIDBKey(&slice, &primary_key_) || !slice.empty()) { | 3550 if (!DecodeIDBKey(&slice, &primary_key_) || !slice.empty()) { |
| 3542 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3551 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3552 *s = InternalInconsistencyStatus(); |
| 3543 return false; | 3553 return false; |
| 3544 } | 3554 } |
| 3545 | 3555 |
| 3546 std::string primary_leveldb_key = | 3556 std::string primary_leveldb_key = |
| 3547 ObjectStoreDataKey::Encode(index_data_key.DatabaseId(), | 3557 ObjectStoreDataKey::Encode(index_data_key.DatabaseId(), |
| 3548 index_data_key.ObjectStoreId(), | 3558 index_data_key.ObjectStoreId(), |
| 3549 *primary_key_); | 3559 *primary_key_); |
| 3550 | 3560 |
| 3551 std::string result; | 3561 std::string result; |
| 3552 bool found = false; | 3562 bool found = false; |
| 3553 leveldb::Status s = | 3563 *s = transaction_->transaction()->Get(primary_leveldb_key, &result, &found); |
| 3554 transaction_->transaction()->Get(primary_leveldb_key, &result, &found); | 3564 if (!s->ok()) { |
| 3555 if (!s.ok()) { | |
| 3556 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3565 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3557 return false; | 3566 return false; |
| 3558 } | 3567 } |
| 3559 if (!found) { | 3568 if (!found) { |
| 3560 transaction_->transaction()->Remove(iterator_->Key()); | 3569 transaction_->transaction()->Remove(iterator_->Key()); |
| 3561 return false; | 3570 return false; |
| 3562 } | 3571 } |
| 3563 if (!result.size()) { | 3572 if (!result.size()) { |
| 3564 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3573 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3565 return false; | 3574 return false; |
| 3566 } | 3575 } |
| 3567 | 3576 |
| 3568 int64 object_store_data_version; | 3577 int64 object_store_data_version; |
| 3569 slice = StringPiece(result); | 3578 slice = StringPiece(result); |
| 3570 if (!DecodeVarInt(&slice, &object_store_data_version)) { | 3579 if (!DecodeVarInt(&slice, &object_store_data_version)) { |
| 3571 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3580 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3581 *s = InternalInconsistencyStatus(); |
| 3572 return false; | 3582 return false; |
| 3573 } | 3583 } |
| 3574 | 3584 |
| 3575 if (object_store_data_version != index_data_version) { | 3585 if (object_store_data_version != index_data_version) { |
| 3576 transaction_->transaction()->Remove(iterator_->Key()); | 3586 transaction_->transaction()->Remove(iterator_->Key()); |
| 3577 return false; | 3587 return false; |
| 3578 } | 3588 } |
| 3579 | 3589 |
| 3580 return true; | 3590 return true; |
| 3581 } | 3591 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3595 Cursor* Clone() override { return new IndexCursorImpl(this); } | 3605 Cursor* Clone() override { return new IndexCursorImpl(this); } |
| 3596 | 3606 |
| 3597 // IndexedDBBackingStore::Cursor | 3607 // IndexedDBBackingStore::Cursor |
| 3598 IndexedDBValue* value() override { return ¤t_value_; } | 3608 IndexedDBValue* value() override { return ¤t_value_; } |
| 3599 const IndexedDBKey& primary_key() const override { return *primary_key_; } | 3609 const IndexedDBKey& primary_key() const override { return *primary_key_; } |
| 3600 const IndexedDBBackingStore::RecordIdentifier& record_identifier() | 3610 const IndexedDBBackingStore::RecordIdentifier& record_identifier() |
| 3601 const override { | 3611 const override { |
| 3602 NOTREACHED(); | 3612 NOTREACHED(); |
| 3603 return record_identifier_; | 3613 return record_identifier_; |
| 3604 } | 3614 } |
| 3605 bool LoadCurrentRow() override; | 3615 bool LoadCurrentRow(leveldb::Status* s) override; |
| 3606 | 3616 |
| 3607 protected: | 3617 protected: |
| 3608 std::string EncodeKey(const IndexedDBKey& key) override { | 3618 std::string EncodeKey(const IndexedDBKey& key) override { |
| 3609 return IndexDataKey::Encode(cursor_options_.database_id, | 3619 return IndexDataKey::Encode(cursor_options_.database_id, |
| 3610 cursor_options_.object_store_id, | 3620 cursor_options_.object_store_id, |
| 3611 cursor_options_.index_id, | 3621 cursor_options_.index_id, |
| 3612 key); | 3622 key); |
| 3613 } | 3623 } |
| 3614 std::string EncodeKey(const IndexedDBKey& key, | 3624 std::string EncodeKey(const IndexedDBKey& key, |
| 3615 const IndexedDBKey& primary_key) override { | 3625 const IndexedDBKey& primary_key) override { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3627 current_value_(other->current_value_), | 3637 current_value_(other->current_value_), |
| 3628 primary_leveldb_key_(other->primary_leveldb_key_) {} | 3638 primary_leveldb_key_(other->primary_leveldb_key_) {} |
| 3629 | 3639 |
| 3630 scoped_ptr<IndexedDBKey> primary_key_; | 3640 scoped_ptr<IndexedDBKey> primary_key_; |
| 3631 IndexedDBValue current_value_; | 3641 IndexedDBValue current_value_; |
| 3632 std::string primary_leveldb_key_; | 3642 std::string primary_leveldb_key_; |
| 3633 | 3643 |
| 3634 DISALLOW_COPY_AND_ASSIGN(IndexCursorImpl); | 3644 DISALLOW_COPY_AND_ASSIGN(IndexCursorImpl); |
| 3635 }; | 3645 }; |
| 3636 | 3646 |
| 3637 bool IndexCursorImpl::LoadCurrentRow() { | 3647 bool IndexCursorImpl::LoadCurrentRow(leveldb::Status* s) { |
| 3638 StringPiece slice(iterator_->Key()); | 3648 StringPiece slice(iterator_->Key()); |
| 3639 IndexDataKey index_data_key; | 3649 IndexDataKey index_data_key; |
| 3640 if (!IndexDataKey::Decode(&slice, &index_data_key)) { | 3650 if (!IndexDataKey::Decode(&slice, &index_data_key)) { |
| 3641 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3651 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3652 *s = InvalidDBKeyStatus(); |
| 3642 return false; | 3653 return false; |
| 3643 } | 3654 } |
| 3644 | 3655 |
| 3645 current_key_ = index_data_key.user_key(); | 3656 current_key_ = index_data_key.user_key(); |
| 3646 DCHECK(current_key_); | 3657 DCHECK(current_key_); |
| 3647 | 3658 |
| 3648 slice = StringPiece(iterator_->Value()); | 3659 slice = StringPiece(iterator_->Value()); |
| 3649 int64 index_data_version; | 3660 int64 index_data_version; |
| 3650 if (!DecodeVarInt(&slice, &index_data_version)) { | 3661 if (!DecodeVarInt(&slice, &index_data_version)) { |
| 3651 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3662 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3663 *s = InternalInconsistencyStatus(); |
| 3652 return false; | 3664 return false; |
| 3653 } | 3665 } |
| 3654 if (!DecodeIDBKey(&slice, &primary_key_)) { | 3666 if (!DecodeIDBKey(&slice, &primary_key_)) { |
| 3655 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3667 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3668 *s = InvalidDBKeyStatus(); |
| 3656 return false; | 3669 return false; |
| 3657 } | 3670 } |
| 3658 | 3671 |
| 3659 DCHECK_EQ(index_data_key.DatabaseId(), database_id_); | 3672 DCHECK_EQ(index_data_key.DatabaseId(), database_id_); |
| 3660 primary_leveldb_key_ = | 3673 primary_leveldb_key_ = |
| 3661 ObjectStoreDataKey::Encode(index_data_key.DatabaseId(), | 3674 ObjectStoreDataKey::Encode(index_data_key.DatabaseId(), |
| 3662 index_data_key.ObjectStoreId(), | 3675 index_data_key.ObjectStoreId(), |
| 3663 *primary_key_); | 3676 *primary_key_); |
| 3664 | 3677 |
| 3665 std::string result; | 3678 std::string result; |
| 3666 bool found = false; | 3679 bool found = false; |
| 3667 leveldb::Status s = | 3680 *s = transaction_->transaction()->Get(primary_leveldb_key_, &result, &found); |
| 3668 transaction_->transaction()->Get(primary_leveldb_key_, &result, &found); | 3681 if (!s->ok()) { |
| 3669 if (!s.ok()) { | |
| 3670 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3682 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3671 return false; | 3683 return false; |
| 3672 } | 3684 } |
| 3673 if (!found) { | 3685 if (!found) { |
| 3674 transaction_->transaction()->Remove(iterator_->Key()); | 3686 transaction_->transaction()->Remove(iterator_->Key()); |
| 3675 return false; | 3687 return false; |
| 3676 } | 3688 } |
| 3677 if (!result.size()) { | 3689 if (!result.size()) { |
| 3678 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3690 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3679 return false; | 3691 return false; |
| 3680 } | 3692 } |
| 3681 | 3693 |
| 3682 int64 object_store_data_version; | 3694 int64 object_store_data_version; |
| 3683 slice = StringPiece(result); | 3695 slice = StringPiece(result); |
| 3684 if (!DecodeVarInt(&slice, &object_store_data_version)) { | 3696 if (!DecodeVarInt(&slice, &object_store_data_version)) { |
| 3685 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); | 3697 INTERNAL_READ_ERROR_UNTESTED(LOAD_CURRENT_ROW); |
| 3698 *s = InternalInconsistencyStatus(); |
| 3686 return false; | 3699 return false; |
| 3687 } | 3700 } |
| 3688 | 3701 |
| 3689 if (object_store_data_version != index_data_version) { | 3702 if (object_store_data_version != index_data_version) { |
| 3690 transaction_->transaction()->Remove(iterator_->Key()); | 3703 transaction_->transaction()->Remove(iterator_->Key()); |
| 3691 return false; | 3704 return false; |
| 3692 } | 3705 } |
| 3693 | 3706 |
| 3694 current_value_.bits = slice.as_string(); | 3707 current_value_.bits = slice.as_string(); |
| 3695 return transaction_->GetBlobInfoForRecord(database_id_, | 3708 *s = transaction_->GetBlobInfoForRecord(database_id_, primary_leveldb_key_, |
| 3696 primary_leveldb_key_, | 3709 ¤t_value_); |
| 3697 ¤t_value_).ok(); | 3710 return s->ok(); |
| 3698 } | 3711 } |
| 3699 | 3712 |
| 3700 bool ObjectStoreCursorOptions( | 3713 bool ObjectStoreCursorOptions( |
| 3701 LevelDBTransaction* transaction, | 3714 LevelDBTransaction* transaction, |
| 3702 int64 database_id, | 3715 int64 database_id, |
| 3703 int64 object_store_id, | 3716 int64 object_store_id, |
| 3704 const IndexedDBKeyRange& range, | 3717 const IndexedDBKeyRange& range, |
| 3705 blink::WebIDBCursorDirection direction, | 3718 blink::WebIDBCursorDirection direction, |
| 3706 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { | 3719 IndexedDBBackingStore::Cursor::CursorOptions* cursor_options) { |
| 3707 cursor_options->database_id = database_id; | 3720 cursor_options->database_id = database_id; |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4419 | 4432 |
| 4420 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( | 4433 IndexedDBBackingStore::Transaction::WriteDescriptor::WriteDescriptor( |
| 4421 const WriteDescriptor& other) = default; | 4434 const WriteDescriptor& other) = default; |
| 4422 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = | 4435 IndexedDBBackingStore::Transaction::WriteDescriptor::~WriteDescriptor() = |
| 4423 default; | 4436 default; |
| 4424 IndexedDBBackingStore::Transaction::WriteDescriptor& | 4437 IndexedDBBackingStore::Transaction::WriteDescriptor& |
| 4425 IndexedDBBackingStore::Transaction::WriteDescriptor:: | 4438 IndexedDBBackingStore::Transaction::WriteDescriptor:: |
| 4426 operator=(const WriteDescriptor& other) = default; | 4439 operator=(const WriteDescriptor& other) = default; |
| 4427 | 4440 |
| 4428 } // namespace content | 4441 } // namespace content |
| OLD | NEW |