| OLD | NEW |
| 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/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/shared_memory.h" | 10 #include "base/memory/shared_memory.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "content/child/child_thread.h" | 12 #include "content/child/child_thread_impl.h" |
| 13 #include "content/child/thread_safe_sender.h" | 13 #include "content/child/thread_safe_sender.h" |
| 14 #include "content/common/fileapi/webblob_messages.h" | 14 #include "content/common/fileapi/webblob_messages.h" |
| 15 #include "storage/common/data_element.h" | 15 #include "storage/common/data_element.h" |
| 16 #include "third_party/WebKit/public/platform/WebBlobData.h" | 16 #include "third_party/WebKit/public/platform/WebBlobData.h" |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | 17 #include "third_party/WebKit/public/platform/WebString.h" |
| 18 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" | 18 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" |
| 19 #include "third_party/WebKit/public/platform/WebURL.h" | 19 #include "third_party/WebKit/public/platform/WebURL.h" |
| 20 | 20 |
| 21 using blink::WebBlobData; | 21 using blink::WebBlobData; |
| 22 using blink::WebString; | 22 using blink::WebString; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 151 } |
| 152 | 152 |
| 153 void WebBlobRegistryImpl::SendOversizedDataForBlob( | 153 void WebBlobRegistryImpl::SendOversizedDataForBlob( |
| 154 const std::string& uuid_str, | 154 const std::string& uuid_str, |
| 155 const blink::WebThreadSafeData& data) { | 155 const blink::WebThreadSafeData& data) { |
| 156 DCHECK_GE(data.size(), kLargeThresholdBytes); | 156 DCHECK_GE(data.size(), kLargeThresholdBytes); |
| 157 // We handle larger amounts of data via SharedMemory instead of | 157 // We handle larger amounts of data via SharedMemory instead of |
| 158 // writing it directly to the IPC channel. | 158 // writing it directly to the IPC channel. |
| 159 size_t shared_memory_size = std::min(data.size(), kMaxSharedMemoryBytes); | 159 size_t shared_memory_size = std::min(data.size(), kMaxSharedMemoryBytes); |
| 160 scoped_ptr<base::SharedMemory> shared_memory( | 160 scoped_ptr<base::SharedMemory> shared_memory( |
| 161 ChildThread::AllocateSharedMemory(shared_memory_size, sender_.get())); | 161 ChildThreadImpl::AllocateSharedMemory(shared_memory_size, sender_.get())); |
| 162 CHECK(shared_memory.get()); | 162 CHECK(shared_memory.get()); |
| 163 if (!shared_memory->Map(shared_memory_size)) | 163 if (!shared_memory->Map(shared_memory_size)) |
| 164 CHECK(false); | 164 CHECK(false); |
| 165 | 165 |
| 166 size_t data_size = data.size(); | 166 size_t data_size = data.size(); |
| 167 const char* data_ptr = data.data(); | 167 const char* data_ptr = data.data(); |
| 168 while (data_size) { | 168 while (data_size) { |
| 169 size_t chunk_size = std::min(data_size, shared_memory_size); | 169 size_t chunk_size = std::min(data_size, shared_memory_size); |
| 170 memcpy(shared_memory->memory(), data_ptr, chunk_size); | 170 memcpy(shared_memory->memory(), data_ptr, chunk_size); |
| 171 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory( | 171 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory( |
| 172 uuid_str, shared_memory->handle(), chunk_size)); | 172 uuid_str, shared_memory->handle(), chunk_size)); |
| 173 data_size -= chunk_size; | 173 data_size -= chunk_size; |
| 174 data_ptr += chunk_size; | 174 data_ptr += chunk_size; |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 // ------ streams stuff ----- | 178 // ------ streams stuff ----- |
| 179 | 179 |
| 180 void WebBlobRegistryImpl::registerStreamURL( | 180 void WebBlobRegistryImpl::registerStreamURL( |
| 181 const WebURL& url, const WebString& content_type) { | 181 const WebURL& url, const WebString& content_type) { |
| 182 DCHECK(ChildThread::current()); | 182 DCHECK(ChildThreadImpl::current()); |
| 183 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8())); | 183 sender_->Send(new StreamHostMsg_StartBuilding(url, content_type.utf8())); |
| 184 } | 184 } |
| 185 | 185 |
| 186 void WebBlobRegistryImpl::registerStreamURL( | 186 void WebBlobRegistryImpl::registerStreamURL( |
| 187 const WebURL& url, const WebURL& src_url) { | 187 const WebURL& url, const WebURL& src_url) { |
| 188 DCHECK(ChildThread::current()); | 188 DCHECK(ChildThreadImpl::current()); |
| 189 sender_->Send(new StreamHostMsg_Clone(url, src_url)); | 189 sender_->Send(new StreamHostMsg_Clone(url, src_url)); |
| 190 } | 190 } |
| 191 | 191 |
| 192 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, | 192 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, |
| 193 const char* data, size_t length) { | 193 const char* data, size_t length) { |
| 194 DCHECK(ChildThread::current()); | 194 DCHECK(ChildThreadImpl::current()); |
| 195 if (length == 0) | 195 if (length == 0) |
| 196 return; | 196 return; |
| 197 if (length < kLargeThresholdBytes) { | 197 if (length < kLargeThresholdBytes) { |
| 198 storage::DataElement item; | 198 storage::DataElement item; |
| 199 item.SetToBytes(data, length); | 199 item.SetToBytes(data, length); |
| 200 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); | 200 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); |
| 201 } else { | 201 } else { |
| 202 // We handle larger amounts of data via SharedMemory instead of | 202 // We handle larger amounts of data via SharedMemory instead of |
| 203 // writing it directly to the IPC channel. | 203 // writing it directly to the IPC channel. |
| 204 size_t shared_memory_size = std::min( | 204 size_t shared_memory_size = std::min( |
| 205 length, kMaxSharedMemoryBytes); | 205 length, kMaxSharedMemoryBytes); |
| 206 scoped_ptr<base::SharedMemory> shared_memory( | 206 scoped_ptr<base::SharedMemory> shared_memory( |
| 207 ChildThread::AllocateSharedMemory(shared_memory_size, | 207 ChildThreadImpl::AllocateSharedMemory(shared_memory_size, |
| 208 sender_.get())); | 208 sender_.get())); |
| 209 CHECK(shared_memory.get()); | 209 CHECK(shared_memory.get()); |
| 210 if (!shared_memory->Map(shared_memory_size)) | 210 if (!shared_memory->Map(shared_memory_size)) |
| 211 CHECK(false); | 211 CHECK(false); |
| 212 | 212 |
| 213 size_t remaining_bytes = length; | 213 size_t remaining_bytes = length; |
| 214 const char* current_ptr = data; | 214 const char* current_ptr = data; |
| 215 while (remaining_bytes) { | 215 while (remaining_bytes) { |
| 216 size_t chunk_size = std::min(remaining_bytes, shared_memory_size); | 216 size_t chunk_size = std::min(remaining_bytes, shared_memory_size); |
| 217 memcpy(shared_memory->memory(), current_ptr, chunk_size); | 217 memcpy(shared_memory->memory(), current_ptr, chunk_size); |
| 218 sender_->Send(new StreamHostMsg_SyncAppendSharedMemory( | 218 sender_->Send(new StreamHostMsg_SyncAppendSharedMemory( |
| 219 url, shared_memory->handle(), chunk_size)); | 219 url, shared_memory->handle(), chunk_size)); |
| 220 remaining_bytes -= chunk_size; | 220 remaining_bytes -= chunk_size; |
| 221 current_ptr += chunk_size; | 221 current_ptr += chunk_size; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 } | 224 } |
| 225 | 225 |
| 226 void WebBlobRegistryImpl::flushStream(const WebURL& url) { | 226 void WebBlobRegistryImpl::flushStream(const WebURL& url) { |
| 227 DCHECK(ChildThread::current()); | 227 DCHECK(ChildThreadImpl::current()); |
| 228 sender_->Send(new StreamHostMsg_Flush(url)); | 228 sender_->Send(new StreamHostMsg_Flush(url)); |
| 229 } | 229 } |
| 230 | 230 |
| 231 void WebBlobRegistryImpl::finalizeStream(const WebURL& url) { | 231 void WebBlobRegistryImpl::finalizeStream(const WebURL& url) { |
| 232 DCHECK(ChildThread::current()); | 232 DCHECK(ChildThreadImpl::current()); |
| 233 sender_->Send(new StreamHostMsg_FinishBuilding(url)); | 233 sender_->Send(new StreamHostMsg_FinishBuilding(url)); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void WebBlobRegistryImpl::abortStream(const WebURL& url) { | 236 void WebBlobRegistryImpl::abortStream(const WebURL& url) { |
| 237 DCHECK(ChildThread::current()); | 237 DCHECK(ChildThreadImpl::current()); |
| 238 sender_->Send(new StreamHostMsg_AbortBuilding(url)); | 238 sender_->Send(new StreamHostMsg_AbortBuilding(url)); |
| 239 } | 239 } |
| 240 | 240 |
| 241 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { | 241 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { |
| 242 DCHECK(ChildThread::current()); | 242 DCHECK(ChildThreadImpl::current()); |
| 243 sender_->Send(new StreamHostMsg_Remove(url)); | 243 sender_->Send(new StreamHostMsg_Remove(url)); |
| 244 } | 244 } |
| 245 | 245 |
| 246 } // namespace content | 246 } // namespace content |
| OLD | NEW |