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

Unified Diff: content/child/blob_storage/blob_transport_controller.cc

Issue 2125913003: [BlobAsync] Fixed shared memory mapping (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | content/child/blob_storage/blob_transport_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/blob_storage/blob_transport_controller.cc
diff --git a/content/child/blob_storage/blob_transport_controller.cc b/content/child/blob_storage/blob_transport_controller.cc
index 0bcadbc85d30e80ac8d13d4cbaad0b5864627a04..706b56d1402027576a27ee74c161ea6db07af1f7 100644
--- a/content/child/blob_storage/blob_transport_controller.cc
+++ b/content/child/blob_storage/blob_transport_controller.cc
@@ -222,6 +222,21 @@ BlobTransportController::ResponsesStatus BlobTransportController::GetResponses(
BlobConsolidation* consolidation = it->second.get();
const auto& consolidated_items = consolidation->consolidated_items();
+ // We need to calculate how much memory we expect to be writing to the memory
+ // segments so we can correctly map it the first time.
+ std::vector<size_t> shared_memory_sizes(memory_handles->size());
+ for (const BlobItemBytesRequest& request : requests) {
+ if (request.transport_strategy !=
+ IPCBlobItemRequestStrategy::SHARED_MEMORY) {
+ continue;
+ }
+ DCHECK_LT(request.handle_index, memory_handles->size())
+ << "Invalid handle index.";
+ shared_memory_sizes[request.handle_index] =
+ std::max<size_t>(shared_memory_sizes[request.handle_index],
+ request.size + request.handle_offset);
+ }
+
// Since we can be writing to the same shared memory handle from multiple
// requests, we keep them in a vector and lazily create them.
ScopedVector<SharedMemory> opened_memory;
@@ -254,10 +269,11 @@ BlobTransportController::ResponsesStatus BlobTransportController::GetResponses(
SharedMemory* memory = opened_memory[request.handle_index];
if (!memory) {
SharedMemoryHandle& handle = (*memory_handles)[request.handle_index];
+ size_t size = shared_memory_sizes[request.handle_index];
DCHECK(SharedMemory::IsHandleValid(handle));
std::unique_ptr<SharedMemory> shared_memory(
new SharedMemory(handle, false));
- if (!shared_memory->Map(request.size))
+ if (!shared_memory->Map(size))
return ResponsesStatus::SHARED_MEMORY_MAP_FAILED;
memory = shared_memory.get();
opened_memory[request.handle_index] = shared_memory.release();
« no previous file with comments | « no previous file | content/child/blob_storage/blob_transport_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698