| Index: third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.h | 
| diff --git a/third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.h b/third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..908c294c2cfc68d13c9dae5edcb8b5db43a0860a | 
| --- /dev/null | 
| +++ b/third_party/WebKit/Source/modules/indexeddb/IDBRequestLoader.h | 
| @@ -0,0 +1,114 @@ | 
| +// 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 IDBRequestLoader_h | 
| +#define IDBRequestLoader_h | 
| + | 
| +#include "core/fileapi/FileReaderLoaderClient.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 FileReaderLoader; | 
| +class IDBKey; | 
| +class IDBRequest; | 
| +class IDBValue; | 
| +class WebIDBCursor; | 
| + | 
| +// Loads IndexedDB values that have been wrapped in Blobs by IDBValueWrapper. | 
| +class IDBRequestLoader : public GarbageCollectedFinalized<IDBRequestLoader>, | 
| +                         public FileReaderLoaderClient { | 
| + public: | 
| +  // Creates a reader that will unwrap IDBValues received by a IDBRequest. | 
| +  IDBRequestLoader(IDBRequest*); | 
| + | 
| +  ~IDBRequestLoader() override; | 
| + | 
| +  static bool NeedsUnwrapping(IDBValue*); | 
| +  static bool NeedUnwrapping(const Vector<RefPtr<IDBValue>>&); | 
| + | 
| +  // Start unwrapping values. | 
| +  // | 
| +  // Exactly one of these methods should be called for a reader. | 
| +  void Start(PassRefPtr<IDBValue>); | 
| +  void Start(const Vector<RefPtr<IDBValue>>&); | 
| +  void Start(IDBKey*, IDBKey* primary_key, PassRefPtr<IDBValue>); | 
| +  void Start(std::unique_ptr<WebIDBCursor> backend, | 
| +             IDBKey*, | 
| +             IDBKey* primary_key, | 
| +             PassRefPtr<IDBValue>); | 
| + | 
| +  // FileReaderLoaderClient implementaton. | 
| +  void DidStartLoading() override; | 
| +  void DidReceiveDataForClient(const char* data, unsigned data_length) override; | 
| +  void DidFinishLoading() override; | 
| +  void DidFail(FileError::ErrorCode) override; | 
| + | 
| +  DEFINE_INLINE_TRACE() { | 
| +    visitor->Trace(request_); | 
| +    visitor->Trace(key_); | 
| +    visitor->Trace(primary_key_); | 
| +  } | 
| + | 
| + private: | 
| +  // The IDBRequest callback that will be called by this reader. | 
| +  enum Mode { | 
| +    kUninitialized = 0, | 
| +    kValue, | 
| +    kValueArray, | 
| +    kKeyPrimaryKeyValue, | 
| +    kBackendKeyPrimaryKeyValue, | 
| +  }; | 
| + | 
| +  // Starts unwrapping the next wrapped IDBValue. | 
| +  // | 
| +  // If no more wrapped IDBValues are found, this calls the IDBRequest | 
| +  // callbacks. | 
| +  void StartNextValue(); | 
| + | 
| +  void ReportSuccess(); | 
| +  void ReportError(); | 
| + | 
| +  // The IDBRequest callback that will be called by this reader. | 
| +  Mode mode_; | 
| + | 
| +  std::unique_ptr<FileReaderLoader> loader_; | 
| + | 
| +  // The IDBRequest whose IDBValues are unwrapped by this reader. | 
| +  Member<IDBRequest> request_; | 
| + | 
| +  // All the values that will be passed back to the IDBRequest. | 
| +  Vector<RefPtr<IDBValue>> values_; | 
| + | 
| +  // 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 backend argument to the IDBRequest callback. | 
| +  std::unique_ptr<WebIDBCursor> backend_; | 
| + | 
| +  // Indexes of the IDBValues in values_ that have been wrapped in Blobs. | 
| +  Vector<unsigned> wrapped_value_indexes_; | 
| + | 
| +  // Buffer used to unwrap an IDBValue. | 
| +  Vector<char> wrapped_data_; | 
| + | 
| +  // The value being currently unwrapped. | 
| +  Vector<RefPtr<IDBValue>>::iterator current_value_; | 
| +}; | 
| + | 
| +}  // namespace blink | 
| + | 
| +#endif  // IDBRequestLoader_h | 
|  |