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