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

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

Issue 2320213004: Port IndexedDB open() and database callbacks to Mojo. (Closed)
Patch Set: Make DatabaseClient an associated interface. Created 4 years, 3 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"
8 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 7 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
9 #include "content/browser/indexed_db/indexed_db_observer_changes.h" 8 #include "content/browser/indexed_db/indexed_db_observer_changes.h"
9 #include "content/common/indexed_db/indexed_db_database_error.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::DatabaseClientAssociatedPtr;
13
12 namespace content { 14 namespace content {
13 15
16 class IndexedDBDatabaseCallbacks::IOThreadHelper {
17 public:
18 IOThreadHelper(DatabaseClientAssociatedPtr client);
19 ~IOThreadHelper();
20
21 void OnForcedClosed();
22 void OnVersionChange(int64_t old_version, int64_t new_version);
23 void OnAbort(int64_t transaction_id, const IndexedDBDatabaseError& error);
24 void OnComplete(int64_t transaction_id);
25
26 private:
27 DatabaseClientAssociatedPtr client_;
28 };
29
14 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( 30 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks(
15 IndexedDBDispatcherHost* dispatcher_host, 31 IndexedDBDispatcherHost* dispatcher_host,
16 int ipc_thread_id, 32 int ipc_thread_id,
17 int ipc_database_callbacks_id) 33 DatabaseClientAssociatedPtr client)
18 : dispatcher_host_(dispatcher_host), 34 : dispatcher_host_(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 io_thread_helper_(nullptr) {
37 if (client)
38 io_thread_helper_ = new IOThreadHelper(std::move(client));
39 }
21 40
22 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {} 41 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {
42 if (io_thread_helper_)
43 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, io_thread_helper_);
44 }
23 45
24 void IndexedDBDatabaseCallbacks::OnForcedClose() { 46 void IndexedDBDatabaseCallbacks::OnForcedClose() {
25 if (!dispatcher_host_.get()) 47 dispatcher_host_ = nullptr;
26 return; 48 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
27 49 base::Bind(&IOThreadHelper::OnForcedClosed,
28 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksForcedClose( 50 base::Unretained(io_thread_helper_)));
29 ipc_thread_id_, ipc_database_callbacks_id_));
30
31 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 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
37 return; 56 base::Bind(&IOThreadHelper::OnVersionChange,
38 57 base::Unretained(io_thread_helper_),
39 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksVersionChange( 58 old_version, new_version));
40 ipc_thread_id_, ipc_database_callbacks_id_, old_version, new_version));
41 } 59 }
42 60
43 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id, 61 void IndexedDBDatabaseCallbacks::OnAbort(int64_t host_transaction_id,
44 const IndexedDBDatabaseError& error) { 62 const IndexedDBDatabaseError& error) {
45 if (!dispatcher_host_.get()) 63 if (!dispatcher_host_.get())
46 return; 64 return;
47 65
48 dispatcher_host_->FinishTransaction(host_transaction_id, false); 66 dispatcher_host_->FinishTransaction(host_transaction_id, false);
49 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksAbort( 67 BrowserThread::PostTask(
50 ipc_thread_id_, 68 BrowserThread::IO, FROM_HERE,
51 ipc_database_callbacks_id_, 69 base::Bind(&IOThreadHelper::OnAbort, base::Unretained(io_thread_helper_),
52 dispatcher_host_->RendererTransactionId(host_transaction_id), 70 dispatcher_host_->RendererTransactionId(host_transaction_id),
53 error.code(), 71 error));
54 error.message()));
55 } 72 }
56 73
57 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) { 74 void IndexedDBDatabaseCallbacks::OnComplete(int64_t host_transaction_id) {
58 if (!dispatcher_host_.get()) 75 if (!dispatcher_host_.get())
59 return; 76 return;
60 77
61 dispatcher_host_->FinishTransaction(host_transaction_id, true); 78 dispatcher_host_->FinishTransaction(host_transaction_id, true);
62 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksComplete( 79 BrowserThread::PostTask(
63 ipc_thread_id_, 80 BrowserThread::IO, FROM_HERE,
64 ipc_database_callbacks_id_, 81 base::Bind(&IOThreadHelper::OnComplete,
65 dispatcher_host_->RendererTransactionId(host_transaction_id))); 82 base::Unretained(io_thread_helper_),
83 dispatcher_host_->RendererTransactionId(host_transaction_id)));
66 } 84 }
67 85
68 void IndexedDBDatabaseCallbacks::OnDatabaseChange( 86 void IndexedDBDatabaseCallbacks::OnDatabaseChange(
69 int32_t ipc_database_id, 87 int32_t ipc_database_id,
70 std::unique_ptr<IndexedDBObserverChanges> changes) { 88 std::unique_ptr<IndexedDBObserverChanges> changes) {
71 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges( 89 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges(
72 ipc_thread_id_, ipc_database_id, 90 ipc_thread_id_, ipc_database_id,
73 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes)))); 91 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes))));
74 } 92 }
75 93
94 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper(
95 DatabaseClientAssociatedPtr client)
96 : client_(std::move(client)) {}
97
98 IndexedDBDatabaseCallbacks::IOThreadHelper::~IOThreadHelper() = default;
99
100 void IndexedDBDatabaseCallbacks::IOThreadHelper::OnForcedClosed() {
101 client_->OnForcedClosed();
102 }
103
104 void IndexedDBDatabaseCallbacks::IOThreadHelper::OnVersionChange(
105 int64_t old_version,
106 int64_t new_version) {
107 client_->OnVersionChange(old_version, new_version);
108 }
109
110 void IndexedDBDatabaseCallbacks::IOThreadHelper::OnAbort(
111 int64_t transaction_id,
112 const IndexedDBDatabaseError& error) {
113 client_->OnTransactionAborted(transaction_id, error);
114 }
115
116 void IndexedDBDatabaseCallbacks::IOThreadHelper::OnComplete(
117 int64_t transaction_id) {
118 client_->OnTransactionCompleted(transaction_id);
119 }
120
76 } // namespace content 121 } // 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_error.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698