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

Side by Side Diff: storage/browser/blob/blob_async_transport_request_builder.cc

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 9
10 #include "base/numerics/safe_math.h" 10 #include "base/numerics/safe_math.h"
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 request.message.transport_strategy = IPCBlobItemRequestStrategy::IPC; 254 request.message.transport_strategy = IPCBlobItemRequestStrategy::IPC;
255 request.message.renderer_item_index = i; 255 request.message.renderer_item_index = i;
256 request.message.renderer_item_offset = 0; 256 request.message.renderer_item_offset = 0;
257 request.message.size = info.length(); 257 request.message.size = info.length();
258 requests_.push_back(request); 258 requests_.push_back(request);
259 builder->AppendFutureData(info.length()); 259 builder->AppendFutureData(info.length());
260 } 260 }
261 } 261 }
262 262
263 /* static */ 263 /* static */
264 bool BlobAsyncTransportRequestBuilder::ShouldBeShortcut(
265 const std::vector<DataElement>& elements,
266 size_t memory_available) {
267 base::CheckedNumeric<size_t> shortcut_bytes = 0;
268 for (const auto& element : elements) {
269 DataElement::Type type = element.type();
270 if (type == DataElement::TYPE_BYTES_DESCRIPTION) {
271 return false;
272 }
273 if (type == DataElement::TYPE_BYTES) {
274 shortcut_bytes += element.length();
275 if (!shortcut_bytes.IsValid()) {
276 return false;
277 }
278 }
279 }
280 return shortcut_bytes.ValueOrDie() <= memory_available;
281 }
282
283 /* static */
284 void BlobAsyncTransportRequestBuilder::ComputeHandleSizes( 264 void BlobAsyncTransportRequestBuilder::ComputeHandleSizes(
285 uint64_t total_memory_size, 265 uint64_t total_memory_size,
286 size_t max_segment_size, 266 size_t max_segment_size,
287 std::vector<size_t>* segment_sizes) { 267 std::vector<size_t>* segment_sizes) {
288 size_t total_max_segments = 268 size_t total_max_segments =
289 static_cast<size_t>(total_memory_size / max_segment_size); 269 static_cast<size_t>(total_memory_size / max_segment_size);
290 bool has_extra_segment = (total_memory_size % max_segment_size) > 0; 270 bool has_extra_segment = (total_memory_size % max_segment_size) > 0;
291 segment_sizes->reserve(total_max_segments + (has_extra_segment ? 1 : 0)); 271 segment_sizes->reserve(total_max_segments + (has_extra_segment ? 1 : 0));
292 segment_sizes->insert(segment_sizes->begin(), total_max_segments, 272 segment_sizes->insert(segment_sizes->begin(), total_max_segments,
293 max_segment_size); 273 max_segment_size);
294 if (has_extra_segment) { 274 if (has_extra_segment) {
295 segment_sizes->push_back(total_memory_size % max_segment_size); 275 segment_sizes->push_back(total_memory_size % max_segment_size);
296 } 276 }
297 } 277 }
298 278
299 } // namespace storage 279 } // namespace storage
OLDNEW
« no previous file with comments | « storage/browser/blob/blob_async_transport_request_builder.h ('k') | storage/browser/blob/blob_data_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698