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

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

Issue 2370643004: Port messages sent by WebIDBFactoryImpl to Mojo. (Closed)
Patch Set: Address last nits and fix leaks in unit tests. Created 4 years, 2 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_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 explicit 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 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper);
30 };
31
14 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( 32 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks(
15 IndexedDBDispatcherHost* dispatcher_host, 33 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host,
16 int ipc_thread_id, 34 int32_t ipc_thread_id,
17 int ipc_database_callbacks_id) 35 DatabaseCallbacksAssociatedPtrInfo callbacks_info)
18 : dispatcher_host_(dispatcher_host), 36 : dispatcher_host_(std::move(dispatcher_host)),
19 ipc_thread_id_(ipc_thread_id), 37 ipc_thread_id_(ipc_thread_id),
20 ipc_database_callbacks_id_(ipc_database_callbacks_id) {} 38 io_helper_(new IOThreadHelper(std::move(callbacks_info))) {}
21 39
22 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {} 40 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {}
23 41
24 void IndexedDBDatabaseCallbacks::OnForcedClose() { 42 void IndexedDBDatabaseCallbacks::OnForcedClose() {
25 if (!dispatcher_host_.get()) 43 if (!dispatcher_host_.get())
26 return; 44 return;
27 45
28 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksForcedClose( 46 DCHECK(io_helper_);
29 ipc_thread_id_, ipc_database_callbacks_id_)); 47 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
30 48 base::Bind(&IOThreadHelper::SendForcedClose,
49 base::Unretained(io_helper_.get())));
31 dispatcher_host_ = NULL; 50 dispatcher_host_ = NULL;
32 } 51 }
33 52
34 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version, 53 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version,
35 int64_t new_version) { 54 int64_t new_version) {
36 if (!dispatcher_host_.get()) 55 if (!dispatcher_host_.get())
37 return; 56 return;
38 57
39 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksVersionChange( 58 DCHECK(io_helper_);
40 ipc_thread_id_, ipc_database_callbacks_id_, old_version, new_version)); 59 BrowserThread::PostTask(
60 BrowserThread::IO, FROM_HERE,
61 base::Bind(&IOThreadHelper::SendVersionChange,
62 base::Unretained(io_helper_.get()), old_version, new_version));
41 } 63 }
42 64
43 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id, 65 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id,
44 const IndexedDBDatabaseError& error) { 66 const IndexedDBDatabaseError& error) {
45 if (!dispatcher_host_.get()) 67 if (!dispatcher_host_.get())
46 return; 68 return;
47 69
48 dispatcher_host_->FinishTransaction(host_transaction_id, false); 70 dispatcher_host_->FinishTransaction(host_transaction_id, false);
49 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksAbort( 71 DCHECK(io_helper_);
50 ipc_thread_id_, 72 BrowserThread::PostTask(
51 ipc_database_callbacks_id_, 73 BrowserThread::IO, FROM_HERE,
52 dispatcher_host_->RendererTransactionId(host_transaction_id), 74 base::Bind(&IOThreadHelper::SendAbort, base::Unretained(io_helper_.get()),
53 error.code(), 75 dispatcher_host_->RendererTransactionId(host_transaction_id),
54 error.message())); 76 error));
55 } 77 }
56 78
57 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) { 79 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) {
58 if (!dispatcher_host_.get()) 80 if (!dispatcher_host_.get())
59 return; 81 return;
60 82
61 dispatcher_host_->FinishTransaction(host_transaction_id, true); 83 dispatcher_host_->FinishTransaction(host_transaction_id, true);
62 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksComplete( 84 DCHECK(io_helper_);
63 ipc_thread_id_, 85 BrowserThread::PostTask(
64 ipc_database_callbacks_id_, 86 BrowserThread::IO, FROM_HERE,
65 dispatcher_host_->RendererTransactionId(host_transaction_id))); 87 base::Bind(&IOThreadHelper::SendComplete,
88 base::Unretained(io_helper_.get()),
89 dispatcher_host_->RendererTransactionId(host_transaction_id)));
66 } 90 }
67 91
68 void IndexedDBDatabaseCallbacks::OnDatabaseChange( 92 void IndexedDBDatabaseCallbacks::OnDatabaseChange(
69 int32_t ipc_database_id, 93 int32_t ipc_database_id,
70 std::unique_ptr<IndexedDBObserverChanges> changes) { 94 std::unique_ptr<IndexedDBObserverChanges> changes) {
95 DCHECK(io_helper_);
71 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges( 96 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges(
72 ipc_thread_id_, ipc_database_id, 97 ipc_thread_id_, ipc_database_id,
73 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes)))); 98 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes))));
74 } 99 }
75 100
101 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper(
102 DatabaseCallbacksAssociatedPtrInfo callbacks_info) {
103 callbacks_.Bind(std::move(callbacks_info));
104 }
105
106 IndexedDBDatabaseCallbacks::IOThreadHelper::~IOThreadHelper() {}
107
108 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendForcedClose() {
109 callbacks_->ForcedClose();
110 }
111
112 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendVersionChange(
113 int64_t old_version,
114 int64_t new_version) {
115 callbacks_->VersionChange(old_version, new_version);
116 }
117
118 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendAbort(
119 int64_t transaction_id,
120 const IndexedDBDatabaseError& error) {
121 callbacks_->Abort(transaction_id, error.code(), error.message());
122 }
123
124 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendComplete(
125 int64_t transaction_id) {
126 callbacks_->Complete(transaction_id);
127 }
128
76 } // namespace content 129 } // 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