| OLD | NEW |
| 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_database_error.h" | 8 #include "content/browser/indexed_db/indexed_db_database_error.h" |
| 8 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
| 9 #include "content/browser/indexed_db/indexed_db_observer_changes.h" | 10 #include "content/browser/indexed_db/indexed_db_observer_changes.h" |
| 10 #include "content/common/indexed_db/indexed_db_messages.h" | 11 #include "content/common/indexed_db/indexed_db_messages.h" |
| 11 | 12 |
| 12 using ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo; | 13 using ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo; |
| 13 | 14 |
| 14 namespace content { | 15 namespace content { |
| 15 | 16 |
| 16 class IndexedDBDatabaseCallbacks::IOThreadHelper { | 17 class IndexedDBDatabaseCallbacks::IOThreadHelper { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 28 | 29 |
| 29 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); | 30 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); |
| 30 }; | 31 }; |
| 31 | 32 |
| 32 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( | 33 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( |
| 33 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, | 34 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, |
| 34 int32_t ipc_thread_id, | 35 int32_t ipc_thread_id, |
| 35 DatabaseCallbacksAssociatedPtrInfo callbacks_info) | 36 DatabaseCallbacksAssociatedPtrInfo callbacks_info) |
| 36 : dispatcher_host_(std::move(dispatcher_host)), | 37 : dispatcher_host_(std::move(dispatcher_host)), |
| 37 ipc_thread_id_(ipc_thread_id), | 38 ipc_thread_id_(ipc_thread_id), |
| 38 io_helper_(new IOThreadHelper(std::move(callbacks_info))) {} | 39 io_helper_(new IOThreadHelper(std::move(callbacks_info))) { |
| 40 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 41 thread_checker_.DetachFromThread(); |
| 42 } |
| 39 | 43 |
| 40 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {} | 44 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() { |
| 45 DCHECK(thread_checker_.CalledOnValidThread()); |
| 46 } |
| 41 | 47 |
| 42 void IndexedDBDatabaseCallbacks::OnForcedClose() { | 48 void IndexedDBDatabaseCallbacks::OnForcedClose() { |
| 43 if (!dispatcher_host_.get()) | 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 50 if (!dispatcher_host_) |
| 44 return; | 51 return; |
| 45 | 52 |
| 46 DCHECK(io_helper_); | 53 DCHECK(io_helper_); |
| 47 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 54 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 48 base::Bind(&IOThreadHelper::SendForcedClose, | 55 base::Bind(&IOThreadHelper::SendForcedClose, |
| 49 base::Unretained(io_helper_.get()))); | 56 base::Unretained(io_helper_.get()))); |
| 50 dispatcher_host_ = NULL; | 57 dispatcher_host_ = NULL; |
| 51 } | 58 } |
| 52 | 59 |
| 53 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version, | 60 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version, |
| 54 int64_t new_version) { | 61 int64_t new_version) { |
| 55 if (!dispatcher_host_.get()) | 62 DCHECK(thread_checker_.CalledOnValidThread()); |
| 63 if (!dispatcher_host_) |
| 56 return; | 64 return; |
| 57 | 65 |
| 58 DCHECK(io_helper_); | 66 DCHECK(io_helper_); |
| 59 BrowserThread::PostTask( | 67 BrowserThread::PostTask( |
| 60 BrowserThread::IO, FROM_HERE, | 68 BrowserThread::IO, FROM_HERE, |
| 61 base::Bind(&IOThreadHelper::SendVersionChange, | 69 base::Bind(&IOThreadHelper::SendVersionChange, |
| 62 base::Unretained(io_helper_.get()), old_version, new_version)); | 70 base::Unretained(io_helper_.get()), old_version, new_version)); |
| 63 } | 71 } |
| 64 | 72 |
| 65 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id, | 73 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id, |
| 66 const IndexedDBDatabaseError& error) { | 74 const IndexedDBDatabaseError& error) { |
| 67 if (!dispatcher_host_.get()) | 75 DCHECK(thread_checker_.CalledOnValidThread()); |
| 76 if (!dispatcher_host_) |
| 68 return; | 77 return; |
| 69 | 78 |
| 70 dispatcher_host_->FinishTransaction(host_transaction_id, false); | 79 dispatcher_host_->FinishTransaction(host_transaction_id, false); |
| 71 DCHECK(io_helper_); | 80 DCHECK(io_helper_); |
| 72 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
| 73 BrowserThread::IO, FROM_HERE, | 82 BrowserThread::IO, FROM_HERE, |
| 74 base::Bind(&IOThreadHelper::SendAbort, base::Unretained(io_helper_.get()), | 83 base::Bind(&IOThreadHelper::SendAbort, base::Unretained(io_helper_.get()), |
| 75 dispatcher_host_->RendererTransactionId(host_transaction_id), | 84 dispatcher_host_->RendererTransactionId(host_transaction_id), |
| 76 error)); | 85 error)); |
| 77 } | 86 } |
| 78 | 87 |
| 79 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) { | 88 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) { |
| 80 if (!dispatcher_host_.get()) | 89 DCHECK(thread_checker_.CalledOnValidThread()); |
| 90 if (!dispatcher_host_) |
| 81 return; | 91 return; |
| 82 | 92 |
| 83 dispatcher_host_->FinishTransaction(host_transaction_id, true); | 93 dispatcher_host_->FinishTransaction(host_transaction_id, true); |
| 84 DCHECK(io_helper_); | 94 DCHECK(io_helper_); |
| 85 BrowserThread::PostTask( | 95 BrowserThread::PostTask( |
| 86 BrowserThread::IO, FROM_HERE, | 96 BrowserThread::IO, FROM_HERE, |
| 87 base::Bind(&IOThreadHelper::SendComplete, | 97 base::Bind(&IOThreadHelper::SendComplete, |
| 88 base::Unretained(io_helper_.get()), | 98 base::Unretained(io_helper_.get()), |
| 89 dispatcher_host_->RendererTransactionId(host_transaction_id))); | 99 dispatcher_host_->RendererTransactionId(host_transaction_id))); |
| 90 } | 100 } |
| 91 | 101 |
| 92 void IndexedDBDatabaseCallbacks::OnDatabaseChange( | 102 void IndexedDBDatabaseCallbacks::OnDatabaseChange( |
| 93 int32_t ipc_database_id, | 103 int32_t ipc_database_id, |
| 94 std::unique_ptr<IndexedDBObserverChanges> changes) { | 104 std::unique_ptr<IndexedDBObserverChanges> changes) { |
| 105 DCHECK(thread_checker_.CalledOnValidThread()); |
| 95 DCHECK(io_helper_); | 106 DCHECK(io_helper_); |
| 96 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges( | 107 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges( |
| 97 ipc_thread_id_, ipc_database_id, | 108 ipc_thread_id_, ipc_database_id, |
| 98 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes)))); | 109 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes)))); |
| 99 } | 110 } |
| 100 | 111 |
| 101 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper( | 112 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper( |
| 102 DatabaseCallbacksAssociatedPtrInfo callbacks_info) { | 113 DatabaseCallbacksAssociatedPtrInfo callbacks_info) { |
| 103 callbacks_.Bind(std::move(callbacks_info)); | 114 callbacks_.Bind(std::move(callbacks_info)); |
| 104 } | 115 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 120 const IndexedDBDatabaseError& error) { | 131 const IndexedDBDatabaseError& error) { |
| 121 callbacks_->Abort(transaction_id, error.code(), error.message()); | 132 callbacks_->Abort(transaction_id, error.code(), error.message()); |
| 122 } | 133 } |
| 123 | 134 |
| 124 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendComplete( | 135 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendComplete( |
| 125 int64_t transaction_id) { | 136 int64_t transaction_id) { |
| 126 callbacks_->Complete(transaction_id); | 137 callbacks_->Complete(transaction_id); |
| 127 } | 138 } |
| 128 | 139 |
| 129 } // namespace content | 140 } // namespace content |
| OLD | NEW |