| 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" |
| 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 class CursorImpl::IDBThreadHelper { | 15 class CursorImpl::IDBThreadHelper { |
| 16 public: | 16 public: |
| 17 explicit IDBThreadHelper(std::unique_ptr<IndexedDBCursor> cursor); | 17 explicit IDBThreadHelper(std::unique_ptr<IndexedDBCursor> cursor); |
| 18 ~IDBThreadHelper(); | 18 ~IDBThreadHelper(); |
| 19 | 19 |
| 20 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); | 20 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); |
| 21 void Continue(const IndexedDBKey& key, | 21 void Continue(const IndexedDBKey& key, |
| 22 const IndexedDBKey& primary_key, | 22 const IndexedDBKey& primary_key, |
| 23 scoped_refptr<IndexedDBCallbacks> callbacks); | 23 scoped_refptr<IndexedDBCallbacks> callbacks); |
| 24 void Prefetch(int32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); | 24 void Prefetch(int32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); |
| 25 void PrefetchReset(int32_t used_prefetches, int32_t unused_prefetches); | 25 void PrefetchReset(int32_t used_prefetches, int32_t unused_prefetches); |
| 26 | 26 |
| 27 private: | 27 private: |
| 28 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | |
| 29 std::unique_ptr<IndexedDBCursor> cursor_; | 28 std::unique_ptr<IndexedDBCursor> cursor_; |
| 30 const url::Origin origin_; | |
| 31 | 29 |
| 32 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); | 30 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); |
| 33 }; | 31 }; |
| 34 | 32 |
| 35 CursorImpl::CursorImpl(std::unique_ptr<IndexedDBCursor> cursor, | 33 CursorImpl::CursorImpl(std::unique_ptr<IndexedDBCursor> cursor, |
| 36 const url::Origin& origin, | 34 const url::Origin& origin, |
| 37 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | 35 IndexedDBDispatcherHost* dispatcher_host) |
| 38 : helper_(new IDBThreadHelper(std::move(cursor))), | 36 : helper_(new IDBThreadHelper(std::move(cursor))), |
| 39 dispatcher_host_(std::move(dispatcher_host)), | 37 dispatcher_host_(dispatcher_host), |
| 40 origin_(origin), | 38 origin_(origin), |
| 41 idb_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 39 idb_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 42 | 40 |
| 43 CursorImpl::~CursorImpl() { | 41 CursorImpl::~CursorImpl() { |
| 44 idb_runner_->DeleteSoon(FROM_HERE, helper_); | 42 idb_runner_->DeleteSoon(FROM_HERE, helper_); |
| 45 } | 43 } |
| 46 | 44 |
| 47 void CursorImpl::Advance( | 45 void CursorImpl::Advance( |
| 48 uint32_t count, | 46 uint32_t count, |
| 49 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 47 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 50 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 48 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 51 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 49 dispatcher_host_, origin_, std::move(callbacks_info))); |
| 52 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Advance, | 50 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Advance, |
| 53 base::Unretained(helper_), count, | 51 base::Unretained(helper_), count, |
| 54 base::Passed(&callbacks))); | 52 base::Passed(&callbacks))); |
| 55 } | 53 } |
| 56 | 54 |
| 57 void CursorImpl::Continue( | 55 void CursorImpl::Continue( |
| 58 const IndexedDBKey& key, | 56 const IndexedDBKey& key, |
| 59 const IndexedDBKey& primary_key, | 57 const IndexedDBKey& primary_key, |
| 60 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 58 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 61 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 59 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 62 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 60 dispatcher_host_, origin_, std::move(callbacks_info))); |
| 63 idb_runner_->PostTask( | 61 idb_runner_->PostTask( |
| 64 FROM_HERE, | 62 FROM_HERE, |
| 65 base::Bind(&IDBThreadHelper::Continue, base::Unretained(helper_), key, | 63 base::Bind(&IDBThreadHelper::Continue, base::Unretained(helper_), key, |
| 66 primary_key, base::Passed(&callbacks))); | 64 primary_key, base::Passed(&callbacks))); |
| 67 } | 65 } |
| 68 | 66 |
| 69 void CursorImpl::Prefetch( | 67 void CursorImpl::Prefetch( |
| 70 int32_t count, | 68 int32_t count, |
| 71 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { | 69 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 72 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( | 70 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 73 dispatcher_host_.get(), origin_, std::move(callbacks_info))); | 71 dispatcher_host_, origin_, std::move(callbacks_info))); |
| 74 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Prefetch, | 72 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Prefetch, |
| 75 base::Unretained(helper_), count, | 73 base::Unretained(helper_), count, |
| 76 base::Passed(&callbacks))); | 74 base::Passed(&callbacks))); |
| 77 } | 75 } |
| 78 | 76 |
| 79 void CursorImpl::PrefetchReset( | 77 void CursorImpl::PrefetchReset( |
| 80 int32_t used_prefetches, | 78 int32_t used_prefetches, |
| 81 int32_t unused_prefetches, | 79 int32_t unused_prefetches, |
| 82 const std::vector<std::string>& unused_blob_uuids) { | 80 const std::vector<std::string>& unused_blob_uuids) { |
| 83 for (const auto& uuid : unused_blob_uuids) | 81 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, | 121 void CursorImpl::IDBThreadHelper::PrefetchReset(int32_t used_prefetches, |
| 124 int32_t unused_prefetches) { | 122 int32_t unused_prefetches) { |
| 125 leveldb::Status s = | 123 leveldb::Status s = |
| 126 cursor_->PrefetchReset(used_prefetches, unused_prefetches); | 124 cursor_->PrefetchReset(used_prefetches, unused_prefetches); |
| 127 // TODO(cmumford): Handle this error (crbug.com/363397) | 125 // TODO(cmumford): Handle this error (crbug.com/363397) |
| 128 if (!s.ok()) | 126 if (!s.ok()) |
| 129 DLOG(ERROR) << "Unable to reset prefetch"; | 127 DLOG(ERROR) << "Unable to reset prefetch"; |
| 130 } | 128 } |
| 131 | 129 |
| 132 } // namespace content | 130 } // namespace content |
| OLD | NEW |