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

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

Issue 1292523002: [BlobAsync] Patch 3: Renderer Classes & Logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@async2
Patch Set: Created 5 years, 4 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "content/child/blob_storage/blob_transport_controller.h"
6
7 #include <vector>
8
9 #include "base/memory/singleton.h"
10 #include "content/child/blob_storage/blob_consolidation.h"
11 #include "content/child/thread_safe_sender.h"
12 #include "content/common/blob_storage/blob_storage_messages.h"
13 #include "ipc/ipc_sender.h"
14 #include "storage/common/blob_storage/blob_item_bytes_request.h"
15 #include "storage/common/blob_storage/blob_item_bytes_response.h"
16
17 namespace content {
18
19 using storage::IPCBlobCreationCancelCode;
20
21 using ConsolidatedItem = BlobConsolidation::ConsolidatedItem;
22 using ReadStatus = BlobConsolidation::ReadStatus;
23 using ResponsesStatus = BlobTransportTemporaryHolder::ResponsesStatus;
24
25 const size_t kLargeThresholdBytes = 250 * 1024;
26
27 BlobTransportController* BlobTransportController::GetInstance() {
28 return Singleton<BlobTransportController>::get();
michaeln 2015/08/18 02:50:35 Does base::LazyInstance<T>::Leaky work for this? S
dmurph 2015/10/07 00:32:36 Done.
29 }
30
31 BlobTransportController::~BlobTransportController() {}
32
33 void BlobTransportController::InitiateBlobTransfer(
34 const std::string& uuid,
35 const std::string& type,
36 scoped_ptr<BlobConsolidation> consolidation,
37 IPC::Sender* sender) {
38 holder_.HoldBlobConsolidation(uuid, consolidation.Pass());
39
40 std::vector<storage::DataElement> descriptions;
41 holder_.GetDescriptions(uuid, kLargeThresholdBytes, &descriptions);
42 sender->Send(new BlobStorageMsg_StartBuildingBlob(uuid, type, descriptions));
43 }
44
45 void BlobTransportController::OnMemoryRequest(
46 const std::string& uuid,
47 const std::vector<storage::BlobItemBytesRequest>& requests,
48 std::vector<base::SharedMemoryHandle>* memory_handles,
49 const std::vector<IPC::PlatformFileForTransit>& file_handles,
50 IPC::Sender* sender) {
51 std::vector<storage::BlobItemBytesResponse> responses;
52 ResponsesStatus status = holder_.GetResponses(uuid, requests, memory_handles,
53 file_handles, &responses);
54
55 bool success = false;
56 switch (status) {
57 case ResponsesStatus::BLOB_NOT_FOUND:
58 LOG(ERROR) << "Unable to find blob " << uuid << ".";
michaeln 2015/08/18 02:50:35 Consider switching these to DVLOG(1). See http://w
dmurph 2015/10/07 00:32:35 Done.
59 return;
60 case ResponsesStatus::INVALID_ITEM_INDEX:
61 LOG(ERROR) << "Index out of bounds for blob item in blob " << uuid << ".";
62 break;
63 case ResponsesStatus::INVALID_DATA_RANGE:
64 LOG(ERROR) << "Data range out of bounds for blob item in blob " << uuid
65 << ".";
66 break;
67 case ResponsesStatus::INVALID_ITEM:
68 LOG(ERROR) << "Requesting data from non-memory item in blob " << uuid
69 << ".";
70 break;
71 case ResponsesStatus::INVALID_HANDLE_INDEX:
72 LOG(ERROR) << "Invalid handle index for transferring in blob " << uuid
73 << ".";
74 break;
75 case ResponsesStatus::SHARED_MEMORY_MAP_FAILED:
76 // 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 // memory. If this scenario happens often, we could delay the response
79 // until we have enough memory. For now we just fail.
80 LOG(ERROR) << "Unable to map shared memory to send blob " << uuid << ".";
81 break;
82 case ResponsesStatus::UNKNOWN:
83 LOG(ERROR) << "Unknown error while populating data for blob " << uuid
84 << ".";
85 break;
86 case ResponsesStatus::SUCCESS:
87 success = true;
88 break;
89 }
90
91 if (success) {
92 sender->Send(new BlobStorageMsg_MemoryItemResponse(uuid, responses));
93 } else {
94 LOG(ERROR) << "Canceling blob transfer for blob " << uuid;
95 CancelBlobTransfer(uuid, IPCBlobCreationCancelCode::UNKNOWN, sender);
96 }
97 }
98
99 void BlobTransportController::OnCancel(
100 const std::string& uuid,
101 storage::IPCBlobCreationCancelCode code) {
102 LOG(ERROR) << "Received blob cancel for blob " << uuid << " with reason:";
103 switch (code) {
104 case IPCBlobCreationCancelCode::UNKNOWN:
105 LOG(ERROR) << "Unknown.";
106 break;
107 case IPCBlobCreationCancelCode::OUT_OF_MEMORY:
108 LOG(ERROR) << "Out of Memory.";
109 break;
110 case IPCBlobCreationCancelCode::FILE_WRITE_FAILED:
111 LOG(ERROR) << "File Write Failed (Invalid cancel reason!).";
112 break;
113 }
114 holder_.ReleaseBlob(uuid);
115 }
116
117 void BlobTransportController::OnDone(const std::string& uuid) {
118 holder_.ReleaseBlob(uuid);
119 }
120
121 void BlobTransportController::OnChannelClose() {
122 // TODO(dmurph): When implementing the disk-backed transport, invalidate async
123 // disk calls so they don't call the sender.
michaeln 2015/08/18 02:50:35 should we clear the map of consolidations here and
dmurph 2015/10/07 00:32:35 Since all of the async versions of the transfers a
124 }
125
126 BlobTransportController::BlobTransportController() {}
127
128 void BlobTransportController::CancelBlobTransfer(
129 const std::string& uuid,
130 storage::IPCBlobCreationCancelCode code,
131 IPC::Sender* sender) {
132 sender->Send(new BlobStorageMsg_CancelBuildingBlob(uuid, code));
133 holder_.ReleaseBlob(uuid);
134 }
135
136 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698