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_database_error.h" | 7 #include "content/browser/indexed_db/indexed_db_database_error.h" |
8 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" | 8 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" |
9 #include "content/browser/indexed_db/indexed_db_observer_changes.h" | 9 #include "content/browser/indexed_db/indexed_db_observer_changes.h" |
10 #include "content/common/indexed_db/indexed_db_messages.h" | 10 #include "content/common/indexed_db/indexed_db_messages.h" |
11 | 11 |
| 12 using ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo; |
| 13 |
12 namespace content { | 14 namespace content { |
13 | 15 |
| 16 class IndexedDBDatabaseCallbacks::IOThreadHelper { |
| 17 public: |
| 18 IOThreadHelper(DatabaseCallbacksAssociatedPtrInfo callbacks_info); |
| 19 ~IOThreadHelper(); |
| 20 |
| 21 void SendForcedClose(); |
| 22 void SendVersionChange(int64_t old_version, int64_t new_version); |
| 23 void SendAbort(int64_t transaction_id, const IndexedDBDatabaseError& error); |
| 24 void SendComplete(int64_t transaction_id); |
| 25 |
| 26 private: |
| 27 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtr callbacks_; |
| 28 }; |
| 29 |
14 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( | 30 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( |
15 IndexedDBDispatcherHost* dispatcher_host, | 31 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, |
16 int ipc_thread_id, | 32 int32_t ipc_thread_id, |
17 int ipc_database_callbacks_id) | 33 DatabaseCallbacksAssociatedPtrInfo callbacks_info) |
18 : dispatcher_host_(dispatcher_host), | 34 : dispatcher_host_(std::move(dispatcher_host)), |
19 ipc_thread_id_(ipc_thread_id), | 35 ipc_thread_id_(ipc_thread_id), |
20 ipc_database_callbacks_id_(ipc_database_callbacks_id) {} | 36 helper_(nullptr) { |
| 37 if (callbacks_info.is_valid()) |
| 38 helper_ = new IOThreadHelper(std::move(callbacks_info)); |
| 39 } |
21 | 40 |
22 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {} | 41 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() { |
| 42 if (helper_) |
| 43 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, helper_); |
| 44 } |
23 | 45 |
24 void IndexedDBDatabaseCallbacks::OnForcedClose() { | 46 void IndexedDBDatabaseCallbacks::OnForcedClose() { |
25 if (!dispatcher_host_.get()) | 47 if (!dispatcher_host_.get()) |
26 return; | 48 return; |
27 | 49 |
28 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksForcedClose( | 50 BrowserThread::PostTask( |
29 ipc_thread_id_, ipc_database_callbacks_id_)); | 51 BrowserThread::IO, FROM_HERE, |
30 | 52 base::Bind(&IOThreadHelper::SendForcedClose, base::Unretained(helper_))); |
31 dispatcher_host_ = NULL; | 53 dispatcher_host_ = NULL; |
32 } | 54 } |
33 | 55 |
34 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version, | 56 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version, |
35 int64_t new_version) { | 57 int64_t new_version) { |
36 if (!dispatcher_host_.get()) | 58 if (!dispatcher_host_.get()) |
37 return; | 59 return; |
38 | 60 |
39 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksVersionChange( | 61 BrowserThread::PostTask( |
40 ipc_thread_id_, ipc_database_callbacks_id_, old_version, new_version)); | 62 BrowserThread::IO, FROM_HERE, |
| 63 base::Bind(&IOThreadHelper::SendVersionChange, base::Unretained(helper_), |
| 64 old_version, new_version)); |
41 } | 65 } |
42 | 66 |
43 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id, | 67 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id, |
44 const IndexedDBDatabaseError& error) { | 68 const IndexedDBDatabaseError& error) { |
45 if (!dispatcher_host_.get()) | 69 if (!dispatcher_host_.get()) |
46 return; | 70 return; |
47 | 71 |
48 dispatcher_host_->FinishTransaction(host_transaction_id, false); | 72 dispatcher_host_->FinishTransaction(host_transaction_id, false); |
49 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksAbort( | 73 BrowserThread::PostTask( |
50 ipc_thread_id_, | 74 BrowserThread::IO, FROM_HERE, |
51 ipc_database_callbacks_id_, | 75 base::Bind(&IOThreadHelper::SendAbort, base::Unretained(helper_), |
52 dispatcher_host_->RendererTransactionId(host_transaction_id), | 76 dispatcher_host_->RendererTransactionId(host_transaction_id), |
53 error.code(), | 77 error)); |
54 error.message())); | |
55 } | 78 } |
56 | 79 |
57 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) { | 80 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) { |
58 if (!dispatcher_host_.get()) | 81 if (!dispatcher_host_.get()) |
59 return; | 82 return; |
60 | 83 |
61 dispatcher_host_->FinishTransaction(host_transaction_id, true); | 84 dispatcher_host_->FinishTransaction(host_transaction_id, true); |
62 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksComplete( | 85 BrowserThread::PostTask( |
63 ipc_thread_id_, | 86 BrowserThread::IO, FROM_HERE, |
64 ipc_database_callbacks_id_, | 87 base::Bind(&IOThreadHelper::SendComplete, base::Unretained(helper_), |
65 dispatcher_host_->RendererTransactionId(host_transaction_id))); | 88 dispatcher_host_->RendererTransactionId(host_transaction_id))); |
66 } | 89 } |
67 | 90 |
68 void IndexedDBDatabaseCallbacks::OnDatabaseChange( | 91 void IndexedDBDatabaseCallbacks::OnDatabaseChange( |
69 int32_t ipc_database_id, | 92 int32_t ipc_database_id, |
70 std::unique_ptr<IndexedDBObserverChanges> changes) { | 93 std::unique_ptr<IndexedDBObserverChanges> changes) { |
71 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges( | 94 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges( |
72 ipc_thread_id_, ipc_database_id, | 95 ipc_thread_id_, ipc_database_id, |
73 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes)))); | 96 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes)))); |
74 } | 97 } |
75 | 98 |
| 99 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper( |
| 100 DatabaseCallbacksAssociatedPtrInfo callbacks_info) { |
| 101 callbacks_.Bind(std::move(callbacks_info)); |
| 102 } |
| 103 |
| 104 IndexedDBDatabaseCallbacks::IOThreadHelper::~IOThreadHelper() {} |
| 105 |
| 106 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendForcedClose() { |
| 107 callbacks_->ForcedClose(); |
| 108 } |
| 109 |
| 110 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendVersionChange( |
| 111 int64_t old_version, |
| 112 int64_t new_version) { |
| 113 callbacks_->VersionChange(old_version, new_version); |
| 114 } |
| 115 |
| 116 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendAbort( |
| 117 int64_t transaction_id, |
| 118 const IndexedDBDatabaseError& error) { |
| 119 callbacks_->Abort(transaction_id, error.code(), error.message()); |
| 120 } |
| 121 |
| 122 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendComplete( |
| 123 int64_t transaction_id) { |
| 124 callbacks_->Complete(transaction_id); |
| 125 } |
| 126 |
76 } // namespace content | 127 } // namespace content |
OLD | NEW |