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

Side by Side Diff: content/child/blob_storage/blob_consolidation.cc

Issue 1414123002: [BlobAsync] Renderer support for blob file writing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-hookup
Patch Set: rebase Created 4 years, 8 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 "content/child/blob_storage/blob_consolidation.h" 5 #include "content/child/blob_storage/blob_consolidation.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
11 #include <string> 11 #include <string>
12 12
13 #include "base/bind.h"
14 #include "base/callback.h"
15
13 using storage::DataElement; 16 using storage::DataElement;
14 using blink::WebThreadSafeData; 17 using blink::WebThreadSafeData;
15 18
16 namespace content { 19 namespace content {
20 namespace {
21 bool WriteMemory(void* memory_out,
22 size_t total_read,
23 const char* memory,
24 size_t size) {
25 memcpy(static_cast<char*>(memory_out) + total_read, memory, size);
26 return true;
27 }
28 } // namespace
17 29
18 using ReadStatus = BlobConsolidation::ReadStatus; 30 using ReadStatus = BlobConsolidation::ReadStatus;
19 31
20 BlobConsolidation::ConsolidatedItem::ConsolidatedItem() 32 BlobConsolidation::ConsolidatedItem::ConsolidatedItem()
21 : type(DataElement::TYPE_UNKNOWN), 33 : type(DataElement::TYPE_UNKNOWN),
22 offset(0), 34 offset(0),
23 length(std::numeric_limits<uint64_t>::max()), 35 length(std::numeric_limits<uint64_t>::max()),
24 expected_modification_time(0) {} 36 expected_modification_time(0) {}
25 37
26 BlobConsolidation::ConsolidatedItem::~ConsolidatedItem() { 38 BlobConsolidation::ConsolidatedItem::~ConsolidatedItem() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 double expected_modification_time) { 104 double expected_modification_time) {
93 if (length == 0) 105 if (length == 0)
94 return; 106 return;
95 consolidated_items_.push_back( 107 consolidated_items_.push_back(
96 ConsolidatedItem(DataElement::TYPE_FILE_FILESYSTEM, offset, length)); 108 ConsolidatedItem(DataElement::TYPE_FILE_FILESYSTEM, offset, length));
97 ConsolidatedItem& item = consolidated_items_.back(); 109 ConsolidatedItem& item = consolidated_items_.back();
98 item.filesystem_url = url; 110 item.filesystem_url = url;
99 item.expected_modification_time = expected_modification_time; 111 item.expected_modification_time = expected_modification_time;
100 } 112 }
101 113
102 ReadStatus BlobConsolidation::ReadMemory(size_t consolidated_item_index, 114 ReadStatus BlobConsolidation::VisitMemory(
103 size_t consolidated_offset, 115 size_t consolidated_item_index,
104 size_t consolidated_size, 116 size_t consolidated_offset,
105 void* memory_out) { 117 size_t consolidated_size,
106 CHECK(memory_out); 118 base::Callback<bool(size_t /* total_memory_read */,
119 const char* /* memory */,
120 size_t /* memory_size */)> visitor) const {
107 if (consolidated_item_index >= consolidated_items_.size()) 121 if (consolidated_item_index >= consolidated_items_.size())
108 return ReadStatus::ERROR_OUT_OF_BOUNDS; 122 return ReadStatus::ERROR_OUT_OF_BOUNDS;
109 123
110 const ConsolidatedItem& item = consolidated_items_[consolidated_item_index]; 124 const ConsolidatedItem& item = consolidated_items_[consolidated_item_index];
111 if (item.type != DataElement::TYPE_BYTES) 125 if (item.type != DataElement::TYPE_BYTES)
112 return ReadStatus::ERROR_WRONG_TYPE; 126 return ReadStatus::ERROR_WRONG_TYPE;
113 127
114 if (consolidated_size + consolidated_offset > item.length) { 128 if (consolidated_size + consolidated_offset > item.length) {
115 LOG(ERROR) << "Invalid consolidated size " << consolidated_size 129 LOG(ERROR) << "Invalid consolidated size " << consolidated_size
116 << " and offset " << consolidated_offset << " vs item length of " 130 << " and offset " << consolidated_offset << " vs item length of "
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 } 162 }
149 } 163 }
150 } 164 }
151 165
152 DCHECK_LT(offset_from_mid, item.data[mid].size()); 166 DCHECK_LT(offset_from_mid, item.data[mid].size());
153 // Read starting from 'mid' and 'offset_from_mid'. 167 // Read starting from 'mid' and 'offset_from_mid'.
154 for (size_t memory_read = 0; 168 for (size_t memory_read = 0;
155 mid < num_items && memory_read < consolidated_size; mid++) { 169 mid < num_items && memory_read < consolidated_size; mid++) {
156 size_t read_size = std::min(item.data[mid].size() - offset_from_mid, 170 size_t read_size = std::min(item.data[mid].size() - offset_from_mid,
157 consolidated_size - memory_read); 171 consolidated_size - memory_read);
158 memcpy(static_cast<char*>(memory_out) + memory_read, 172 bool cont = visitor.Run(memory_read,
159 item.data[mid].data() + offset_from_mid, read_size); 173 item.data[mid].data() + offset_from_mid, read_size);
174 if (!cont)
kinuko 2016/04/15 15:02:31 What's 'cont'? Continue? It's not too obvious wh
dmurph 2016/04/20 21:15:34 Added comment, and comment on method signature.
175 return ReadStatus::EARLY_ABORT;
160 offset_from_mid = 0; 176 offset_from_mid = 0;
161 memory_read += read_size; 177 memory_read += read_size;
162 } 178 }
163 return ReadStatus::OK; 179 return ReadStatus::OK;
164 } 180 }
165 181
182 ReadStatus BlobConsolidation::ReadMemory(size_t consolidated_item_index,
183 size_t consolidated_offset,
184 size_t consolidated_size,
185 void* memory_out) const {
186 CHECK(memory_out);
187 return VisitMemory(consolidated_item_index, consolidated_offset,
188 consolidated_size, base::Bind(&WriteMemory, memory_out));
189 }
190
166 } // namespace content 191 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698