• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <deque>
9 #include <vector>
10 
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"
21 
22 namespace content {
23 class ThreadSafeSender;
24 
25 class CONTENT_EXPORT WebIDBCursorImpl
NON_EXPORTED_BASE(public blink::WebIDBCursor)26     : NON_EXPORTED_BASE(public blink::WebIDBCursor) {
27  public:
28   WebIDBCursorImpl(int32 ipc_cursor_id,
29                    int64 transaction_id,
30                    ThreadSafeSender* thread_safe_sender);
31   virtual ~WebIDBCursorImpl();
32 
33   virtual void advance(unsigned long count, blink::WebIDBCallbacks* callback);
34   virtual void continueFunction(const blink::WebIDBKey& key,
35                                 blink::WebIDBCallbacks* callback);
36   virtual void continueFunction(const blink::WebIDBKey& key,
37                                 const blink::WebIDBKey& primary_key,
38                                 blink::WebIDBCallbacks* callback);
39   virtual void postSuccessHandlerCallback();
40 
41   void SetPrefetchData(
42       const std::vector<IndexedDBKey>& keys,
43       const std::vector<IndexedDBKey>& primary_keys,
44       const std::vector<blink::WebData>& values,
45       const std::vector<blink::WebVector<blink::WebBlobInfo> >& blob_info);
46 
47   void CachedAdvance(unsigned long count, blink::WebIDBCallbacks* callbacks);
48   void CachedContinue(blink::WebIDBCallbacks* callbacks);
49 
50   // This method is virtual so it can be overridden in unit tests.
51   virtual void ResetPrefetchCache();
52 
53   int64 transaction_id() const { return transaction_id_; }
54 
55  private:
56   FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorReset);
57   FRIEND_TEST_ALL_PREFIXES(IndexedDBDispatcherTest, CursorTransactionId);
58   FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, AdvancePrefetchTest);
59   FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchReset);
60   FRIEND_TEST_ALL_PREFIXES(WebIDBCursorImplTest, PrefetchTest);
61 
62   int32 ipc_cursor_id_;
63   int64 transaction_id_;
64 
65   // Prefetch cache.
66   std::deque<IndexedDBKey> prefetch_keys_;
67   std::deque<IndexedDBKey> prefetch_primary_keys_;
68   std::deque<blink::WebData> prefetch_values_;
69   std::deque<blink::WebVector<blink::WebBlobInfo> > prefetch_blob_info_;
70 
71   // Number of continue calls that would qualify for a pre-fetch.
72   int continue_count_;
73 
74   // Number of items used from the last prefetch.
75   int used_prefetches_;
76 
77   // Number of onsuccess handlers we are waiting for.
78   int pending_onsuccess_callbacks_;
79 
80   // Number of items to request in next prefetch.
81   int prefetch_amount_;
82 
83   scoped_refptr<ThreadSafeSender> thread_safe_sender_;
84 
85   enum { kInvalidCursorId = -1 };
86   enum { kPrefetchContinueThreshold = 2 };
87   enum { kMinPrefetchAmount = 5 };
88   enum { kMaxPrefetchAmount = 100 };
89 };
90 
91 }  // namespace content
92 
93 #endif  // CONTENT_CHILD_INDEXED_DB_WEBIDBCURSOR_IMPL_H_
94