| 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 <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
| 12 #include "base/memory/shared_memory.h" | 12 #include "base/memory/shared_memory.h" |
| 13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "content/child/blob_storage/blob_consolidation.h" | 14 #include "content/child/blob_storage/blob_consolidation.h" |
| 15 #include "content/child/thread_safe_sender.h" | 15 #include "content/child/thread_safe_sender.h" |
| 16 #include "content/common/fileapi/webblob_messages.h" |
| 16 #include "ipc/ipc_sender.h" | 17 #include "ipc/ipc_sender.h" |
| 17 #include "storage/common/blob_storage/blob_item_bytes_request.h" | 18 #include "storage/common/blob_storage/blob_item_bytes_request.h" |
| 18 #include "storage/common/blob_storage/blob_item_bytes_response.h" | 19 #include "storage/common/blob_storage/blob_item_bytes_response.h" |
| 19 #include "storage/common/data_element.h" | 20 #include "storage/common/data_element.h" |
| 20 | 21 |
| 21 using base::SharedMemory; | 22 using base::SharedMemory; |
| 22 using base::SharedMemoryHandle; | 23 using base::SharedMemoryHandle; |
| 23 using storage::BlobItemBytesRequest; | 24 using storage::BlobItemBytesRequest; |
| 24 using storage::BlobItemBytesResponse; | 25 using storage::BlobItemBytesResponse; |
| 25 using storage::IPCBlobItemRequestStrategy; | 26 using storage::IPCBlobItemRequestStrategy; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 39 } // namespace | 40 } // namespace |
| 40 | 41 |
| 41 BlobTransportController* BlobTransportController::GetInstance() { | 42 BlobTransportController* BlobTransportController::GetInstance() { |
| 42 return g_controller.Pointer(); | 43 return g_controller.Pointer(); |
| 43 } | 44 } |
| 44 | 45 |
| 45 BlobTransportController::~BlobTransportController() {} | 46 BlobTransportController::~BlobTransportController() {} |
| 46 | 47 |
| 47 void BlobTransportController::InitiateBlobTransfer( | 48 void BlobTransportController::InitiateBlobTransfer( |
| 48 const std::string& uuid, | 49 const std::string& uuid, |
| 49 const std::string& type, | |
| 50 scoped_ptr<BlobConsolidation> consolidation, | 50 scoped_ptr<BlobConsolidation> consolidation, |
| 51 IPC::Sender* sender) { | 51 IPC::Sender* sender) { |
| 52 BlobConsolidation* consolidation_ptr = consolidation.get(); | 52 BlobConsolidation* consolidation_ptr = consolidation.get(); |
| 53 blob_storage_.insert(std::make_pair(uuid, std::move(consolidation))); | 53 blob_storage_[uuid] = std::move(consolidation); |
| 54 std::vector<storage::DataElement> descriptions; | 54 std::vector<storage::DataElement> descriptions; |
| 55 GetDescriptions(consolidation_ptr, kLargeThresholdBytes, &descriptions); | 55 GetDescriptions(consolidation_ptr, kLargeThresholdBytes, &descriptions); |
| 56 // TODO(dmurph): Uncomment when IPC messages are added. | 56 sender->Send(new BlobStorageMsg_StartBuildingBlob(uuid, descriptions)); |
| 57 // sender->Send(new BlobStorageMsg_StartBuildingBlob(uuid, type, | |
| 58 // descriptions)); | |
| 59 } | 57 } |
| 60 | 58 |
| 61 void BlobTransportController::OnMemoryRequest( | 59 void BlobTransportController::OnMemoryRequest( |
| 62 const std::string& uuid, | 60 const std::string& uuid, |
| 63 const std::vector<storage::BlobItemBytesRequest>& requests, | 61 const std::vector<storage::BlobItemBytesRequest>& requests, |
| 64 std::vector<base::SharedMemoryHandle>* memory_handles, | 62 std::vector<base::SharedMemoryHandle>* memory_handles, |
| 65 const std::vector<IPC::PlatformFileForTransit>& file_handles, | 63 const std::vector<IPC::PlatformFileForTransit>& file_handles, |
| 66 IPC::Sender* sender) { | 64 IPC::Sender* sender) { |
| 67 std::vector<storage::BlobItemBytesResponse> responses; | 65 std::vector<storage::BlobItemBytesResponse> responses; |
| 68 ResponsesStatus status = | 66 ResponsesStatus status = |
| 69 GetResponses(uuid, requests, memory_handles, file_handles, &responses); | 67 GetResponses(uuid, requests, memory_handles, file_handles, &responses); |
| 70 | 68 |
| 71 switch (status) { | 69 switch (status) { |
| 72 case ResponsesStatus::BLOB_NOT_FOUND: | 70 case ResponsesStatus::BLOB_NOT_FOUND: |
| 73 // sender->Send(new BlobStorageMsg_CancelBuildingBlob(uuid, | 71 // sender->Send(new BlobStorageMsg_CancelBuildingBlob(uuid, |
| 74 // IPCBlobCreationCancelCode::UNKNOWN)); | 72 // IPCBlobCreationCancelCode::UNKNOWN)); |
| 75 return; | 73 return; |
| 76 case ResponsesStatus::SHARED_MEMORY_MAP_FAILED: | 74 case ResponsesStatus::SHARED_MEMORY_MAP_FAILED: |
| 77 // This would happen if the renderer process doesn't have enough memory | 75 // This would happen if the renderer process doesn't have enough memory |
| 78 // to map the shared memory, which is possible if we don't have much | 76 // to map the shared memory, which is possible if we don't have much |
| 79 // memory. If this scenario happens often, we could delay the response | 77 // memory. If this scenario happens often, we could delay the response |
| 80 // until we have enough memory. For now we just fail. | 78 // until we have enough memory. For now we just fail. |
| 81 CHECK(false) << "Unable to map shared memory to send blob " << uuid | 79 CHECK(false) << "Unable to map shared memory to send blob " << uuid |
| 82 << "."; | 80 << "."; |
| 83 break; | 81 break; |
| 84 case ResponsesStatus::SUCCESS: | 82 case ResponsesStatus::SUCCESS: |
| 85 break; | 83 break; |
| 86 } | 84 } |
| 87 | 85 |
| 88 // TODO(dmurph): Uncomment when IPC messages are added. | 86 sender->Send(new BlobStorageMsg_MemoryItemResponse(uuid, responses)); |
| 89 // sender->Send(new BlobStorageMsg_MemoryItemResponse(uuid, responses)); | |
| 90 } | 87 } |
| 91 | 88 |
| 92 void BlobTransportController::OnCancel( | 89 void BlobTransportController::OnCancel( |
| 93 const std::string& uuid, | 90 const std::string& uuid, |
| 94 storage::IPCBlobCreationCancelCode code) { | 91 storage::IPCBlobCreationCancelCode code) { |
| 95 DVLOG(1) << "Received blob cancel for blob " << uuid << " with reason:"; | 92 DVLOG(1) << "Received blob cancel for blob " << uuid << " with reason:"; |
| 96 switch (code) { | 93 switch (code) { |
| 97 case IPCBlobCreationCancelCode::UNKNOWN: | 94 case IPCBlobCreationCancelCode::UNKNOWN: |
| 98 DVLOG(1) << "Unknown."; | 95 DVLOG(1) << "Unknown."; |
| 99 break; | 96 break; |
| 100 case IPCBlobCreationCancelCode::OUT_OF_MEMORY: | 97 case IPCBlobCreationCancelCode::OUT_OF_MEMORY: |
| 101 DVLOG(1) << "Out of Memory."; | 98 DVLOG(1) << "Out of Memory."; |
| 102 break; | 99 break; |
| 100 case IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT: |
| 101 DVLOG(1) |
| 102 << "Sourced died in transit. Invalid cancel reason from the Browser."; |
| 103 break; |
| 103 case IPCBlobCreationCancelCode::FILE_WRITE_FAILED: | 104 case IPCBlobCreationCancelCode::FILE_WRITE_FAILED: |
| 104 DVLOG(1) << "File Write Failed (Invalid cancel reason!)."; | 105 DVLOG(1) << "File Write Failed."; |
| 105 break; | 106 break; |
| 106 } | 107 } |
| 107 ReleaseBlobConsolidation(uuid); | 108 ReleaseBlobConsolidation(uuid); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void BlobTransportController::OnDone(const std::string& uuid) { | 111 void BlobTransportController::OnDone(const std::string& uuid) { |
| 111 ReleaseBlobConsolidation(uuid); | 112 ReleaseBlobConsolidation(uuid); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void BlobTransportController::Clear() { | 115 void BlobTransportController::Clear() { |
| 115 blob_storage_.clear(); | 116 blob_storage_.clear(); |
| 116 } | 117 } |
| 117 | 118 |
| 118 BlobTransportController::BlobTransportController() {} | 119 BlobTransportController::BlobTransportController() {} |
| 119 | 120 |
| 120 void BlobTransportController::CancelBlobTransfer(const std::string& uuid, | 121 void BlobTransportController::CancelBlobTransfer(const std::string& uuid, |
| 121 IPCBlobCreationCancelCode code, | 122 IPCBlobCreationCancelCode code, |
| 122 IPC::Sender* sender) { | 123 IPC::Sender* sender) { |
| 123 // TODO(dmurph): Uncomment when IPC messages are added. | 124 sender->Send(new BlobStorageMsg_CancelBuildingBlob(uuid, code)); |
| 124 // sender->Send(new BlobStorageMsg_CancelBuildingBlob(uuid, code)); | |
| 125 ReleaseBlobConsolidation(uuid); | 125 ReleaseBlobConsolidation(uuid); |
| 126 } | 126 } |
| 127 | 127 |
| 128 void BlobTransportController::GetDescriptions( | 128 void BlobTransportController::GetDescriptions( |
| 129 BlobConsolidation* consolidation, | 129 BlobConsolidation* consolidation, |
| 130 size_t max_data_population, | 130 size_t max_data_population, |
| 131 std::vector<storage::DataElement>* out) { | 131 std::vector<storage::DataElement>* out) { |
| 132 DCHECK(out->empty()); | 132 DCHECK(out->empty()); |
| 133 DCHECK(consolidation); | 133 DCHECK(consolidation); |
| 134 const auto& consolidated_items = consolidation->consolidated_items(); | 134 const auto& consolidated_items = consolidation->consolidated_items(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 } | 252 } |
| 253 return ResponsesStatus::SUCCESS; | 253 return ResponsesStatus::SUCCESS; |
| 254 } | 254 } |
| 255 | 255 |
| 256 void BlobTransportController::ReleaseBlobConsolidation( | 256 void BlobTransportController::ReleaseBlobConsolidation( |
| 257 const std::string& uuid) { | 257 const std::string& uuid) { |
| 258 blob_storage_.erase(uuid); | 258 blob_storage_.erase(uuid); |
| 259 } | 259 } |
| 260 | 260 |
| 261 } // namespace content | 261 } // namespace content |
| OLD | NEW |