| OLD | NEW |
| 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_transport_controller.h" | 5 #include "content/child/blob_storage/blob_transport_controller.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 file->WriteAtCurrentPos(memory, static_cast<int>(writing_size)); | 83 file->WriteAtCurrentPos(memory, static_cast<int>(writing_size)); |
| 84 bool write_failed = actual_written < 0; | 84 bool write_failed = actual_written < 0; |
| 85 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.RendererFileWriteFailed", write_failed); | 85 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.RendererFileWriteFailed", write_failed); |
| 86 if (write_failed) | 86 if (write_failed) |
| 87 return false; | 87 return false; |
| 88 written += actual_written; | 88 written += actual_written; |
| 89 } | 89 } |
| 90 return true; | 90 return true; |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool WriteSingleRequestToDisk(const BlobConsolidation* consolidation, | 93 base::Optional<base::Time> WriteSingleRequestToDisk( |
| 94 const BlobItemBytesRequest& request, | 94 const BlobConsolidation* consolidation, |
| 95 File* file) { | 95 const BlobItemBytesRequest& request, |
| 96 File* file) { |
| 96 if (!file->IsValid()) | 97 if (!file->IsValid()) |
| 97 return false; | 98 return base::nullopt; |
| 98 int64_t seek_distance = file->Seek( | 99 int64_t seek_distance = file->Seek( |
| 99 File::FROM_BEGIN, base::checked_cast<int64_t>(request.handle_offset)); | 100 File::FROM_BEGIN, base::checked_cast<int64_t>(request.handle_offset)); |
| 100 bool seek_failed = seek_distance < 0; | 101 bool seek_failed = seek_distance < 0; |
| 101 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.RendererFileSeekFailed", seek_failed); | 102 UMA_HISTOGRAM_BOOLEAN("Storage.Blob.RendererFileSeekFailed", seek_failed); |
| 102 if (seek_failed) | 103 if (seek_failed) { |
| 103 return false; | 104 return base::nullopt; |
| 105 } |
| 104 BlobConsolidation::ReadStatus status = consolidation->VisitMemory( | 106 BlobConsolidation::ReadStatus status = consolidation->VisitMemory( |
| 105 request.renderer_item_index, request.renderer_item_offset, request.size, | 107 request.renderer_item_index, request.renderer_item_offset, request.size, |
| 106 base::Bind(&WriteSingleChunk, file)); | 108 base::Bind(&WriteSingleChunk, file)); |
| 107 if (status != BlobConsolidation::ReadStatus::OK) | 109 if (status != BlobConsolidation::ReadStatus::OK) |
| 108 return false; | 110 return base::nullopt; |
| 109 return true; | 111 File::Info info; |
| 112 file->GetInfo(&info); |
| 113 return base::make_optional(info.last_modified); |
| 110 } | 114 } |
| 111 | 115 |
| 112 base::Optional<std::vector<BlobItemBytesResponse>> WriteDiskRequests( | 116 base::Optional<std::vector<BlobItemBytesResponse>> WriteDiskRequests( |
| 113 scoped_refptr<BlobConsolidation> consolidation, | 117 scoped_refptr<BlobConsolidation> consolidation, |
| 114 std::unique_ptr<std::vector<BlobItemBytesRequest>> requests, | 118 std::unique_ptr<std::vector<BlobItemBytesRequest>> requests, |
| 115 const std::vector<IPC::PlatformFileForTransit>& file_handles) { | 119 const std::vector<IPC::PlatformFileForTransit>& file_handles) { |
| 116 std::vector<BlobItemBytesResponse> responses; | 120 std::vector<BlobItemBytesResponse> responses; |
| 121 std::vector<base::Time> last_modified_times; |
| 122 last_modified_times.resize(file_handles.size()); |
| 117 // We grab ownership of the file handles here. When this vector is destroyed | 123 // We grab ownership of the file handles here. When this vector is destroyed |
| 118 // it will close the files. | 124 // it will close the files. |
| 119 std::vector<File> files; | 125 std::vector<File> files; |
| 120 files.reserve(file_handles.size()); | 126 files.reserve(file_handles.size()); |
| 121 for (const auto& file_handle : file_handles) { | 127 for (const auto& file_handle : file_handles) { |
| 122 files.emplace_back(IPC::PlatformFileForTransitToFile(file_handle)); | 128 files.emplace_back(IPC::PlatformFileForTransitToFile(file_handle)); |
| 123 } | 129 } |
| 124 for (const auto& request : *requests) { | 130 for (const auto& request : *requests) { |
| 125 if (!WriteSingleRequestToDisk(consolidation.get(), request, | 131 base::Optional<base::Time> last_modified = WriteSingleRequestToDisk( |
| 126 &files[request.handle_index])) { | 132 consolidation.get(), request, &files[request.handle_index]); |
| 133 if (!last_modified) { |
| 127 return base::nullopt; | 134 return base::nullopt; |
| 128 } | 135 } |
| 136 last_modified_times[request.handle_index] = last_modified.value(); |
| 129 } | 137 } |
| 130 // The last modified time needs to be collected after we flush the file. | |
| 131 std::vector<base::Time> last_modified_times; | |
| 132 last_modified_times.resize(file_handles.size()); | |
| 133 for (size_t i = 0; i < files.size(); ++i) { | |
| 134 auto& file = files[i]; | |
| 135 if (!file.Flush()) | |
| 136 return base::nullopt; | |
| 137 File::Info info; | |
| 138 if (!file.GetInfo(&info)) | |
| 139 return base::nullopt; | |
| 140 last_modified_times[i] = info.last_modified; | |
| 141 } | |
| 142 | |
| 143 for (const auto& request : *requests) { | 138 for (const auto& request : *requests) { |
| 144 responses.push_back(BlobItemBytesResponse(request.request_number)); | 139 responses.push_back(BlobItemBytesResponse(request.request_number)); |
| 145 responses.back().time_file_modified = | 140 responses.back().time_file_modified = |
| 146 last_modified_times[request.handle_index]; | 141 last_modified_times[request.handle_index]; |
| 147 } | 142 } |
| 148 | 143 |
| 149 return responses; | 144 return responses; |
| 150 } | 145 } |
| 151 | 146 |
| 152 } // namespace | 147 } // namespace |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 401 |
| 407 void BlobTransportController::ReleaseBlobConsolidation( | 402 void BlobTransportController::ReleaseBlobConsolidation( |
| 408 const std::string& uuid) { | 403 const std::string& uuid) { |
| 409 if (blob_storage_.erase(uuid)) { | 404 if (blob_storage_.erase(uuid)) { |
| 410 main_thread_runner_->PostTask(FROM_HERE, | 405 main_thread_runner_->PostTask(FROM_HERE, |
| 411 base::Bind(&DecChildProcessRefCount)); | 406 base::Bind(&DecChildProcessRefCount)); |
| 412 } | 407 } |
| 413 } | 408 } |
| 414 | 409 |
| 415 } // namespace content | 410 } // namespace content |
| OLD | NEW |