Chromium Code Reviews| Index: content/browser/indexed_db/indexed_db_database.cc |
| diff --git a/content/browser/indexed_db/indexed_db_database.cc b/content/browser/indexed_db/indexed_db_database.cc |
| index 97dc1d7ca07dd0610606f0c05d1923344d154c9e..a93273acdc3429d3c4a9fb31afd003671d9521c2 100644 |
| --- a/content/browser/indexed_db/indexed_db_database.cc |
| +++ b/content/browser/indexed_db/indexed_db_database.cc |
| @@ -5,6 +5,7 @@ |
| #include "content/browser/indexed_db/indexed_db_database.h" |
| #include <math.h> |
| +#include <limits> |
| #include <set> |
| #include "base/auto_reset.h" |
| @@ -490,6 +491,24 @@ void IndexedDBDatabase::Abort(int64 transaction_id, |
| transaction->Abort(error); |
| } |
| +void IndexedDBDatabase::GetAll(int64 transaction_id, |
| + int64 object_store_id, |
| + scoped_ptr<IndexedDBKeyRange> key_range, |
| + int64 max_count, |
| + scoped_refptr<IndexedDBCallbacks> callbacks) { |
| + IDB_TRACE1("IndexedDBDatabase::GetAll", "txn.id", transaction_id); |
| + IndexedDBTransaction* transaction = GetTransaction(transaction_id); |
| + if (!transaction) |
| + return; |
| + |
| + if (!ValidateObjectStoreId(object_store_id)) |
| + return; |
| + |
| + transaction->ScheduleTask( |
| + base::Bind(&IndexedDBDatabase::GetAllOperation, this, object_store_id, |
| + Passed(&key_range), max_count, callbacks)); |
| +} |
| + |
| void IndexedDBDatabase::Get(int64 transaction_id, |
| int64 object_store_id, |
| int64 index_id, |
| @@ -676,6 +695,81 @@ void IndexedDBDatabase::GetOperation( |
| callbacks->OnSuccess(&value); |
| } |
| +void IndexedDBDatabase::GetAllOperation( |
| + int64 object_store_id, |
| + scoped_ptr<IndexedDBKeyRange> key_range, |
| + int64 max_count, |
| + scoped_refptr<IndexedDBCallbacks> callbacks, |
| + IndexedDBTransaction* transaction) { |
| + IDB_TRACE1("IndexedDBDatabase::GetAllOperation", "txn.id", transaction->id()); |
| + |
| + DCHECK_GE(max_count, 0); |
| + if (!max_count) |
| + max_count = std::numeric_limits<decltype(max_count)>::max(); |
| + |
| + DCHECK(metadata_.object_stores.find(object_store_id) != |
| + metadata_.object_stores.end()); |
| + |
| + leveldb::Status s; |
| + |
| + scoped_ptr<IndexedDBBackingStore::Cursor> backing_store_cursor; |
| + if (key_range->IsEmpty()) { |
| + backing_store_cursor = backing_store_->OpenObjectStoreCursor( |
| + transaction->BackingStoreTransaction(), id(), object_store_id, |
| + *key_range, blink::WebIDBCursorDirectionNext, &s); |
| + } else { |
| + backing_store_cursor = backing_store_->OpenObjectStoreCursor( |
| + transaction->BackingStoreTransaction(), id(), object_store_id, |
| + *key_range, blink::WebIDBCursorDirectionNext, &s); |
| + } |
| + |
| + if (!s.ok()) { |
| + DLOG(ERROR) << "Unable to open cursor operation: " << s.ToString(); |
| + IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| + "Internal error deleting data in range"); |
| + if (s.IsCorruption()) { |
| + factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), |
| + error); |
| + } |
| + } |
| + |
| + std::vector<IndexedDBValue> found_values; |
| + if (!backing_store_cursor) { |
| + callbacks->OnSuccessArray(&found_values); |
| + return; |
| + } |
| + |
| + bool did_first_seek = false; |
| + do { |
| + bool cursor_valid; |
| + if (did_first_seek) { |
| + cursor_valid = backing_store_cursor->Continue(&s); |
| + } else { |
| + cursor_valid = backing_store_cursor->FirstSeek(&s); |
| + did_first_seek = true; |
| + } |
| + if (!s.ok()) { |
| + IndexedDBDatabaseError error(blink::WebIDBDatabaseExceptionUnknownError, |
| + "Internal error in GetRecord."); |
| + callbacks->OnError(error); |
| + |
| + if (s.IsCorruption()) |
| + factory_->HandleBackingStoreCorruption(backing_store_->origin_url(), |
| + error); |
| + return; |
| + } |
| + |
| + if (!cursor_valid) |
| + break; |
| + |
| + IndexedDBValue value; |
| + value.swap(*backing_store_cursor->value()); |
| + found_values.push_back(value); |
| + } while (found_values.size() < static_cast<size_t>(max_count)); |
|
jsbell
2015/04/08 18:23:52
What's our behavior if the result size is > max IP
cmumford
2015/04/17 23:01:14
I added the size check & TODO for the next patch,
|
| + |
| + callbacks->OnSuccessArray(&found_values); |
| +} |
| + |
| static scoped_ptr<IndexedDBKey> GenerateKey( |
| IndexedDBBackingStore* backing_store, |
| IndexedDBTransaction* transaction, |