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

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

Issue 2511403003: Send IndexedDB observations through IDBDatabaseCallbacks. (Closed)
Patch Set: Rebased. Created 4 years, 1 month 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_context_impl.h" 7 #include "content/browser/indexed_db/indexed_db_context_impl.h"
8 #include "content/browser/indexed_db/indexed_db_database_error.h" 8 #include "content/browser/indexed_db/indexed_db_database_error.h"
9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h" 9 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
10 #include "content/browser/indexed_db/indexed_db_observer_changes.h"
11 #include "content/common/indexed_db/indexed_db_messages.h"
12 10
13 using ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo; 11 using ::indexed_db::mojom::DatabaseCallbacksAssociatedPtrInfo;
14 12
15 namespace content { 13 namespace content {
16 14
17 class IndexedDBDatabaseCallbacks::IOThreadHelper { 15 class IndexedDBDatabaseCallbacks::IOThreadHelper {
18 public: 16 public:
19 explicit IOThreadHelper(DatabaseCallbacksAssociatedPtrInfo callbacks_info); 17 explicit IOThreadHelper(DatabaseCallbacksAssociatedPtrInfo callbacks_info);
20 ~IOThreadHelper(); 18 ~IOThreadHelper();
21 19
22 void SendForcedClose(); 20 void SendForcedClose();
23 void SendVersionChange(int64_t old_version, int64_t new_version); 21 void SendVersionChange(int64_t old_version, int64_t new_version);
24 void SendAbort(int64_t transaction_id, const IndexedDBDatabaseError& error); 22 void SendAbort(int64_t transaction_id, const IndexedDBDatabaseError& error);
25 void SendComplete(int64_t transaction_id); 23 void SendComplete(int64_t transaction_id);
24 void SendChanges(::indexed_db::mojom::ObserverChangesPtr changes);
26 25
27 private: 26 private:
28 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtr callbacks_; 27 ::indexed_db::mojom::DatabaseCallbacksAssociatedPtr callbacks_;
29 28
30 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper); 29 DISALLOW_COPY_AND_ASSIGN(IOThreadHelper);
31 }; 30 };
32 31
33 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks( 32 IndexedDBDatabaseCallbacks::IndexedDBDatabaseCallbacks(
34 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host, 33 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host,
35 int32_t ipc_thread_id,
36 DatabaseCallbacksAssociatedPtrInfo callbacks_info) 34 DatabaseCallbacksAssociatedPtrInfo callbacks_info)
37 : dispatcher_host_(std::move(dispatcher_host)), 35 : dispatcher_host_(std::move(dispatcher_host)),
38 ipc_thread_id_(ipc_thread_id),
39 io_helper_(new IOThreadHelper(std::move(callbacks_info))) { 36 io_helper_(new IOThreadHelper(std::move(callbacks_info))) {
40 DCHECK_CURRENTLY_ON(BrowserThread::IO); 37 DCHECK_CURRENTLY_ON(BrowserThread::IO);
41 thread_checker_.DetachFromThread(); 38 thread_checker_.DetachFromThread();
42 } 39 }
43 40
44 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() { 41 IndexedDBDatabaseCallbacks::~IndexedDBDatabaseCallbacks() {
45 DCHECK(thread_checker_.CalledOnValidThread()); 42 DCHECK(thread_checker_.CalledOnValidThread());
46 } 43 }
47 44
48 void IndexedDBDatabaseCallbacks::OnForcedClose() { 45 void IndexedDBDatabaseCallbacks::OnForcedClose() {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 dispatcher_host_->FinishTransaction(host_transaction_id, true); 90 dispatcher_host_->FinishTransaction(host_transaction_id, true);
94 DCHECK(io_helper_); 91 DCHECK(io_helper_);
95 BrowserThread::PostTask( 92 BrowserThread::PostTask(
96 BrowserThread::IO, FROM_HERE, 93 BrowserThread::IO, FROM_HERE,
97 base::Bind(&IOThreadHelper::SendComplete, 94 base::Bind(&IOThreadHelper::SendComplete,
98 base::Unretained(io_helper_.get()), 95 base::Unretained(io_helper_.get()),
99 dispatcher_host_->RendererTransactionId(host_transaction_id))); 96 dispatcher_host_->RendererTransactionId(host_transaction_id)));
100 } 97 }
101 98
102 void IndexedDBDatabaseCallbacks::OnDatabaseChange( 99 void IndexedDBDatabaseCallbacks::OnDatabaseChange(
103 std::unique_ptr<IndexedDBObserverChanges> changes) { 100 ::indexed_db::mojom::ObserverChangesPtr changes) {
104 DCHECK(thread_checker_.CalledOnValidThread()); 101 DCHECK(thread_checker_.CalledOnValidThread());
105 DCHECK(io_helper_); 102 DCHECK(io_helper_);
106 dispatcher_host_->Send(new IndexedDBMsg_DatabaseCallbacksChanges( 103 BrowserThread::PostTask(
107 ipc_thread_id_, 104 BrowserThread::IO, FROM_HERE,
108 IndexedDBDispatcherHost::ConvertObserverChanges(std::move(changes)))); 105 base::Bind(&IOThreadHelper::SendChanges,
106 base::Unretained(io_helper_.get()), base::Passed(&changes)));
109 } 107 }
110 108
111 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper( 109 IndexedDBDatabaseCallbacks::IOThreadHelper::IOThreadHelper(
112 DatabaseCallbacksAssociatedPtrInfo callbacks_info) { 110 DatabaseCallbacksAssociatedPtrInfo callbacks_info) {
113 callbacks_.Bind(std::move(callbacks_info)); 111 callbacks_.Bind(std::move(callbacks_info));
114 } 112 }
115 113
116 IndexedDBDatabaseCallbacks::IOThreadHelper::~IOThreadHelper() {} 114 IndexedDBDatabaseCallbacks::IOThreadHelper::~IOThreadHelper() {}
117 115
118 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendForcedClose() { 116 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendForcedClose() {
(...skipping 10 matching lines...) Expand all
129 int64_t transaction_id, 127 int64_t transaction_id,
130 const IndexedDBDatabaseError& error) { 128 const IndexedDBDatabaseError& error) {
131 callbacks_->Abort(transaction_id, error.code(), error.message()); 129 callbacks_->Abort(transaction_id, error.code(), error.message());
132 } 130 }
133 131
134 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendComplete( 132 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendComplete(
135 int64_t transaction_id) { 133 int64_t transaction_id) {
136 callbacks_->Complete(transaction_id); 134 callbacks_->Complete(transaction_id);
137 } 135 }
138 136
137 void IndexedDBDatabaseCallbacks::IOThreadHelper::SendChanges(
138 ::indexed_db::mojom::ObserverChangesPtr changes) {
139 callbacks_->Changes(std::move(changes));
140 }
141
139 } // namespace content 142 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698