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

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: comments, simplifications 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/blob_storage_context.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 blob_offset,
17 uint64_t size) {
michaeln 2016/07/07 20:05:23 some naming suggestions: source, slice_offset, sli
dmurph 2016/07/11 23:33:27 Done.
18 const auto& source_items = source.items();
michaeln 2016/07/07 20:05:23 what if source_items is empty? can that happen?
dmurph 2016/07/11 23:33:27 That shouldn't happen, as we check to see if we ne
19 const auto& offsets = source.offsets();
20 size_t mid = std::upper_bound(offsets.begin(), offsets.end(), blob_offset) -
21 offsets.begin();
22 uint64_t offset_from_mid =
michaeln 2016/07/07 20:05:23 for these two locals, names like item_index and it
dmurph 2016/07/11 23:33:27 Done.
23 mid == 0 ? blob_offset : blob_offset - offsets[mid - 1];
24 size_t num_items = source_items.size();
25
26 LOG(ERROR) << "doing a slice at " << blob_offset << " with size " << size;
27 size_t first_item_index = mid;
28 copying_memory_size = 0;
29
30 bool first_item = true;
31 bool last_item_memory_sliced = false;
32 // Read starting from 'mid' and 'offset_from_mid'.
33 for (uint64_t memory_read = 0; mid < num_items && memory_read < size; mid++) {
michaeln 2016/07/07 20:05:23 it looks like |memory_read| also accumulates the s
dmurph 2016/07/11 23:33:27 Done.
34 const scoped_refptr<BlobDataItem>& item = source_items[mid]->item();
35 uint64_t length = item->length();
36 if (length == 0) {
michaeln 2016/07/07 20:05:23 do we have zero length items? i think at some poin
dmurph 2016/07/11 23:33:27 We shouldn't. I'll dcheck this.
37 continue;
38 }
39 DCHECK_NE(length, std::numeric_limits<uint64_t>::max());
40 DCHECK_NE(length, 0ull);
41
42 last_item_memory_sliced = false;
43 LOG(ERROR) << item->length();
44 bool can_share_item =
michaeln 2016/07/07 20:05:23 since this local is only used in the if below, get
dmurph 2016/07/11 23:33:27 Done.
45 offset_from_mid == 0 && size - memory_read >= item->length();
46
47 if (can_share_item) {
48 LOG(ERROR) << "we can share";
49 dest_items.push_back(source_items[mid]);
50 memory_read += length;
51 first_item = false;
52 continue;
53 }
54
55 uint64_t read_size =
56 std::min(item->length() - offset_from_mid, size - memory_read);
57 memory_read += read_size;
58
59 scoped_refptr<BlobDataItem> data_item;
60 switch (item->type()) {
61 case DataElement::TYPE_BYTES_DESCRIPTION:
62 case DataElement::TYPE_BYTES: {
63 if (first_item) {
64 has_sliced_first_memory_item = true;
65 first_item_slice_offset = offset_from_mid;
66 first_source_item = source_items[first_item_index];
67 }
68 LOG(ERROR) << "we're sliceing a bytes item!";
69 last_item_memory_sliced = true;
70 copying_memory_size += read_size;
71 std::unique_ptr<DataElement> element(new DataElement());
72 element->SetToBytesDescription(base::checked_cast<size_t>(read_size));
73 data_item = new BlobDataItem(std::move(element), nullptr);
michaeln 2016/07/07 20:05:23 when do we really copy the data?
dmurph 2016/07/11 23:33:27 When the blob is finished constructing. The flatte
74 } break;
75 case DataElement::TYPE_FILE: {
76 std::unique_ptr<DataElement> element(new DataElement());
77 element->SetToFilePathRange(item->path(),
78 item->offset() + offset_from_mid, read_size,
79 item->expected_modification_time());
80 data_item = new BlobDataItem(std::move(element), item->data_handle_);
81 } break;
82 case DataElement::TYPE_FILE_FILESYSTEM: {
83 std::unique_ptr<DataElement> element(new DataElement());
84 element->SetToFileSystemUrlRange(
85 item->filesystem_url(), item->offset() + offset_from_mid, read_size,
86 item->expected_modification_time());
87 data_item = new BlobDataItem(std::move(element), nullptr);
88 } break;
89 case DataElement::TYPE_DISK_CACHE_ENTRY: {
90 std::unique_ptr<DataElement> element(new DataElement());
91 element->SetToDiskCacheEntryRange(item->offset() + offset_from_mid,
92 read_size);
93 data_item = new BlobDataItem(std::move(element), item->data_handle_,
94 item->disk_cache_entry(),
95 item->disk_cache_stream_index(),
96 item->disk_cache_side_stream_index());
97 } break;
98 case DataElement::TYPE_BLOB:
99 case DataElement::TYPE_UNKNOWN:
100 CHECK(false) << "Illegal blob item type: " << item->type();
101 }
102 dest_items.push_back(new ShareableBlobDataItem(
103 BlobStorageContext::GetAndIncrementItemId(), std::move(data_item)));
104 first_item = false;
105 offset_from_mid = 0;
106 }
107 if (last_item_memory_sliced &&
108 !(has_sliced_first_memory_item && dest_items.size() == 1)) {
109 has_sliced_last_memory_item = true;
110 last_source_item = source_items[mid - 1];
111 }
112 }
113
114 BlobSlice::~BlobSlice() {}
115
116 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698