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

Side by Side Diff: content/browser/indexed_db/indexed_db_database_callbacks.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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/indexed_db_database_callbacks.h" 5 #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
6 6
7 #include "content/browser/indexed_db/indexed_db_context_impl.h" 7 #include "content/browser/indexed_db/indexed_db_context_impl.h"
8 #include "content/browser/indexed_db/indexed_db_database_error.h" 8 #include "content/browser/indexed_db/indexed_db_database_error.h"
9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
10 #include "content/browser/indexed_db/indexed_db_transaction.h" 10 #include "content/browser/indexed_db/indexed_db_transaction.h"
11 11
12 using ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo; 12 using ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo;
13 13
14 namespace content { 14 namespace content {
15 15
16 class IndexedDBDatabaseCallbacks::IOThreadHelper { 16 class IndexedDBDatabaseCallbacks::IOThreadHelper {
17 public: 17 public:
18 explicit IOThreadHelper(DatabaseCallbacksAssociatedPtrInfo callbacks_info); 18 explicit IOThreadHelper(DatabaseCallbacksAssociatedPtrInfo callbacks_info);
19 ~IOThreadHelper(); 19 ~IOThreadHelper();
20 20
21 void SendForcedClose(); 21 void SendForcedClose();
22 void SendVersionChange(int64_t old_version, int64_t new_version); 22 void SendVersionChange(int64_t old_version, int64_t new_version);
23 void SendAbort(int64_t transaction_id, const IndexedDBDatabaseError& error); 23 void SendAbort(int64_t transaction_id, const IndexedDBDatabaseError& error);
24 void SendComplete(int64_t transaction_id); 24 void SendComplete(int64_t transaction_id);
25 void SendChanges(::indexed_db::mojom::ObserverChangesPtr changes); 25 void SendChanges(::indexed_db::mojom::ObserverChangesPtr changes);
26 void OnConnectionError();
26 27
27 private: 28 private:
28 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtr callbacks_; 29 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtr callbacks_;
29 30
30 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); 31 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper);
31 }; 32 };
32 33
33 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( 34 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks(
34 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, 35 scoped_refptr<IndexedDBContextImpl> context,
35 DatabaseCallbacksAssociatedPtrInfo callbacks_info) 36 DatabaseCallbacksAssociatedPtrInfo callbacks_info)
36 : dispatcher_host_(std::move(dispatcher_host)), 37 : indexed_db_context_(std::move(context)),
37 io_helper_(new IOThreadHelper(std::move(callbacks_info))) { 38 io_helper_(new IOThreadHelper(std::move(callbacks_info))) {
38 DCHECK_CURRENTLY_ON(BrowserThread::IO); 39 DCHECK_CURRENTLY_ON(BrowserThread::IO);
39 thread_checker_.DetachFromThread(); 40 thread_checker_.DetachFromThread();
40 } 41 }
41 42
42 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() { 43 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {
43 DCHECK(thread_checker_.CalledOnValidThread()); 44 DCHECK(thread_checker_.CalledOnValidThread());
44 } 45 }
45 46
46 void IndexedDBDatabaseCallbacks::OnForcedClose() { 47 void IndexedDBDatabaseCallbacks::OnForcedClose() {
47 DCHECK(thread_checker_.CalledOnValidThread()); 48 DCHECK(thread_checker_.CalledOnValidThread());
48 if (!dispatcher_host_) 49 if (complete_)
49 return; 50 return;
50 51
51 DCHECK(io_helper_); 52 DCHECK(io_helper_);
52 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 53 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
53 base::Bind(&IOThreadHelper::SendForcedClose, 54 base::Bind(&IOThreadHelper::SendForcedClose,
54 base::Unretained(io_helper_.get()))); 55 base::Unretained(io_helper_.get())));
55 dispatcher_host_ = NULL; 56 complete_ = true;
56 } 57 }
57 58
58 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version, 59 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version,
59 int64_t new_version) { 60 int64_t new_version) {
60 DCHECK(thread_checker_.CalledOnValidThread()); 61 DCHECK(thread_checker_.CalledOnValidThread());
61 if (!dispatcher_host_) 62 if (complete_)
62 return; 63 return;
63 64
64 DCHECK(io_helper_); 65 DCHECK(io_helper_);
65 BrowserThread::PostTask( 66 BrowserThread::PostTask(
66 BrowserThread::IO, FROM_HERE, 67 BrowserThread::IO, FROM_HERE,
67 base::Bind(&IOThreadHelper::SendVersionChange, 68 base::Bind(&IOThreadHelper::SendVersionChange,
68 base::Unretained(io_helper_.get()), old_version, new_version)); 69 base::Unretained(io_helper_.get()), old_version, new_version));
69 } 70 }
70 71
71 void IndexedDBDatabaseCallbacks::OnAbort( 72 void IndexedDBDatabaseCallbacks::OnAbort(
72 const IndexedDBTransaction& transaction, 73 const IndexedDBTransaction& transaction,
73 const IndexedDBDatabaseError& error) { 74 const IndexedDBDatabaseError& error) {
74 DCHECK(thread_checker_.CalledOnValidThread()); 75 DCHECK(thread_checker_.CalledOnValidThread());
75 if (!dispatcher_host_) 76 if (complete_)
76 return; 77 return;
77 78
78 DCHECK(io_helper_); 79 DCHECK(io_helper_);
79 BrowserThread::PostTask( 80 BrowserThread::PostTask(
80 BrowserThread::IO, FROM_HERE, 81 BrowserThread::IO, FROM_HERE,
81 base::Bind(&IOThreadHelper::SendAbort, base::Unretained(io_helper_.get()), 82 base::Bind(&IOThreadHelper::SendAbort, base::Unretained(io_helper_.get()),
82 transaction.id(), error)); 83 transaction.id(), error));
83 } 84 }
84 85
85 void IndexedDBDatabaseCallbacks::OnComplete( 86 void IndexedDBDatabaseCallbacks::OnComplete(
86 const IndexedDBTransaction& transaction) { 87 const IndexedDBTransaction& transaction) {
87 DCHECK(thread_checker_.CalledOnValidThread()); 88 DCHECK(thread_checker_.CalledOnValidThread());
88 if (!dispatcher_host_) 89 if (complete_)
89 return; 90 return;
90 91
91 dispatcher_host_->context()->TransactionComplete( 92 indexed_db_context_->TransactionComplete(transaction.database()->origin());
92 transaction.database()->origin());
93 DCHECK(io_helper_); 93 DCHECK(io_helper_);
94 BrowserThread::PostTask( 94 BrowserThread::PostTask(
95 BrowserThread::IO, FROM_HERE, 95 BrowserThread::IO, FROM_HERE,
96 base::Bind(&IOThreadHelper::SendComplete, 96 base::Bind(&IOThreadHelper::SendComplete,
97 base::Unretained(io_helper_.get()), transaction.id())); 97 base::Unretained(io_helper_.get()), transaction.id()));
98 } 98 }
99 99
100 void IndexedDBDatabaseCallbacks::OnDatabaseChange( 100 void IndexedDBDatabaseCallbacks::OnDatabaseChange(
101 ::indexed_db::mojom::ObserverChangesPtr changes) { 101 ::indexed_db::mojom::ObserverChangesPtr changes) {
102 DCHECK(thread_checker_.CalledOnValidThread()); 102 DCHECK(thread_checker_.CalledOnValidThread());
103 DCHECK(io_helper_); 103 DCHECK(io_helper_);
104 BrowserThread::PostTask( 104 BrowserThread::PostTask(
105 BrowserThread::IO, FROM_HERE, 105 BrowserThread::IO, FROM_HERE,
106 base::Bind(&IOThreadHelper::SendChanges, 106 base::Bind(&IOThreadHelper::SendChanges,
107 base::Unretained(io_helper_.get()), base::Passed(&changes))); 107 base::Unretained(io_helper_.get()), base::Passed(&changes)));
108 } 108 }
109 109
110 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper( 110 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper(
111 DatabaseCallbacksAssociatedPtrInfo callbacks_info) { 111 DatabaseCallbacksAssociatedPtrInfo callbacks_info) {
112 if (!callbacks_info.is_valid())
113 return;
112 callbacks_.Bind(std::move(callbacks_info)); 114 callbacks_.Bind(std::move(callbacks_info));
115 callbacks_.set_connection_error_handler(
116 base::Bind(&IOThreadHelper::OnConnectionError, base::Unretained(this)));
113 } 117 }
114 118
115 IndexedDBDatabaseCallbacks::IOThreadHelper::~IOThreadHelper() {} 119 IndexedDBDatabaseCallbacks::IOThreadHelper::~IOThreadHelper() {}
116 120
117 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendForcedClose() { 121 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendForcedClose() {
118 callbacks_->ForcedClose(); 122 if (callbacks_)
123 callbacks_->ForcedClose();
119 } 124 }
120 125
121 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendVersionChange( 126 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendVersionChange(
122 int64_t old_version, 127 int64_t old_version,
123 int64_t new_version) { 128 int64_t new_version) {
124 callbacks_->VersionChange(old_version, new_version); 129 if (callbacks_)
130 callbacks_->VersionChange(old_version, new_version);
125 } 131 }
126 132
127 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendAbort( 133 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendAbort(
128 int64_t transaction_id, 134 int64_t transaction_id,
129 const IndexedDBDatabaseError& error) { 135 const IndexedDBDatabaseError& error) {
130 callbacks_->Abort(transaction_id, error.code(), error.message()); 136 if (callbacks_)
137 callbacks_->Abort(transaction_id, error.code(), error.message());
131 } 138 }
132 139
133 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendComplete( 140 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendComplete(
134 int64_t transaction_id) { 141 int64_t transaction_id) {
135 callbacks_->Complete(transaction_id); 142 if (callbacks_)
143 callbacks_->Complete(transaction_id);
136 } 144 }
137 145
138 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendChanges( 146 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendChanges(
139 ::indexed_db::mojom::ObserverChangesPtr changes) { 147 ::indexed_db::mojom::ObserverChangesPtr changes) {
140 callbacks_->Changes(std::move(changes)); 148 if (callbacks_)
149 callbacks_->Changes(std::move(changes));
150 }
151
152 void IndexedDBDatabaseCallbacks::IOThreadHelper::OnConnectionError() {
153 callbacks_.reset();
141 } 154 }
142 155
143 } // namespace content 156 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_database_callbacks.h ('k') | content/browser/indexed_db/indexed_db_database_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698