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

Unified Diff: third_party/WebKit/Source/modules/indexeddb/IDBRequestQueueItem.cpp

Issue 2822453003: Wrap large IndexedDB values into Blobs before writing to LevelDB. (Closed)
Patch Set: WIP: Getting IDBRequestTest.EventsAfterStopping to pass. 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/indexeddb/IDBRequestQueueItem.cpp
diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBRequestQueueItem.cpp b/third_party/WebKit/Source/modules/indexeddb/IDBRequestQueueItem.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..a4ee80e41565632e6759e68ecfada860a20129ef
--- /dev/null
+++ b/third_party/WebKit/Source/modules/indexeddb/IDBRequestQueueItem.cpp
@@ -0,0 +1,206 @@
+
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "modules/indexeddb/IDBRequestQueueItem.h"
+
+#include "core/dom/DOMException.h"
+#include "modules/indexeddb/IDBKey.h"
+#include "modules/indexeddb/IDBRequest.h"
+#include "modules/indexeddb/IDBRequestLoader.h"
+#include "modules/indexeddb/IDBValue.h"
+#include "platform/wtf/PtrUtil.h"
+#include "public/platform/modules/indexeddb/WebIDBCursor.h"
+
+namespace blink {
+
+IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
+ DOMException* error)
+ : request_(request), error_(error), mode_(kError), ready_(true) {
+#if DCHECK_IS_ON()
+ DCHECK_EQ(request->queue_item_, nullptr);
+ request_->queue_item_ = this;
+#endif // DCHECK_IS_ON()
+}
+
+IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request, int64_t value)
+ : request_(request), int64_value_(value), mode_(kInt64Value), ready_(true) {
+#if DCHECK_IS_ON()
+ DCHECK_EQ(request->queue_item_, nullptr);
+ request_->queue_item_ = this;
+#endif // DCHECK_IS_ON()
+}
+
+IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request)
+ : request_(request), mode_(kNoArguments), ready_(true) {
+#if DCHECK_IS_ON()
+ DCHECK_EQ(request->queue_item_, nullptr);
+ request_->queue_item_ = this;
+#endif // DCHECK_IS_ON()
+}
+
+IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request, IDBKey* key)
+ : request_(request), key_(key), mode_(kKey), ready_(true) {
+#if DCHECK_IS_ON()
+ DCHECK_EQ(request->queue_item_, nullptr);
+ request_->queue_item_ = this;
+#endif // DCHECK_IS_ON()
+}
+
+IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
+ PassRefPtr<IDBValue> value,
+ bool attach_loader)
+ : request_(request), mode_(kValue), ready_(!attach_loader) {
+#if DCHECK_IS_ON()
+ DCHECK_EQ(request->queue_item_, nullptr);
+ request_->queue_item_ = this;
+#endif // DCHECK_IS_ON()
+ values_.push_back(std::move(value));
+ if (attach_loader)
jsbell 2017/05/15 23:37:38 Should we DCHECK_EQ(attach_loader, NeedsUnwrapping
pwnall 2017/05/19 18:27:34 The loader DCHECKs that the values given to it nee
+ loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
+}
+
+IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
+ const Vector<RefPtr<IDBValue>>& values,
+ bool attach_loader)
+ : request_(request),
+ values_(values),
+ mode_(kValueArray),
+ ready_(attach_loader) {
+#if DCHECK_IS_ON()
+ DCHECK_EQ(request->queue_item_, nullptr);
+ request_->queue_item_ = this;
+#endif // DCHECK_IS_ON()
+ if (attach_loader)
jsbell 2017/05/15 23:37:38 Should we DCHECK_EQ(attach_loader, NeedUnwrapping(
pwnall 2017/05/19 18:27:34 Same as above :)
+ loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
+}
+
+IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
+ IDBKey* key,
+ IDBKey* primary_key,
+ PassRefPtr<IDBValue> value,
+ bool attach_loader)
+ : request_(request),
+ key_(key),
+ primary_key_(primary_key),
+ mode_(kKeyPrimaryKeyValue),
+ ready_(!attach_loader) {
+#if DCHECK_IS_ON()
+ DCHECK_EQ(request->queue_item_, nullptr);
+ request_->queue_item_ = this;
+#endif // DCHECK_IS_ON()
+ values_.push_back(std::move(value));
+ if (attach_loader)
+ loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
+}
+
+IDBRequestQueueItem::IDBRequestQueueItem(IDBRequest* request,
+ std::unique_ptr<WebIDBCursor> backend,
+ IDBKey* key,
+ IDBKey* primary_key,
+ PassRefPtr<IDBValue> value,
+ bool attach_loader)
+ : request_(request),
+ key_(key),
+ primary_key_(primary_key),
+ backend_(std::move(backend)),
+ mode_(kBackendKeyPrimaryKeyValue),
+ ready_(!attach_loader) {
+#if DCHECK_IS_ON()
+ DCHECK_EQ(request->queue_item_, nullptr);
+ request_->queue_item_ = this;
+#endif // DCHECK_IS_ON()
+ values_.push_back(std::move(value));
+ if (attach_loader)
+ loader_ = WTF::MakeUnique<IDBRequestLoader>(this, &values_);
+}
+
+IDBRequestQueueItem::~IDBRequestQueueItem() {
+#if DCHECK_IS_ON()
+ DCHECK(ready_);
+ DCHECK(callback_fired_);
+#endif // DCHECK_IS_ON()
+}
+
+void IDBRequestQueueItem::MarkReady() {
dmurph 2017/05/15 19:32:23 Can we rename this NotifyTransactionResultReady? O
pwnall 2017/05/15 23:15:00 I didn't like this name either, and I left it ther
pwnall 2017/05/19 18:27:34 How about OnResultLoadComplete()?
+ DCHECK(!ready_);
+ ready_ = true;
+
+ request_->transaction()->OnResultReady();
+}
+
+void IDBRequestQueueItem::MarkReady(DOMException* error) {
+ DCHECK(!ready_);
+ DCHECK(mode_ != kError);
+
+ mode_ = kError;
+ error_ = error;
+
+ // This is not necessary, but releases non-trivial amounts of memory early.
+ values_.clear();
+
+ MarkReady();
+}
+
+void IDBRequestQueueItem::StartLoading() {
+ if (loader_) {
+ DCHECK(!ready_);
+ loader_->Start();
+ }
+}
+
+void IDBRequestQueueItem::FireCallback() {
+#if DCHECK_IS_ON()
+ DCHECK(ready_);
+ DCHECK(!callback_fired_);
+ callback_fired_ = true;
+
+ DCHECK_EQ(request_->queue_item_, this);
+ request_->queue_item_ = nullptr;
+#endif // DCHECK_IS_ON()
+
+ switch (mode_) {
+ case kError:
+ DCHECK(error_);
+ request_->EnqueueResponse(error_);
+ break;
+
+ case kBackendKeyPrimaryKeyValue:
+ DCHECK_EQ(values_.size(), 1U);
+ request_->EnqueueResponse(std::move(backend_), key_, primary_key_,
+ std::move(values_.front()));
+ break;
+
+ case kInt64Value:
+ DCHECK_EQ(values_.size(), 0U);
+ request_->EnqueueResponse(int64_value_);
+ break;
+
+ case kKeyPrimaryKeyValue:
+ DCHECK_EQ(values_.size(), 1U);
+ request_->EnqueueResponse(key_, primary_key_, std::move(values_.front()));
+ break;
+
+ case kKey:
+ DCHECK_EQ(values_.size(), 0U);
+ request_->EnqueueResponse(key_);
+ break;
+
+ case kNoArguments:
+ DCHECK_EQ(values_.size(), 0U);
+ request_->EnqueueResponse();
+ break;
+
+ case kValue:
+ DCHECK_EQ(values_.size(), 1U);
+ request_->EnqueueResponse(std::move(values_.front()));
+ break;
+
+ case kValueArray:
+ request_->EnqueueResponse(values_);
+ break;
+ }
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698