Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: content/browser/indexed_db/indexed_db_cursor.h

Issue 2472213003: [IndexedDB] Refactoring to remove ref ptrs and host transaction ids. (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/browser/indexed_db/indexed_db_transaction.h" 18 #include "content/browser/indexed_db/indexed_db_transaction.h"
18 #include "content/common/indexed_db/indexed_db_key_range.h" 19 #include "content/common/indexed_db/indexed_db_key_range.h"
19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h" 20 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
20 21
21 namespace content { 22 namespace content {
22 23
23 class CONTENT_EXPORT IndexedDBCursor 24 class CONTENT_EXPORT IndexedDBCursor {
24 : NON_EXPORTED_BASE(public base::RefCounted<IndexedDBCursor>) {
25 public: 25 public:
26 IndexedDBCursor(std::unique_ptr<IndexedDBBackingStore::Cursor> cursor, 26 IndexedDBCursor(std::unique_ptr<IndexedDBBackingStore::Cursor> cursor,
27 indexed_db::CursorType cursor_type, 27 indexed_db::CursorType cursor_type,
28 blink::WebIDBTaskType task_type, 28 blink::WebIDBTaskType task_type,
29 IndexedDBTransaction* transaction); 29 IndexedDBTransaction* transaction);
30 ~IndexedDBCursor();
30 31
31 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); 32 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks);
32 void Continue(std::unique_ptr<IndexedDBKey> key, 33 void Continue(std::unique_ptr<IndexedDBKey> key,
33 std::unique_ptr<IndexedDBKey> primary_key, 34 std::unique_ptr<IndexedDBKey> primary_key,
34 scoped_refptr<IndexedDBCallbacks> callbacks); 35 scoped_refptr<IndexedDBCallbacks> callbacks);
35 void PrefetchContinue(int number_to_fetch, 36 void PrefetchContinue(int number_to_fetch,
36 scoped_refptr<IndexedDBCallbacks> callbacks); 37 scoped_refptr<IndexedDBCallbacks> callbacks);
37 leveldb::Status PrefetchReset(int used_prefetches, int unused_prefetches); 38 leveldb::Status PrefetchReset(int used_prefetches, int unused_prefetches);
38 39
39 const IndexedDBKey& key() const { return cursor_->key(); } 40 const IndexedDBKey& key() const { return cursor_->key(); }
40 const IndexedDBKey& primary_key() const { return cursor_->primary_key(); } 41 const IndexedDBKey& primary_key() const { return cursor_->primary_key(); }
41 IndexedDBValue* Value() const { 42 IndexedDBValue* Value() const {
42 return (cursor_type_ == indexed_db::CURSOR_KEY_ONLY) ? NULL 43 return (cursor_type_ == indexed_db::CURSOR_KEY_ONLY) ? NULL
43 : cursor_->value(); 44 : cursor_->value();
44 } 45 }
46
47 void RemoveCursorFromTransaction();
45 void Close(); 48 void Close();
46 49
47 leveldb::Status CursorIterationOperation( 50 leveldb::Status CursorIterationOperation(
48 std::unique_ptr<IndexedDBKey> key, 51 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 leveldb::Status CursorAdvanceOperation( 55 leveldb::Status CursorAdvanceOperation(
53 uint32_t count, 56 uint32_t count,
54 scoped_refptr<IndexedDBCallbacks> callbacks, 57 scoped_refptr<IndexedDBCallbacks> callbacks,
55 IndexedDBTransaction* transaction); 58 IndexedDBTransaction* transaction);
56 leveldb::Status CursorPrefetchIterationOperation( 59 leveldb::Status CursorPrefetchIterationOperation(
57 int number_to_fetch, 60 int number_to_fetch,
58 scoped_refptr<IndexedDBCallbacks> callbacks, 61 scoped_refptr<IndexedDBCallbacks> callbacks,
59 IndexedDBTransaction* transaction); 62 IndexedDBTransaction* transaction);
60 63
61 private: 64 private:
62 friend class base::RefCounted<IndexedDBCursor>;
63
64 ~IndexedDBCursor();
65
66 blink::WebIDBTaskType task_type_; 65 blink::WebIDBTaskType task_type_;
67 indexed_db::CursorType cursor_type_; 66 indexed_db::CursorType cursor_type_;
68 const scoped_refptr<IndexedDBTransaction> transaction_; 67
68 // We rely on the transaction calling Close() to clear this.
69 IndexedDBTransaction* transaction_;
69 70
70 // Must be destroyed before transaction_. 71 // Must be destroyed before transaction_.
cmumford 2016/12/01 19:14:51 Should Close() assert that cursor_ is null?
dmurph 2016/12/01 21:12:23 No, as the IndexedDBTransaction calls it in CloseA
71 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor_; 72 std::unique_ptr<IndexedDBBackingStore::Cursor> cursor_;
72 // Must be destroyed before transaction_. 73 // Must be destroyed before transaction_.
73 std::unique_ptr<IndexedDBBackingStore::Cursor> saved_cursor_; 74 std::unique_ptr<IndexedDBBackingStore::Cursor> saved_cursor_;
74 75
75 bool closed_; 76 bool closed_;
76 77
78 base::WeakPtrFactory<IndexedDBCursor> ptr_factory_;
79
77 DISALLOW_COPY_AND_ASSIGN(IndexedDBCursor); 80 DISALLOW_COPY_AND_ASSIGN(IndexedDBCursor);
78 }; 81 };
79 82
80 } // namespace content 83 } // namespace content
81 84
82 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_ 85 #endif // CONTENT_BROWSER_INDEXED_DB_INDEXED_DB_CURSOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698