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