IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / child / indexed_db / webidbcursor_impl.h
blob55520225603737b6dbd8728b71e15fbb611e97e6
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.
5 #ifndef CONTENT_CHILD_INDEXED_DB_PROXY_WEBIDBCURSOR_IMPL_H_
6 #define CONTENT_CHILD_INDEXED_DB_PROXY_WEBIDBCURSOR_IMPL_H_
8 #include <deque>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/memory/ref_counted.h"
15 #include "content/common/content_export.h"
16 #include "content/common/indexed_db/indexed_db_key.h"
17 #include "third_party/WebKit/public/platform/WebData.h"
18 #include "third_party/WebKit/public/platform/WebIDBCallbacks.h"
19 #include "third_party/WebKit/public/platform/WebIDBCursor.h"
20 #include "third_party/WebKit/public/platform/WebIDBKey.h"
22 namespace content {
23 class ThreadSafeSender;
25 class CONTENT_EXPORT WebIDBCursorImpl
26 : NON_EXPORTED_BASE(public blink::WebIDBCursor) {
27 public:
28 WebIDBCursorImpl(int32 ipc_cursor_id, ThreadSafeSender* thread_safe_sender);
29 virtual ~WebIDBCursorImpl();
31 virtual void advance(unsigned long count, blink::WebIDBCallbacks* callback);
32 virtual void continueFunction(const blink::WebIDBKey& key,
33 blink::WebIDBCallbacks* callback);
34 virtual void continueFunction(const blink::WebIDBKey& key,
35 const blink::WebIDBKey& primary_key,
36 blink::WebIDBCallbacks* callback);
37 virtual void postSuccessHandlerCallback();
39 void SetPrefetchData(const std::vector<IndexedDBKey>& keys,
40 const std::vector<IndexedDBKey>& primary_keys,
41 const std::vector<blink::WebData>& values);
43 void CachedAdvance(unsigned long count, blink::WebIDBCallbacks* callbacks);
44 void CachedContinue(blink::WebIDBCallbacks* callbacks);
45 void ResetPrefetchCache();
47 private:
48 FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchTest);
49 FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, AdvancePrefetchTest);
50 FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchReset);
52 int32 ipc_cursor_id_;
54 // Prefetch cache.
55 std::deque<IndexedDBKey> prefetch_keys_;
56 std::deque<IndexedDBKey> prefetch_primary_keys_;
57 std::deque<blink::WebData> prefetch_values_;
59 // Number of continue calls that would qualify for a pre-fetch.
60 int continue_count_;
62 // Number of items used from the last prefetch.
63 int used_prefetches_;
65 // Number of onsuccess handlers we are waiting for.
66 int pending_onsuccess_callbacks_;
68 // Number of items to request in next prefetch.
69 int prefetch_amount_;
71 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
73 enum { kInvalidCursorId = -1 };
74 enum { kPrefetchContinueThreshold = 2 };
75 enum { kMinPrefetchAmount = 5 };
76 enum { kMaxPrefetchAmount = 100 };
79 } // namespace content
81 #endif // CONTENT_CHILD_INDEXED_DB_PROXY_WEBIDBCURSOR_IMPL_H_