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.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 "third_party/WebKit/public/platform/WebBlobData.h" | 15 #include "third_party/WebKit/public/platform/WebBlobData.h" |
16 #include "third_party/WebKit/public/platform/WebString.h" | 16 #include "third_party/WebKit/public/platform/WebString.h" |
17 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" | 17 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" |
18 #include "third_party/WebKit/public/platform/WebURL.h" | 18 #include "third_party/WebKit/public/platform/WebURL.h" |
19 #include "webkit/common/blob/blob_data.h" | 19 #include "storage/common/blob/blob_data.h" |
20 | 20 |
21 using blink::WebBlobData; | 21 using blink::WebBlobData; |
22 using blink::WebString; | 22 using blink::WebString; |
23 using blink::WebThreadSafeData; | 23 using blink::WebThreadSafeData; |
24 using blink::WebURL; | 24 using blink::WebURL; |
25 | 25 |
26 namespace content { | 26 namespace content { |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
(...skipping 19 matching lines...) Expand all Loading... |
49 while (data.itemAt(i++, data_item)) { | 49 while (data.itemAt(i++, data_item)) { |
50 switch (data_item.type) { | 50 switch (data_item.type) { |
51 case WebBlobData::Item::TypeData: { | 51 case WebBlobData::Item::TypeData: { |
52 // WebBlobData does not allow partial data items. | 52 // WebBlobData does not allow partial data items. |
53 DCHECK(!data_item.offset && data_item.length == -1); | 53 DCHECK(!data_item.offset && data_item.length == -1); |
54 SendDataForBlob(uuid_str, data_item.data); | 54 SendDataForBlob(uuid_str, data_item.data); |
55 break; | 55 break; |
56 } | 56 } |
57 case WebBlobData::Item::TypeFile: | 57 case WebBlobData::Item::TypeFile: |
58 if (data_item.length) { | 58 if (data_item.length) { |
59 webkit_blob::BlobData::Item item; | 59 storage::BlobData::Item item; |
60 item.SetToFilePathRange( | 60 item.SetToFilePathRange( |
61 base::FilePath::FromUTF16Unsafe(data_item.filePath), | 61 base::FilePath::FromUTF16Unsafe(data_item.filePath), |
62 static_cast<uint64>(data_item.offset), | 62 static_cast<uint64>(data_item.offset), |
63 static_cast<uint64>(data_item.length), | 63 static_cast<uint64>(data_item.length), |
64 base::Time::FromDoubleT(data_item.expectedModificationTime)); | 64 base::Time::FromDoubleT(data_item.expectedModificationTime)); |
65 sender_->Send( | 65 sender_->Send( |
66 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | 66 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); |
67 } | 67 } |
68 break; | 68 break; |
69 case WebBlobData::Item::TypeBlob: | 69 case WebBlobData::Item::TypeBlob: |
70 if (data_item.length) { | 70 if (data_item.length) { |
71 webkit_blob::BlobData::Item item; | 71 storage::BlobData::Item item; |
72 item.SetToBlobRange( | 72 item.SetToBlobRange( |
73 data_item.blobUUID.utf8(), | 73 data_item.blobUUID.utf8(), |
74 static_cast<uint64>(data_item.offset), | 74 static_cast<uint64>(data_item.offset), |
75 static_cast<uint64>(data_item.length)); | 75 static_cast<uint64>(data_item.length)); |
76 sender_->Send( | 76 sender_->Send( |
77 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | 77 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); |
78 } | 78 } |
79 break; | 79 break; |
80 case WebBlobData::Item::TypeFileSystemURL: | 80 case WebBlobData::Item::TypeFileSystemURL: |
81 if (data_item.length) { | 81 if (data_item.length) { |
82 // We only support filesystem URL as of now. | 82 // We only support filesystem URL as of now. |
83 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem()); | 83 DCHECK(GURL(data_item.fileSystemURL).SchemeIsFileSystem()); |
84 webkit_blob::BlobData::Item item; | 84 storage::BlobData::Item item; |
85 item.SetToFileSystemUrlRange( | 85 item.SetToFileSystemUrlRange( |
86 data_item.fileSystemURL, | 86 data_item.fileSystemURL, |
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( | 90 sender_->Send( |
91 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | 91 new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); |
92 } | 92 } |
93 break; | 93 break; |
94 default: | 94 default: |
(...skipping 20 matching lines...) Expand all Loading... |
115 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { | 115 void WebBlobRegistryImpl::revokePublicBlobURL(const WebURL& url) { |
116 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); | 116 sender_->Send(new BlobHostMsg_RevokePublicURL(url)); |
117 } | 117 } |
118 | 118 |
119 void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str, | 119 void WebBlobRegistryImpl::SendDataForBlob(const std::string& uuid_str, |
120 const WebThreadSafeData& data) { | 120 const WebThreadSafeData& data) { |
121 | 121 |
122 if (data.size() == 0) | 122 if (data.size() == 0) |
123 return; | 123 return; |
124 if (data.size() < kLargeThresholdBytes) { | 124 if (data.size() < kLargeThresholdBytes) { |
125 webkit_blob::BlobData::Item item; | 125 storage::BlobData::Item item; |
126 item.SetToBytes(data.data(), data.size()); | 126 item.SetToBytes(data.data(), data.size()); |
127 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); | 127 sender_->Send(new BlobHostMsg_AppendBlobDataItem(uuid_str, item)); |
128 } else { | 128 } else { |
129 // We handle larger amounts of data via SharedMemory instead of | 129 // We handle larger amounts of data via SharedMemory instead of |
130 // writing it directly to the IPC channel. | 130 // writing it directly to the IPC channel. |
131 size_t shared_memory_size = std::min( | 131 size_t shared_memory_size = std::min( |
132 data.size(), kMaxSharedMemoryBytes); | 132 data.size(), kMaxSharedMemoryBytes); |
133 scoped_ptr<base::SharedMemory> shared_memory( | 133 scoped_ptr<base::SharedMemory> shared_memory( |
134 ChildThread::AllocateSharedMemory(shared_memory_size, | 134 ChildThread::AllocateSharedMemory(shared_memory_size, |
135 sender_.get())); | 135 sender_.get())); |
(...skipping 25 matching lines...) Expand all Loading... |
161 DCHECK(ChildThread::current()); | 161 DCHECK(ChildThread::current()); |
162 sender_->Send(new StreamHostMsg_Clone(url, src_url)); | 162 sender_->Send(new StreamHostMsg_Clone(url, src_url)); |
163 } | 163 } |
164 | 164 |
165 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, | 165 void WebBlobRegistryImpl::addDataToStream(const WebURL& url, |
166 WebThreadSafeData& data) { | 166 WebThreadSafeData& data) { |
167 DCHECK(ChildThread::current()); | 167 DCHECK(ChildThread::current()); |
168 if (data.size() == 0) | 168 if (data.size() == 0) |
169 return; | 169 return; |
170 if (data.size() < kLargeThresholdBytes) { | 170 if (data.size() < kLargeThresholdBytes) { |
171 webkit_blob::BlobData::Item item; | 171 storage::BlobData::Item item; |
172 item.SetToBytes(data.data(), data.size()); | 172 item.SetToBytes(data.data(), data.size()); |
173 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); | 173 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); |
174 } else { | 174 } else { |
175 // We handle larger amounts of data via SharedMemory instead of | 175 // We handle larger amounts of data via SharedMemory instead of |
176 // writing it directly to the IPC channel. | 176 // writing it directly to the IPC channel. |
177 size_t shared_memory_size = std::min( | 177 size_t shared_memory_size = std::min( |
178 data.size(), kMaxSharedMemoryBytes); | 178 data.size(), kMaxSharedMemoryBytes); |
179 scoped_ptr<base::SharedMemory> shared_memory( | 179 scoped_ptr<base::SharedMemory> shared_memory( |
180 ChildThread::AllocateSharedMemory(shared_memory_size, | 180 ChildThread::AllocateSharedMemory(shared_memory_size, |
181 sender_.get())); | 181 sender_.get())); |
(...skipping 21 matching lines...) Expand all Loading... |
203 DCHECK(ChildThread::current()); | 203 DCHECK(ChildThread::current()); |
204 sender_->Send(new StreamHostMsg_AbortBuilding(url)); | 204 sender_->Send(new StreamHostMsg_AbortBuilding(url)); |
205 } | 205 } |
206 | 206 |
207 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { | 207 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { |
208 DCHECK(ChildThread::current()); | 208 DCHECK(ChildThread::current()); |
209 sender_->Send(new StreamHostMsg_Remove(url)); | 209 sender_->Send(new StreamHostMsg_Remove(url)); |
210 } | 210 } |
211 | 211 |
212 } // namespace content | 212 } // namespace content |
OLD | NEW |