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

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

Issue 1963293002: Replacing Indexed DB Chromium IPC with Mojo Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring after Passing URLRequestContextGetter. Created 4 years, 4 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
« no previous file with comments | « content/browser/indexed_db/database_impl.h ('k') | content/browser/indexed_db/indexed_db.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/browser/indexed_db/database_impl.h"
6
7 #include <string>
8 #include <utility>
9 #include <vector>
10
11 #include "content/browser/indexed_db/indexed_db_connection.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/indexed_db_context.h"
14 #include "content/public/browser/storage_partition.h"
15 #include "mojo/public/cpp/bindings/binding.h"
16 #include "mojo/public/cpp/bindings/interface_request.h"
17
18 namespace content {
19
20 using ::indexed_db::mojom::BlobInfoPtr;
21 using ::indexed_db::mojom::CursorDirection;
22 using ::indexed_db::mojom::DatabaseRequest;
23 using ::indexed_db::mojom::GetResult;
24 using ::indexed_db::mojom::GetResultPtr;
25 using ::indexed_db::mojom::KeyPtr;
26 using ::indexed_db::mojom::KeyRangePtr;
27 using ::indexed_db::mojom::PutMode;
28 using ::indexed_db::mojom::TaskType;
29 using ::indexed_db::mojom::TransactionMode;
30
31 DatabaseImpl::DatabaseImpl(BrowserContext* context,
32 IndexedDBContext* indexed_db_context,
33 DatabaseRequest request)
34 : context_(context),
35 indexed_db_context_(indexed_db_context),
36 binding_(this, std::move(request)) {
37 // TODO(cmumford): Eventually delete member if not needed.
38 (void)context_;
39 }
40
41 DatabaseImpl::~DatabaseImpl() = default;
42
43 void DatabaseImpl::Create(BrowserContext* context, DatabaseRequest request) {
44 // TODO(cmumford): Is |Default| OK?
45 StoragePartition* storage_partition =
46 BrowserContext::GetDefaultStoragePartition(context);
47 new DatabaseImpl(context, storage_partition->GetIndexedDBContext(),
48 std::move(request));
49 }
50
51 void DatabaseImpl::CreateObjectStore(int64_t transaction_id,
52 int64_t object_store_id,
53 const std::string& name,
54 const IndexedDBKeyPath& key_path,
55 bool auto_increment) {}
56
57 void DatabaseImpl::DeleteObjectStore(int64_t transaction_id,
58 int64_t object_store_id) {}
59
60 void DatabaseImpl::CreateTransaction(int64_t id,
61 const std::vector<int64_t>& scope,
62 TransactionMode transaction_mode) {}
63
64 void DatabaseImpl::DatabaseImpl::Close() {}
65
66 void DatabaseImpl::VersionChangeIgnored() {}
67
68 void DatabaseImpl::Abort(int64_t transaction_id) {}
69
70 void DatabaseImpl::Commit(int64_t transaction_id) {}
71
72 void DatabaseImpl::CreateIndex(int64_t transaction_id,
73 int64_t object_store_id,
74 int64_t index_id,
75 const std::string& name,
76 const IndexedDBKeyPath& key_path,
77 bool unique,
78 bool multi_entry) {}
79
80 void DatabaseImpl::DeleteIndex(int64_t transaction_id,
81 int64_t object_store_id,
82 int64_t index_id) {}
83
84 void DatabaseImpl::Get(int64_t transaction_id,
85 int64_t object_store_id,
86 int64_t index_id,
87 KeyRangePtr key_range,
88 bool key_only,
89 const GetCallback& callback) {
90 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
91 #if 0
92 IndexedDBConnection* connection =
93 GetOrTerminateProcess(&connection_map_, database_id);
94 if (!connection || !connection->IsConnected())
95 return;
96
97 connection->database()->Get(
98 HostTransactionId(transaction_id), object_store_id,
99 index_id,
100 base::WrapUnique(new IndexedDBKeyRange(key_range)),
101 params.key_only, callbacks);
102 #endif
103 #if 0
104 DCHECK(parent_->context()->TaskRunner()->RunsTasksOnCurrentThread());
105 IndexedDBConnection* connection =
106 parent_->GetOrTerminateProcess(&map_, params.ipc_database_id);
107 if (!connection || !connection->IsConnected())
108 return;
109
110 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
111 parent_, params.ipc_thread_id, params.ipc_callbacks_id));
112 connection->database()->Get(
113 parent_->HostTransactionId(params.transaction_id), params.object_store_id,
114 params.index_id,
115 base::WrapUnique(new IndexedDBKeyRange(params.key_range)),
116 params.key_only, callbacks);
117 #endif
118
119 // TODO(cmumford): Set the error data.
120 IndexedDBDatabaseError error;
121 // TODO(cmumford): Can we somehow use GetResult::From()?
122 GetResultPtr result = GetResult::New();
123 result->set_error(error);
124 callback.Run(std::move(result));
125 }
126
127 void DatabaseImpl::GetAll(int64_t transaction_id,
128 int64_t object_store_id,
129 int64_t index_id,
130 KeyRangePtr key_range,
131 int64_t max_count,
132 bool key_only) {}
133
134 void DatabaseImpl::Put(int64_t transaction_id,
135 int64_t object_store_id,
136 const std::vector<int8_t>& value,
137 std::vector<BlobInfoPtr> blob_info,
138 KeyPtr key,
139 PutMode put_mode,
140 const std::vector<int64_t>& index_ids,
141 std::vector<std::vector<KeyPtr>> index_keys) {}
142
143 void DatabaseImpl::DeleteRange(int64_t transaction_id,
144 int64_t object_store_id,
145 KeyRangePtr key_range) {}
146
147 void DatabaseImpl::Clear(int64_t transaction_id, int64_t object_store_id) {}
148
149 void DatabaseImpl::SetIndexKeys(int64_t transaction_id,
150 int64_t object_store_id,
151 KeyPtr primary_key,
152 const std::vector<int64_t>& index_ids,
153 std::vector<std::vector<KeyPtr>> index_keys) {}
154
155 void DatabaseImpl::SetIndexesReady(int64_t transaction_id,
156 int64_t object_store_id,
157 const std::vector<int64_t>& index_ids) {}
158
159 void DatabaseImpl::OpenCursor(int64_t transaction_id,
160 int64_t object_store_id,
161 int64_t index_id,
162 KeyRangePtr key_range,
163 CursorDirection direction,
164 bool key_only,
165 TaskType task_type) {}
166
167 void DatabaseImpl::Count(int64_t transaction_id,
168 int64_t object_store_id,
169 int64_t index_id,
170 KeyRangePtr key_range) {}
171
172 void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) {}
173
174 void DatabaseImpl::CrashRendererAndClosePipe(
175 bad_message::BadMessageReason reason) {
176 // TODO(cmumford): Replace with preferred solution once implemented.
177 // https://groups.google.com/a/chromium.org/forum/#!topic/chromium-mojo/aPfAww 28ELo
178 bad_message::ReceivedBadMessage(GetRenderProcessHost(), reason);
179
180 // Looks like we need to use Binding instead of StrongBinding to get Close().
181 // binding_.Close();
182 }
183
184 RenderProcessHost* DatabaseImpl::GetRenderProcessHost() {
185 // TODO(cmumford): Need to implement this.
186 NOTREACHED();
187 // return render_frame_host_->GetProcess();
188 return nullptr;
189 }
190
191 //////////////////////////////////////////////////////////////////////
192 // Helper templates.
193 //
194
195 template <typename ObjectType>
196 ObjectType* DatabaseImpl::GetOrTerminateProcess(
197 IDMap<ObjectType, IDMapOwnPointer>* map,
198 int32_t ipc_return_object_id) {
199 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
200 ObjectType* return_object = map->Lookup(ipc_return_object_id);
201 if (!return_object) {
202 NOTREACHED() << "Uh oh, couldn't find object with id "
203 << ipc_return_object_id;
204 CrashRendererAndClosePipe(bad_message::IDBDH_GET_OR_TERMINATE);
205 }
206 return return_object;
207 }
208
209 template <typename ObjectType>
210 ObjectType* DatabaseImpl::GetOrTerminateProcess(RefIDMap<ObjectType>* map,
211 int32_t ipc_return_object_id) {
212 DCHECK(indexed_db_context_->TaskRunner()->RunsTasksOnCurrentThread());
213 ObjectType* return_object = map->Lookup(ipc_return_object_id);
214 if (!return_object) {
215 NOTREACHED() << "Uh oh, couldn't find object with id "
216 << ipc_return_object_id;
217 CrashRendererAndClosePipe(bad_message::IDBDH_GET_OR_TERMINATE);
218 }
219 return return_object;
220 }
221
222 template <typename MapType>
223 void DatabaseImpl::DestroyObject(MapType* map, int32_t ipc_object_id) {
224 GetOrTerminateProcess(map, ipc_object_id);
225 map->Remove(ipc_object_id);
226 }
227
228 #if 0
229 int64_t DatabaseImpl::HostTransactionId(int64_t transaction_id) {
230 // Inject the renderer process id into the transaction id, to
231 // uniquely identify this transaction, and effectively bind it to
232 // the renderer that initiated it. The lower 32 bits of
233 // transaction_id are guaranteed to be unique within that renderer.
234 base::ProcessId pid = peer_pid();
235 DCHECK(!(transaction_id >> 32)) << "Transaction ids can only be 32 bits";
236 static_assert(sizeof(base::ProcessId) <= sizeof(int32_t),
237 "Process ID must fit in 32 bits");
238
239 return transaction_id | (static_cast<uint64_t>(pid) << 32);
240 }
241
242 int64_t DatabaseImpl::RendererTransactionId(int64_t host_transaction_id) {
243 DCHECK(host_transaction_id >> 32 == peer_pid())
244 << "Invalid renderer target for transaction id";
245 return host_transaction_id & 0xffffffff;
246 }
247 #endif
248
249 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/database_impl.h ('k') | content/browser/indexed_db/indexed_db.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698