Chromium Code Reviews| Index: third_party/WebKit/Source/modules/indexeddb/IDBRequestQueue.h |
| diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBRequestQueue.h b/third_party/WebKit/Source/modules/indexeddb/IDBRequestQueue.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a375cfa214e8bc3063c4a1a3d896e68996b02c46 |
| --- /dev/null |
| +++ b/third_party/WebKit/Source/modules/indexeddb/IDBRequestQueue.h |
| @@ -0,0 +1,140 @@ |
| +// 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. |
| + |
| +#ifndef IDBRequestQueue_h |
| +#define IDBRequestQueue_h |
| + |
| +#include "platform/heap/Handle.h" |
| +#include "platform/wtf/PassRefPtr.h" |
| +#include "platform/wtf/RefPtr.h" |
| +#include "platform/wtf/Vector.h" |
| + |
| +#include <memory> |
| + |
| +namespace blink { |
| + |
| +class DOMException; |
| +class IDBKey; |
| +class IDBRequest; |
| +class IDBRequestLoader; |
| +class IDBValue; |
| +class WebIDBCursor; |
| + |
| +// Queues up a transaction's IDBRequest results for orderly delivery. |
| +// |
| +// The IndexedDB specification requires that the events corresponding to IDB |
| +// request results fire in the order in which the requests were issued. The |
| +// browser-side backend processes requests in order, but the Blink side may need |
| +// to perform post-processing on the results (e.g., large value unwrapping). |
|
jsbell
2017/05/05 00:29:37
nit: no ,
pwnall
2017/05/11 23:54:24
Done.
|
| +// When a result needs post-processing, this queue captures all results received |
| +// during the post-processing steps. The events for these results may only fire |
| +// after the post-processed result's event is fired. |
| +class IDBRequestQueueItem |
|
jsbell
2017/05/05 00:29:37
Filename should be IDBRequestQueueItem ?
pwnall
2017/05/11 23:54:24
Done.
|
| + : public GarbageCollectedFinalized<IDBRequestQueueItem> { |
|
jsbell
2017/05/05 00:29:37
Why GC'd? I would imagine this would be owned by t
pwnall
2017/05/11 23:54:24
Done.
I was being lazy and avoiding learning about
|
| + public: |
| + IDBRequestQueueItem(IDBRequest*, DOMException*); |
| + IDBRequestQueueItem(IDBRequest*, IDBKey*); |
| + IDBRequestQueueItem(IDBRequest*, PassRefPtr<IDBValue>); |
| + IDBRequestQueueItem(IDBRequest*, const Vector<RefPtr<IDBValue>>&); |
| + IDBRequestQueueItem(IDBRequest*, |
| + IDBKey*, |
| + IDBKey* primary_key, |
| + PassRefPtr<IDBValue>); |
| + IDBRequestQueueItem(IDBRequest*, |
| + std::unique_ptr<WebIDBCursor> backend, |
| + IDBKey*, |
| + IDBKey* primary_key, |
| + PassRefPtr<IDBValue>); |
| + |
| + // False if this result still requires post-processing. |
| + inline bool IsReady() { return ready_; } |
| + |
| + // The request whose queued result is tracked by this item. |
| + inline IDBRequest* Request() { return request_; } |
| + |
| + // Creates a IDBRequestLoader to post-process the IDBRequest's result. |
| + void AttachLoader(); |
| + |
| + // Starts post-processing the IDBRequest's result. |
| + // |
| + // This method must be called after the IDBRequestQueueItem is enqueued into |
| + // the appropriate queue, because it is possible for the loading operation to |
| + // complete synchronously, in which case IDBtransaction::OnResultReady() will |
|
jsbell
2017/05/05 00:29:37
nit: IDBTransaction
pwnall
2017/05/11 23:54:24
Done.
|
| + // be called with the (presumably) enqueued IDBRequest before this method |
| + // returns. |
| + void StartLoading(); |
| + |
| + // Calls the correct overload of OnSuccess/OnError on the associated request. |
| + // |
| + // This should only be called by the request's IDBTransaction. |
| + void FireCallback(); |
| + |
| + // Marks the result as having being post-processed. |
| + // |
| + // This method should only be called by the associated IDBRequestLoader. |
| + void MarkReady(); |
| + // Called when an error occurs during result post-processing. |
| + // |
| + // This method should only be called by the associated IDBRequestLoader. |
| + void MarkReady(DOMException* error); |
| + |
| + DECLARE_TRACE(); |
| + |
| + private: |
| + // The IDBRequest callback that will be called for this result. |
| + enum Mode { |
| + kError, |
| + kBackendKeyPrimaryKeyValue, |
| + kKey, |
| + kKeyPrimaryKeyValue, |
| + kValue, |
| + kValueArray, |
| + }; |
| + |
| + // Performs post-processing on this result. |
| + // |
| + // nullptr for results that do not require post-processing and for results |
| + // whose post-processing has completed. |
| + Member<IDBRequestLoader> loader_; |
| + |
| + // The IDBRequest that will receive a callback for this result. |
| + Member<IDBRequest> request_; |
| + |
| + // The key argument to the IDBRequest callback. |
| + // |
| + // Only used if mode_ is kKeyPrimaryKeyValue. |
| + Member<IDBKey> key_; |
| + |
| + // The primary_key argument to the IDBRequest callback. |
| + // |
| + // Only used if mode_ is kKeyPrimaryKeyValue. |
| + Member<IDBKey> primary_key_; |
| + |
| + // The error argument to the IDBRequest callback. |
| + // |
| + // Only used if the mode_ is kError. |
| + Member<DOMException> error_; |
| + |
| + // All the values that will be passed back to the IDBRequest. |
| + Vector<RefPtr<IDBValue>> values_; |
| + |
| + // The backend argument to the IDBRequest callback. |
| + std::unique_ptr<WebIDBCursor> backend_; |
| + |
| + // The IDBRequest callback that will be called for this result. |
| + Mode mode_; |
| + |
| + // False if this result still requires post-processing. |
| + bool ready_ = true; |
| + |
| +#if DCHECK_IS_ON() |
| + bool callback_fired_; |
| +#endif // DCHECK_IS_ON() |
| +}; |
| + |
| +using IDBRequestQueue = HeapDeque<Member<IDBRequestQueueItem>>; |
| + |
| +} // namespace blink |
| + |
| +#endif // IDBRequestQueue_h |