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

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

Issue 610333002: [WebBlobRegistry] Use char* than WebThreadSafeData (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 2 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
« no previous file with comments | « content/child/webblobregistry_impl.h ('k') | content/test/mock_webblob_registry_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 157 }
158 158
159 void WebBlobRegistryImpl::registerStreamURL( 159 void WebBlobRegistryImpl::registerStreamURL(
160 const WebURL& url, const WebURL& src_url) { 160 const WebURL& url, const WebURL& src_url) {
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 addDataToStream(url, data.data(), data.size());
168 }
169
170 void WebBlobRegistryImpl::addDataToStream(const WebURL& url,
171 const char* data, size_t length) {
167 DCHECK(ChildThread::current()); 172 DCHECK(ChildThread::current());
168 if (data.size() == 0) 173 if (length == 0)
169 return; 174 return;
170 if (data.size() < kLargeThresholdBytes) { 175 if (length < kLargeThresholdBytes) {
171 storage::BlobData::Item item; 176 storage::BlobData::Item item;
172 item.SetToBytes(data.data(), data.size()); 177 item.SetToBytes(data, length);
173 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item)); 178 sender_->Send(new StreamHostMsg_AppendBlobDataItem(url, item));
174 } else { 179 } else {
175 // We handle larger amounts of data via SharedMemory instead of 180 // We handle larger amounts of data via SharedMemory instead of
176 // writing it directly to the IPC channel. 181 // writing it directly to the IPC channel.
177 size_t shared_memory_size = std::min( 182 size_t shared_memory_size = std::min(
178 data.size(), kMaxSharedMemoryBytes); 183 length, kMaxSharedMemoryBytes);
179 scoped_ptr<base::SharedMemory> shared_memory( 184 scoped_ptr<base::SharedMemory> shared_memory(
180 ChildThread::AllocateSharedMemory(shared_memory_size, 185 ChildThread::AllocateSharedMemory(shared_memory_size,
181 sender_.get())); 186 sender_.get()));
182 CHECK(shared_memory.get()); 187 CHECK(shared_memory.get());
183 188
184 size_t data_size = data.size(); 189 size_t remaining_bytes = length;
185 const char* data_ptr = data.data(); 190 const char* current_ptr = data;
186 while (data_size) { 191 while (remaining_bytes) {
187 size_t chunk_size = std::min(data_size, shared_memory_size); 192 size_t chunk_size = std::min(remaining_bytes, shared_memory_size);
188 memcpy(shared_memory->memory(), data_ptr, chunk_size); 193 memcpy(shared_memory->memory(), current_ptr, chunk_size);
189 sender_->Send(new StreamHostMsg_SyncAppendSharedMemory( 194 sender_->Send(new StreamHostMsg_SyncAppendSharedMemory(
190 url, shared_memory->handle(), chunk_size)); 195 url, shared_memory->handle(), chunk_size));
191 data_size -= chunk_size; 196 remaining_bytes -= chunk_size;
192 data_ptr += chunk_size; 197 current_ptr += chunk_size;
193 } 198 }
194 } 199 }
195 } 200 }
196 201
197 void WebBlobRegistryImpl::finalizeStream(const WebURL& url) { 202 void WebBlobRegistryImpl::finalizeStream(const WebURL& url) {
198 DCHECK(ChildThread::current()); 203 DCHECK(ChildThread::current());
199 sender_->Send(new StreamHostMsg_FinishBuilding(url)); 204 sender_->Send(new StreamHostMsg_FinishBuilding(url));
200 } 205 }
201 206
202 void WebBlobRegistryImpl::abortStream(const WebURL& url) { 207 void WebBlobRegistryImpl::abortStream(const WebURL& url) {
203 DCHECK(ChildThread::current()); 208 DCHECK(ChildThread::current());
204 sender_->Send(new StreamHostMsg_AbortBuilding(url)); 209 sender_->Send(new StreamHostMsg_AbortBuilding(url));
205 } 210 }
206 211
207 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) { 212 void WebBlobRegistryImpl::unregisterStreamURL(const WebURL& url) {
208 DCHECK(ChildThread::current()); 213 DCHECK(ChildThread::current());
209 sender_->Send(new StreamHostMsg_Remove(url)); 214 sender_->Send(new StreamHostMsg_Remove(url));
210 } 215 }
211 216
212 } // namespace content 217 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webblobregistry_impl.h ('k') | content/test/mock_webblob_registry_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698