| Index: third_party/WebKit/Source/platform/blob/BlobData.cpp
|
| diff --git a/third_party/WebKit/Source/platform/blob/BlobData.cpp b/third_party/WebKit/Source/platform/blob/BlobData.cpp
|
| index 2f3b3ba8ef5011228607deaa2029eaa0bdd18864..0396854d3e66c9dbfe5e0e269aaa3dd33e4ae349 100644
|
| --- a/third_party/WebKit/Source/platform/blob/BlobData.cpp
|
| +++ b/third_party/WebKit/Source/platform/blob/BlobData.cpp
|
| @@ -31,15 +31,22 @@
|
| #include "platform/blob/BlobData.h"
|
|
|
| #include <memory>
|
| +#include "mojo/public/cpp/bindings/strong_binding.h"
|
| +#include "platform/CrossThreadFunctional.h"
|
| #include "platform/UUID.h"
|
| +#include "platform/WebTaskRunner.h"
|
| +#include "platform/blob/BlobBytesProvider.h"
|
| #include "platform/blob/BlobRegistry.h"
|
| #include "platform/text/LineEnding.h"
|
| #include "platform/wtf/PassRefPtr.h"
|
| #include "platform/wtf/PtrUtil.h"
|
| #include "platform/wtf/RefPtr.h"
|
| +#include "platform/wtf/Time.h"
|
| #include "platform/wtf/Vector.h"
|
| #include "platform/wtf/text/CString.h"
|
| #include "platform/wtf/text/TextEncoding.h"
|
| +#include "public/platform/InterfaceProvider.h"
|
| +#include "public/platform/Platform.h"
|
|
|
| namespace blink {
|
|
|
| @@ -59,6 +66,18 @@ bool IsValidBlobType(const String& type) {
|
| return true;
|
| }
|
|
|
| +Time TimeFromDouble(double dt) {
|
| + if (dt == 0 || std::isnan(dt))
|
| + return Time();
|
| + return Time::FromSeconds(base::Time::kTimeTToMicrosecondsOffset / 1000000 +
|
| + dt);
|
| +}
|
| +
|
| +void BindBytesProvider(std::unique_ptr<BlobBytesProvider> provider,
|
| + storage::mojom::blink::BytesProviderRequest request) {
|
| + mojo::MakeStrongBinding(std::move(provider), std::move(request));
|
| +}
|
| +
|
| } // namespace
|
|
|
| const long long BlobDataItem::kToEndOfFile = -1;
|
| @@ -242,7 +261,12 @@ BlobDataHandle::BlobDataHandle()
|
| : uuid_(CreateCanonicalUUIDString()),
|
| size_(0),
|
| is_single_unknown_size_file_(false) {
|
| - BlobRegistry::RegisterBlobData(uuid_, BlobData::Create());
|
| + // BlobRegistry::RegisterBlobData(uuid_, BlobData::Create());
|
| +
|
| + storage::mojom::blink::BlobRegistryPtr registry;
|
| + Platform::Current()->GetInterfaceProvider()->GetInterface(
|
| + MakeRequest(®istry));
|
| + registry->Register(MakeRequest(&blob_), uuid_, "", "", {});
|
| }
|
|
|
| BlobDataHandle::BlobDataHandle(std::unique_ptr<BlobData> data, long long size)
|
| @@ -250,7 +274,91 @@ BlobDataHandle::BlobDataHandle(std::unique_ptr<BlobData> data, long long size)
|
| type_(data->ContentType().IsolatedCopy()),
|
| size_(size),
|
| is_single_unknown_size_file_(data->IsSingleUnknownSizeFile()) {
|
| - BlobRegistry::RegisterBlobData(uuid_, std::move(data));
|
| + storage::mojom::blink::BlobRegistryPtr registry;
|
| + // TODO(mek): Getting interface relies on main thread to make progress, even
|
| + // in workers.
|
| + Platform::Current()->GetInterfaceProvider()->GetInterface(
|
| + MakeRequest(®istry));
|
| +
|
| + base::SingleThreadTaskRunner* io_runner = BlobRegistry::GetIORunner();
|
| + // TODO(mek): Get max data population from somewhere.
|
| + size_t max_data_population = 5; // 250 * 1024;
|
| + Vector<storage::mojom::blink::DataElementPtr> elements;
|
| + size_t current_memory_population = 0;
|
| + BlobBytesProvider* last_bytes_provider = nullptr;
|
| + storage::mojom::blink::DataElementPtr nullElement = nullptr;
|
| + for (const auto& item : data->Items()) {
|
| + switch (item.type) {
|
| + case BlobDataItem::kData:
|
| + if (item.data->length() != 0) {
|
| + const storage::mojom::blink::DataElementPtr& lastElement =
|
| + elements.IsEmpty() ? nullElement : elements.back();
|
| + if (current_memory_population + item.data->length() <=
|
| + max_data_population) {
|
| + if (lastElement && lastElement->is_bytes()) {
|
| + lastElement->get_bytes().Append(item.data->data(),
|
| + item.data->length());
|
| + } else {
|
| + Vector<uint8_t> bytes;
|
| + bytes.Append(item.data->data(), item.data->length());
|
| + elements.push_back(
|
| + storage::mojom::blink::DataElement::NewBytes(bytes));
|
| + }
|
| + } else {
|
| + if (lastElement && lastElement->is_large_bytes() &&
|
| + last_bytes_provider) {
|
| + lastElement->get_large_bytes()->length += item.data->length();
|
| + last_bytes_provider->AppendData(item.data);
|
| + } else {
|
| + storage::mojom::blink::BytesProviderPtr ptr;
|
| + if (io_runner) {
|
| + auto provider = WTF::MakeUnique<BlobBytesProvider>(item.data);
|
| + last_bytes_provider = provider.get();
|
| + io_runner->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&BindBytesProvider,
|
| + base::Passed(std::move(provider)),
|
| + base::Passed(mojo::MakeRequest(&ptr))));
|
| + last_bytes_provider->uuid = uuid_.IsolatedCopy();
|
| + } else
|
| + mojo::MakeRequest(&ptr);
|
| + elements.push_back(
|
| + storage::mojom::blink::DataElement::NewLargeBytes(
|
| + storage::mojom::blink::DataElementBytes::New(
|
| + item.data->length(), std::move(ptr))));
|
| + }
|
| + }
|
| + }
|
| + break;
|
| + case BlobDataItem::kFile:
|
| + if (item.length != 0)
|
| + elements.push_back(storage::mojom::blink::DataElement::NewFile(
|
| + storage::mojom::blink::DataElementFile::New(
|
| + item.path.IsNull() ? "" : item.path, item.offset, item.length,
|
| + TimeFromDouble(item.expected_modification_time))));
|
| + break;
|
| + case BlobDataItem::kBlob:
|
| + if (item.length != 0) {
|
| + storage::mojom::blink::BlobPtr blob;
|
| + item.blob_data_handle->blob_->Clone(MakeRequest(&blob));
|
| + elements.push_back(storage::mojom::blink::DataElement::NewBlob(
|
| + storage::mojom::blink::DataElementBlob::New(
|
| + std::move(blob), item.offset, item.length)));
|
| + }
|
| + break;
|
| + case BlobDataItem::kFileSystemURL:
|
| + if (item.length != 0)
|
| + elements.push_back(
|
| + storage::mojom::blink::DataElement::NewFileFilesystem(
|
| + storage::mojom::blink::DataElementFilesystemURL::New(
|
| + item.file_system_url, item.offset, item.length,
|
| + TimeFromDouble(item.expected_modification_time))));
|
| + break;
|
| + }
|
| + }
|
| + registry->Register(MakeRequest(&blob_), uuid_, type_.IsNull() ? "" : type_,
|
| + "", std::move(elements));
|
| + // BlobRegistry::RegisterBlobData(uuid_, std::move(data));
|
| }
|
|
|
| BlobDataHandle::BlobDataHandle(const String& uuid,
|
| @@ -260,11 +368,16 @@ BlobDataHandle::BlobDataHandle(const String& uuid,
|
| type_(IsValidBlobType(type) ? type.IsolatedCopy() : ""),
|
| size_(size),
|
| is_single_unknown_size_file_(false) {
|
| - BlobRegistry::AddBlobDataRef(uuid_);
|
| + // BlobRegistry::AddBlobDataRef(uuid_);
|
| +
|
| + storage::mojom::blink::BlobRegistryPtr registry;
|
| + Platform::Current()->GetInterfaceProvider()->GetInterface(
|
| + MakeRequest(®istry));
|
| + registry->DeprecatedGetBlob(uuid_, MakeRequest(&blob_));
|
| }
|
|
|
| BlobDataHandle::~BlobDataHandle() {
|
| - BlobRegistry::RemoveBlobDataRef(uuid_);
|
| + // BlobRegistry::RemoveBlobDataRef(uuid_);
|
| }
|
|
|
| } // namespace blink
|
|
|