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

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: Require explicit wrapping when discarding map keys. 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_(nullptr) {
39 if (callbacks_info.is_valid())
40 io_helper_ = new IOThreadHelper(std::move(callbacks_info));
41 }
21 42
22 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {} 43 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {
44 if (io_helper_)
45 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, io_helper_);
46 }
23 47
24 void IndexedDBDatabaseCallbacks::OnForcedClose() { 48 void IndexedDBDatabaseCallbacks::OnForcedClose() {
25 if (!dispatcher_host_.get()) 49 if (!dispatcher_host_.get())
26 return; 50 return;
27 51
28 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksForcedClose( 52 DCHECK(io_helper_);
29 ipc_thread_id_, ipc_database_callbacks_id_)); 53 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
30 54 base::Bind(&IOThreadHelper::SendForcedClose,
55 base::Unretained(io_helper_)));
31 dispatcher_host_ = NULL; 56 dispatcher_host_ = NULL;
32 } 57 }
33 58
34 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version, 59 void IndexedDBDatabaseCallbacks::OnVersionChange(int64_t old_version,
35 int64_t new_version) { 60 int64_t new_version) {
36 if (!dispatcher_host_.get()) 61 if (!dispatcher_host_.get())
37 return; 62 return;
38 63
39 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksVersionChange( 64 DCHECK(io_helper_);
40 ipc_thread_id_, ipc_database_callbacks_id_, old_version, new_version)); 65 BrowserThread::PostTask(
66 BrowserThread::IO, FROM_HERE,
67 base::Bind(&IOThreadHelper::SendVersionChange,
68 base::Unretained(io_helper_), old_version, new_version));
41 } 69 }
42 70
43 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id, 71 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id,
44 const IndexedDBDatabaseError& error) { 72 const IndexedDBDatabaseError& error) {
45 if (!dispatcher_host_.get()) 73 if (!dispatcher_host_.get())
46 return; 74 return;
47 75
48 dispatcher_host_->FinishTransaction(host_transaction_id, false); 76 dispatcher_host_->FinishTransaction(host_transaction_id, false);
49 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksAbort( 77 DCHECK(io_helper_);
50 ipc_thread_id_, 78 BrowserThread::PostTask(
51 ipc_database_callbacks_id_, 79 BrowserThread::IO, FROM_HERE,
52 dispatcher_host_->RendererTransactionId(host_transaction_id), 80 base::Bind(&IOThreadHelper::SendAbort, base::Unretained(io_helper_),
53 error.code(), 81 dispatcher_host_->RendererTransactionId(host_transaction_id),
54 error.message())); 82 error));
55 } 83 }
56 84
57 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) { 85 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) {
58 if (!dispatcher_host_.get()) 86 if (!dispatcher_host_.get())
59 return; 87 return;
60 88
61 dispatcher_host_->FinishTransaction(host_transaction_id, true); 89 dispatcher_host_->FinishTransaction(host_transaction_id, true);
62 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksComplete( 90 DCHECK(io_helper_);
63 ipc_thread_id_, 91 BrowserThread::PostTask(
64 ipc_database_callbacks_id_, 92 BrowserThread::IO, FROM_HERE,
65 dispatcher_host_->RendererTransactionId(host_transaction_id))); 93 base::Bind(&IOThreadHelper::SendComplete, base::Unretained(io_helper_),
94 dispatcher_host_->RendererTransactionId(host_transaction_id)));
66 } 95 }
67 96
68 void IndexedDBDatabaseCallbacks::OnDatabaseChange( 97 void IndexedDBDatabaseCallbacks::OnDatabaseChange(
69 int32_t ipc_database_id, 98 int32_t ipc_database_id,
70 std::unique_ptr<IndexedDBObserverChanges> changes) { 99 std::unique_ptr<IndexedDBObserverChanges> changes) {
100 DCHECK(io_helper_);
71 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges( 101 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges(
72 ipc_thread_id_, ipc_database_id, 102 ipc_thread_id_, ipc_database_id,
73 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes)))); 103 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes))));
74 } 104 }
75 105
106 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper(
107 DatabaseCallbacksAssociatedPtrInfo callbacks_info) {
108 callbacks_.Bind(std::move(callbacks_info));
109 }
110
111 IndexedDBDatabaseCallbacks::IOThreadHelper::~IOThreadHelper() {}
112
113 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendForcedClose() {
114 callbacks_->ForcedClose();
115 }
116
117 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendVersionChange(
118 int64_t old_version,
119 int64_t new_version) {
120 callbacks_->VersionChange(old_version, new_version);
121 }
122
123 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendAbort(
124 int64_t transaction_id,
125 const IndexedDBDatabaseError& error) {
126 callbacks_->Abort(transaction_id, error.code(), error.message());
127 }
128
129 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendComplete(
130 int64_t transaction_id) {
131 callbacks_->Complete(transaction_id);
132 }
133
76 } // namespace content 134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698