Commit 703e7a89 authored by tyoshino's avatar tyoshino Committed by Commit bot

[WebBlobRegistry] Use char* than WebThreadSafeData

We don't need to wrap the data with WebThreadSafeData here. Just use a
pair of const char* and size_t.

This is Chromium side CL

Blink side CL: https://codereview.chromium.org/611923002/

R=yhirano,jam
BUG=417093

Review URL: https://codereview.chromium.org/610333002

Cr-Commit-Position: refs/heads/master@{#300064}
parent 24f3d915
......@@ -164,32 +164,37 @@ void WebBlobRegistryImpl::registerStreamURL(
void WebBlobRegistryImpl::addDataToStream(const WebURL& url,
WebThreadSafeData& data) {
addDataToStream(url, data.data(), data.size());
}
void WebBlobRegistryImpl::addDataToStream(const WebURL& url,
const char* data, size_t length) {
DCHECK(ChildThread::current());
if (data.size() == 0)
if (length == 0)
return;
if (data.size() < kLargeThresholdBytes) {
if (length < kLargeThresholdBytes) {
storage::BlobData::Item item;
item.SetToBytes(data.data(), data.size());
item.SetToBytes(data, length);
sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item));
} else {
// We handle larger amounts of data via SharedMemory instead of
// writing it directly to the IPC channel.
size_t shared_memory_size = std::min(
data.size(), kMaxSharedMemoryBytes);
length, kMaxSharedMemoryBytes);
scoped_ptr<base::SharedMemory> shared_memory(
ChildThread::AllocateSharedMemory(shared_memory_size,
sender_.get()));
CHECK(shared_memory.get());
size_t data_size = data.size();
const char* data_ptr = data.data();
while (data_size) {
size_t chunk_size = std::min(data_size, shared_memory_size);
memcpy(shared_memory->memory(), data_ptr, chunk_size);
size_t remaining_bytes = length;
const char* current_ptr = data;
while (remaining_bytes) {
size_t chunk_size = std::min(remaining_bytes, shared_memory_size);
memcpy(shared_memory->memory(), current_ptr, chunk_size);
sender_->Send(new StreamHostMsg_SyncAppendSharedMemory(
url, shared_memory->handle(), chunk_size));
data_size -= chunk_size;
data_ptr += chunk_size;
remaining_bytes -= chunk_size;
current_ptr += chunk_size;
}
}
}
......
......@@ -10,6 +10,10 @@
#include "base/memory/ref_counted.h"
#include "third_party/WebKit/public/platform/WebBlobRegistry.h"
namespace blink {
class WebThreadSafeData;
} // namespace blink
namespace content {
class ThreadSafeSender;
......@@ -31,8 +35,11 @@ class WebBlobRegistryImpl : public blink::WebBlobRegistry {
const blink::WebString& content_type);
virtual void registerStreamURL(const blink::WebURL& url,
const blink::WebURL& src_url);
// TODO(tyoshino): Remove once removed in Blink side.
virtual void addDataToStream(const blink::WebURL& url,
blink::WebThreadSafeData& data);
virtual void addDataToStream(const blink::WebURL& url,
const char* data, size_t length);
virtual void finalizeStream(const blink::WebURL& url);
virtual void abortStream(const blink::WebURL& url);
virtual void unregisterStreamURL(const blink::WebURL& url);
......
......@@ -6,7 +6,6 @@
#include "third_party/WebKit/public/platform/WebBlobData.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/platform/WebThreadSafeData.h"
#include "third_party/WebKit/public/platform/WebURL.h"
using blink::WebBlobData;
......@@ -51,6 +50,11 @@ void MockWebBlobRegistryImpl::addDataToStream(const WebURL& url,
WebThreadSafeData& data) {
}
void MockWebBlobRegistryImpl::addDataToStream(const WebURL& url,
const char* data,
size_t length) {
}
void MockWebBlobRegistryImpl::finalizeStream(const WebURL& url) {
}
......
......@@ -8,6 +8,10 @@
#include "base/macros.h"
#include "third_party/WebKit/public/platform/WebBlobRegistry.h"
namespace blink {
class WebThreadSafeData;
} // namespace blink
namespace content {
class MockWebBlobRegistryImpl : public blink::WebBlobRegistry {
......@@ -28,8 +32,11 @@ class MockWebBlobRegistryImpl : public blink::WebBlobRegistry {
const blink::WebString& content_type);
virtual void registerStreamURL(const blink::WebURL& url,
const blink::WebURL& src_url);
// TODO(tyoshino): Remove once removed in Blink side.
virtual void addDataToStream(const blink::WebURL& url,
blink::WebThreadSafeData& data);
virtual void addDataToStream(const blink::WebURL& url,
const char* data, size_t length);
virtual void finalizeStream(const blink::WebURL& url);
virtual void abortStream(const blink::WebURL& url);
virtual void unregisterStreamURL(const blink::WebURL& url);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment