indexed_db_cursor.h revision 0529e5d033099cbfc42635f6f6183833b09dff6e
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 3// found in the LICENSE file. 4 5#ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ 6#define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ 7 8#include <string> 9 10#include "base/basictypes.h" 11#include "base/memory/ref_counted.h" 12#include "base/memory/scoped_ptr.h" 13#include "content/browser/indexed_db/indexed_db_backing_store.h" 14#include "content/browser/indexed_db/indexed_db_database.h" 15#include "content/common/indexed_db/indexed_db_key_range.h" 16 17namespace content { 18 19class IndexedDBTransaction; 20 21class CONTENT_EXPORT IndexedDBCursor 22 : NON_EXPORTED_BASE(public base::RefCounted<IndexedDBCursor>) { 23 public: 24 IndexedDBCursor(scoped_ptr<IndexedDBBackingStore::Cursor> cursor, 25 indexed_db::CursorType cursor_type, 26 IndexedDBDatabase::TaskType task_type, 27 IndexedDBTransaction* transaction); 28 29 void Advance(uint32 count, scoped_refptr<IndexedDBCallbacks> callbacks); 30 void Continue(scoped_ptr<IndexedDBKey> key, 31 scoped_ptr<IndexedDBKey> primary_key, 32 scoped_refptr<IndexedDBCallbacks> callbacks); 33 void PrefetchContinue(int number_to_fetch, 34 scoped_refptr<IndexedDBCallbacks> callbacks); 35 leveldb::Status PrefetchReset(int used_prefetches, int unused_prefetches); 36 37 const IndexedDBKey& key() const { return cursor_->key(); } 38 const IndexedDBKey& primary_key() const { return cursor_->primary_key(); } 39 IndexedDBValue* Value() const { 40 return (cursor_type_ == indexed_db::CURSOR_KEY_ONLY) ? NULL 41 : cursor_->value(); 42 } 43 void Close(); 44 45 void CursorIterationOperation(scoped_ptr<IndexedDBKey> key, 46 scoped_ptr<IndexedDBKey> primary_key, 47 scoped_refptr<IndexedDBCallbacks> callbacks, 48 IndexedDBTransaction* transaction); 49 void CursorAdvanceOperation(uint32 count, 50 scoped_refptr<IndexedDBCallbacks> callbacks, 51 IndexedDBTransaction* transaction); 52 void CursorPrefetchIterationOperation( 53 int number_to_fetch, 54 scoped_refptr<IndexedDBCallbacks> callbacks, 55 IndexedDBTransaction* transaction); 56 57 private: 58 friend class base::RefCounted<IndexedDBCursor>; 59 60 ~IndexedDBCursor(); 61 62 IndexedDBDatabase::TaskType task_type_; 63 indexed_db::CursorType cursor_type_; 64 const scoped_refptr<IndexedDBTransaction> transaction_; 65 66 // Must be destroyed before transaction_. 67 scoped_ptr<IndexedDBBackingStore::Cursor> cursor_; 68 // Must be destroyed before transaction_. 69 scoped_ptr<IndexedDBBackingStore::Cursor> saved_cursor_; 70 71 bool closed_; 72}; 73 74} // namespace content 75 76#endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ 77