1 // Copyright 2016 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_CURSOR_IMPL_H_
6 #define CONTENT_BROWSER_INDEXED_DB_CURSOR_IMPL_H_
7 
8 #include <memory>
9 
10 #include "base/memory/ref_counted.h"
11 #include "base/sequence_checker.h"
12 #include "third_party/blink/public/common/indexeddb/indexeddb_key.h"
13 #include "third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h"
14 #include "url/origin.h"
15 
16 namespace base {
17 class SequencedTaskRunner;
18 }
19 
20 namespace content {
21 
22 class IndexedDBCursor;
23 class IndexedDBDispatcherHost;
24 
25 class CursorImpl : public blink::mojom::IDBCursor {
26  public:
27   CursorImpl(std::unique_ptr<IndexedDBCursor> cursor,
28              const url::Origin& origin,
29              IndexedDBDispatcherHost* dispatcher_host,
30              scoped_refptr<base::SequencedTaskRunner> idb_runner);
31   ~CursorImpl() override;
32 
33   // blink::mojom::IDBCursor implementation
34   void Advance(uint32_t count,
35                blink::mojom::IDBCursor::AdvanceCallback callback) override;
36   void CursorContinue(
37       const blink::IndexedDBKey& key,
38       const blink::IndexedDBKey& primary_key,
39       blink::mojom::IDBCursor::CursorContinueCallback callback) override;
40   void Prefetch(int32_t count,
41                 blink::mojom::IDBCursor::PrefetchCallback callback) override;
42   void PrefetchReset(int32_t used_prefetches,
43                      int32_t unused_prefetches) override;
44 
45   void OnRemoveBinding(base::OnceClosure remove_binding_cb);
46 
47  private:
48   // This raw pointer is safe because all CursorImpl instances are owned by an
49   // IndexedDBDispatcherHost.
50   IndexedDBDispatcherHost* dispatcher_host_;
51   const url::Origin origin_;
52   scoped_refptr<base::SequencedTaskRunner> idb_runner_;
53   std::unique_ptr<IndexedDBCursor> cursor_;
54 
55   SEQUENCE_CHECKER(sequence_checker_);
56 
57   DISALLOW_COPY_AND_ASSIGN(CursorImpl);
58 };
59 
60 }  // namespace content
61 
62 #endif  // CONTENT_BROWSER_INDEXED_DB_CURSOR_IMPL_H_
63