OLD | NEW |
| (Empty) |
1 // Copyright 2013 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_CHILD_INDEXED_DB_WEBIDBCURSOR_IMPL_H_ | |
6 #define CONTENT_CHILD_INDEXED_DB_WEBIDBCURSOR_IMPL_H_ | |
7 | |
8 #include <stdint.h> | |
9 | |
10 #include <deque> | |
11 #include <vector> | |
12 | |
13 #include "base/compiler_specific.h" | |
14 #include "base/gtest_prod_util.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "content/common/content_export.h" | |
17 #include "content/common/indexed_db/indexed_db_key.h" | |
18 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCallbacks.h
" | |
19 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBCursor.h" | |
20 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBKey.h" | |
21 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBValue.h" | |
22 | |
23 namespace content { | |
24 class ThreadSafeSender; | |
25 | |
26 class CONTENT_EXPORT WebIDBCursorImpl | |
27 : NON_EXPORTED_BASE(public blink::WebIDBCursor) { | |
28 public: | |
29 WebIDBCursorImpl(int32_t ipc_cursor_id, | |
30 int64_t transaction_id, | |
31 ThreadSafeSender* thread_safe_sender); | |
32 ~WebIDBCursorImpl() override; | |
33 | |
34 void advance(unsigned long count, blink::WebIDBCallbacks* callback) override; | |
35 virtual void continueFunction(const blink::WebIDBKey& key, | |
36 blink::WebIDBCallbacks* callback); | |
37 void continueFunction(const blink::WebIDBKey& key, | |
38 const blink::WebIDBKey& primary_key, | |
39 blink::WebIDBCallbacks* callback) override; | |
40 void postSuccessHandlerCallback() override; | |
41 | |
42 void SetPrefetchData(const std::vector<IndexedDBKey>& keys, | |
43 const std::vector<IndexedDBKey>& primary_keys, | |
44 const std::vector<blink::WebIDBValue>& values); | |
45 | |
46 void CachedAdvance(unsigned long count, blink::WebIDBCallbacks* callbacks); | |
47 void CachedContinue(blink::WebIDBCallbacks* callbacks); | |
48 | |
49 // This method is virtual so it can be overridden in unit tests. | |
50 virtual void ResetPrefetchCache(); | |
51 | |
52 int64_t transaction_id() const { return transaction_id_; } | |
53 | |
54 private: | |
55 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset); | |
56 FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId); | |
57 FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, AdvancePrefetchTest); | |
58 FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchReset); | |
59 FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchTest); | |
60 | |
61 enum { kInvalidCursorId = -1 }; | |
62 enum { kPrefetchContinueThreshold = 2 }; | |
63 enum { kMinPrefetchAmount = 5 }; | |
64 enum { kMaxPrefetchAmount = 100 }; | |
65 | |
66 int32_t ipc_cursor_id_; | |
67 int64_t transaction_id_; | |
68 | |
69 // Prefetch cache. | |
70 std::deque<IndexedDBKey> prefetch_keys_; | |
71 std::deque<IndexedDBKey> prefetch_primary_keys_; | |
72 std::deque<blink::WebIDBValue> prefetch_values_; | |
73 | |
74 // Number of continue calls that would qualify for a pre-fetch. | |
75 int continue_count_; | |
76 | |
77 // Number of items used from the last prefetch. | |
78 int used_prefetches_; | |
79 | |
80 // Number of onsuccess handlers we are waiting for. | |
81 int pending_onsuccess_callbacks_; | |
82 | |
83 // Number of items to request in next prefetch. | |
84 int prefetch_amount_; | |
85 | |
86 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | |
87 }; | |
88 | |
89 } // namespace content | |
90 | |
91 #endif // CONTENT_CHILD_INDEXED_DB_WEBIDBCURSOR_IMPL_H_ | |
OLD | NEW |