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

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

Issue 2449953008: Port messages sent by WebIDBDatabaseImpl to Mojo. (Closed)
Patch Set: Address more comments from dcheng@. 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
(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 "content/browser/bad_message.h"
8 #include "content/browser/child_process_security_policy_impl.h"
9 #include "content/browser/indexed_db/indexed_db_connection.h"
10 #include "content/browser/indexed_db/indexed_db_context_impl.h"
11 #include "content/browser/indexed_db/indexed_db_dispatcher_host.h"
12 #include "content/browser/indexed_db/indexed_db_value.h"
13 #include "content/common/indexed_db/indexed_db_messages.h"
14 #include "storage/browser/blob/blob_storage_context.h"
15 #include "storage/browser/quota/quota_manager_proxy.h"
16 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBDatabaseExc eption.h"
17
18 using std::swap;
19
20 namespace content {
21
22 namespace {
23 const char kInvalidBlobUuid[] = "Blob UUID is invalid";
24 } // namespace
25
26 class DatabaseImpl::IDBThreadHelper {
27 public:
28 IDBThreadHelper(std::unique_ptr<IndexedDBConnection> connection,
29 const url::Origin& origin,
30 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host);
31 ~IDBThreadHelper();
32
33 void CreateObjectStore(int64_t transaction_id,
34 int64_t object_store_id,
35 const base::string16& name,
36 const IndexedDBKeyPath& key_path,
37 bool auto_increment);
38 void DeleteObjectStore(int64_t transaction_id, int64_t object_store_id);
39 void RenameObjectStore(int64_t transaction_id,
40 int64_t object_store_id,
41 const base::string16& new_name);
42 void CreateTransaction(int64_t transaction_id,
43 const std::vector<int64_t>& object_store_ids,
44 blink::WebIDBTransactionMode mode);
45 void Close();
46 void VersionChangeIgnored();
47 void AddObserver(int64_t transaction_id,
48 int32_t observer_id,
49 bool include_transaction,
50 bool no_records,
51 bool values,
52 uint16_t operation_types);
53 void RemoveObservers(const std::vector<int32_t>& observers);
54 void Get(int64_t transaction_id,
55 int64_t object_store_id,
56 int64_t index_id,
57 const IndexedDBKeyRange& key_range,
58 bool key_only,
59 scoped_refptr<IndexedDBCallbacks> callbacks);
60 void GetAll(int64_t transaction_id,
61 int64_t object_store_id,
62 int64_t index_id,
63 const IndexedDBKeyRange& key_range,
64 bool key_only,
65 int64_t max_count,
66 scoped_refptr<IndexedDBCallbacks> callbacks);
67 void Put(int64_t transaction_id,
68 int64_t object_store_id,
69 ::indexed_db::mojom::ValuePtr value,
70 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles,
71 const IndexedDBKey& key,
72 blink::WebIDBPutMode mode,
73 const std::vector<IndexedDBIndexKeys>& index_keys,
74 scoped_refptr<IndexedDBCallbacks> callbacks);
75 void SetIndexKeys(int64_t transaction_id,
76 int64_t object_store_id,
77 const IndexedDBKey& primary_key,
78 const std::vector<IndexedDBIndexKeys>& index_keys);
79 void SetIndexesReady(int64_t transaction_id,
80 int64_t object_store_id,
81 const std::vector<int64_t>& index_ids);
82 void OpenCursor(int64_t transaction_id,
83 int64_t object_store_id,
84 int64_t index_id,
85 const IndexedDBKeyRange& key_range,
86 blink::WebIDBCursorDirection direction,
87 bool key_only,
88 blink::WebIDBTaskType task_type,
89 scoped_refptr<IndexedDBCallbacks> callbacks);
90 void Count(int64_t transaction_id,
91 int64_t object_store_id,
92 int64_t index_id,
93 const IndexedDBKeyRange& key_range,
94 scoped_refptr<IndexedDBCallbacks> callbacks);
95 void DeleteRange(int64_t transaction_id,
96 int64_t object_store_id,
97 const IndexedDBKeyRange& key_range,
98 scoped_refptr<IndexedDBCallbacks> callbacks);
99 void Clear(int64_t transaction_id,
100 int64_t object_store_id,
101 scoped_refptr<IndexedDBCallbacks> callbacks);
102 void CreateIndex(int64_t transaction_id,
103 int64_t object_store_id,
104 int64_t index_id,
105 const base::string16& name,
106 const IndexedDBKeyPath& key_path,
107 bool unique,
108 bool multi_entry);
109 void DeleteIndex(int64_t transaction_id,
110 int64_t object_store_id,
111 int64_t index_id);
112 void RenameIndex(int64_t transaction_id,
113 int64_t object_store_id,
114 int64_t index_id,
115 const base::string16& new_name);
116 void Abort(int64_t transaction_id);
117 void Commit(int64_t transaction_id);
118 void OnGotUsageAndQuotaForCommit(int64_t transaction_id,
119 storage::QuotaStatusCode status,
120 int64_t usage,
121 int64_t quota);
122 void AckReceivedBlobs(const std::vector<std::string>& uuids);
123
124 private:
125 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host_;
126 std::unique_ptr<IndexedDBConnection> connection_;
127 const url::Origin origin_;
128 base::WeakPtrFactory<IDBThreadHelper> weak_factory_;
129 };
130
131 DatabaseImpl::DatabaseImpl(
132 std::unique_ptr<IndexedDBConnection> connection,
133 const url::Origin& origin,
134 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host)
135 : dispatcher_host_(dispatcher_host),
136 origin_(origin),
137 idb_runner_(base::ThreadTaskRunnerHandle::Get()) {
138 helper_ = new IDBThreadHelper(std::move(connection), origin,
139 std::move(dispatcher_host));
140 }
141
142 DatabaseImpl::~DatabaseImpl() {
143 idb_runner_->DeleteSoon(FROM_HERE, helper_);
144 }
145
146 void DatabaseImpl::CreateObjectStore(int64_t transaction_id,
147 int64_t object_store_id,
148 const base::string16& name,
149 const IndexedDBKeyPath& key_path,
150 bool auto_increment) {
151 idb_runner_->PostTask(
152 FROM_HERE, base::Bind(&IDBThreadHelper::CreateObjectStore,
153 base::Unretained(helper_), transaction_id,
154 object_store_id, name, key_path, auto_increment));
155 }
156
157 void DatabaseImpl::DeleteObjectStore(int64_t transaction_id,
158 int64_t object_store_id) {
159 idb_runner_->PostTask(
160 FROM_HERE,
161 base::Bind(&IDBThreadHelper::DeleteObjectStore, base::Unretained(helper_),
162 transaction_id, object_store_id));
163 }
164
165 void DatabaseImpl::RenameObjectStore(int64_t transaction_id,
166 int64_t object_store_id,
167 const base::string16& new_name) {
168 idb_runner_->PostTask(
169 FROM_HERE,
170 base::Bind(&IDBThreadHelper::RenameObjectStore, base::Unretained(helper_),
171 transaction_id, object_store_id, new_name));
172 }
173
174 void DatabaseImpl::CreateTransaction(
175 int64_t transaction_id,
176 const std::vector<int64_t>& object_store_ids,
177 blink::WebIDBTransactionMode mode) {
178 idb_runner_->PostTask(
179 FROM_HERE,
180 base::Bind(&IDBThreadHelper::CreateTransaction, base::Unretained(helper_),
181 transaction_id, object_store_ids, mode));
182 }
183
184 void DatabaseImpl::Close() {
185 idb_runner_->PostTask(FROM_HERE, base::Bind(&IDBThreadHelper::Close,
186 base::Unretained(helper_)));
187 }
188
189 void DatabaseImpl::VersionChangeIgnored() {
190 idb_runner_->PostTask(FROM_HERE,
191 base::Bind(&IDBThreadHelper::VersionChangeIgnored,
192 base::Unretained(helper_)));
193 }
194
195 void DatabaseImpl::AddObserver(int64_t transaction_id,
196 int32_t observer_id,
197 bool include_transaction,
198 bool no_records,
199 bool values,
200 uint16_t operation_types) {
201 idb_runner_->PostTask(
202 FROM_HERE,
203 base::Bind(&IDBThreadHelper::AddObserver, base::Unretained(helper_),
204 transaction_id, observer_id, include_transaction, no_records,
205 values, operation_types));
206 }
207
208 void DatabaseImpl::RemoveObservers(const std::vector<int32_t>& observers) {
209 idb_runner_->PostTask(FROM_HERE,
210 base::Bind(&IDBThreadHelper::RemoveObservers,
211 base::Unretained(helper_), observers));
212 }
213
214 void DatabaseImpl::Get(
215 int64_t transaction_id,
216 int64_t object_store_id,
217 int64_t index_id,
218 const IndexedDBKeyRange& key_range,
219 bool key_only,
220 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
221 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
222 dispatcher_host_.get(), origin_, std::move(callbacks_info)));
223 idb_runner_->PostTask(
224 FROM_HERE, base::Bind(&IDBThreadHelper::Get, base::Unretained(helper_),
225 transaction_id, object_store_id, index_id,
226 key_range, key_only, base::Passed(&callbacks)));
227 }
228
229 void DatabaseImpl::GetAll(
230 int64_t transaction_id,
231 int64_t object_store_id,
232 int64_t index_id,
233 const IndexedDBKeyRange& key_range,
234 bool key_only,
235 int64_t max_count,
236 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
237 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
238 dispatcher_host_.get(), origin_, std::move(callbacks_info)));
239 idb_runner_->PostTask(
240 FROM_HERE,
241 base::Bind(&IDBThreadHelper::GetAll, base::Unretained(helper_),
242 transaction_id, object_store_id, index_id, key_range, key_only,
243 max_count, base::Passed(&callbacks)));
244 }
245
246 void DatabaseImpl::Put(
247 int64_t transaction_id,
248 int64_t object_store_id,
249 ::indexed_db::mojom::ValuePtr value,
250 const IndexedDBKey& key,
251 blink::WebIDBPutMode mode,
252 const std::vector<IndexedDBIndexKeys>& index_keys,
253 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
254 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles;
255 for (const auto& info : value->blob_or_file_info) {
256 std::unique_ptr<storage::BlobDataHandle> handle =
257 dispatcher_host_->blob_storage_context()->GetBlobDataFromUUID(
258 info->uuid);
259 if (!handle) {
260 mojo::ReportBadMessage(kInvalidBlobUuid);
261 return;
262 }
263 handles.push_back(std::move(handle));
264 }
265
266 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
267 dispatcher_host_.get(), origin_, std::move(callbacks_info)));
268
269 idb_runner_->PostTask(
270 FROM_HERE, base::Bind(&IDBThreadHelper::Put, base::Unretained(helper_),
271 transaction_id, object_store_id,
272 base::Passed(&value), base::Passed(&handles), key,
273 mode, index_keys, base::Passed(&callbacks)));
274 }
275
276 void DatabaseImpl::SetIndexKeys(
277 int64_t transaction_id,
278 int64_t object_store_id,
279 const IndexedDBKey& primary_key,
280 const std::vector<IndexedDBIndexKeys>& index_keys) {
281 idb_runner_->PostTask(
282 FROM_HERE,
283 base::Bind(&IDBThreadHelper::SetIndexKeys, base::Unretained(helper_),
284 transaction_id, object_store_id, primary_key, index_keys));
285 }
286
287 void DatabaseImpl::SetIndexesReady(int64_t transaction_id,
288 int64_t object_store_id,
289 const std::vector<int64_t>& index_ids) {
290 idb_runner_->PostTask(
291 FROM_HERE,
292 base::Bind(&IDBThreadHelper::SetIndexesReady, base::Unretained(helper_),
293 transaction_id, object_store_id, index_ids));
294 }
295
296 void DatabaseImpl::OpenCursor(
297 int64_t transaction_id,
298 int64_t object_store_id,
299 int64_t index_id,
300 const IndexedDBKeyRange& key_range,
301 blink::WebIDBCursorDirection direction,
302 bool key_only,
303 blink::WebIDBTaskType task_type,
304 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
305 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
306 dispatcher_host_.get(), origin_, std::move(callbacks_info)));
307 idb_runner_->PostTask(
308 FROM_HERE,
309 base::Bind(&IDBThreadHelper::OpenCursor, base::Unretained(helper_),
310 transaction_id, object_store_id, index_id, key_range,
311 direction, key_only, task_type, base::Passed(&callbacks)));
312 }
313
314 void DatabaseImpl::Count(
315 int64_t transaction_id,
316 int64_t object_store_id,
317 int64_t index_id,
318 const IndexedDBKeyRange& key_range,
319 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
320 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
321 dispatcher_host_.get(), origin_, std::move(callbacks_info)));
322 idb_runner_->PostTask(
323 FROM_HERE, base::Bind(&IDBThreadHelper::Count, base::Unretained(helper_),
324 transaction_id, object_store_id, index_id,
325 key_range, base::Passed(&callbacks)));
326 }
327
328 void DatabaseImpl::DeleteRange(
329 int64_t transaction_id,
330 int64_t object_store_id,
331 const IndexedDBKeyRange& key_range,
332 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
333 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
334 dispatcher_host_.get(), origin_, std::move(callbacks_info)));
335 idb_runner_->PostTask(
336 FROM_HERE,
337 base::Bind(&IDBThreadHelper::DeleteRange, base::Unretained(helper_),
338 transaction_id, object_store_id, key_range,
339 base::Passed(&callbacks)));
340 }
341
342 void DatabaseImpl::Clear(
343 int64_t transaction_id,
344 int64_t object_store_id,
345 ::indexed_db::mojom::CallbacksAssociatedPtrInfo callbacks_info) {
346 scoped_refptr<IndexedDBCallbacks> callbacks(new IndexedDBCallbacks(
347 dispatcher_host_.get(), origin_, std::move(callbacks_info)));
348 idb_runner_->PostTask(
349 FROM_HERE,
350 base::Bind(&IDBThreadHelper::Clear, base::Unretained(helper_),
351 transaction_id, object_store_id, base::Passed(&callbacks)));
352 }
353
354 void DatabaseImpl::CreateIndex(int64_t transaction_id,
355 int64_t object_store_id,
356 int64_t index_id,
357 const base::string16& name,
358 const IndexedDBKeyPath& key_path,
359 bool unique,
360 bool multi_entry) {
361 idb_runner_->PostTask(
362 FROM_HERE,
363 base::Bind(&IDBThreadHelper::CreateIndex, base::Unretained(helper_),
364 transaction_id, object_store_id, index_id, name, key_path,
365 unique, multi_entry));
366 }
367
368 void DatabaseImpl::DeleteIndex(int64_t transaction_id,
369 int64_t object_store_id,
370 int64_t index_id) {
371 idb_runner_->PostTask(
372 FROM_HERE,
373 base::Bind(&IDBThreadHelper::DeleteIndex, base::Unretained(helper_),
374 transaction_id, object_store_id, index_id));
375 }
376
377 void DatabaseImpl::RenameIndex(int64_t transaction_id,
378 int64_t object_store_id,
379 int64_t index_id,
380 const base::string16& new_name) {
381 idb_runner_->PostTask(
382 FROM_HERE,
383 base::Bind(&IDBThreadHelper::RenameIndex, base::Unretained(helper_),
384 transaction_id, object_store_id, index_id, new_name));
385 }
386
387 void DatabaseImpl::Abort(int64_t transaction_id) {
388 idb_runner_->PostTask(
389 FROM_HERE, base::Bind(&IDBThreadHelper::Abort, base::Unretained(helper_),
390 transaction_id));
391 }
392
393 void DatabaseImpl::Commit(int64_t transaction_id) {
394 idb_runner_->PostTask(
395 FROM_HERE, base::Bind(&IDBThreadHelper::Commit, base::Unretained(helper_),
396 transaction_id));
397 }
398
399 void DatabaseImpl::AckReceivedBlobs(const std::vector<std::string>& uuids) {
400 for (const auto& uuid : uuids)
401 dispatcher_host_->DropBlobData(uuid);
402 }
403
404 DatabaseImpl::IDBThreadHelper::IDBThreadHelper(
405 std::unique_ptr<IndexedDBConnection> connection,
406 const url::Origin& origin,
407 scoped_refptr<IndexedDBDispatcherHost> dispatcher_host)
408 : dispatcher_host_(std::move(dispatcher_host)),
409 connection_(std::move(connection)),
410 origin_(origin),
411 weak_factory_(this) {
412 dispatcher_host_->context()->ConnectionOpened(origin_, connection.get());
413 }
414
415 DatabaseImpl::IDBThreadHelper::~IDBThreadHelper() {
416 if (connection_->IsConnected())
417 connection_->Close();
418 dispatcher_host_->context()->ConnectionClosed(origin_, connection_.get());
419 }
420
421 void DatabaseImpl::IDBThreadHelper::CreateObjectStore(
422 int64_t transaction_id,
423 int64_t object_store_id,
424 const base::string16& name,
425 const IndexedDBKeyPath& key_path,
426 bool auto_increment) {
427 if (!connection_->IsConnected())
428 return;
429
430 connection_->database()->CreateObjectStore(
431 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
432 name, key_path, auto_increment);
433 }
434
435 void DatabaseImpl::IDBThreadHelper::DeleteObjectStore(int64_t transaction_id,
436 int64_t object_store_id) {
437 if (!connection_->IsConnected())
438 return;
439
440 connection_->database()->DeleteObjectStore(
441 dispatcher_host_->HostTransactionId(transaction_id), object_store_id);
442 }
443
444 void DatabaseImpl::IDBThreadHelper::RenameObjectStore(
445 int64_t transaction_id,
446 int64_t object_store_id,
447 const base::string16& new_name) {
448 if (!connection_->IsConnected())
449 return;
450
451 connection_->database()->RenameObjectStore(
452 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
453 new_name);
454 }
455
456 void DatabaseImpl::IDBThreadHelper::CreateTransaction(
457 int64_t transaction_id,
458 const std::vector<int64_t>& object_store_ids,
459 blink::WebIDBTransactionMode mode) {
460 if (!connection_->IsConnected())
461 return;
462
463 int64_t host_transaction_id =
464 dispatcher_host_->HostTransactionId(transaction_id);
465 if (!dispatcher_host_->RegisterTransactionId(host_transaction_id, origin_)) {
466 DLOG(ERROR) << "Duplicate host_transaction_id.";
467 return;
468 }
469
470 connection_->database()->CreateTransaction(
471 host_transaction_id, connection_.get(), object_store_ids, mode);
472 }
473
474 void DatabaseImpl::IDBThreadHelper::Close() {
475 if (!connection_->IsConnected())
476 return;
477
478 connection_->Close();
479 }
480
481 void DatabaseImpl::IDBThreadHelper::VersionChangeIgnored() {
482 if (!connection_->IsConnected())
483 return;
484
485 connection_->VersionChangeIgnored();
486 }
487
488 void DatabaseImpl::IDBThreadHelper::AddObserver(int64_t transaction_id,
489 int32_t observer_id,
490 bool include_transaction,
491 bool no_records,
492 bool values,
493 uint16_t operation_types) {
494 if (!connection_->IsConnected())
495 return;
496
497 IndexedDBObserver::Options options(include_transaction, no_records, values,
498 operation_types);
499 connection_->database()->AddPendingObserver(
500 dispatcher_host_->HostTransactionId(transaction_id), observer_id,
501 options);
502 }
503
504 void DatabaseImpl::IDBThreadHelper::RemoveObservers(
505 const std::vector<int32_t>& observers) {
506 if (!connection_->IsConnected())
507 return;
508
509 connection_->RemoveObservers(observers);
510 }
511
512 void DatabaseImpl::IDBThreadHelper::Get(
513 int64_t transaction_id,
514 int64_t object_store_id,
515 int64_t index_id,
516 const IndexedDBKeyRange& key_range,
517 bool key_only,
518 scoped_refptr<IndexedDBCallbacks> callbacks) {
519 if (!connection_->IsConnected())
520 return;
521
522 connection_->database()->Get(
523 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
524 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), key_only,
525 callbacks);
526 }
527
528 void DatabaseImpl::IDBThreadHelper::GetAll(
529 int64_t transaction_id,
530 int64_t object_store_id,
531 int64_t index_id,
532 const IndexedDBKeyRange& key_range,
533 bool key_only,
534 int64_t max_count,
535 scoped_refptr<IndexedDBCallbacks> callbacks) {
536 if (!connection_->IsConnected())
537 return;
538
539 connection_->database()->GetAll(
540 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
541 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), key_only,
542 max_count, std::move(callbacks));
543 }
544
545 void DatabaseImpl::IDBThreadHelper::Put(
546 int64_t transaction_id,
547 int64_t object_store_id,
548 ::indexed_db::mojom::ValuePtr mojo_value,
549 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles,
550 const IndexedDBKey& key,
551 blink::WebIDBPutMode mode,
552 const std::vector<IndexedDBIndexKeys>& index_keys,
553 scoped_refptr<IndexedDBCallbacks> callbacks) {
554 if (!connection_->IsConnected())
555 return;
556
557 int64_t host_transaction_id =
558 dispatcher_host_->HostTransactionId(transaction_id);
559
560 ChildProcessSecurityPolicyImpl* policy =
561 ChildProcessSecurityPolicyImpl::GetInstance();
562 std::vector<IndexedDBBlobInfo> blob_info(
563 mojo_value->blob_or_file_info.size());
564 for (size_t i = 0; i < mojo_value->blob_or_file_info.size(); ++i) {
565 const auto& info = mojo_value->blob_or_file_info[i];
566 if (info->file) {
567 if (!info->file->path.empty()) {
568 if (!policy->CanReadFile(dispatcher_host_->ipc_process_id(),
569 info->file->path)) {
570 bad_message::ReceivedBadMessage(dispatcher_host_.get(),
571 bad_message::IDBDH_CAN_READ_FILE);
572 return;
573 }
574 }
575 blob_info[i] = IndexedDBBlobInfo(info->uuid, info->file->path,
576 info->file->name, info->mime_type);
577 if (info->size != static_cast<uint64_t>(-1)) {
578 blob_info[i].set_last_modified(info->file->last_modified);
579 blob_info[i].set_size(info->size);
580 }
581 } else {
582 blob_info[i] = IndexedDBBlobInfo(info->uuid, info->mime_type, info->size);
583 }
584 }
585
586 uint64_t commit_size = mojo_value->bits.size();
587 IndexedDBValue value;
588 swap(value.bits, mojo_value->bits);
589 swap(value.blob_info, blob_info);
590 connection_->database()->Put(host_transaction_id, object_store_id, &value,
591 &handles, base::MakeUnique<IndexedDBKey>(key),
592 mode, std::move(callbacks), index_keys);
593
594 // Size can't be big enough to overflow because it represents the
595 // actual bytes passed through IPC.
596 dispatcher_host_->AddToTransaction(host_transaction_id, commit_size);
597 }
598
599 void DatabaseImpl::IDBThreadHelper::SetIndexKeys(
600 int64_t transaction_id,
601 int64_t object_store_id,
602 const IndexedDBKey& primary_key,
603 const std::vector<IndexedDBIndexKeys>& index_keys) {
604 if (!connection_->IsConnected())
605 return;
606
607 connection_->database()->SetIndexKeys(
608 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
609 base::MakeUnique<IndexedDBKey>(primary_key), index_keys);
610 }
611
612 void DatabaseImpl::IDBThreadHelper::SetIndexesReady(
613 int64_t transaction_id,
614 int64_t object_store_id,
615 const std::vector<int64_t>& index_ids) {
616 if (!connection_->IsConnected())
617 return;
618
619 connection_->database()->SetIndexesReady(
620 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
621 index_ids);
622 }
623
624 void DatabaseImpl::IDBThreadHelper::OpenCursor(
625 int64_t transaction_id,
626 int64_t object_store_id,
627 int64_t index_id,
628 const IndexedDBKeyRange& key_range,
629 blink::WebIDBCursorDirection direction,
630 bool key_only,
631 blink::WebIDBTaskType task_type,
632 scoped_refptr<IndexedDBCallbacks> callbacks) {
633 if (!connection_->IsConnected())
634 return;
635
636 connection_->database()->OpenCursor(
637 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
638 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range), direction,
639 key_only, task_type, std::move(callbacks));
640 }
641
642 void DatabaseImpl::IDBThreadHelper::Count(
643 int64_t transaction_id,
644 int64_t object_store_id,
645 int64_t index_id,
646 const IndexedDBKeyRange& key_range,
647 scoped_refptr<IndexedDBCallbacks> callbacks) {
648 if (!connection_->IsConnected())
649 return;
650
651 connection_->database()->Count(
652 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
653 index_id, base::MakeUnique<IndexedDBKeyRange>(key_range),
654 std::move(callbacks));
655 }
656
657 void DatabaseImpl::IDBThreadHelper::DeleteRange(
658 int64_t transaction_id,
659 int64_t object_store_id,
660 const IndexedDBKeyRange& key_range,
661 scoped_refptr<IndexedDBCallbacks> callbacks) {
662 if (!connection_->IsConnected())
663 return;
664
665 connection_->database()->DeleteRange(
666 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
667 base::MakeUnique<IndexedDBKeyRange>(key_range), std::move(callbacks));
668 }
669
670 void DatabaseImpl::IDBThreadHelper::Clear(
671 int64_t transaction_id,
672 int64_t object_store_id,
673 scoped_refptr<IndexedDBCallbacks> callbacks) {
674 if (!connection_->IsConnected())
675 return;
676
677 connection_->database()->Clear(
678 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
679 callbacks);
680 }
681
682 void DatabaseImpl::IDBThreadHelper::CreateIndex(
683 int64_t transaction_id,
684 int64_t object_store_id,
685 int64_t index_id,
686 const base::string16& name,
687 const IndexedDBKeyPath& key_path,
688 bool unique,
689 bool multi_entry) {
690 if (!connection_->IsConnected())
691 return;
692
693 connection_->database()->CreateIndex(
694 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
695 index_id, name, key_path, unique, multi_entry);
696 }
697
698 void DatabaseImpl::IDBThreadHelper::DeleteIndex(int64_t transaction_id,
699 int64_t object_store_id,
700 int64_t index_id) {
701 if (!connection_->IsConnected())
702 return;
703
704 connection_->database()->DeleteIndex(
705 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
706 index_id);
707 }
708
709 void DatabaseImpl::IDBThreadHelper::RenameIndex(
710 int64_t transaction_id,
711 int64_t object_store_id,
712 int64_t index_id,
713 const base::string16& new_name) {
714 if (!connection_->IsConnected())
715 return;
716
717 connection_->database()->RenameIndex(
718 dispatcher_host_->HostTransactionId(transaction_id), object_store_id,
719 index_id, new_name);
720 }
721
722 void DatabaseImpl::IDBThreadHelper::Abort(int64_t transaction_id) {
723 if (!connection_->IsConnected())
724 return;
725
726 connection_->database()->Abort(
727 dispatcher_host_->HostTransactionId(transaction_id));
728 }
729
730 void DatabaseImpl::IDBThreadHelper::Commit(int64_t transaction_id) {
731 if (!connection_->IsConnected())
732 return;
733
734 int64_t host_transaction_id =
735 dispatcher_host_->HostTransactionId(transaction_id);
736 // May have been aborted by back end before front-end could request commit.
737 int64_t transaction_size;
738 if (!dispatcher_host_->GetTransactionSize(host_transaction_id,
739 &transaction_size))
740 return;
741
742 // Always allow empty or delete-only transactions.
743 if (transaction_size == 0) {
744 connection_->database()->Commit(host_transaction_id);
745 return;
746 }
747
748 dispatcher_host_->context()->quota_manager_proxy()->GetUsageAndQuota(
749 dispatcher_host_->context()->TaskRunner(), origin_.GetURL(),
750 storage::kStorageTypeTemporary,
751 base::Bind(&IDBThreadHelper::OnGotUsageAndQuotaForCommit,
752 weak_factory_.GetWeakPtr(), transaction_id));
753 }
754
755 void DatabaseImpl::IDBThreadHelper::OnGotUsageAndQuotaForCommit(
756 int64_t transaction_id,
757 storage::QuotaStatusCode status,
758 int64_t usage,
759 int64_t quota) {
760 // May have disconnected while quota check was pending.
761 if (!connection_->IsConnected())
762 return;
763
764 int64_t host_transaction_id =
765 dispatcher_host_->HostTransactionId(transaction_id);
766 // May have aborted while quota check was pending.
767 int64_t transaction_size;
768 if (!dispatcher_host_->GetTransactionSize(host_transaction_id,
769 &transaction_size))
770 return;
771
772 if (status == storage::kQuotaStatusOk && usage + transaction_size <= quota) {
773 connection_->database()->Commit(host_transaction_id);
774 } else {
775 connection_->database()->Abort(
776 host_transaction_id,
777 IndexedDBDatabaseError(blink::WebIDBDatabaseExceptionQuotaError));
778 }
779 }
780
781 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/database_impl.h ('k') | content/browser/indexed_db/indexed_db_callbacks.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698