| Index: storage/browser/blob/blob_async_transport_strategy.cc
|
| diff --git a/storage/browser/blob/blob_async_transport_strategy.cc b/storage/browser/blob/blob_async_transport_strategy.cc
|
| index 8dbe52ed9a33712d33a5466dc7a6b1439dc5fdb0..ce86cc93ae549802ad994e7b3636bf2e8a91287a 100644
|
| --- a/storage/browser/blob/blob_async_transport_strategy.cc
|
| +++ b/storage/browser/blob/blob_async_transport_strategy.cc
|
| @@ -190,96 +190,60 @@ void ForEachWithSegment(const std::vector<DataElement>& elements,
|
|
|
| BlobAsyncTransportStrategy::RendererMemoryItemRequest::
|
| RendererMemoryItemRequest()
|
| - : browser_item_index(0), browser_item_offset(0), received(false) {}
|
| + : browser_item_index(0), browser_item_offset(0) {}
|
|
|
| BlobAsyncTransportStrategy::BlobAsyncTransportStrategy()
|
| : error_(BlobAsyncTransportStrategy::ERROR_NONE), total_bytes_size_(0) {}
|
|
|
| BlobAsyncTransportStrategy::~BlobAsyncTransportStrategy() {}
|
|
|
| -// if total_blob_size > |memory_available| (say 400MB)
|
| -// Request all data in files
|
| -// (Segment all of the existing data into
|
| -// file blocks, of <= |max_file_size|)
|
| -// else if total_blob_size > |max_ipc_memory_size| (say 150KB)
|
| -// Request all data in shared memory
|
| -// (Segment all of the existing data into
|
| -// shared memory blocks, of <= |max_shared_memory_size|)
|
| -// else
|
| -// Request all data to be sent over IPC
|
| -void BlobAsyncTransportStrategy::Initialize(
|
| - size_t max_ipc_memory_size,
|
| - size_t max_shared_memory_size,
|
| +// Initializes the transport strategy for file requests.
|
| +void BlobAsyncTransportStrategy::InitializeForFileRequests(
|
| size_t max_file_size,
|
| - uint64_t disk_space_left,
|
| - size_t memory_available,
|
| const std::string& uuid,
|
| - const std::vector<DataElement>& blob_item_infos) {
|
| - DCHECK(handle_sizes_.empty());
|
| + uint64_t blob_total_size,
|
| + const std::vector<DataElement>& blob_item_infos,
|
| + BlobDataBuilder* builder) {
|
| DCHECK(requests_.empty());
|
| - DCHECK(!builder_.get());
|
| - builder_.reset(new BlobDataBuilder(uuid));
|
| - error_ = BlobAsyncTransportStrategy::ERROR_NONE;
|
| -
|
| - size_t memory_items = 0;
|
| - base::CheckedNumeric<uint64_t> total_size_checked = 0;
|
| - for (const auto& info : blob_item_infos) {
|
| - if (!IsBytes(info.type())) {
|
| - continue;
|
| - }
|
| - total_size_checked += info.length();
|
| - ++memory_items;
|
| - }
|
| -
|
| - if (!total_size_checked.IsValid()) {
|
| - DVLOG(1) << "Impossible total size of all memory elements.";
|
| - error_ = BlobAsyncTransportStrategy::ERROR_INVALID_PARAMS;
|
| - return;
|
| - }
|
| -
|
| - total_bytes_size_ = total_size_checked.ValueOrDie();
|
| -
|
| - // See if we have enough memory.
|
| - if (total_bytes_size_ >
|
| - disk_space_left + static_cast<uint64_t>(memory_available)) {
|
| - error_ = BlobAsyncTransportStrategy::ERROR_TOO_LARGE;
|
| - return;
|
| - }
|
| -
|
| - // If we're more than the available memory, then we're going straight to disk.
|
| - if (total_bytes_size_ > memory_available) {
|
| - if (total_bytes_size_ > disk_space_left) {
|
| - error_ = BlobAsyncTransportStrategy::ERROR_TOO_LARGE;
|
| - return;
|
| - }
|
| - ComputeHandleSizes(total_bytes_size_, max_file_size, &handle_sizes_);
|
| - FileStorageStrategy strategy(&requests_, builder_.get());
|
| - ForEachWithSegment(blob_item_infos, static_cast<uint64_t>(max_file_size),
|
| - &strategy);
|
| - return;
|
| - }
|
| + total_bytes_size_ = blob_total_size;
|
| + ComputeHandleSizes(total_bytes_size_, max_file_size, &file_handle_sizes_);
|
| + FileStorageStrategy strategy(&requests_, builder);
|
| + ForEachWithSegment(blob_item_infos, static_cast<uint64_t>(max_file_size),
|
| + &strategy);
|
| +}
|
|
|
| - if (total_bytes_size_ > max_ipc_memory_size) {
|
| - // Note: The size must be <= std::numeric_limits<size_t>::max(). Otherwise
|
| - // we are guarenteed to be caught by the if statement above,
|
| - // |total_bytes_size_ > memory_available|.
|
| - ComputeHandleSizes(total_bytes_size_, max_shared_memory_size,
|
| - &handle_sizes_);
|
| - SharedMemoryStorageStrategy strategy(max_shared_memory_size, &requests_,
|
| - builder_.get());
|
| - ForEachWithSegment(blob_item_infos,
|
| - static_cast<uint64_t>(max_shared_memory_size),
|
| - &strategy);
|
| - return;
|
| - }
|
| +void BlobAsyncTransportStrategy::InitializeForSharedMemoryRequests(
|
| + size_t max_shared_memory_size,
|
| + const std::string& uuid,
|
| + uint64_t blob_total_size,
|
| + const std::vector<DataElement>& blob_item_infos,
|
| + BlobDataBuilder* builder) {
|
| + DCHECK(requests_.empty());
|
| + DCHECK(blob_total_size <= std::numeric_limits<size_t>::max());
|
| + total_bytes_size_ = blob_total_size;
|
| + ComputeHandleSizes(total_bytes_size_, max_shared_memory_size,
|
| + &shared_memory_handle_sizes_);
|
| + SharedMemoryStorageStrategy strategy(max_shared_memory_size, &requests_,
|
| + builder);
|
| + ForEachWithSegment(blob_item_infos,
|
| + static_cast<uint64_t>(max_shared_memory_size), &strategy);
|
| +}
|
|
|
| - // Since they can all fit in IPC memory, we don't need to segment anything,
|
| - // and just request them straight in IPC.
|
| +void BlobAsyncTransportStrategy::InitializeForIPCTransportation(
|
| + size_t max_ipc_memory_size,
|
| + const std::string& uuid,
|
| + uint64_t blob_total_size,
|
| + const std::vector<DataElement>& blob_item_infos,
|
| + BlobDataBuilder* builder) {
|
| + DCHECK(requests_.empty());
|
| + // We don't ssegment anything, and just request the memory items directly
|
| + // in IPC.
|
| size_t items_length = blob_item_infos.size();
|
| + total_bytes_size_ = blob_total_size;
|
| for (size_t i = 0; i < items_length; i++) {
|
| const auto& info = blob_item_infos.at(i);
|
| if (!IsBytes(info.type())) {
|
| - builder_->AppendIPCDataElement(info);
|
| + builder->AppendIPCDataElement(info);
|
| continue;
|
| }
|
| BlobAsyncTransportStrategy::RendererMemoryItemRequest request;
|
| @@ -291,7 +255,7 @@ void BlobAsyncTransportStrategy::Initialize(
|
| request.message.renderer_item_offset = 0;
|
| request.message.size = info.length();
|
| requests_.push_back(request);
|
| - builder_->AppendFutureData(info.length());
|
| + builder->AppendFutureData(info.length());
|
| }
|
| }
|
|
|
|
|