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

Side by Side Diff: content/browser/blob_storage/blob_dispatcher_host.cc

Issue 2055053003: [BlobAsync] Disk support for blob storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/browser/blob_storage/blob_dispatcher_host.h" 5 #include "content/browser/blob_storage/blob_dispatcher_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/metrics/histogram_macros.h" 10 #include "base/metrics/histogram_macros.h"
11 #include "content/browser/bad_message.h" 11 #include "content/browser/bad_message.h"
12 #include "content/browser/blob_storage/chrome_blob_storage_context.h" 12 #include "content/browser/blob_storage/chrome_blob_storage_context.h"
13 #include "content/browser/child_process_security_policy_impl.h" 13 #include "content/browser/child_process_security_policy_impl.h"
14 #include "content/browser/fileapi/browser_file_system_helper.h" 14 #include "content/browser/fileapi/browser_file_system_helper.h"
15 #include "content/common/fileapi/webblob_messages.h" 15 #include "content/common/fileapi/webblob_messages.h"
16 #include "ipc/ipc_platform_file.h" 16 #include "ipc/ipc_platform_file.h"
17 #include "storage/browser/blob/blob_data_handle.h"
17 #include "storage/browser/blob/blob_storage_context.h" 18 #include "storage/browser/blob/blob_storage_context.h"
18 #include "storage/browser/blob/blob_transport_result.h" 19 #include "storage/browser/blob/internal_blob_data.h"
19 #include "storage/browser/fileapi/file_system_context.h" 20 #include "storage/browser/fileapi/file_system_context.h"
20 #include "storage/browser/fileapi/file_system_url.h" 21 #include "storage/browser/fileapi/file_system_url.h"
21 #include "storage/common/blob_storage/blob_item_bytes_request.h" 22 #include "storage/common/blob_storage/blob_item_bytes_request.h"
22 #include "storage/common/blob_storage/blob_item_bytes_response.h" 23 #include "storage/common/blob_storage/blob_item_bytes_response.h"
23 #include "storage/common/data_element.h" 24 #include "storage/common/data_element.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 using storage::BlobStorageContext; 27 using storage::BlobStorageContext;
27 using storage::BlobStorageRegistry; 28 using storage::BlobStorageRegistry;
28 using storage::BlobTransportResult; 29 using storage::BlobStatus;
29 using storage::DataElement; 30 using storage::DataElement;
30 using storage::IPCBlobCreationCancelCode;
31 using storage::FileSystemURL; 31 using storage::FileSystemURL;
32 32
33 namespace content { 33 namespace content {
34 namespace { 34 namespace {
35 35
36 // These are used for UMA stats, don't change. 36 // These are used for UMA stats, don't change.
37 enum RefcountOperation { 37 enum RefcountOperation {
38 BDH_DECREMENT = 0, 38 BDH_DECREMENT = 0,
39 BDH_INCREMENT, 39 BDH_INCREMENT,
40 BDH_TRACING_ENUM_LAST 40 BDH_TRACING_ENUM_LAST
(...skipping 16 matching lines...) Expand all
57 57
58 void BlobDispatcherHost::OnChannelClosing() { 58 void BlobDispatcherHost::OnChannelClosing() {
59 ClearHostFromBlobStorageContext(); 59 ClearHostFromBlobStorageContext();
60 public_blob_urls_.clear(); 60 public_blob_urls_.clear();
61 blobs_inuse_map_.clear(); 61 blobs_inuse_map_.clear();
62 } 62 }
63 63
64 bool BlobDispatcherHost::OnMessageReceived(const IPC::Message& message) { 64 bool BlobDispatcherHost::OnMessageReceived(const IPC::Message& message) {
65 bool handled = true; 65 bool handled = true;
66 IPC_BEGIN_MESSAGE_MAP(BlobDispatcherHost, message) 66 IPC_BEGIN_MESSAGE_MAP(BlobDispatcherHost, message)
67 IPC_MESSAGE_HANDLER(BlobStorageMsg_RegisterBlobUUID, OnRegisterBlobUUID) 67 IPC_MESSAGE_HANDLER(BlobStorageMsg_RegisterBlob, OnRegisterBlob)
68 IPC_MESSAGE_HANDLER(BlobStorageMsg_StartBuildingBlob, OnStartBuildingBlob)
69 IPC_MESSAGE_HANDLER(BlobStorageMsg_MemoryItemResponse, OnMemoryItemResponse) 68 IPC_MESSAGE_HANDLER(BlobStorageMsg_MemoryItemResponse, OnMemoryItemResponse)
70 IPC_MESSAGE_HANDLER(BlobStorageMsg_CancelBuildingBlob, OnCancelBuildingBlob) 69 IPC_MESSAGE_HANDLER(BlobStorageMsg_SendBlobStatus, OnCancelBuildingBob)
71 IPC_MESSAGE_HANDLER(BlobHostMsg_IncrementRefCount, OnIncrementBlobRefCount) 70 IPC_MESSAGE_HANDLER(BlobHostMsg_IncrementRefCount, OnIncrementBlobRefCount)
72 IPC_MESSAGE_HANDLER(BlobHostMsg_DecrementRefCount, OnDecrementBlobRefCount) 71 IPC_MESSAGE_HANDLER(BlobHostMsg_DecrementRefCount, OnDecrementBlobRefCount)
73 IPC_MESSAGE_HANDLER(BlobHostMsg_RegisterPublicURL, OnRegisterPublicBlobURL) 72 IPC_MESSAGE_HANDLER(BlobHostMsg_RegisterPublicURL, OnRegisterPublicBlobURL)
74 IPC_MESSAGE_HANDLER(BlobHostMsg_RevokePublicURL, OnRevokePublicBlobURL) 73 IPC_MESSAGE_HANDLER(BlobHostMsg_RevokePublicURL, OnRevokePublicBlobURL)
75 IPC_MESSAGE_UNHANDLED(handled = false) 74 IPC_MESSAGE_UNHANDLED(handled = false)
76 IPC_END_MESSAGE_MAP() 75 IPC_END_MESSAGE_MAP()
77 return handled; 76 return handled;
78 } 77 }
79 78
80 void BlobDispatcherHost::OnRegisterBlobUUID( 79 void BlobDispatcherHost::OnRegisterBlob(
81 const std::string& uuid, 80 const std::string& uuid,
82 const std::string& content_type, 81 const std::string& content_type,
83 const std::string& content_disposition, 82 const std::string& content_disposition,
84 const std::set<std::string>& referenced_blob_uuids) { 83 const std::vector<storage::DataElement>& descriptions) {
85 DCHECK_CURRENTLY_ON(BrowserThread::IO); 84 DCHECK_CURRENTLY_ON(BrowserThread::IO);
86 BlobStorageContext* context = this->context(); 85 BlobStorageContext* context = this->context();
87 if (uuid.empty() || context->registry().HasEntry(uuid) || 86 if (uuid.empty() || context->registry().HasEntry(uuid) ||
88 async_builder_.IsBeingBuilt(uuid)) { 87 async_builder_.IsBeingBuilt(uuid)) {
89 bad_message::ReceivedBadMessage(this, bad_message::BDH_UUID_REGISTERED); 88 bad_message::ReceivedBadMessage(this, bad_message::BDH_UUID_REGISTERED);
90 return; 89 return;
91 } 90 }
92 blobs_inuse_map_[uuid] = 1;
93 BlobTransportResult result = async_builder_.RegisterBlobUUID(
94 uuid, content_type, content_disposition, referenced_blob_uuids, context);
95 switch (result) {
96 case BlobTransportResult::BAD_IPC:
97 blobs_inuse_map_.erase(uuid);
98 bad_message::ReceivedBadMessage(this,
99 bad_message::BDH_CONSTRUCTION_FAILED);
100 break;
101 case BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN:
102 // The async builder builds the blob as broken, and we just need to send
103 // the cancel message back to the renderer.
104 Send(new BlobStorageMsg_CancelBuildingBlob(
105 uuid, IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN));
106 break;
107 case BlobTransportResult::DONE:
108 break;
109 case BlobTransportResult::CANCEL_MEMORY_FULL:
110 case BlobTransportResult::CANCEL_FILE_ERROR:
111 case BlobTransportResult::CANCEL_UNKNOWN:
112 case BlobTransportResult::PENDING_RESPONSES:
113 NOTREACHED();
114 break;
115 }
116 }
117
118 void BlobDispatcherHost::OnStartBuildingBlob(
119 const std::string& uuid,
120 const std::vector<storage::DataElement>& descriptions) {
121 DCHECK_CURRENTLY_ON(BrowserThread::IO);
122 if (uuid.empty()) {
123 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC);
124 return;
125 }
126 BlobStorageContext* context = this->context();
127 const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid);
128 if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) {
129 // We ignore messages for blobs that don't exist to handle the case where
130 // the renderer de-refs a blob that we're still constructing, and there are
131 // no references to that blob. We ignore broken as well, in the case where
132 // we decided to break a blob after RegisterBlobUUID is called.
133 // Second, if the last dereference of the blob happened on a different host,
134 // then we still haven't gotten rid of the 'building' state in the original
135 // host. So we call cancel, and send the message just in case that happens.
136 if (async_builder_.IsBeingBuilt(uuid)) {
137 async_builder_.CancelBuildingBlob(
138 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING,
139 context);
140 Send(new BlobStorageMsg_CancelBuildingBlob(
141 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING));
142 }
143 return;
144 }
145 if (!async_builder_.IsBeingBuilt(uuid)) {
146 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC);
147 return;
148 }
149 91
150 ChildProcessSecurityPolicyImpl* security_policy = 92 ChildProcessSecurityPolicyImpl* security_policy =
151 ChildProcessSecurityPolicyImpl::GetInstance(); 93 ChildProcessSecurityPolicyImpl::GetInstance();
152 for (const DataElement& item : descriptions) { 94 for (const DataElement& item : descriptions) {
153 // For each source object that provides the data for the blob, ensure that 95 // For each source object that provides the data for the blob, ensure that
154 // this process has permission to read it. 96 // this process has permission to read it.
155 switch (item.type()) { 97 switch (item.type()) {
156 case storage::DataElement::TYPE_FILE_FILESYSTEM: { 98 case storage::DataElement::TYPE_FILE_FILESYSTEM: {
157 FileSystemURL filesystem_url( 99 FileSystemURL filesystem_url(
158 file_system_context_->CrackURL(item.filesystem_url())); 100 file_system_context_->CrackURL(item.filesystem_url()));
159 if (!FileSystemURLIsValid(file_system_context_.get(), filesystem_url) || 101 if (!FileSystemURLIsValid(file_system_context_.get(), filesystem_url) ||
160 !security_policy->CanReadFileSystemFile(process_id_, 102 !security_policy->CanReadFileSystemFile(process_id_,
161 filesystem_url)) { 103 filesystem_url)) {
162 async_builder_.CancelBuildingBlob( 104 async_builder_.CancelBuildingBlob(
163 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context); 105 uuid, BlobStatus::ERR_FILE_WRITE_FAILED, context);
164 Send(new BlobStorageMsg_CancelBuildingBlob( 106 SendFinalBlobStatus(uuid, BlobStatus::ERR_FILE_WRITE_FAILED);
165 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
166 return; 107 return;
167 } 108 }
168 break; 109 break;
169 } 110 }
170 case storage::DataElement::TYPE_FILE: { 111 case storage::DataElement::TYPE_FILE: {
171 if (!security_policy->CanReadFile(process_id_, item.path())) { 112 if (!security_policy->CanReadFile(process_id_, item.path())) {
172 async_builder_.CancelBuildingBlob( 113 async_builder_.CancelBuildingBlob(
173 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context); 114 uuid, BlobStatus::ERR_FILE_WRITE_FAILED, context);
174 Send(new BlobStorageMsg_CancelBuildingBlob( 115 SendFinalBlobStatus(uuid, BlobStatus::ERR_FILE_WRITE_FAILED);
175 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
176 return; 116 return;
177 } 117 }
178 break; 118 break;
179 } 119 }
180 case storage::DataElement::TYPE_BLOB: 120 case storage::DataElement::TYPE_BLOB:
181 case storage::DataElement::TYPE_BYTES_DESCRIPTION: 121 case storage::DataElement::TYPE_BYTES_DESCRIPTION:
182 case storage::DataElement::TYPE_BYTES: { 122 case storage::DataElement::TYPE_BYTES: {
183 // Bytes are already in hand; no need to check read permission. 123 // Bytes are already in hand; no need to check read permission.
184 // TODO(nick): For TYPE_BLOB, can we actually get here for blobs 124 // TODO(nick): For TYPE_BLOB, can we actually get here for blobs
185 // originally created by other processes? If so, is that cool? 125 // originally created by other processes? If so, is that cool?
186 break; 126 break;
187 } 127 }
188 case storage::DataElement::TYPE_UNKNOWN: 128 case storage::DataElement::TYPE_UNKNOWN:
189 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: { 129 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: {
190 NOTREACHED(); // Should have been caught by IPC deserialization. 130 NOTREACHED(); // Should have been caught by IPC deserialization.
191 break; 131 break;
192 } 132 }
193 } 133 }
194 } 134 }
135 blobs_inuse_map_[uuid] = 1;
195 136
196 // |this| owns async_builder_ so using base::Unretained(this) is safe. 137 async_builder_.RegisterBlob(
197 BlobTransportResult result = async_builder_.StartBuildingBlob( 138 uuid, content_type, content_disposition, descriptions, context,
198 uuid, descriptions, context->memory_available(), context,
199 base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this), 139 base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this),
200 uuid)); 140 uuid),
201 SendIPCResponse(uuid, result); 141 base::Bind(&BlobDispatcherHost::SendFinalBlobStatus,
142 base::Unretained(this), uuid));
202 } 143 }
203 144
204 void BlobDispatcherHost::OnMemoryItemResponse( 145 void BlobDispatcherHost::OnMemoryItemResponse(
205 const std::string& uuid, 146 const std::string& uuid,
206 const std::vector<storage::BlobItemBytesResponse>& responses) { 147 const std::vector<storage::BlobItemBytesResponse>& responses) {
207 DCHECK_CURRENTLY_ON(BrowserThread::IO); 148 DCHECK_CURRENTLY_ON(BrowserThread::IO);
208 if (uuid.empty()) { 149 if (uuid.empty()) {
209 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); 150 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
210 return; 151 return;
211 } 152 }
212 BlobStorageContext* context = this->context(); 153 BlobStorageContext* context = this->context();
213 const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid); 154 const storage::InternalBlobData* entry = context->registry().GetEntry(uuid);
214 if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) { 155 if (!entry || BlobStatusIsError(entry->status())) {
215 // We ignore messages for blobs that don't exist to handle the case where 156 // We ignore messages for blobs that don't exist to handle the case where
216 // the renderer de-refs a blob that we're still constructing, and there are 157 // the renderer de-refs a blob that we're still constructing, and there are
217 // no references to that blob. We ignore broken as well, in the case where 158 // no references to that blob. We ignore broken as well, in the case where
218 // we decided to break a blob after sending the memory request. 159 // we decided to break a blob after sending the memory request.
219 // Note: if a blob is broken, then it can't be in the async_builder. 160 // Note: if a blob is broken, then it can't be in the async_builder.
220 // Second, if the last dereference of the blob happened on a different host, 161 // Second, if the last dereference of the blob happened on a different host,
221 // then we still haven't gotten rid of the 'building' state in the original 162 // then we still haven't gotten rid of the 'building' state in the original
222 // host. So we call cancel, and send the message just in case that happens. 163 // host. So we call cancel, and send the message just in case that happens.
223 if (async_builder_.IsBeingBuilt(uuid)) { 164 if (async_builder_.IsBeingBuilt(uuid)) {
224 async_builder_.CancelBuildingBlob( 165 async_builder_.CancelBuildingBlob(
225 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, 166 uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context);
226 context); 167 SendFinalBlobStatus(uuid,
227 Send(new BlobStorageMsg_CancelBuildingBlob( 168 BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING);
228 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING));
229 } 169 }
230 return; 170 return;
231 } 171 }
232 if (!async_builder_.IsBeingBuilt(uuid)) { 172 if (!async_builder_.IsBeingBuilt(uuid)) {
233 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); 173 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
234 return; 174 return;
235 } 175 }
236 BlobTransportResult result = 176 BlobStatus result =
237 async_builder_.OnMemoryResponses(uuid, responses, context); 177 async_builder_.OnMemoryResponses(uuid, responses, context);
238 SendIPCResponse(uuid, result); 178 if (BlobStatusIsPending(result))
179 return;
180 SendFinalBlobStatus(uuid, result);
239 } 181 }
240 182
241 void BlobDispatcherHost::OnCancelBuildingBlob( 183 void BlobDispatcherHost::OnCancelBuildingBob(const std::string& uuid,
242 const std::string& uuid, 184 const storage::BlobStatus code) {
243 const storage::IPCBlobCreationCancelCode code) {
244 DCHECK_CURRENTLY_ON(BrowserThread::IO); 185 DCHECK_CURRENTLY_ON(BrowserThread::IO);
245 if (uuid.empty()) { 186 if (uuid.empty()) {
246 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); 187 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
247 return; 188 return;
248 } 189 }
249 BlobStorageContext* context = this->context(); 190 BlobStorageContext* context = this->context();
250 const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid); 191 const storage::InternalBlobData* entry = context->registry().GetEntry(uuid);
251 if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) { 192 if (!entry || BlobStatusIsError(entry->status())) {
252 // We ignore messages for blobs that don't exist to handle the case where 193 // We ignore messages for blobs that don't exist to handle the case where
253 // the renderer de-refs a blob that we're still constructing, and there are 194 // the renderer de-refs a blob that we're still constructing, and there are
254 // no references to that blob. We ignore broken as well, in the case where 195 // no references to that blob. We ignore broken as well, in the case where
255 // we decided to break a blob and the renderer also decided to cancel. 196 // we decided to break a blob and the renderer also decided to cancel.
256 // Note: if a blob is broken, then it can't be in the async_builder. 197 // Note: if a blob is broken, then it can't be in the async_builder.
257 // Second, if the last dereference of the blob happened on a different host, 198 // Second, if the last dereference of the blob happened on a different host,
258 // then we still haven't gotten rid of the 'building' state in the original 199 // then we still haven't gotten rid of the 'building' state in the original
259 // host. So we call cancel just in case this happens. 200 // host. So we call cancel just in case this happens.
260 if (async_builder_.IsBeingBuilt(uuid)) { 201 if (async_builder_.IsBeingBuilt(uuid)) {
261 async_builder_.CancelBuildingBlob( 202 async_builder_.CancelBuildingBlob(
262 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, 203 uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context);
263 context);
264 } 204 }
265 return; 205 return;
266 } 206 }
267 if (!async_builder_.IsBeingBuilt(uuid)) { 207 // We should only get these messages for errors.
268 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); 208 if (!async_builder_.IsBeingBuilt(uuid) || !storage::BlobStatusIsError(code)) {
209 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
269 return; 210 return;
270 } 211 }
271 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. " 212 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. "
272 << " Reason: " << static_cast<int>(code) << "."; 213 << " Reason: " << static_cast<int>(code) << ".";
273 async_builder_.CancelBuildingBlob(uuid, code, context); 214 async_builder_.CancelBuildingBlob(uuid, code, context);
274 } 215 }
275 216
276 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) { 217 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) {
277 DCHECK_CURRENTLY_ON(BrowserThread::IO); 218 DCHECK_CURRENTLY_ON(BrowserThread::IO);
278 BlobStorageContext* context = this->context(); 219 BlobStorageContext* context = this->context();
(...skipping 27 matching lines...) Expand all
306 context->DecrementBlobRefCount(uuid); 247 context->DecrementBlobRefCount(uuid);
307 blobs_inuse_map_[uuid] -= 1; 248 blobs_inuse_map_[uuid] -= 1;
308 if (blobs_inuse_map_[uuid] == 0) { 249 if (blobs_inuse_map_[uuid] == 0) {
309 blobs_inuse_map_.erase(uuid); 250 blobs_inuse_map_.erase(uuid);
310 // If the blob has been deleted in the context and we're still building it, 251 // If the blob has been deleted in the context and we're still building it,
311 // this means we have no references waiting to read it. Clear the building 252 // this means we have no references waiting to read it. Clear the building
312 // state and send a cancel message to the renderer. 253 // state and send a cancel message to the renderer.
313 if (async_builder_.IsBeingBuilt(uuid) && 254 if (async_builder_.IsBeingBuilt(uuid) &&
314 !context->registry().HasEntry(uuid)) { 255 !context->registry().HasEntry(uuid)) {
315 async_builder_.CancelBuildingBlob( 256 async_builder_.CancelBuildingBlob(
316 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, 257 uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context);
317 context); 258 SendFinalBlobStatus(uuid,
318 Send(new BlobStorageMsg_CancelBuildingBlob( 259 BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING);
319 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING));
320 } 260 }
321 } 261 }
322 } 262 }
323 263
324 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url, 264 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url,
325 const std::string& uuid) { 265 const std::string& uuid) {
326 DCHECK_CURRENTLY_ON(BrowserThread::IO); 266 DCHECK_CURRENTLY_ON(BrowserThread::IO);
327 ChildProcessSecurityPolicyImpl* security_policy = 267 ChildProcessSecurityPolicyImpl* security_policy =
328 ChildProcessSecurityPolicyImpl::GetInstance(); 268 ChildProcessSecurityPolicyImpl::GetInstance();
329 269
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 context()->RevokePublicBlobURL(public_url); 305 context()->RevokePublicBlobURL(public_url);
366 public_blob_urls_.erase(public_url); 306 public_blob_urls_.erase(public_url);
367 } 307 }
368 308
369 storage::BlobStorageContext* BlobDispatcherHost::context() { 309 storage::BlobStorageContext* BlobDispatcherHost::context() {
370 return blob_storage_context_->context(); 310 return blob_storage_context_->context();
371 } 311 }
372 312
373 void BlobDispatcherHost::SendMemoryRequest( 313 void BlobDispatcherHost::SendMemoryRequest(
374 const std::string& uuid, 314 const std::string& uuid,
375 std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests, 315 std::vector<storage::BlobItemBytesRequest> requests,
376 std::unique_ptr<std::vector<base::SharedMemoryHandle>> memory_handles, 316 std::vector<base::SharedMemoryHandle> memory_handles,
377 std::unique_ptr<std::vector<base::File>> files) { 317 std::vector<base::File> files) {
378 DCHECK_CURRENTLY_ON(BrowserThread::IO); 318 DCHECK_CURRENTLY_ON(BrowserThread::IO);
379 std::vector<IPC::PlatformFileForTransit> file_handles; 319 std::vector<IPC::PlatformFileForTransit> file_handles;
380 // TODO(dmurph): Support file-backed blob transportation. 320 for (base::File& file : files) {
381 DCHECK(files->empty()); 321 file_handles.push_back(IPC::TakePlatformFileForTransit(std::move(file)));
382 Send(new BlobStorageMsg_RequestMemoryItem(uuid, *requests, *memory_handles, 322 }
323 Send(new BlobStorageMsg_RequestMemoryItem(uuid, requests, memory_handles,
383 file_handles)); 324 file_handles));
384 } 325 }
385 326
386 void BlobDispatcherHost::SendIPCResponse(const std::string& uuid, 327 void BlobDispatcherHost::SendFinalBlobStatus(const std::string& uuid,
387 storage::BlobTransportResult result) { 328 BlobStatus status) {
388 switch (result) { 329 if (storage::BlobStatusIsBadIPC(status)) {
389 case BlobTransportResult::BAD_IPC: 330 blobs_inuse_map_.erase(uuid);
390 bad_message::ReceivedBadMessage(this, 331 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
391 bad_message::BDH_CONSTRUCTION_FAILED); 332 return;
392 return;
393 case BlobTransportResult::CANCEL_MEMORY_FULL:
394 Send(new BlobStorageMsg_CancelBuildingBlob(
395 uuid, IPCBlobCreationCancelCode::OUT_OF_MEMORY));
396 return;
397 case BlobTransportResult::CANCEL_FILE_ERROR:
398 Send(new BlobStorageMsg_CancelBuildingBlob(
399 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
400 return;
401 case BlobTransportResult::CANCEL_REFERENCED_BLOB_BROKEN:
402 Send(new BlobStorageMsg_CancelBuildingBlob(
403 uuid, IPCBlobCreationCancelCode::REFERENCED_BLOB_BROKEN));
404 return;
405 case BlobTransportResult::CANCEL_UNKNOWN:
406 Send(new BlobStorageMsg_CancelBuildingBlob(
407 uuid, IPCBlobCreationCancelCode::UNKNOWN));
408 return;
409 case BlobTransportResult::PENDING_RESPONSES:
410 return;
411 case BlobTransportResult::DONE:
412 Send(new BlobStorageMsg_DoneBuildingBlob(uuid));
413 return;
414 } 333 }
415 NOTREACHED(); 334 DCHECK(!BlobStatusIsPending(status));
335 Send(new BlobStorageMsg_SendBlobStatus(uuid, status));
416 } 336 }
417 337
418 bool BlobDispatcherHost::IsInUseInHost(const std::string& uuid) { 338 bool BlobDispatcherHost::IsInUseInHost(const std::string& uuid) {
419 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); 339 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end();
420 } 340 }
421 341
422 bool BlobDispatcherHost::IsUrlRegisteredInHost(const GURL& blob_url) { 342 bool BlobDispatcherHost::IsUrlRegisteredInHost(const GURL& blob_url) {
423 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); 343 return public_blob_urls_.find(blob_url) != public_blob_urls_.end();
424 } 344 }
425 345
426 void BlobDispatcherHost::ClearHostFromBlobStorageContext() { 346 void BlobDispatcherHost::ClearHostFromBlobStorageContext() {
427 BlobStorageContext* context = this->context(); 347 BlobStorageContext* context = this->context();
428 for (const auto& url : public_blob_urls_) { 348 for (const auto& url : public_blob_urls_) {
429 context->RevokePublicBlobURL(url); 349 context->RevokePublicBlobURL(url);
430 } 350 }
431 for (const auto& uuid_refnum_pair : blobs_inuse_map_) { 351 for (const auto& uuid_refnum_pair : blobs_inuse_map_) {
432 for (int i = 0; i < uuid_refnum_pair.second; ++i) 352 for (int i = 0; i < uuid_refnum_pair.second; ++i)
433 context->DecrementBlobRefCount(uuid_refnum_pair.first); 353 context->DecrementBlobRefCount(uuid_refnum_pair.first);
434 } 354 }
435 async_builder_.CancelAll(context); 355 async_builder_.CancelAll(context);
436 } 356 }
437 357
438 } // namespace content 358 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/blob_storage/blob_dispatcher_host.h ('k') | content/browser/blob_storage/blob_dispatcher_host_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698