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

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

Issue 2727733004: [IndexedDB] Closing mojo connections when renderer quits (Closed)
Patch Set: comments Created 3 years, 8 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/threading/thread_task_runner_handle.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 class CursorImpl::IDBThreadHelper { 16 class CursorImpl::IDBThreadHelper {
16 public: 17 public:
17 explicit IDBThreadHelper(std::unique_ptr<IndexedDBCursor> cursor); 18 explicit IDBThreadHelper(std::unique_ptr<IndexedDBCursor> cursor);
18 ~IDBThreadHelper(); 19 ~IDBThreadHelper();
19 20
20 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); 21 void Advance(uint32_t count, scoped_refptr<IndexedDBCallbacks> callbacks);
21 void Continue(const IndexedDBKey& key, 22 void Continue(const IndexedDBKey& key,
22 const IndexedDBKey& primary_key, 23 const IndexedDBKey& primary_key,
23 scoped_refptr<IndexedDBCallbacks> callbacks); 24 scoped_refptr<IndexedDBCallbacks> callbacks);
24 void Prefetch(int32_t count, scoped_refptr<IndexedDBCallbacks> callbacks); 25 void Prefetch(int32_t count, scoped_refptr<IndexedDBCallbacks> callbacks);
25 void PrefetchReset(int32_t used_prefetches, int32_t unused_prefetches); 26 void PrefetchReset(int32_t used_prefetches, int32_t unused_prefetches);
26 27
27 private: 28 private:
28 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
29 std::unique_ptr<IndexedDBCursor> cursor_; 29 std::unique_ptr<IndexedDBCursor> cursor_;
30 const url::Origin origin_;
31 30
32 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper); 31 DISALLOW_COPY_AND_ASSIGN(IDBThreadHelper);
33 }; 32 };
34 33
35 CursorImpl::CursorImpl(std::unique_ptr<IndexedDBCursor> cursor, 34 CursorImpl::CursorImpl(std::unique_ptr<IndexedDBCursor> cursor,
36 const url::Origin& origin, 35 const url::Origin& origin,
37 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host) 36 IndexedDBDispatcherHost* dispatcher_host,
37 scoped_refptr<base::SequencedTaskRunner> idb_runner)
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_(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(new IndexedDBCallbacks( 50 scoped_refptr<IndexedDBCallbacks> callbacks(
51 dispatcher_host_.get(), origin_, std::move(callbacks_info))); 51 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
52 std::move(callbacks_info), idb_runner_));
52 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Advance, 53 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Advance,
53 base::Unretained(helper_), count, 54 base::Unretained(helper_), count,
54 base::Passed(&callbacks))); 55 base::Passed(&callbacks)));
55 } 56 }
56 57
57 void CursorImpl::Continue( 58 void CursorImpl::Continue(
58 const IndexedDBKey& key, 59 const IndexedDBKey& key,
59 const IndexedDBKey& primary_key, 60 const IndexedDBKey& primary_key,
60 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { 61 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
61 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 62 scoped_refptr<IndexedDBCallbacks> callbacks(
62 dispatcher_host_.get(), origin_, std::move(callbacks_info))); 63 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
64 std::move(callbacks_info), idb_runner_));
63 idb_runner_->PostTask( 65 idb_runner_->PostTask(
64 FROM_HERE, 66 FROM_HERE,
65 base::Bind(&IDBThreadHelper::Continue, base::Unretained(helper_), key, 67 base::Bind(&IDBThreadHelper::Continue, base::Unretained(helper_), key,
66 primary_key, base::Passed(&callbacks))); 68 primary_key, base::Passed(&callbacks)));
67 } 69 }
68 70
69 void CursorImpl::Prefetch( 71 void CursorImpl::Prefetch(
70 int32_t count, 72 int32_t count,
71 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) { 73 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
72 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks( 74 scoped_refptr<IndexedDBCallbacks> callbacks(
73 dispatcher_host_.get(), origin_, std::move(callbacks_info))); 75 new IndexedDBCallbacks(dispatcher_host_->AsWeakPtr(), origin_,
76 std::move(callbacks_info), idb_runner_));
74 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Prefetch, 77 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Prefetch,
75 base::Unretained(helper_), count, 78 base::Unretained(helper_), count,
76 base::Passed(&callbacks))); 79 base::Passed(&callbacks)));
77 } 80 }
78 81
79 void CursorImpl::PrefetchReset( 82 void CursorImpl::PrefetchReset(
80 int32_t used_prefetches, 83 int32_t used_prefetches,
81 int32_t unused_prefetches, 84 int32_t unused_prefetches,
82 const std::vector<std::string>& unused_blob_uuids) { 85 const std::vector<std::string>& unused_blob_uuids) {
83 for (const auto& uuid : unused_blob_uuids) 86 for (const auto& uuid : unused_blob_uuids)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 void CursorImpl::IDBThreadHelper::PrefetchReset(int32_t used_prefetches, 126 void CursorImpl::IDBThreadHelper::PrefetchReset(int32_t used_prefetches,
124 int32_t unused_prefetches) { 127 int32_t unused_prefetches) {
125 leveldb::Status s = 128 leveldb::Status s =
126 cursor_->PrefetchReset(used_prefetches, unused_prefetches); 129 cursor_->PrefetchReset(used_prefetches, unused_prefetches);
127 // TODO(cmumford): Handle this error (crbug.com/363397) 130 // TODO(cmumford): Handle this error (crbug.com/363397)
128 if (!s.ok()) 131 if (!s.ok())
129 DLOG(ERROR) << "Unable to reset prefetch"; 132 DLOG(ERROR) << "Unable to reset prefetch";
130 } 133 }
131 134
132 } // namespace content 135 } // 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