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