OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/indexed_db/cursor_impl.h" |
| 6 |
| 7 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 8 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 class CursorImpl::IDBThreadHelper { |
| 14 public: |
| 15 explicit IDBThreadHelper(scoped_refptr<IndexedDBCursor> cursor); |
| 16 ~IDBThreadHelper(); |
| 17 |
| 18 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); |
| 19 void Continue(const IndexedDBKey& key, |
| 20 const IndexedDBKey& primary_key, |
| 21 scoped_refptr<IndexedDBCallbacks> callbacks); |
| 22 void Prefetch(int32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); |
| 23 void PrefetchReset(int32_t used_prefetches, int32_t unused_prefetches); |
| 24 |
| 25 private: |
| 26 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; |
| 27 scoped_refptr<IndexedDBCursor> cursor_; |
| 28 const url::Origin origin_; |
| 29 |
| 30 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); |
| 31 }; |
| 32 |
| 33 CursorImpl::CursorImpl(scoped_refptr<IndexedDBCursor> cursor, |
| 34 const url::Origin& origin, |
| 35 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) |
| 36 : helper_(new IDBThreadHelper(std::move(cursor))), |
| 37 dispatcher_host_(std::move(dispatcher_host)), |
| 38 origin_(origin), |
| 39 idb_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 40 |
| 41 CursorImpl::~CursorImpl() { |
| 42 idb_runner_->DeleteSoon(FROM_HERE, helper_); |
| 43 } |
| 44 |
| 45 void CursorImpl::Advance( |
| 46 uint32_t count, |
| 47 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 48 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 49 dispatcher_host_.get(), origin_, std::move(callbacks_info))); |
| 50 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Advance, |
| 51 base::Unretained(helper_), count, |
| 52 base::Passed(&callbacks))); |
| 53 } |
| 54 |
| 55 void CursorImpl::Continue( |
| 56 const IndexedDBKey& key, |
| 57 const IndexedDBKey& primary_key, |
| 58 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 59 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 60 dispatcher_host_.get(), origin_, std::move(callbacks_info))); |
| 61 idb_runner_->PostTask( |
| 62 FROM_HERE, |
| 63 base::Bind(&IDBThreadHelper::Continue, base::Unretained(helper_), key, |
| 64 primary_key, base::Passed(&callbacks))); |
| 65 } |
| 66 |
| 67 void CursorImpl::Prefetch( |
| 68 int32_t count, |
| 69 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { |
| 70 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( |
| 71 dispatcher_host_.get(), origin_, std::move(callbacks_info))); |
| 72 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Prefetch, |
| 73 base::Unretained(helper_), count, |
| 74 base::Passed(&callbacks))); |
| 75 } |
| 76 |
| 77 void CursorImpl::PrefetchReset( |
| 78 int32_t used_prefetches, |
| 79 int32_t unused_prefetches, |
| 80 const std::vector<std::string>& unused_blob_uuids) { |
| 81 for (const auto& uuid : unused_blob_uuids) |
| 82 dispatcher_host_->DropBlobData(uuid); |
| 83 |
| 84 idb_runner_->PostTask( |
| 85 FROM_HERE, |
| 86 base::Bind(&IDBThreadHelper::PrefetchReset, base::Unretained(helper_), |
| 87 used_prefetches, unused_prefetches)); |
| 88 } |
| 89 |
| 90 CursorImpl::IDBThreadHelper::IDBThreadHelper( |
| 91 scoped_refptr<IndexedDBCursor> cursor) |
| 92 : cursor_(std::move(cursor)) {} |
| 93 |
| 94 CursorImpl::IDBThreadHelper::~IDBThreadHelper() {} |
| 95 |
| 96 void CursorImpl::IDBThreadHelper::Advance( |
| 97 uint32_t count, |
| 98 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 99 cursor_->Advance(count, std::move(callbacks)); |
| 100 } |
| 101 |
| 102 void CursorImpl::IDBThreadHelper::Continue( |
| 103 const IndexedDBKey& key, |
| 104 const IndexedDBKey& primary_key, |
| 105 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 106 cursor_->Continue( |
| 107 key.IsValid() ? base::MakeUnique<IndexedDBKey>(key) : nullptr, |
| 108 primary_key.IsValid() ? base::MakeUnique<IndexedDBKey>(primary_key) |
| 109 : nullptr, |
| 110 std::move(callbacks)); |
| 111 } |
| 112 |
| 113 void CursorImpl::IDBThreadHelper::Prefetch( |
| 114 int32_t count, |
| 115 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 116 cursor_->PrefetchContinue(count, std::move(callbacks)); |
| 117 } |
| 118 |
| 119 void CursorImpl::IDBThreadHelper::PrefetchReset(int32_t used_prefetches, |
| 120 int32_t unused_prefetches) { |
| 121 leveldb::Status s = |
| 122 cursor_->PrefetchReset(used_prefetches, unused_prefetches); |
| 123 // TODO(cmumford): Handle this error (crbug.com/363397) |
| 124 if (!s.ok()) |
| 125 DLOG(ERROR) << "Unable to reset prefetch"; |
| 126 } |
| 127 |
| 128 } // namespace content |
OLD | NEW |