OLD | NEW |
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/threading/thread_task_runner_handle.h" | 8 #include "base/threading/thread_task_runner_handle.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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 private: | 27 private: |
28 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | 28 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; |
29 std::unique_ptr<IndexedDBCursor> cursor_; | 29 std::unique_ptr<IndexedDBCursor> cursor_; |
30 const url::Origin origin_; | 30 const url::Origin origin_; |
31 | 31 |
32 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); | 32 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); |
33 }; | 33 }; |
34 | 34 |
35 CursorImpl::CursorImpl(std::unique_ptr<IndexedDBCursor> cursor, | 35 CursorImpl::CursorImpl(std::unique_ptr<IndexedDBCursor> cursor, |
36 const url::Origin& origin, | 36 const url::Origin& origin, |
37 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | 37 IndexedDBDispatcherHost* dispatcher_host) |
38 : helper_(new IDBThreadHelper(std::move(cursor))), | 38 : helper_(new IDBThreadHelper(std::move(cursor))), |
39 dispatcher_host_(std::move(dispatcher_host)), | 39 dispatcher_host_(dispatcher_host), |
40 origin_(origin), | 40 origin_(origin), |
41 idb_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 41 idb_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
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(new IndexedDBCallbacks( | 50 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
51 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 51 dispatcher_host_, origin_, std::move(callbacks_info))); |
52 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Advance, | 52 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Advance, |
53 base::Unretained(helper_), count, | 53 base::Unretained(helper_), count, |
54 base::Passed(&callbacks))); | 54 base::Passed(&callbacks))); |
55 } | 55 } |
56 | 56 |
57 void CursorImpl::Continue( | 57 void CursorImpl::Continue( |
58 const IndexedDBKey& key, | 58 const IndexedDBKey& key, |
59 const IndexedDBKey& primary_key, | 59 const IndexedDBKey& primary_key, |
60 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 60 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
61 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 61 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
62 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 62 dispatcher_host_, origin_, std::move(callbacks_info))); |
63 idb_runner_->PostTask( | 63 idb_runner_->PostTask( |
64 FROM_HERE, | 64 FROM_HERE, |
65 base::Bind(&IDBThreadHelper::Continue, base::Unretained(helper_), key, | 65 base::Bind(&IDBThreadHelper::Continue, base::Unretained(helper_), key, |
66 primary_key, base::Passed(&callbacks))); | 66 primary_key, base::Passed(&callbacks))); |
67 } | 67 } |
68 | 68 |
69 void CursorImpl::Prefetch( | 69 void CursorImpl::Prefetch( |
70 int32_t count, | 70 int32_t count, |
71 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 71 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
72 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 72 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
73 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 73 dispatcher_host_, origin_, std::move(callbacks_info))); |
74 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Prefetch, | 74 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Prefetch, |
75 base::Unretained(helper_), count, | 75 base::Unretained(helper_), count, |
76 base::Passed(&callbacks))); | 76 base::Passed(&callbacks))); |
77 } | 77 } |
78 | 78 |
79 void CursorImpl::PrefetchReset( | 79 void CursorImpl::PrefetchReset( |
80 int32_t used_prefetches, | 80 int32_t used_prefetches, |
81 int32_t unused_prefetches, | 81 int32_t unused_prefetches, |
82 const std::vector<std::string>& unused_blob_uuids) { | 82 const std::vector<std::string>& unused_blob_uuids) { |
83 for (const auto& uuid : unused_blob_uuids) | 83 for (const auto& uuid : unused_blob_uuids) |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 void CursorImpl::IDBThreadHelper::PrefetchReset(int32_t used_prefetches, | 123 void CursorImpl::IDBThreadHelper::PrefetchReset(int32_t used_prefetches, |
124 int32_t unused_prefetches) { | 124 int32_t unused_prefetches) { |
125 leveldb::Status s = | 125 leveldb::Status s = |
126 cursor_->PrefetchReset(used_prefetches, unused_prefetches); | 126 cursor_->PrefetchReset(used_prefetches, unused_prefetches); |
127 // TODO(cmumford): Handle this error (crbug.com/363397) | 127 // TODO(cmumford): Handle this error (crbug.com/363397) |
128 if (!s.ok()) | 128 if (!s.ok()) |
129 DLOG(ERROR) << "Unable to reset prefetch"; | 129 DLOG(ERROR) << "Unable to reset prefetch"; |
130 } | 130 } |
131 | 131 |
132 } // namespace content | 132 } // namespace content |
OLD | NEW |