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

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: Fixed layout tests, cleaned up test visibility 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_builder.h"
10 #include "storage/browser/blob/blob_data_item.h"
11 #include "storage/browser/blob/internal_blob_data.h"
12 #include "storage/browser/blob/shareable_blob_data_item.h"
13
14 namespace storage {
15
16 BlobSlice::BlobSlice(const InternalBlobData& source,
17 uint64_t slice_offset,
18 uint64_t slice_size) {
19 const auto& source_items = source.items();
20 const auto& offsets = source.offsets();
21 LOG(ERROR) << "doing a slice at " << slice_offset << " with size "
22 << slice_size;
23 DCHECK_LE(slice_offset + slice_size, source.total_size());
24 size_t item_index =
25 std::upper_bound(offsets.begin(), offsets.end(), slice_offset) -
26 offsets.begin();
27 uint64_t item_offset =
28 item_index == 0 ? slice_offset : slice_offset - offsets[item_index - 1];
29 size_t num_items = source_items.size();
30
31 size_t first_item_index = item_index;
32 copying_memory_size = 0;
33
34 // Read starting from 'first_item_index' and 'item_offset'.
35 for (uint64_t total_sliced = 0;
36 item_index < num_items && total_sliced < slice_size; item_index++) {
37 const scoped_refptr<BlobDataItem>& source_item =
38 source_items[item_index]->item();
39 uint64_t source_length = source_item->length();
40 DCHECK_NE(source_length, std::numeric_limits<uint64_t>::max());
41 DCHECK_NE(source_length, 0ull);
42
43 uint64_t read_size =
44 std::min(source_length - item_offset, slice_size - total_sliced);
45 total_sliced += read_size;
46
47 if (read_size == source_length) {
48 // We can share the entire item.
49 LOG(ERROR) << "we can share";
50 dest_items.push_back(source_items[item_index]);
51 continue;
52 }
53
54 scoped_refptr<BlobDataItem> data_item;
55 switch (source_item->type()) {
56 case DataElement::TYPE_BYTES_DESCRIPTION:
57 case DataElement::TYPE_BYTES: {
58 if (item_index == first_item_index) {
59 first_item_slice_offset = item_offset;
60 first_source_item = source_items[item_index];
61 } else {
62 last_source_item = source_items[item_index];
63 }
64 LOG(ERROR) << "we're slicing a bytes item!";
65 copying_memory_size += read_size;
66 // Since we don't have quota yet for memory, we create temporary items
michaeln 2016/08/15 22:44:42 terminilogy nit: "unpopulated" might be a good ter
67 // for this data. When our blob is finished constructing, all dependent
68 // blobs are done, and we have enough memory quota, we'll copy the data
69 // over.
70 std::unique_ptr<DataElement> element(new DataElement());
71 element->SetToBytesDescription(base::checked_cast<size_t>(read_size));
72 data_item = new BlobDataItem(std::move(element));
73 break;
74 }
75 case DataElement::TYPE_FILE: {
76 std::unique_ptr<DataElement> element(new DataElement());
77 element->SetToFilePathRange(
78 source_item->path(), source_item->offset() + item_offset, read_size,
79 source_item->expected_modification_time());
80 data_item =
81 new BlobDataItem(std::move(element), source_item->data_handle_);
82
83 if (source_item->path().value() ==
84 std::string(BlobDataBuilder::kAppendFutureFileTemporaryFileName)) {
85 // Since we don't have file path / reference for our future file, we
86 // create another file item with this temporary file name. When our
87 // blob is finished constructing, all dependent blobs are done, and we
88 // can copy the handle over.
89 LOG(ERROR) << "we're slicing a temp file item!";
90 if (item_index == first_item_index) {
91 first_item_slice_offset = item_offset;
92 first_source_item = source_items[item_index];
93 } else {
94 last_source_item = source_items[item_index];
95 }
96 }
97 break;
98 }
99 case DataElement::TYPE_FILE_FILESYSTEM: {
100 std::unique_ptr<DataElement> element(new DataElement());
101 element->SetToFileSystemUrlRange(
102 source_item->filesystem_url(), source_item->offset() + item_offset,
103 read_size, source_item->expected_modification_time());
104 data_item = new BlobDataItem(std::move(element));
105 break;
106 }
107 case DataElement::TYPE_DISK_CACHE_ENTRY: {
108 std::unique_ptr<DataElement> element(new DataElement());
109 element->SetToDiskCacheEntryRange(source_item->offset() + item_offset,
110 read_size);
111 data_item =
112 new BlobDataItem(std::move(element), source_item->data_handle_,
113 source_item->disk_cache_entry(),
114 source_item->disk_cache_stream_index(),
115 source_item->disk_cache_side_stream_index());
116 break;
117 }
118 case DataElement::TYPE_BLOB:
119 case DataElement::TYPE_UNKNOWN:
120 CHECK(false) << "Illegal blob item type: " << source_item->type();
121 }
122 dest_items.push_back(new ShareableBlobDataItem(std::move(data_item)));
123 item_offset = 0;
124 }
125 }
126
127 BlobSlice::~BlobSlice() {}
128
129 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698