| 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 "content/browser/indexed_db/indexed_db_callbacks.h" | 7 #include "content/browser/indexed_db/indexed_db_callbacks.h" |
| 8 #include "content/browser/indexed_db/indexed_db_cursor.h" | 8 #include "content/browser/indexed_db/indexed_db_cursor.h" |
| 9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 10 | 10 |
| 11 namespace content { | 11 namespace content { |
| 12 | 12 |
| 13 class CursorImpl::IDBThreadHelper { | 13 class CursorImpl::IDBThreadHelper { |
| 14 public: | 14 public: |
| 15 explicit IDBThreadHelper(scoped_refptr<IndexedDBCursor> cursor); | 15 explicit IDBThreadHelper(std::unique_ptr<IndexedDBCursor> cursor); |
| 16 ~IDBThreadHelper(); | 16 ~IDBThreadHelper(); |
| 17 | 17 |
| 18 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); | 18 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); |
| 19 void Continue(const IndexedDBKey& key, | 19 void Continue(const IndexedDBKey& key, |
| 20 const IndexedDBKey& primary_key, | 20 const IndexedDBKey& primary_key, |
| 21 scoped_refptr<IndexedDBCallbacks> callbacks); | 21 scoped_refptr<IndexedDBCallbacks> callbacks); |
| 22 void Prefetch(int32_t count, 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); | 23 void PrefetchReset(int32_t used_prefetches, int32_t unused_prefetches); |
| 24 | 24 |
| 25 private: | 25 private: |
| 26 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; | 26 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_; |
| 27 scoped_refptr<IndexedDBCursor> cursor_; | 27 std::unique_ptr<IndexedDBCursor> cursor_; |
| 28 const url::Origin origin_; | 28 const url::Origin origin_; |
| 29 | 29 |
| 30 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); | 30 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 CursorImpl::CursorImpl(scoped_refptr<IndexedDBCursor> cursor, | 33 CursorImpl::CursorImpl(std::unique_ptr<IndexedDBCursor> cursor, |
| 34 const url::Origin& origin, | 34 const url::Origin& origin, |
| 35 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) | 35 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) |
| 36 : helper_(new IDBThreadHelper(std::move(cursor))), | 36 : helper_(new IDBThreadHelper(std::move(cursor))), |
| 37 dispatcher_host_(std::move(dispatcher_host)), | 37 dispatcher_host_(std::move(dispatcher_host)), |
| 38 origin_(origin), | 38 origin_(origin), |
| 39 idb_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 39 idb_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
| 40 | 40 |
| 41 CursorImpl::~CursorImpl() { | 41 CursorImpl::~CursorImpl() { |
| 42 idb_runner_->DeleteSoon(FROM_HERE, helper_); | 42 idb_runner_->DeleteSoon(FROM_HERE, helper_); |
| 43 } | 43 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 for (const auto& uuid : unused_blob_uuids) | 81 for (const auto& uuid : unused_blob_uuids) |
| 82 dispatcher_host_->DropBlobData(uuid); | 82 dispatcher_host_->DropBlobData(uuid); |
| 83 | 83 |
| 84 idb_runner_->PostTask( | 84 idb_runner_->PostTask( |
| 85 FROM_HERE, | 85 FROM_HERE, |
| 86 base::Bind(&IDBThreadHelper::PrefetchReset, base::Unretained(helper_), | 86 base::Bind(&IDBThreadHelper::PrefetchReset, base::Unretained(helper_), |
| 87 used_prefetches, unused_prefetches)); | 87 used_prefetches, unused_prefetches)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 CursorImpl::IDBThreadHelper::IDBThreadHelper( | 90 CursorImpl::IDBThreadHelper::IDBThreadHelper( |
| 91 scoped_refptr<IndexedDBCursor> cursor) | 91 std::unique_ptr<IndexedDBCursor> cursor) |
| 92 : cursor_(std::move(cursor)) {} | 92 : cursor_(std::move(cursor)) {} |
| 93 | 93 |
| 94 CursorImpl::IDBThreadHelper::~IDBThreadHelper() {} | 94 CursorImpl::IDBThreadHelper::~IDBThreadHelper() { |
| 95 cursor_->RemoveCursorFromTransaction(); |
| 96 } |
| 95 | 97 |
| 96 void CursorImpl::IDBThreadHelper::Advance( | 98 void CursorImpl::IDBThreadHelper::Advance( |
| 97 uint32_t count, | 99 uint32_t count, |
| 98 scoped_refptr<IndexedDBCallbacks> callbacks) { | 100 scoped_refptr<IndexedDBCallbacks> callbacks) { |
| 99 cursor_->Advance(count, std::move(callbacks)); | 101 cursor_->Advance(count, std::move(callbacks)); |
| 100 } | 102 } |
| 101 | 103 |
| 102 void CursorImpl::IDBThreadHelper::Continue( | 104 void CursorImpl::IDBThreadHelper::Continue( |
| 103 const IndexedDBKey& key, | 105 const IndexedDBKey& key, |
| 104 const IndexedDBKey& primary_key, | 106 const IndexedDBKey& primary_key, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 119 void CursorImpl::IDBThreadHelper::PrefetchReset(int32_t used_prefetches, | 121 void CursorImpl::IDBThreadHelper::PrefetchReset(int32_t used_prefetches, |
| 120 int32_t unused_prefetches) { | 122 int32_t unused_prefetches) { |
| 121 leveldb::Status s = | 123 leveldb::Status s = |
| 122 cursor_->PrefetchReset(used_prefetches, unused_prefetches); | 124 cursor_->PrefetchReset(used_prefetches, unused_prefetches); |
| 123 // TODO(cmumford): Handle this error (crbug.com/363397) | 125 // TODO(cmumford): Handle this error (crbug.com/363397) |
| 124 if (!s.ok()) | 126 if (!s.ok()) |
| 125 DLOG(ERROR) << "Unable to reset prefetch"; | 127 DLOG(ERROR) << "Unable to reset prefetch"; |
| 126 } | 128 } |
| 127 | 129 |
| 128 } // namespace content | 130 } // namespace content |
| OLD | NEW |