Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
| 18 #include "storage/browser/blob/blob_entry.h" | |
| 17 #include "storage/browser/blob/blob_storage_context.h" | 19 #include "storage/browser/blob/blob_storage_context.h" |
| 18 #include "storage/browser/blob/blob_transport_result.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 15 matching lines...) Expand all Loading... | |
| 56 } | 56 } |
| 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 // Note: The only time a renderer sends a blob status message is to cancel. | |
| 66 IPC_BEGIN_MESSAGE_MAP(BlobDispatcherHost, message) | 67 IPC_BEGIN_MESSAGE_MAP(BlobDispatcherHost, message) |
| 67 IPC_MESSAGE_HANDLER(BlobStorageMsg_RegisterBlobUUID, OnRegisterBlobUUID) | 68 IPC_MESSAGE_HANDLER(BlobStorageMsg_RegisterBlob, OnRegisterBlob) |
| 68 IPC_MESSAGE_HANDLER(BlobStorageMsg_StartBuildingBlob, OnStartBuildingBlob) | |
| 69 IPC_MESSAGE_HANDLER(BlobStorageMsg_MemoryItemResponse, OnMemoryItemResponse) | 69 IPC_MESSAGE_HANDLER(BlobStorageMsg_MemoryItemResponse, OnMemoryItemResponse) |
| 70 IPC_MESSAGE_HANDLER(BlobStorageMsg_CancelBuildingBlob, OnCancelBuildingBlob) | 70 IPC_MESSAGE_HANDLER(BlobStorageMsg_SendBlobStatus, OnCancelBuildingBlob) |
| 71 IPC_MESSAGE_HANDLER(BlobHostMsg_IncrementRefCount, OnIncrementBlobRefCount) | 71 IPC_MESSAGE_HANDLER(BlobHostMsg_IncrementRefCount, OnIncrementBlobRefCount) |
| 72 IPC_MESSAGE_HANDLER(BlobHostMsg_DecrementRefCount, OnDecrementBlobRefCount) | 72 IPC_MESSAGE_HANDLER(BlobHostMsg_DecrementRefCount, OnDecrementBlobRefCount) |
| 73 IPC_MESSAGE_HANDLER(BlobHostMsg_RegisterPublicURL, OnRegisterPublicBlobURL) | 73 IPC_MESSAGE_HANDLER(BlobHostMsg_RegisterPublicURL, OnRegisterPublicBlobURL) |
| 74 IPC_MESSAGE_HANDLER(BlobHostMsg_RevokePublicURL, OnRevokePublicBlobURL) | 74 IPC_MESSAGE_HANDLER(BlobHostMsg_RevokePublicURL, OnRevokePublicBlobURL) |
| 75 IPC_MESSAGE_UNHANDLED(handled = false) | 75 IPC_MESSAGE_UNHANDLED(handled = false) |
| 76 IPC_END_MESSAGE_MAP() | 76 IPC_END_MESSAGE_MAP() |
| 77 return handled; | 77 return handled; |
| 78 } | 78 } |
| 79 | 79 |
| 80 void BlobDispatcherHost::OnRegisterBlobUUID( | 80 void BlobDispatcherHost::OnRegisterBlob( |
| 81 const std::string& uuid, | 81 const std::string& uuid, |
| 82 const std::string& content_type, | 82 const std::string& content_type, |
| 83 const std::string& content_disposition, | 83 const std::string& content_disposition, |
| 84 const std::set<std::string>& referenced_blob_uuids) { | 84 const std::vector<storage::DataElement>& descriptions) { |
| 85 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 85 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 86 BlobStorageContext* context = this->context(); | 86 BlobStorageContext* context = this->context(); |
| 87 if (uuid.empty() || context->registry().HasEntry(uuid) || | 87 if (uuid.empty() || context->registry().HasEntry(uuid) || |
| 88 async_builder_.IsBeingBuilt(uuid)) { | 88 transport_host_.IsBeingBuilt(uuid)) { |
| 89 bad_message::ReceivedBadMessage(this, bad_message::BDH_UUID_REGISTERED); | 89 bad_message::ReceivedBadMessage(this, bad_message::BDH_UUID_REGISTERED); |
| 90 return; | 90 return; |
| 91 } | 91 } |
| 92 | |
| 93 DCHECK(!base::ContainsKey(blobs_inuse_map_, uuid)); | |
| 92 blobs_inuse_map_[uuid] = 1; | 94 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 | 95 |
| 150 ChildProcessSecurityPolicyImpl* security_policy = | 96 ChildProcessSecurityPolicyImpl* security_policy = |
| 151 ChildProcessSecurityPolicyImpl::GetInstance(); | 97 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 152 for (const DataElement& item : descriptions) { | 98 for (const DataElement& item : descriptions) { |
| 153 // For each source object that provides the data for the blob, ensure that | 99 // For each source object that provides the data for the blob, ensure that |
| 154 // this process has permission to read it. | 100 // this process has permission to read it. |
| 155 switch (item.type()) { | 101 switch (item.type()) { |
| 156 case storage::DataElement::TYPE_FILE_FILESYSTEM: { | 102 case storage::DataElement::TYPE_FILE_FILESYSTEM: { |
| 157 FileSystemURL filesystem_url( | 103 FileSystemURL filesystem_url( |
| 158 file_system_context_->CrackURL(item.filesystem_url())); | 104 file_system_context_->CrackURL(item.filesystem_url())); |
| 159 if (!FileSystemURLIsValid(file_system_context_.get(), filesystem_url) || | 105 if (!FileSystemURLIsValid(file_system_context_.get(), filesystem_url) || |
| 160 !security_policy->CanReadFileSystemFile(process_id_, | 106 !security_policy->CanReadFileSystemFile(process_id_, |
| 161 filesystem_url)) { | 107 filesystem_url)) { |
| 162 async_builder_.CancelBuildingBlob( | 108 std::unique_ptr<storage::BlobDataHandle> broken_handle = |
| 163 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context); | 109 context->AddBrokenBlob(uuid, content_type, content_disposition, |
| 164 Send(new BlobStorageMsg_CancelBuildingBlob( | 110 BlobStatus::ERR_FILE_WRITE_FAILED); |
| 165 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED)); | 111 context->IncrementBlobRefCount(uuid); |
| 112 SendFinalBlobStatus(uuid, BlobStatus::ERR_FILE_WRITE_FAILED); | |
|
kinuko
2016/11/11 17:51:14
I'm wondering how we could make this code flow a l
| |
| 166 return; | 113 return; |
| 167 } | 114 } |
| 168 break; | 115 break; |
| 169 } | 116 } |
| 170 case storage::DataElement::TYPE_FILE: { | 117 case storage::DataElement::TYPE_FILE: { |
| 171 if (!security_policy->CanReadFile(process_id_, item.path())) { | 118 if (!security_policy->CanReadFile(process_id_, item.path())) { |
| 172 async_builder_.CancelBuildingBlob( | 119 std::unique_ptr<storage::BlobDataHandle> broken_handle = |
| 173 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context); | 120 context->AddBrokenBlob(uuid, content_type, content_disposition, |
| 174 Send(new BlobStorageMsg_CancelBuildingBlob( | 121 BlobStatus::ERR_FILE_WRITE_FAILED); |
| 175 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED)); | 122 context->IncrementBlobRefCount(uuid); |
| 123 SendFinalBlobStatus(uuid, BlobStatus::ERR_FILE_WRITE_FAILED); | |
| 176 return; | 124 return; |
| 177 } | 125 } |
| 178 break; | 126 break; |
| 179 } | 127 } |
| 180 case storage::DataElement::TYPE_BLOB: | 128 case storage::DataElement::TYPE_BLOB: |
| 181 case storage::DataElement::TYPE_BYTES_DESCRIPTION: | 129 case storage::DataElement::TYPE_BYTES_DESCRIPTION: |
| 182 case storage::DataElement::TYPE_BYTES: { | 130 case storage::DataElement::TYPE_BYTES: { |
| 183 // Bytes are already in hand; no need to check read permission. | 131 // Bytes are already in hand; no need to check read permission. |
| 184 // TODO(nick): For TYPE_BLOB, can we actually get here for blobs | 132 // TODO(nick): For TYPE_BLOB, can we actually get here for blobs |
| 185 // originally created by other processes? If so, is that cool? | 133 // originally created by other processes? If so, is that cool? |
| 186 break; | 134 break; |
| 187 } | 135 } |
| 188 case storage::DataElement::TYPE_UNKNOWN: | 136 case storage::DataElement::TYPE_UNKNOWN: |
| 189 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: { | 137 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: { |
| 190 NOTREACHED(); // Should have been caught by IPC deserialization. | 138 NOTREACHED(); // Should have been caught by IPC deserialization. |
| 191 break; | 139 break; |
| 192 } | 140 } |
| 193 } | 141 } |
| 194 } | 142 } |
| 195 | 143 |
| 196 // |this| owns async_builder_ so using base::Unretained(this) is safe. | 144 transport_host_.StartBuildingBlob( |
| 197 BlobTransportResult result = async_builder_.StartBuildingBlob( | 145 uuid, content_type, content_disposition, descriptions, context, |
| 198 uuid, descriptions, context->memory_available(), context, | |
| 199 base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this), | 146 base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this), |
| 200 uuid)); | 147 uuid), |
| 201 SendIPCResponse(uuid, result); | 148 base::Bind(&BlobDispatcherHost::SendFinalBlobStatus, |
| 149 base::Unretained(this), uuid)); | |
| 202 } | 150 } |
| 203 | 151 |
| 204 void BlobDispatcherHost::OnMemoryItemResponse( | 152 void BlobDispatcherHost::OnMemoryItemResponse( |
| 205 const std::string& uuid, | 153 const std::string& uuid, |
| 206 const std::vector<storage::BlobItemBytesResponse>& responses) { | 154 const std::vector<storage::BlobItemBytesResponse>& responses) { |
| 207 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 155 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 208 if (uuid.empty()) { | 156 if (uuid.empty()) { |
| 209 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); | 157 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED); |
| 210 return; | 158 return; |
| 211 } | 159 } |
| 212 BlobStorageContext* context = this->context(); | 160 BlobStorageContext* context = this->context(); |
| 213 const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid); | 161 const storage::BlobEntry* entry = context->registry().GetEntry(uuid); |
| 214 if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) { | 162 if (!entry || BlobStatusIsError(entry->status())) { |
| 215 // We ignore messages for blobs that don't exist to handle the case where | 163 // 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 | 164 // 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 | 165 // 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. | 166 // 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. | 167 // 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, | 168 // 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 | 169 // 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. | 170 // host. So we call cancel, and send the message just in case that happens. |
| 223 if (async_builder_.IsBeingBuilt(uuid)) { | 171 if (transport_host_.IsBeingBuilt(uuid)) { |
| 224 async_builder_.CancelBuildingBlob( | 172 transport_host_.CancelBuildingBlob( |
| 225 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, | 173 uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context); |
| 226 context); | 174 SendFinalBlobStatus(uuid, |
| 227 Send(new BlobStorageMsg_CancelBuildingBlob( | 175 BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING); |
| 228 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING)); | |
| 229 } | 176 } |
| 230 return; | 177 return; |
| 231 } | 178 } |
| 232 if (!async_builder_.IsBeingBuilt(uuid)) { | 179 if (!transport_host_.IsBeingBuilt(uuid)) { |
| 233 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); | 180 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED); |
| 234 return; | 181 return; |
| 235 } | 182 } |
| 236 BlobTransportResult result = | 183 BlobStatus result = |
| 237 async_builder_.OnMemoryResponses(uuid, responses, context); | 184 transport_host_.OnMemoryResponses(uuid, responses, context); |
| 238 SendIPCResponse(uuid, result); | 185 if (BlobStatusIsPending(result)) |
| 186 return; | |
| 187 SendFinalBlobStatus(uuid, result); | |
| 239 } | 188 } |
| 240 | 189 |
| 241 void BlobDispatcherHost::OnCancelBuildingBlob( | 190 void BlobDispatcherHost::OnCancelBuildingBlob(const std::string& uuid, |
| 242 const std::string& uuid, | 191 const storage::BlobStatus code) { |
| 243 const storage::IPCBlobCreationCancelCode code) { | |
| 244 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 192 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 245 if (uuid.empty()) { | 193 if (uuid.empty()) { |
| 246 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); | 194 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED); |
| 247 return; | 195 return; |
| 248 } | 196 } |
| 249 BlobStorageContext* context = this->context(); | 197 BlobStorageContext* context = this->context(); |
| 250 const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid); | 198 const storage::BlobEntry* entry = context->registry().GetEntry(uuid); |
| 251 if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) { | 199 if (!entry || BlobStatusIsError(entry->status())) { |
| 252 // We ignore messages for blobs that don't exist to handle the case where | 200 // 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 | 201 // 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 | 202 // 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. | 203 // 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. | 204 // 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, | 205 // 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 | 206 // 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. | 207 // host. So we call cancel just in case this happens. |
| 260 if (async_builder_.IsBeingBuilt(uuid)) { | 208 if (transport_host_.IsBeingBuilt(uuid)) { |
| 261 async_builder_.CancelBuildingBlob( | 209 transport_host_.CancelBuildingBlob( |
| 262 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, | 210 uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context); |
| 263 context); | |
| 264 } | 211 } |
| 265 return; | 212 return; |
| 266 } | 213 } |
| 267 if (!async_builder_.IsBeingBuilt(uuid)) { | 214 if (!transport_host_.IsBeingBuilt(uuid) || |
| 268 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); | 215 !storage::BlobStatusIsError(code)) { |
| 216 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED); | |
| 269 return; | 217 return; |
| 270 } | 218 } |
| 271 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. " | 219 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. " |
| 272 << " Reason: " << static_cast<int>(code) << "."; | 220 << " Reason: " << static_cast<int>(code) << "."; |
| 273 async_builder_.CancelBuildingBlob(uuid, code, context); | 221 transport_host_.CancelBuildingBlob(uuid, code, context); |
| 274 } | 222 } |
| 275 | 223 |
| 276 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) { | 224 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) { |
| 277 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 225 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 278 BlobStorageContext* context = this->context(); | 226 BlobStorageContext* context = this->context(); |
| 279 if (uuid.empty()) { | 227 if (uuid.empty()) { |
| 280 bad_message::ReceivedBadMessage( | 228 bad_message::ReceivedBadMessage( |
| 281 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION); | 229 this, bad_message::BDH_INVALID_REFCOUNT_OPERATION); |
| 282 return; | 230 return; |
| 283 } | 231 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 303 return; | 251 return; |
| 304 } | 252 } |
| 305 BlobStorageContext* context = this->context(); | 253 BlobStorageContext* context = this->context(); |
| 306 context->DecrementBlobRefCount(uuid); | 254 context->DecrementBlobRefCount(uuid); |
| 307 blobs_inuse_map_[uuid] -= 1; | 255 blobs_inuse_map_[uuid] -= 1; |
| 308 if (blobs_inuse_map_[uuid] == 0) { | 256 if (blobs_inuse_map_[uuid] == 0) { |
| 309 blobs_inuse_map_.erase(uuid); | 257 blobs_inuse_map_.erase(uuid); |
| 310 // If the blob has been deleted in the context and we're still building it, | 258 // 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 | 259 // this means we have no references waiting to read it. Clear the building |
| 312 // state and send a cancel message to the renderer. | 260 // state and send a cancel message to the renderer. |
| 313 if (async_builder_.IsBeingBuilt(uuid) && | 261 if (transport_host_.IsBeingBuilt(uuid) && |
| 314 !context->registry().HasEntry(uuid)) { | 262 !context->registry().HasEntry(uuid)) { |
| 315 async_builder_.CancelBuildingBlob( | 263 transport_host_.CancelBuildingBlob( |
| 316 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, | 264 uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context); |
| 317 context); | 265 SendFinalBlobStatus(uuid, |
| 318 Send(new BlobStorageMsg_CancelBuildingBlob( | 266 BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING); |
| 319 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING)); | |
| 320 } | 267 } |
| 321 } | 268 } |
| 322 } | 269 } |
| 323 | 270 |
| 324 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url, | 271 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url, |
| 325 const std::string& uuid) { | 272 const std::string& uuid) { |
| 326 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 273 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 327 ChildProcessSecurityPolicyImpl* security_policy = | 274 ChildProcessSecurityPolicyImpl* security_policy = |
| 328 ChildProcessSecurityPolicyImpl::GetInstance(); | 275 ChildProcessSecurityPolicyImpl::GetInstance(); |
| 329 | 276 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 context()->RevokePublicBlobURL(public_url); | 312 context()->RevokePublicBlobURL(public_url); |
| 366 public_blob_urls_.erase(public_url); | 313 public_blob_urls_.erase(public_url); |
| 367 } | 314 } |
| 368 | 315 |
| 369 storage::BlobStorageContext* BlobDispatcherHost::context() { | 316 storage::BlobStorageContext* BlobDispatcherHost::context() { |
| 370 return blob_storage_context_->context(); | 317 return blob_storage_context_->context(); |
| 371 } | 318 } |
| 372 | 319 |
| 373 void BlobDispatcherHost::SendMemoryRequest( | 320 void BlobDispatcherHost::SendMemoryRequest( |
| 374 const std::string& uuid, | 321 const std::string& uuid, |
| 375 std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests, | 322 std::vector<storage::BlobItemBytesRequest> requests, |
| 376 std::unique_ptr<std::vector<base::SharedMemoryHandle>> memory_handles, | 323 std::vector<base::SharedMemoryHandle> memory_handles, |
| 377 std::unique_ptr<std::vector<base::File>> files) { | 324 std::vector<base::File> files) { |
| 378 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 325 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 379 std::vector<IPC::PlatformFileForTransit> file_handles; | 326 std::vector<IPC::PlatformFileForTransit> file_handles; |
| 380 // TODO(dmurph): Support file-backed blob transportation. | 327 for (base::File& file : files) { |
| 381 DCHECK(files->empty()); | 328 file_handles.push_back(IPC::TakePlatformFileForTransit(std::move(file))); |
| 382 Send(new BlobStorageMsg_RequestMemoryItem(uuid, *requests, *memory_handles, | 329 } |
| 330 Send(new BlobStorageMsg_RequestMemoryItem(uuid, requests, memory_handles, | |
| 383 file_handles)); | 331 file_handles)); |
| 384 } | 332 } |
| 385 | 333 |
| 386 void BlobDispatcherHost::SendIPCResponse(const std::string& uuid, | 334 void BlobDispatcherHost::SendFinalBlobStatus(const std::string& uuid, |
| 387 storage::BlobTransportResult result) { | 335 BlobStatus status) { |
| 388 switch (result) { | 336 if (storage::BlobStatusIsBadIPC(status)) { |
| 389 case BlobTransportResult::BAD_IPC: | 337 // A bad ipc status means it has already been removed from the transport |
| 390 bad_message::ReceivedBadMessage(this, | 338 // host and context. |
| 391 bad_message::BDH_CONSTRUCTION_FAILED); | 339 blobs_inuse_map_.erase(uuid); |
| 392 return; | 340 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED); |
| 393 case BlobTransportResult::CANCEL_MEMORY_FULL: | 341 return; |
| 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 } | 342 } |
| 415 NOTREACHED(); | 343 DCHECK(!BlobStatusIsPending(status)); |
| 344 Send(new BlobStorageMsg_SendBlobStatus(uuid, status)); | |
| 416 } | 345 } |
| 417 | 346 |
| 418 bool BlobDispatcherHost::IsInUseInHost(const std::string& uuid) { | 347 bool BlobDispatcherHost::IsInUseInHost(const std::string& uuid) { |
| 419 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); | 348 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); |
| 420 } | 349 } |
| 421 | 350 |
| 422 bool BlobDispatcherHost::IsUrlRegisteredInHost(const GURL& blob_url) { | 351 bool BlobDispatcherHost::IsUrlRegisteredInHost(const GURL& blob_url) { |
| 423 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); | 352 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); |
| 424 } | 353 } |
| 425 | 354 |
| 426 void BlobDispatcherHost::ClearHostFromBlobStorageContext() { | 355 void BlobDispatcherHost::ClearHostFromBlobStorageContext() { |
| 427 BlobStorageContext* context = this->context(); | 356 BlobStorageContext* context = this->context(); |
| 428 for (const auto& url : public_blob_urls_) { | 357 for (const auto& url : public_blob_urls_) { |
| 429 context->RevokePublicBlobURL(url); | 358 context->RevokePublicBlobURL(url); |
| 430 } | 359 } |
| 431 for (const auto& uuid_refnum_pair : blobs_inuse_map_) { | 360 for (const auto& uuid_refnum_pair : blobs_inuse_map_) { |
| 432 for (int i = 0; i < uuid_refnum_pair.second; ++i) | 361 for (int i = 0; i < uuid_refnum_pair.second; ++i) |
| 433 context->DecrementBlobRefCount(uuid_refnum_pair.first); | 362 context->DecrementBlobRefCount(uuid_refnum_pair.first); |
| 434 } | 363 } |
| 435 async_builder_.CancelAll(context); | 364 transport_host_.CancelAll(context); |
| 436 } | 365 } |
| 437 | 366 |
| 438 } // namespace content | 367 } // namespace content |
| OLD | NEW |