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

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

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: added shared memory test, and fixed memory leak Created 4 years, 10 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_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
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 << "Source 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.";
106 break;
107 case IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING:
108 DVLOG(1) << "Blob was dereferenced before building finished, and no one "
109 << "was waiting to read it.";
110 break;
111 case IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN:
112 DVLOG(1) << "Referenced blob was broken.";
105 break; 113 break;
106 } 114 }
107 ReleaseBlobConsolidation(uuid); 115 ReleaseBlobConsolidation(uuid);
108 } 116 }
109 117
110 void BlobTransportController::OnDone(const std::string& uuid) { 118 void BlobTransportController::OnDone(const std::string& uuid) {
111 ReleaseBlobConsolidation(uuid); 119 ReleaseBlobConsolidation(uuid);
112 } 120 }
113 121
114 void BlobTransportController::Clear() { 122 void BlobTransportController::Clear() {
115 blob_storage_.clear(); 123 blob_storage_.clear();
116 } 124 }
117 125
118 BlobTransportController::BlobTransportController() {} 126 BlobTransportController::BlobTransportController() {}
119 127
120 void BlobTransportController::CancelBlobTransfer(const std::string& uuid, 128 void BlobTransportController::CancelBlobTransfer(const std::string& uuid,
121 IPCBlobCreationCancelCode code, 129 IPCBlobCreationCancelCode code,
122 IPC::Sender* sender) { 130 IPC::Sender* sender) {
123 // TODO(dmurph): Uncomment when IPC messages are added. 131 sender->Send(new BlobStorageMsg_CancelBuildingBlob(uuid, code));
124 // sender->Send(new BlobStorageMsg_CancelBuildingBlob(uuid, code));
125 ReleaseBlobConsolidation(uuid); 132 ReleaseBlobConsolidation(uuid);
126 } 133 }
127 134
128 void BlobTransportController::GetDescriptions( 135 void BlobTransportController::GetDescriptions(
129 BlobConsolidation* consolidation, 136 BlobConsolidation* consolidation,
130 size_t max_data_population, 137 size_t max_data_population,
131 std::vector<storage::DataElement>* out) { 138 std::vector<storage::DataElement>* out) {
132 DCHECK(out->empty()); 139 DCHECK(out->empty());
133 DCHECK(consolidation); 140 DCHECK(consolidation);
134 const auto& consolidated_items = consolidation->consolidated_items(); 141 const auto& consolidated_items = consolidation->consolidated_items();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 } 259 }
253 return ResponsesStatus::SUCCESS; 260 return ResponsesStatus::SUCCESS;
254 } 261 }
255 262
256 void BlobTransportController::ReleaseBlobConsolidation( 263 void BlobTransportController::ReleaseBlobConsolidation(
257 const std::string& uuid) { 264 const std::string& uuid) {
258 blob_storage_.erase(uuid); 265 blob_storage_.erase(uuid);
259 } 266 }
260 267
261 } // namespace content 268 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698