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 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ | 5 #ifndef CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ |
6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ | 6 #define CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ |
7 | 7 |
| 8 #include <vector> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
10 #include "content/common/indexed_db/indexed_db_key.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" |
11 | 16 |
12 namespace content { | 17 namespace content { |
13 | 18 |
14 class IndexedDBCallbacksWrapper; | 19 class IndexedDBDatabase; |
| 20 class IndexedDBTransaction; |
15 | 21 |
16 class IndexedDBCursor : public base::RefCounted<IndexedDBCursor> { | 22 class CONTENT_EXPORT IndexedDBCursor |
| 23 : NON_EXPORTED_BASE(public base::RefCounted<IndexedDBCursor>) { |
17 public: | 24 public: |
18 virtual void Advance(uint32 count, | 25 static scoped_refptr<IndexedDBCursor> Create( |
19 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) = 0; | 26 scoped_ptr<IndexedDBBackingStore::Cursor> cursor, |
20 virtual void ContinueFunction( | 27 indexed_db::CursorType cursor_type, |
21 scoped_ptr<IndexedDBKey> key, | 28 IndexedDBTransaction* transaction) { |
22 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) = 0; | 29 return make_scoped_refptr( |
23 virtual void PrefetchContinue( | 30 new IndexedDBCursor(cursor.Pass(), |
24 int number_to_fetch, | 31 cursor_type, |
25 scoped_refptr<IndexedDBCallbacksWrapper> callbacks) = 0; | 32 IndexedDBDatabase::NORMAL_TASK, |
26 virtual void PrefetchReset(int used_prefetches, int unused_prefetches) = 0; | 33 transaction)); |
27 virtual void PostSuccessHandlerCallback() = 0; | 34 } |
| 35 static scoped_refptr<IndexedDBCursor> Create( |
| 36 scoped_ptr<IndexedDBBackingStore::Cursor> cursor, |
| 37 indexed_db::CursorType cursor_type, |
| 38 IndexedDBDatabase::TaskType task_type, |
| 39 IndexedDBTransaction* transaction) { |
| 40 return make_scoped_refptr(new IndexedDBCursor( |
| 41 cursor.Pass(), cursor_type, task_type, transaction)); |
| 42 } |
28 | 43 |
29 protected: | 44 // IndexedDBCursor |
30 virtual ~IndexedDBCursor() {} | 45 void Advance(uint32 count, |
| 46 scoped_refptr<IndexedDBCallbacksWrapper> callbacks); |
| 47 void ContinueFunction(scoped_ptr<IndexedDBKey> key, |
| 48 scoped_refptr<IndexedDBCallbacksWrapper> callbacks); |
| 49 void PrefetchContinue(int number_to_fetch, |
| 50 scoped_refptr<IndexedDBCallbacksWrapper> callbacks); |
| 51 void PrefetchReset(int used_prefetches, int unused_prefetches); |
| 52 |
| 53 const IndexedDBKey& key() const { return cursor_->key(); } |
| 54 const IndexedDBKey& primary_key() const { return cursor_->primary_key(); } |
| 55 std::vector<char>* Value() const { |
| 56 return (cursor_type_ == indexed_db::CURSOR_KEY_ONLY) ? NULL |
| 57 : cursor_->Value(); |
| 58 } |
| 59 void Close(); |
| 60 |
| 61 private: |
31 friend class base::RefCounted<IndexedDBCursor>; | 62 friend class base::RefCounted<IndexedDBCursor>; |
| 63 |
| 64 IndexedDBCursor(scoped_ptr<IndexedDBBackingStore::Cursor> cursor, |
| 65 indexed_db::CursorType cursor_type, |
| 66 IndexedDBDatabase::TaskType task_type, |
| 67 IndexedDBTransaction* transaction); |
| 68 ~IndexedDBCursor(); |
| 69 |
| 70 class CursorIterationOperation; |
| 71 class CursorAdvanceOperation; |
| 72 class CursorPrefetchIterationOperation; |
| 73 |
| 74 IndexedDBDatabase::TaskType task_type_; |
| 75 indexed_db::CursorType cursor_type_; |
| 76 const scoped_refptr<IndexedDBTransaction> transaction_; |
| 77 |
| 78 // Must be destroyed before transaction_. |
| 79 scoped_ptr<IndexedDBBackingStore::Cursor> cursor_; |
| 80 // Must be destroyed before transaction_. |
| 81 scoped_ptr<IndexedDBBackingStore::Cursor> saved_cursor_; |
| 82 |
| 83 bool closed_; |
32 }; | 84 }; |
33 | 85 |
34 } // namespace content | 86 } // namespace content |
35 | 87 |
36 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ | 88 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ |
OLD | NEW |