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/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
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_AppendBlobDataItemToBlobOrStream(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())); |
55 CHECK(shared_memory.get()); | 55 CHECK(shared_memory.get()); |
56 while (data_size) { | 56 while (data_size) { |
57 size_t chunk_size = std::min(data_size, shared_memory_size); | 57 size_t chunk_size = std::min(data_size, shared_memory_size); |
58 memcpy(shared_memory->memory(), data_ptr, chunk_size); | 58 memcpy(shared_memory->memory(), data_ptr, chunk_size); |
59 sender_->Send(new BlobHostMsg_SyncAppendSharedMemory( | 59 sender_->Send(new BlobHostMsg_SyncAppendSharedMemoryToBlobOrStream( |
60 url, shared_memory->handle(), chunk_size)); | 60 url, shared_memory->handle(), chunk_size)); |
61 data_size -= chunk_size; | 61 data_size -= chunk_size; |
62 data_ptr += chunk_size; | 62 data_ptr += chunk_size; |
63 } | 63 } |
64 } | 64 } |
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( |
91 new BlobHostMsg_AppendBlobDataItemToBlobOrStream(url, item)); | |
91 } | 92 } |
92 break; | 93 break; |
93 case WebBlobData::Item::TypeBlob: | 94 case WebBlobData::Item::TypeBlob: |
94 if (data_item.length) { | 95 if (data_item.length) { |
96 webkit_blob::BlobData::Item item; | |
95 item.SetToBlobUrlRange( | 97 item.SetToBlobUrlRange( |
96 data_item.blobURL, | 98 data_item.blobURL, |
97 static_cast<uint64>(data_item.offset), | 99 static_cast<uint64>(data_item.offset), |
98 static_cast<uint64>(data_item.length)); | 100 static_cast<uint64>(data_item.length)); |
99 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); | 101 sender_->Send( |
102 new BlobHostMsg_AppendBlobDataItemToBlobOrStream(url, item)); | |
100 } | 103 } |
101 break; | 104 break; |
102 case WebBlobData::Item::TypeURL: | 105 case WebBlobData::Item::TypeURL: |
103 if (data_item.length) { | 106 if (data_item.length) { |
104 // We only support filesystem URL as of now. | 107 // We only support filesystem URL as of now. |
105 DCHECK(GURL(data_item.url).SchemeIsFileSystem()); | 108 DCHECK(GURL(data_item.url).SchemeIsFileSystem()); |
109 webkit_blob::BlobData::Item item; | |
106 item.SetToFileSystemUrlRange( | 110 item.SetToFileSystemUrlRange( |
107 data_item.url, | 111 data_item.url, |
108 static_cast<uint64>(data_item.offset), | 112 static_cast<uint64>(data_item.offset), |
109 static_cast<uint64>(data_item.length), | 113 static_cast<uint64>(data_item.length), |
110 base::Time::FromDoubleT(data_item.expectedModificationTime)); | 114 base::Time::FromDoubleT(data_item.expectedModificationTime)); |
111 sender_->Send(new BlobHostMsg_AppendBlobDataItem(url, item)); | 115 sender_->Send( |
116 new BlobHostMsg_AppendBlobDataItemToBlobOrStream(url, item)); | |
112 } | 117 } |
113 break; | 118 break; |
114 default: | 119 default: |
115 NOTREACHED(); | 120 NOTREACHED(); |
116 } | 121 } |
117 } | 122 } |
118 sender_->Send(new BlobHostMsg_FinishBuildingBlob( | 123 sender_->Send(new BlobHostMsg_FinishBuildingBlob( |
119 url, data.contentType().utf8().data())); | 124 url, data.contentType().utf8().data())); |
120 } | 125 } |
121 | 126 |
127 void WebBlobRegistryImpl::registerStreamURL( | |
128 const WebURL& url, const WebString& content_type) { | |
129 DCHECK(ChildThread::current()->message_loop() == | |
jam
2013/07/23 15:52:36
nit: here and in the rest of the file, ChildThread
tyoshino (SeeGerritForStatus)
2013/07/24 12:14:20
oh. Done.
| |
130 base::MessageLoop::current()); | |
131 sender_->Send(new BlobHostMsg_StartBuildingStream(url, content_type.utf8())); | |
132 } | |
133 | |
122 void WebBlobRegistryImpl::registerBlobURL( | 134 void WebBlobRegistryImpl::registerBlobURL( |
123 const WebURL& url, const WebURL& src_url) { | 135 const WebURL& url, const WebURL& src_url) { |
124 DCHECK(ChildThread::current()->message_loop() == | 136 DCHECK(ChildThread::current()->message_loop() == |
125 base::MessageLoop::current()); | 137 base::MessageLoop::current()); |
126 sender_->Send(new BlobHostMsg_CloneBlob(url, src_url)); | 138 sender_->Send(new BlobHostMsg_CloneBlobOrStream(url, src_url)); |
139 } | |
140 | |
141 void WebBlobRegistryImpl::addDataToStream(const WebKit::WebURL& url, | |
142 WebKit::WebThreadSafeData& data) { | |
143 DCHECK(ChildThread::current()->message_loop() == | |
144 base::MessageLoop::current()); | |
145 SendData(url, data); | |
146 } | |
147 | |
148 void WebBlobRegistryImpl::finalizeStream(const WebURL& url) { | |
149 DCHECK(ChildThread::current()->message_loop() == | |
150 base::MessageLoop::current()); | |
151 sender_->Send(new BlobHostMsg_FinishBuildingStream(url)); | |
127 } | 152 } |
128 | 153 |
129 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { | 154 void WebBlobRegistryImpl::unregisterBlobURL(const WebURL& url) { |
130 DCHECK(ChildThread::current()->message_loop() == | 155 DCHECK(ChildThread::current()->message_loop() == |
131 base::MessageLoop::current()); | 156 base::MessageLoop::current()); |
132 sender_->Send(new BlobHostMsg_RemoveBlob(url)); | 157 sender_->Send(new BlobHostMsg_RemoveBlobOrStream(url)); |
133 } | 158 } |
134 | 159 |
135 } // namespace content | 160 } // namespace content |
OLD | NEW |