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