OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "storage/browser/blob/blob_data_builder.h" | 5 #include "storage/browser/blob/blob_data_builder.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/numerics/safe_conversions.h" | 13 #include "base/numerics/safe_conversions.h" |
14 #include "base/numerics/safe_math.h" | 14 #include "base/numerics/safe_math.h" |
15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
16 #include "net/disk_cache/disk_cache.h" | 16 #include "net/disk_cache/disk_cache.h" |
17 #include "storage/browser/blob/shareable_file_reference.h" | |
18 | 17 |
19 namespace storage { | 18 namespace storage { |
20 | 19 |
21 namespace { | 20 namespace { |
22 | 21 |
23 const static int kInvalidDiskCacheSideStreamIndex = -1; | 22 const static int kInvalidDiskCacheSideStreamIndex = -1; |
24 | 23 |
25 } // namespace | 24 } // namespace |
26 | 25 |
27 const char BlobDataBuilder::kAppendFutureFileTemporaryFileName[] = | 26 const char BlobDataBuilder::kAppendFutureFileTemporaryFileName[] = |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 offset, length, base::Time()); | 117 offset, length, base::Time()); |
119 items_.push_back(new BlobDataItem(std::move(element))); | 118 items_.push_back(new BlobDataItem(std::move(element))); |
120 return items_.size() - 1; | 119 return items_.size() - 1; |
121 } | 120 } |
122 | 121 |
123 bool BlobDataBuilder::PopulateFutureFile( | 122 bool BlobDataBuilder::PopulateFutureFile( |
124 size_t index, | 123 size_t index, |
125 const scoped_refptr<ShareableFileReference>& file_reference, | 124 const scoped_refptr<ShareableFileReference>& file_reference, |
126 const base::Time& expected_modification_time) { | 125 const base::Time& expected_modification_time) { |
127 DCHECK_LT(index, items_.size()); | 126 DCHECK_LT(index, items_.size()); |
128 DataElement* old_element = items_.at(index)->data_element_ptr(); | 127 DataElement* element = items_.at(index)->data_element_ptr(); |
129 | 128 |
130 if (old_element->type() != DataElement::TYPE_FILE) { | 129 if (element->type() != DataElement::TYPE_FILE) { |
131 DVLOG(1) << "Invalid item type."; | 130 DVLOG(1) << "Invalid item type."; |
132 return false; | 131 return false; |
133 } else if (old_element->path().AsUTF8Unsafe() != | 132 } else if (element->path().AsUTF8Unsafe() != |
134 std::string(kAppendFutureFileTemporaryFileName)) { | 133 std::string(kAppendFutureFileTemporaryFileName)) { |
135 DVLOG(1) << "Item not created by AppendFutureFile"; | 134 DVLOG(1) << "Item not created by AppendFutureFile"; |
136 return false; | 135 return false; |
137 } | 136 } |
138 uint64_t length = old_element->length(); | 137 uint64_t length = element->length(); |
139 uint64_t offset = old_element->offset(); | 138 uint64_t offset = element->offset(); |
140 std::unique_ptr<DataElement> element(new DataElement()); | 139 items_.at(index)->data_handle_ = std::move(file_reference); |
141 element->SetToFilePathRange(file_reference->path(), offset, length, | 140 element->SetToFilePathRange(file_reference->path(), offset, length, |
142 expected_modification_time); | 141 expected_modification_time); |
143 items_[index] = new BlobDataItem(std::move(element), file_reference); | |
144 return true; | 142 return true; |
145 } | 143 } |
146 | 144 |
147 void BlobDataBuilder::AppendFile(const base::FilePath& file_path, | 145 void BlobDataBuilder::AppendFile(const base::FilePath& file_path, |
148 uint64_t offset, | 146 uint64_t offset, |
149 uint64_t length, | 147 uint64_t length, |
150 const base::Time& expected_modification_time) { | 148 const base::Time& expected_modification_time) { |
151 std::unique_ptr<DataElement> element(new DataElement()); | 149 std::unique_ptr<DataElement> element(new DataElement()); |
152 element->SetToFilePathRange(file_path, offset, length, | 150 element->SetToFilePathRange(file_path, offset, length, |
153 expected_modification_time); | 151 expected_modification_time); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 << ", content_type: " << x.content_type_ | 218 << ", content_type: " << x.content_type_ |
221 << ", content_disposition: " << x.content_disposition_ << ", items: ["; | 219 << ", content_disposition: " << x.content_disposition_ << ", items: ["; |
222 for (const auto& item : x.items_) { | 220 for (const auto& item : x.items_) { |
223 PrintTo(*item, os); | 221 PrintTo(*item, os); |
224 *os << ", "; | 222 *os << ", "; |
225 } | 223 } |
226 *os << "]}"; | 224 *os << "]}"; |
227 } | 225 } |
228 | 226 |
229 } // namespace storage | 227 } // namespace storage |
OLD | NEW |