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

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

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build and browsertest fixes 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "storage/browser/blob/blob_slice.h"
6
7 #include <algorithm>
8
9 #include "storage/browser/blob/blob_data_item.h"
10 #include "storage/browser/blob/internal_blob_data.h"
11 #include "storage/browser/blob/shareable_blob_data_item.h"
12
13 namespace storage {
14
15 BlobSlice::BlobSlice(const InternalBlobData& source,
16 uint64_t slice_offset,
17 uint64_t slice_size) {
18 const auto& source_items = source.items();
19 const auto& offsets = source.offsets();
20 LOG(ERROR) << "doing a slice at " << slice_offset << " with size "
21 << slice_size;
22 DCHECK_LE(slice_offset + slice_size, source.total_size());
23 size_t item_index =
24 std::upper_bound(offsets.begin(), offsets.end(), slice_offset) -
25 offsets.begin();
26 uint64_t item_offset =
27 item_index == 0 ? slice_offset : slice_offset - offsets[item_index - 1];
28 size_t num_items = source_items.size();
29
30 size_t first_item_index = item_index;
31 copying_memory_size = 0;
32
33 bool first_item = true;
34 bool last_item_memory_sliced = false;
35 // Read starting from 'mid' and 'offset_from_mid'.
36 for (uint64_t total_sliced = 0;
37 item_index < num_items && total_sliced < slice_size; item_index++) {
38 const scoped_refptr<BlobDataItem>& item = source_items[item_index]->item();
39 uint64_t length = item->length();
40 DCHECK_NE(length, std::numeric_limits<uint64_t>::max());
41 DCHECK_NE(length, 0ull);
42
43 last_item_memory_sliced = false;
44
45 if (item_offset == 0 && slice_size - total_sliced >= item->length()) {
46 // We can share the entire item.
47 LOG(ERROR) << "we can share";
48 dest_items.push_back(source_items[item_index]);
49 total_sliced += length;
50 first_item = false;
51 continue;
52 }
53
54 uint64_t read_size =
55 std::min(item->length() - item_offset, slice_size - total_sliced);
56 total_sliced += read_size;
57
58 scoped_refptr<BlobDataItem> data_item;
59 switch (item->type()) {
60 case DataElement::TYPE_BYTES_DESCRIPTION:
61 case DataElement::TYPE_BYTES: {
62 if (first_item) {
63 has_sliced_first_memory_item = true;
64 first_item_slice_offset = item_offset;
65 first_source_item = source_items[first_item_index];
66 }
67 LOG(ERROR) << "we're sliceing a bytes item!";
68 last_item_memory_sliced = true;
69 copying_memory_size += read_size;
70 // Since we don't have quota yet for memory, we create temporary items
71 // for this data. When our blob is finished constructing, all dependent
72 // blobs are done, and we have enough memory quota, we'll copy the data
73 // over.
74 std::unique_ptr<DataElement> element(new DataElement());
75 element->SetToBytesDescription(base::checked_cast<size_t>(read_size));
76 data_item = new BlobDataItem(std::move(element));
77 } break;
78 case DataElement::TYPE_FILE: {
79 std::unique_ptr<DataElement> element(new DataElement());
80 element->SetToFilePathRange(item->path(), item->offset() + item_offset,
81 read_size,
82 item->expected_modification_time());
83 data_item = new BlobDataItem(std::move(element), item->data_handle_);
84 } break;
85 case DataElement::TYPE_FILE_FILESYSTEM: {
86 std::unique_ptr<DataElement> element(new DataElement());
87 element->SetToFileSystemUrlRange(
88 item->filesystem_url(), item->offset() + item_offset, read_size,
89 item->expected_modification_time());
90 data_item = new BlobDataItem(std::move(element));
91 } break;
92 case DataElement::TYPE_DISK_CACHE_ENTRY: {
93 std::unique_ptr<DataElement> element(new DataElement());
94 element->SetToDiskCacheEntryRange(item->offset() + item_offset,
95 read_size);
96 data_item = new BlobDataItem(std::move(element), item->data_handle_,
97 item->disk_cache_entry(),
98 item->disk_cache_stream_index(),
99 item->disk_cache_side_stream_index());
100 } break;
101 case DataElement::TYPE_BLOB:
102 case DataElement::TYPE_UNKNOWN:
103 CHECK(false) << "Illegal blob item type: " << item->type();
104 }
105 dest_items.push_back(new ShareableBlobDataItem(std::move(data_item)));
106 first_item = false;
107 item_offset = 0;
108 }
109 if (last_item_memory_sliced &&
110 !(has_sliced_first_memory_item && dest_items.size() == 1)) {
111 has_sliced_last_memory_item = true;
112 last_source_item = source_items[item_index - 1];
113 }
114 }
115
116 BlobSlice::~BlobSlice() {}
117
118 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698