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

Side by Side Diff: content/child/webblobregistry_impl.cc

Issue 15817013: Add Stream support to WebBlobRegistry and FileAPIMessageFilter. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase, bug fix, unittests Created 7 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/webblobregistry_impl.h" 5 #include "content/child/webblobregistry_impl.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 14 matching lines...) Expand all
25 namespace content { 25 namespace content {
26 26
27 WebBlobRegistryImpl::WebBlobRegistryImpl(ThreadSafeSender* sender) 27 WebBlobRegistryImpl::WebBlobRegistryImpl(ThreadSafeSender* sender)
28 : sender_(sender) { 28 : sender_(sender) {
29 } 29 }
30 30
31 WebBlobRegistryImpl::~WebBlobRegistryImpl() { 31 WebBlobRegistryImpl::~WebBlobRegistryImpl() {
32 } 32 }
33 33
34 void WebBlobRegistryImpl::SendData(const WebURL& url, 34 void WebBlobRegistryImpl::SendData(const WebURL& url,
35 const WebThreadSafeData& data, 35 const WebThreadSafeData& data) {
36 webkit_blob::BlobData::Item* item) {
37 const size_t kLargeThresholdBytes = 250 * 1024; 36 const size_t kLargeThresholdBytes = 250 * 1024;
38 const size_t kMaxSharedMemoryBytes = 10 * 1024 * 1024; 37 const size_t kMaxSharedMemoryBytes = 10 * 1024 * 1024;
39 38
40 if (data.size() == 0) 39 if (data.size() == 0)
41 return; 40 return;
42 if (data.size() < kLargeThresholdBytes) { 41 if (data.size() < kLargeThresholdBytes) {
43 item->SetToBytes(data.data(), data.size()); 42 webkit_blob::BlobData::Item item;
44 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, *item)); 43 item.SetToBytes(data.data(), data.size());
44 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
45 } else { 45 } else {
46 // We handle larger amounts of data via SharedMemory instead of 46 // We handle larger amounts of data via SharedMemory instead of
47 // writing it directly to the IPC channel. 47 // writing it directly to the IPC channel.
48 size_t data_size = data.size(); 48 size_t data_size = data.size();
49 const char* data_ptr = data.data(); 49 const char* data_ptr = data.data();
50 size_t shared_memory_size = std::min( 50 size_t shared_memory_size = std::min(
51 data_size, kMaxSharedMemoryBytes); 51 data_size, kMaxSharedMemoryBytes);
52 scoped_ptr<base::SharedMemory> shared_memory( 52 scoped_ptr<base::SharedMemory> shared_memory(
53 ChildThread::AllocateSharedMemory(shared_memory_size, 53 ChildThread::AllocateSharedMemory(shared_memory_size,
54 sender_.get())); 54 sender_.get()));
(...skipping 10 matching lines...) Expand all
65 } 65 }
66 66
67 void WebBlobRegistryImpl::registerBlobURL( 67 void WebBlobRegistryImpl::registerBlobURL(
68 const WebURL& url, WebBlobData& data) { 68 const WebURL& url, WebBlobData& data) {
69 DCHECK(ChildThread::current()->message_loop() == 69 DCHECK(ChildThread::current()->message_loop() ==
70 base::MessageLoop::current()); 70 base::MessageLoop::current());
71 sender_->Send(new BlobHostMsg_StartBuildingBlob(url)); 71 sender_->Send(new BlobHostMsg_StartBuildingBlob(url));
72 size_t i = 0; 72 size_t i = 0;
73 WebBlobData::Item data_item; 73 WebBlobData::Item data_item;
74 while (data.itemAt(i++, data_item)) { 74 while (data.itemAt(i++, data_item)) {
75 webkit_blob::BlobData::Item item;
76 switch (data_item.type) { 75 switch (data_item.type) {
77 case WebBlobData::Item::TypeData: { 76 case WebBlobData::Item::TypeData: {
78 // WebBlobData does not allow partial data items. 77 // WebBlobData does not allow partial data items.
79 DCHECK(!data_item.offset && data_item.length == -1); 78 DCHECK(!data_item.offset && data_item.length == -1);
80 SendData(url, data_item.data, &item); 79 SendData(url, data_item.data);
81 break; 80 break;
82 } 81 }
83 case WebBlobData::Item::TypeFile: 82 case WebBlobData::Item::TypeFile:
84 if (data_item.length) { 83 if (data_item.length) {
84 webkit_blob::BlobData::Item item;
85 item.SetToFilePathRange( 85 item.SetToFilePathRange(
86 base::FilePath::FromUTF16Unsafe(data_item.filePath), 86 base::FilePath::FromUTF16Unsafe(data_item.filePath),
87 static_cast<uint64>(data_item.offset), 87 static_cast<uint64>(data_item.offset),
88 static_cast<uint64>(data_item.length), 88 static_cast<uint64>(data_item.length),
89 base::Time::FromDoubleT(data_item.expectedModificationTime)); 89 base::Time::FromDoubleT(data_item.expectedModificationTime));
90 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); 90 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
91 } 91 }
92 break; 92 break;
93 case WebBlobData::Item::TypeBlob: 93 case WebBlobData::Item::TypeBlob:
94 if (data_item.length) { 94 if (data_item.length) {
95 webkit_blob::BlobData::Item item;
95 item.SetToBlobUrlRange( 96 item.SetToBlobUrlRange(
96 data_item.blobURL, 97 data_item.blobURL,
97 static_cast<uint64>(data_item.offset), 98 static_cast<uint64>(data_item.offset),
98 static_cast<uint64>(data_item.length)); 99 static_cast<uint64>(data_item.length));
99 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); 100 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
100 } 101 }
101 break; 102 break;
102 case WebBlobData::Item::TypeURL: 103 case WebBlobData::Item::TypeURL:
103 if (data_item.length) { 104 if (data_item.length) {
104 // We only support filesystem URL as of now. 105 // We only support filesystem URL as of now.
105 DCHECK(GURL(data_item.url).SchemeIsFileSystem()); 106 DCHECK(GURL(data_item.url).SchemeIsFileSystem());
107 webkit_blob::BlobData::Item item;
106 item.SetToFileSystemUrlRange( 108 item.SetToFileSystemUrlRange(
107 data_item.url, 109 data_item.url,
108 static_cast<uint64>(data_item.offset), 110 static_cast<uint64>(data_item.offset),
109 static_cast<uint64>(data_item.length), 111 static_cast<uint64>(data_item.length),
110 base::Time::FromDoubleT(data_item.expectedModificationTime)); 112 base::Time::FromDoubleT(data_item.expectedModificationTime));
111 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); 113 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item));
112 } 114 }
113 break; 115 break;
114 default: 116 default:
115 NOTREACHED(); 117 NOTREACHED();
116 } 118 }
117 } 119 }
118 sender_->Send(new BlobHostMsg_FinishBuildingBlob( 120 sender_->Send(new BlobHostMsg_FinishBuildingBlob(
119 url, data.contentType().utf8().data())); 121 url, data.contentType().utf8().data()));
120 } 122 }
121 123
124 void WebBlobRegistryImpl::registerStreamURL(
125 const WebURL& url, const WebString& content_type) {
126 DCHECK(ChildThread::current()->message_loop() ==
127 base::MessageLoop::current());
128 sender_->Send(new BlobHostMsg_StartBuildingStream(url, content_type.utf8()));
129 }
130
122 void WebBlobRegistryImpl::registerBlobURL( 131 void WebBlobRegistryImpl::registerBlobURL(
123 const WebURL& url, const WebURL& src_url) { 132 const WebURL& url, const WebURL& src_url) {
124 DCHECK(ChildThread::current()->message_loop() == 133 DCHECK(ChildThread::current()->message_loop() ==
125 base::MessageLoop::current()); 134 base::MessageLoop::current());
126 sender_->Send(new BlobHostMsg_CloneBlob(url, src_url)); 135 sender_->Send(new BlobHostMsg_CloneBlob(url, src_url));
127 } 136 }
128 137
138 void WebBlobRegistryImpl::addDataToStream(const WebKit::WebURL& url,
139 WebKit::WebThreadSafeData& data) {
140 DCHECK(ChildThread::current()->message_loop() ==
141 base::MessageLoop::current());
142 SendData(url, data);
143 }
144
145 void WebBlobRegistryImpl::finalizeStream(const WebURL& url) {
146 DCHECK(ChildThread::current()->message_loop() ==
147 base::MessageLoop::current());
148 sender_->Send(new BlobHostMsg_FinishBuildingBlob(url, ""));
149 }
150
129 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { 151 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) {
130 DCHECK(ChildThread::current()->message_loop() == 152 DCHECK(ChildThread::current()->message_loop() ==
131 base::MessageLoop::current()); 153 base::MessageLoop::current());
132 sender_->Send(new BlobHostMsg_RemoveBlob(url)); 154 sender_->Send(new BlobHostMsg_RemoveBlob(url));
133 } 155 }
134 156
135 } // namespace content 157 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698