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