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

Side by Side Diff: third_party/WebKit/Source/modules/indexeddb/IDBRequest.cpp

Issue 2822453003: Wrap large IndexedDB values into Blobs before writing to LevelDB. (Closed)
Patch Set: Fixed compilation errors on Windows and no-DCHECKs. Created 3 years, 7 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 23 matching lines...) Expand all
34 #include "bindings/modules/v8/ToV8ForModules.h" 34 #include "bindings/modules/v8/ToV8ForModules.h"
35 #include "bindings/modules/v8/V8BindingForModules.h" 35 #include "bindings/modules/v8/V8BindingForModules.h"
36 #include "core/dom/DOMException.h" 36 #include "core/dom/DOMException.h"
37 #include "core/dom/ExceptionCode.h" 37 #include "core/dom/ExceptionCode.h"
38 #include "core/dom/ExecutionContext.h" 38 #include "core/dom/ExecutionContext.h"
39 #include "core/events/EventQueue.h" 39 #include "core/events/EventQueue.h"
40 #include "modules/IndexedDBNames.h" 40 #include "modules/IndexedDBNames.h"
41 #include "modules/indexeddb/IDBCursorWithValue.h" 41 #include "modules/indexeddb/IDBCursorWithValue.h"
42 #include "modules/indexeddb/IDBDatabase.h" 42 #include "modules/indexeddb/IDBDatabase.h"
43 #include "modules/indexeddb/IDBEventDispatcher.h" 43 #include "modules/indexeddb/IDBEventDispatcher.h"
44 #include "modules/indexeddb/IDBRequestLoader.h"
44 #include "modules/indexeddb/IDBTracing.h" 45 #include "modules/indexeddb/IDBTracing.h"
45 #include "modules/indexeddb/IDBValue.h" 46 #include "modules/indexeddb/IDBValue.h"
46 #include "modules/indexeddb/WebIDBCallbacksImpl.h" 47 #include "modules/indexeddb/WebIDBCallbacksImpl.h"
47 #include "platform/SharedBuffer.h" 48 #include "platform/SharedBuffer.h"
48 #include "public/platform/WebBlobInfo.h" 49 #include "public/platform/WebBlobInfo.h"
49 50
50 using blink::WebIDBCursor; 51 using blink::WebIDBCursor;
51 52
52 namespace blink { 53 namespace blink {
53 54
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 if (!GetExecutionContext()) 233 if (!GetExecutionContext())
233 return false; 234 return false;
234 DCHECK(ready_state_ == PENDING || ready_state_ == DONE); 235 DCHECK(ready_state_ == PENDING || ready_state_ == DONE);
235 if (request_aborted_) 236 if (request_aborted_)
236 return false; 237 return false;
237 DCHECK_EQ(ready_state_, PENDING); 238 DCHECK_EQ(ready_state_, PENDING);
238 DCHECK(!error_ && !result_); 239 DCHECK(!error_ && !result_);
239 return true; 240 return true;
240 } 241 }
241 242
243 void IDBRequest::QueueResult(DOMException* error) {
244 outgoing_blob_handles_.clear();
245
246 if (!transaction_ || !transaction_->HasQueuedResult())
247 return OnError(error);
248
249 transaction_->EnqueueResult(new IDBRequestQueueItem(this, error));
250 }
251
252 void IDBRequest::QueueResult(IDBKey* key) {
253 outgoing_blob_handles_.clear();
254
255 DCHECK(transaction_);
256 if (!transaction_->HasQueuedResult())
257 return OnSuccess(key);
258
259 transaction_->EnqueueResult(new IDBRequestQueueItem(this, key));
260 }
261
262 void IDBRequest::QueueResult(std::unique_ptr<WebIDBCursor> backend,
263 IDBKey* key,
264 IDBKey* primary_key,
265 PassRefPtr<IDBValue> value) {
266 bool needs_unwrapping = IDBRequestLoader::NeedsUnwrapping(value.Get());
267
268 DCHECK(transaction_);
269 if (!transaction_->HasQueuedResult() && !needs_unwrapping)
270 return OnSuccess(std::move(backend), key, primary_key, std::move(value));
271
272 IDBRequestQueueItem* queue_item = new IDBRequestQueueItem(
273 this, std::move(backend), key, primary_key, std::move(value));
274 if (needs_unwrapping)
275 queue_item->AttachLoader();
276 transaction_->EnqueueResult(queue_item);
277 queue_item->StartLoading();
278 }
279 void IDBRequest::QueueResult(PassRefPtr<IDBValue> value) {
280 bool needs_unwrapping = IDBRequestLoader::NeedsUnwrapping(value.Get());
281
282 DCHECK(transaction_);
283 if (!transaction_->HasQueuedResult() && !needs_unwrapping)
284 return OnSuccess(std::move(value));
285
286 IDBRequestQueueItem* queue_item =
287 new IDBRequestQueueItem(this, std::move(value));
288 if (needs_unwrapping)
289 queue_item->AttachLoader();
290 transaction_->EnqueueResult(queue_item);
291 queue_item->StartLoading();
292 }
293
294 void IDBRequest::QueueResult(const Vector<RefPtr<IDBValue>>& values) {
295 bool needs_unwrapping = IDBRequestLoader::NeedUnwrapping(values);
296
297 DCHECK(transaction_);
298 if (!transaction_->HasQueuedResult() && !needs_unwrapping)
299 return OnSuccess(values);
300
301 IDBRequestQueueItem* queue_item = new IDBRequestQueueItem(this, values);
302 if (needs_unwrapping)
303 queue_item->AttachLoader();
304 transaction_->EnqueueResult(queue_item);
305 queue_item->StartLoading();
306 }
307
308 void IDBRequest::QueueResult(IDBKey* key,
309 IDBKey* primary_key,
310 PassRefPtr<IDBValue> value) {
311 bool needs_unwrapping = IDBRequestLoader::NeedsUnwrapping(value.Get());
312
313 DCHECK(transaction_);
314 if (!transaction_->HasQueuedResult() && !needs_unwrapping)
315 return OnSuccess(key, primary_key, std::move(value));
316
317 IDBRequestQueueItem* queue_item =
318 new IDBRequestQueueItem(this, key, primary_key, std::move(value));
319 if (needs_unwrapping)
320 queue_item->AttachLoader();
321 transaction_->EnqueueResult(queue_item);
322 queue_item->StartLoading();
323 }
324
242 void IDBRequest::OnError(DOMException* error) { 325 void IDBRequest::OnError(DOMException* error) {
243 IDB_TRACE("IDBRequest::onError()"); 326 IDB_TRACE("IDBRequest::onError()");
244 ClearPutOperationBlobs();
dmurph 2017/05/04 22:27:07 Would we put these in the QueueResult callsa as we
pwnall 2017/05/11 23:54:23 I called clear() directly on the vector. It seemed
245 if (!ShouldEnqueueEvent()) 327 if (!ShouldEnqueueEvent())
246 return; 328 return;
247 329
248 error_ = error; 330 error_ = error;
249 SetResult(IDBAny::CreateUndefined()); 331 SetResult(IDBAny::CreateUndefined());
250 pending_cursor_.Clear(); 332 pending_cursor_.Clear();
251 EnqueueEvent(Event::CreateCancelableBubble(EventTypeNames::error)); 333 EnqueueEvent(Event::CreateCancelableBubble(EventTypeNames::error));
252 } 334 }
253 335
254 void IDBRequest::OnSuccess(const Vector<String>& string_list) { 336 void IDBRequest::OnSuccess(const Vector<String>& string_list) {
(...skipping 28 matching lines...) Expand all
283 this, source_.Get(), transaction_.Get()); 365 this, source_.Get(), transaction_.Get());
284 break; 366 break;
285 default: 367 default:
286 NOTREACHED(); 368 NOTREACHED();
287 } 369 }
288 SetResultCursor(cursor, key, primary_key, std::move(value)); 370 SetResultCursor(cursor, key, primary_key, std::move(value));
289 } 371 }
290 372
291 void IDBRequest::OnSuccess(IDBKey* idb_key) { 373 void IDBRequest::OnSuccess(IDBKey* idb_key) {
292 IDB_TRACE("IDBRequest::onSuccess(IDBKey)"); 374 IDB_TRACE("IDBRequest::onSuccess(IDBKey)");
293 ClearPutOperationBlobs();
294 if (!ShouldEnqueueEvent()) 375 if (!ShouldEnqueueEvent())
295 return; 376 return;
296 377
297 if (idb_key && idb_key->IsValid()) 378 if (idb_key && idb_key->IsValid())
298 OnSuccessInternal(IDBAny::Create(idb_key)); 379 OnSuccessInternal(IDBAny::Create(idb_key));
299 else 380 else
300 OnSuccessInternal(IDBAny::CreateUndefined()); 381 OnSuccessInternal(IDBAny::CreateUndefined());
301 } 382 }
302 383
303 void IDBRequest::OnSuccess(const Vector<RefPtr<IDBValue>>& values) { 384 void IDBRequest::OnSuccess(const Vector<RefPtr<IDBValue>>& values) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 void IDBRequest::OnSuccess() { 436 void IDBRequest::OnSuccess() {
356 IDB_TRACE("IDBRequest::onSuccess()"); 437 IDB_TRACE("IDBRequest::onSuccess()");
357 if (!ShouldEnqueueEvent()) 438 if (!ShouldEnqueueEvent())
358 return; 439 return;
359 OnSuccessInternal(IDBAny::CreateUndefined()); 440 OnSuccessInternal(IDBAny::CreateUndefined());
360 } 441 }
361 442
362 void IDBRequest::OnSuccessInternal(IDBAny* result) { 443 void IDBRequest::OnSuccessInternal(IDBAny* result) {
363 DCHECK(GetExecutionContext()); 444 DCHECK(GetExecutionContext());
364 DCHECK(!pending_cursor_); 445 DCHECK(!pending_cursor_);
365 DCHECK(transit_blob_handles_.IsEmpty()); 446 DCHECK(outgoing_blob_handles_.IsEmpty());
366 SetResult(result); 447 SetResult(result);
367 EnqueueEvent(Event::Create(EventTypeNames::success)); 448 EnqueueEvent(Event::Create(EventTypeNames::success));
368 } 449 }
369 450
370 void IDBRequest::SetResult(IDBAny* result) { 451 void IDBRequest::SetResult(IDBAny* result) {
371 result_ = result; 452 result_ = result;
372 result_dirty_ = true; 453 result_dirty_ = true;
373 } 454 }
374 455
375 void IDBRequest::OnSuccess(IDBKey* key, 456 void IDBRequest::OnSuccess(IDBKey* key,
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 } 637 }
557 638
558 void IDBRequest::DequeueEvent(Event* event) { 639 void IDBRequest::DequeueEvent(Event* event) {
559 for (size_t i = 0; i < enqueued_events_.size(); ++i) { 640 for (size_t i = 0; i < enqueued_events_.size(); ++i) {
560 if (enqueued_events_[i].Get() == event) 641 if (enqueued_events_[i].Get() == event)
561 enqueued_events_.erase(i); 642 enqueued_events_.erase(i);
562 } 643 }
563 } 644 }
564 645
565 } // namespace blink 646 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698