| Index: content/browser/indexed_db/indexed_db_database_callbacks.cc
|
| diff --git a/content/browser/indexed_db/indexed_db_database_callbacks.cc b/content/browser/indexed_db/indexed_db_database_callbacks.cc
|
| index ab09e9074deda5ce5b92e1d4084bb428b06468af..fcba0a3cb7b62c8e3ce82e4abc776418e2d4d9af 100644
|
| --- a/content/browser/indexed_db/indexed_db_database_callbacks.cc
|
| +++ b/content/browser/indexed_db/indexed_db_database_callbacks.cc
|
| @@ -4,40 +4,58 @@
|
|
|
| #include "content/browser/indexed_db/indexed_db_database_callbacks.h"
|
|
|
| -#include "content/browser/indexed_db/indexed_db_database_error.h"
|
| #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
|
| #include "content/browser/indexed_db/indexed_db_observer_changes.h"
|
| +#include "content/common/indexed_db/indexed_db_database_error.h"
|
| #include "content/common/indexed_db/indexed_db_messages.h"
|
|
|
| +using ::indexed_db::mojom::DatabaseClientAssociatedPtr;
|
| +
|
| namespace content {
|
|
|
| +class IndexedDBDatabaseCallbacks::IOThreadHelper {
|
| + public:
|
| + IOThreadHelper(DatabaseClientAssociatedPtr client);
|
| + ~IOThreadHelper();
|
| +
|
| + void OnForcedClosed();
|
| + void OnVersionChange(int64_t old_version, int64_t new_version);
|
| + void OnAbort(int64_t transaction_id, const IndexedDBDatabaseError& error);
|
| + void OnComplete(int64_t transaction_id);
|
| +
|
| + private:
|
| + DatabaseClientAssociatedPtr client_;
|
| +};
|
| +
|
| IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks(
|
| IndexedDBDispatcherHost* dispatcher_host,
|
| int ipc_thread_id,
|
| - int ipc_database_callbacks_id)
|
| + DatabaseClientAssociatedPtr client)
|
| : dispatcher_host_(dispatcher_host),
|
| ipc_thread_id_(ipc_thread_id),
|
| - ipc_database_callbacks_id_(ipc_database_callbacks_id) {}
|
| + io_thread_helper_(nullptr) {
|
| + if (client)
|
| + io_thread_helper_ = new IOThreadHelper(std::move(client));
|
| +}
|
|
|
| -IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {}
|
| +IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {
|
| + if (io_thread_helper_)
|
| + BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, io_thread_helper_);
|
| +}
|
|
|
| void IndexedDBDatabaseCallbacks::OnForcedClose() {
|
| - if (!dispatcher_host_.get())
|
| - return;
|
| -
|
| - dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksForcedClose(
|
| - ipc_thread_id_, ipc_database_callbacks_id_));
|
| -
|
| - dispatcher_host_ = NULL;
|
| + dispatcher_host_ = nullptr;
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&IOThreadHelper::OnForcedClosed,
|
| + base::Unretained(io_thread_helper_)));
|
| }
|
|
|
| void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version,
|
| int64_t new_version) {
|
| - if (!dispatcher_host_.get())
|
| - return;
|
| -
|
| - dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksVersionChange(
|
| - ipc_thread_id_, ipc_database_callbacks_id_, old_version, new_version));
|
| + BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&IOThreadHelper::OnVersionChange,
|
| + base::Unretained(io_thread_helper_),
|
| + old_version, new_version));
|
| }
|
|
|
| void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id,
|
| @@ -46,12 +64,11 @@ void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id,
|
| return;
|
|
|
| dispatcher_host_->FinishTransaction(host_transaction_id, false);
|
| - dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksAbort(
|
| - ipc_thread_id_,
|
| - ipc_database_callbacks_id_,
|
| - dispatcher_host_->RendererTransactionId(host_transaction_id),
|
| - error.code(),
|
| - error.message()));
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&IOThreadHelper::OnAbort, base::Unretained(io_thread_helper_),
|
| + dispatcher_host_->RendererTransactionId(host_transaction_id),
|
| + error));
|
| }
|
|
|
| void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) {
|
| @@ -59,10 +76,11 @@ void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) {
|
| return;
|
|
|
| dispatcher_host_->FinishTransaction(host_transaction_id, true);
|
| - dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksComplete(
|
| - ipc_thread_id_,
|
| - ipc_database_callbacks_id_,
|
| - dispatcher_host_->RendererTransactionId(host_transaction_id)));
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO, FROM_HERE,
|
| + base::Bind(&IOThreadHelper::OnComplete,
|
| + base::Unretained(io_thread_helper_),
|
| + dispatcher_host_->RendererTransactionId(host_transaction_id)));
|
| }
|
|
|
| void IndexedDBDatabaseCallbacks::OnDatabaseChange(
|
| @@ -73,4 +91,31 @@ void IndexedDBDatabaseCallbacks::OnDatabaseChange(
|
| IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes))));
|
| }
|
|
|
| +IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper(
|
| + DatabaseClientAssociatedPtr client)
|
| + : client_(std::move(client)) {}
|
| +
|
| +IndexedDBDatabaseCallbacks::IOThreadHelper::~IOThreadHelper() = default;
|
| +
|
| +void IndexedDBDatabaseCallbacks::IOThreadHelper::OnForcedClosed() {
|
| + client_->OnForcedClosed();
|
| +}
|
| +
|
| +void IndexedDBDatabaseCallbacks::IOThreadHelper::OnVersionChange(
|
| + int64_t old_version,
|
| + int64_t new_version) {
|
| + client_->OnVersionChange(old_version, new_version);
|
| +}
|
| +
|
| +void IndexedDBDatabaseCallbacks::IOThreadHelper::OnAbort(
|
| + int64_t transaction_id,
|
| + const IndexedDBDatabaseError& error) {
|
| + client_->OnTransactionAborted(transaction_id, error);
|
| +}
|
| +
|
| +void IndexedDBDatabaseCallbacks::IOThreadHelper::OnComplete(
|
| + int64_t transaction_id) {
|
| + client_->OnTransactionCompleted(transaction_id);
|
| +}
|
| +
|
| } // namespace content
|
|
|