Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1741)

Side by Side Diff: content/browser/indexed_db/cursor_impl.cc

Issue 1504033007: Move Indexed DB from dedicated thread to task scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@timer
Patch Set: Tweak traits Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/indexed_db/cursor_impl.h ('k') | content/browser/indexed_db/database_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "content/browser/indexed_db/cursor_impl.h" 5 #include "content/browser/indexed_db/cursor_impl.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/sequenced_task_runner.h" 8 #include "base/sequenced_task_runner.h"
9 #include "content/browser/indexed_db/indexed_db_callbacks.h" 9 #include "content/browser/indexed_db/indexed_db_callbacks.h"
10 #include "content/browser/indexed_db/indexed_db_cursor.h" 10 #include "content/browser/indexed_db/indexed_db_cursor.h"
11 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 11 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
12 12
13 namespace content { 13 namespace content {
14 14
15 // Expected to be constructed on IO thread, and used/destroyed on IDB thread. 15 // Expected to be constructed on IO thread, and used/destroyed on IDB sequence.
16 class CursorImpl::IDBThreadHelper { 16 class CursorImpl::IDBSequenceHelper {
17 public: 17 public:
18 explicit IDBThreadHelper(std::unique_ptr<IndexedDBCursor> cursor); 18 explicit IDBSequenceHelper(std::unique_ptr<IndexedDBCursor> cursor);
19 ~IDBThreadHelper(); 19 ~IDBSequenceHelper();
20 20
21 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); 21 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks);
22 void Continue(const IndexedDBKey& key, 22 void Continue(const IndexedDBKey& key,
23 const IndexedDBKey& primary_key, 23 const IndexedDBKey& primary_key,
24 scoped_refptr<IndexedDBCallbacks> callbacks); 24 scoped_refptr<IndexedDBCallbacks> callbacks);
25 void Prefetch(int32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); 25 void Prefetch(int32_t count, scoped_refptr<IndexedDBCallbacks> callbacks);
26 void PrefetchReset(int32_t used_prefetches, int32_t unused_prefetches); 26 void PrefetchReset(int32_t used_prefetches, int32_t unused_prefetches);
27 27
28 private: 28 private:
29 std::unique_ptr<IndexedDBCursor> cursor_; 29 std::unique_ptr<IndexedDBCursor> cursor_;
30 30
31 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); 31 DISALLOW_COPY_AND_ASSIGN(IDBSequenceHelper);
32 }; 32 };
33 33
34 CursorImpl::CursorImpl(std::unique_ptr<IndexedDBCursor> cursor, 34 CursorImpl::CursorImpl(std::unique_ptr<IndexedDBCursor> cursor,
35 const url::Origin& origin, 35 const url::Origin& origin,
36 IndexedDBDispatcherHost* dispatcher_host, 36 IndexedDBDispatcherHost* dispatcher_host,
37 scoped_refptr<base::SequencedTaskRunner> idb_runner) 37 scoped_refptr<base::SequencedTaskRunner> idb_runner)
38 : helper_(new IDBThreadHelper(std::move(cursor))), 38 : helper_(new IDBSequenceHelper(std::move(cursor))),
39 dispatcher_host_(dispatcher_host), 39 dispatcher_host_(dispatcher_host),
40 origin_(origin), 40 origin_(origin),
41 idb_runner_(std::move(idb_runner)) {} 41 idb_runner_(std::move(idb_runner)) {}
42 42
43 CursorImpl::~CursorImpl() { 43 CursorImpl::~CursorImpl() {
44 idb_runner_->DeleteSoon(FROM_HERE, helper_); 44 idb_runner_->DeleteSoon(FROM_HERE, helper_);
45 } 45 }
46 46
47 void CursorImpl::Advance( 47 void CursorImpl::Advance(
48 uint32_t count, 48 uint32_t count,
49 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { 49 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
50 scoped_refptr<IndexedDBCallbacks> callbacks( 50 scoped_refptr<IndexedDBCallbacks> callbacks(
51 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, 51 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
52 std::move(callbacks_info), idb_runner_)); 52 std::move(callbacks_info), idb_runner_));
53 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Advance, 53 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBSequenceHelper::Advance,
54 base::Unretained(helper_), count, 54 base::Unretained(helper_), count,
55 base::Passed(&callbacks))); 55 base::Passed(&callbacks)));
56 } 56 }
57 57
58 void CursorImpl::Continue( 58 void CursorImpl::Continue(
59 const IndexedDBKey& key, 59 const IndexedDBKey& key,
60 const IndexedDBKey& primary_key, 60 const IndexedDBKey& primary_key,
61 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { 61 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
62 scoped_refptr<IndexedDBCallbacks> callbacks( 62 scoped_refptr<IndexedDBCallbacks> callbacks(
63 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, 63 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
64 std::move(callbacks_info), idb_runner_)); 64 std::move(callbacks_info), idb_runner_));
65 idb_runner_->PostTask( 65 idb_runner_->PostTask(
66 FROM_HERE, 66 FROM_HERE,
67 base::Bind(&IDBThreadHelper::Continue, base::Unretained(helper_), key, 67 base::Bind(&IDBSequenceHelper::Continue, base::Unretained(helper_), key,
68 primary_key, base::Passed(&callbacks))); 68 primary_key, base::Passed(&callbacks)));
69 } 69 }
70 70
71 void CursorImpl::Prefetch( 71 void CursorImpl::Prefetch(
72 int32_t count, 72 int32_t count,
73 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { 73 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
74 scoped_refptr<IndexedDBCallbacks> callbacks( 74 scoped_refptr<IndexedDBCallbacks> callbacks(
75 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_, 75 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
76 std::move(callbacks_info), idb_runner_)); 76 std::move(callbacks_info), idb_runner_));
77 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Prefetch, 77 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBSequenceHelper::Prefetch,
78 base::Unretained(helper_), count, 78 base::Unretained(helper_), count,
79 base::Passed(&callbacks))); 79 base::Passed(&callbacks)));
80 } 80 }
81 81
82 void CursorImpl::PrefetchReset( 82 void CursorImpl::PrefetchReset(
83 int32_t used_prefetches, 83 int32_t used_prefetches,
84 int32_t unused_prefetches, 84 int32_t unused_prefetches,
85 const std::vector<std::string>& unused_blob_uuids) { 85 const std::vector<std::string>& unused_blob_uuids) {
86 for (const auto& uuid : unused_blob_uuids) 86 for (const auto& uuid : unused_blob_uuids)
87 dispatcher_host_->DropBlobData(uuid); 87 dispatcher_host_->DropBlobData(uuid);
88 88
89 idb_runner_->PostTask( 89 idb_runner_->PostTask(
90 FROM_HERE, 90 FROM_HERE,
91 base::Bind(&IDBThreadHelper::PrefetchReset, base::Unretained(helper_), 91 base::Bind(&IDBSequenceHelper::PrefetchReset, base::Unretained(helper_),
92 used_prefetches, unused_prefetches)); 92 used_prefetches, unused_prefetches));
93 } 93 }
94 94
95 CursorImpl::IDBThreadHelper::IDBThreadHelper( 95 CursorImpl::IDBSequenceHelper::IDBSequenceHelper(
96 std::unique_ptr<IndexedDBCursor> cursor) 96 std::unique_ptr<IndexedDBCursor> cursor)
97 : cursor_(std::move(cursor)) {} 97 : cursor_(std::move(cursor)) {}
98 98
99 CursorImpl::IDBThreadHelper::~IDBThreadHelper() {} 99 CursorImpl::IDBSequenceHelper::~IDBSequenceHelper() {}
100 100
101 void CursorImpl::IDBThreadHelper::Advance( 101 void CursorImpl::IDBSequenceHelper::Advance(
102 uint32_t count, 102 uint32_t count,
103 scoped_refptr<IndexedDBCallbacks> callbacks) { 103 scoped_refptr<IndexedDBCallbacks> callbacks) {
104 cursor_->Advance(count, std::move(callbacks)); 104 cursor_->Advance(count, std::move(callbacks));
105 } 105 }
106 106
107 void CursorImpl::IDBThreadHelper::Continue( 107 void CursorImpl::IDBSequenceHelper::Continue(
108 const IndexedDBKey& key, 108 const IndexedDBKey& key,
109 const IndexedDBKey& primary_key, 109 const IndexedDBKey& primary_key,
110 scoped_refptr<IndexedDBCallbacks> callbacks) { 110 scoped_refptr<IndexedDBCallbacks> callbacks) {
111 cursor_->Continue( 111 cursor_->Continue(
112 key.IsValid() ? base::MakeUnique<IndexedDBKey>(key) : nullptr, 112 key.IsValid() ? base::MakeUnique<IndexedDBKey>(key) : nullptr,
113 primary_key.IsValid() ? base::MakeUnique<IndexedDBKey>(primary_key) 113 primary_key.IsValid() ? base::MakeUnique<IndexedDBKey>(primary_key)
114 : nullptr, 114 : nullptr,
115 std::move(callbacks)); 115 std::move(callbacks));
116 } 116 }
117 117
118 void CursorImpl::IDBThreadHelper::Prefetch( 118 void CursorImpl::IDBSequenceHelper::Prefetch(
119 int32_t count, 119 int32_t count,
120 scoped_refptr<IndexedDBCallbacks> callbacks) { 120 scoped_refptr<IndexedDBCallbacks> callbacks) {
121 cursor_->PrefetchContinue(count, std::move(callbacks)); 121 cursor_->PrefetchContinue(count, std::move(callbacks));
122 } 122 }
123 123
124 void CursorImpl::IDBThreadHelper::PrefetchReset(int32_t used_prefetches, 124 void CursorImpl::IDBSequenceHelper::PrefetchReset(int32_t used_prefetches,
125 int32_t unused_prefetches) { 125 int32_t unused_prefetches) {
126 leveldb::Status s = 126 leveldb::Status s =
127 cursor_->PrefetchReset(used_prefetches, unused_prefetches); 127 cursor_->PrefetchReset(used_prefetches, unused_prefetches);
128 // TODO(cmumford): Handle this error (crbug.com/363397) 128 // TODO(cmumford): Handle this error (crbug.com/363397)
129 if (!s.ok()) 129 if (!s.ok())
130 DLOG(ERROR) << "Unable to reset prefetch"; 130 DLOG(ERROR) << "Unable to reset prefetch";
131 } 131 }
132 132
133 } // namespace content 133 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/cursor_impl.h ('k') | content/browser/indexed_db/database_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698