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" | |
| 14 #include "content/browser/fileapi/browser_file_system_helper.h" | |
| 13 #include "content/common/fileapi/webblob_messages.h" | 15 #include "content/common/fileapi/webblob_messages.h" |
| 14 #include "ipc/ipc_platform_file.h" | 16 #include "ipc/ipc_platform_file.h" |
| 15 #include "storage/browser/blob/blob_storage_context.h" | 17 #include "storage/browser/blob/blob_storage_context.h" |
| 16 #include "storage/browser/blob/blob_transport_result.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_url.h" | |
| 17 #include "storage/common/blob_storage/blob_item_bytes_request.h" | 21 #include "storage/common/blob_storage/blob_item_bytes_request.h" |
| 18 #include "storage/common/blob_storage/blob_item_bytes_response.h" | 22 #include "storage/common/blob_storage/blob_item_bytes_response.h" |
| 19 #include "storage/common/data_element.h" | 23 #include "storage/common/data_element.h" |
| 20 #include "url/gurl.h" | 24 #include "url/gurl.h" |
| 21 | 25 |
| 22 using storage::BlobStorageContext; | 26 using storage::BlobStorageContext; |
| 23 using storage::BlobStorageRegistry; | 27 using storage::BlobStorageRegistry; |
| 24 using storage::BlobTransportResult; | 28 using storage::BlobTransportResult; |
| 29 using storage::DataElement; | |
| 25 using storage::IPCBlobCreationCancelCode; | 30 using storage::IPCBlobCreationCancelCode; |
| 31 using storage::FileSystemURL; | |
| 26 | 32 |
| 27 namespace content { | 33 namespace content { |
| 28 namespace { | 34 namespace { |
| 29 | 35 |
| 30 // These are used for UMA stats, don't change. | 36 // These are used for UMA stats, don't change. |
| 31 enum RefcountOperation { | 37 enum RefcountOperation { |
| 32 BDH_DECREMENT = 0, | 38 BDH_DECREMENT = 0, |
| 33 BDH_INCREMENT, | 39 BDH_INCREMENT, |
| 34 BDH_TRACING_ENUM_LAST | 40 BDH_TRACING_ENUM_LAST |
| 35 }; | 41 }; |
| 36 | 42 |
| 37 } // namespace | 43 } // namespace |
| 38 | 44 |
| 39 BlobDispatcherHost::BlobDispatcherHost( | 45 BlobDispatcherHost::BlobDispatcherHost( |
| 46 int process_id, | |
| 47 storage::FileSystemContext* file_system_context, | |
| 40 ChromeBlobStorageContext* blob_storage_context) | 48 ChromeBlobStorageContext* blob_storage_context) |
| 41 : BrowserMessageFilter(BlobMsgStart), | 49 : BrowserMessageFilter(BlobMsgStart), |
| 50 process_id_(process_id), | |
| 51 file_system_context_(file_system_context), | |
| 52 security_policy_(ChildProcessSecurityPolicyImpl::GetInstance()), | |
|
kinuko
2016/08/05 15:27:31
Do we want to store this pointer in this class? I
dmurph
2016/08/05 19:12:45
Sure, I was just modeling fileapi_message_filter.
| |
| 42 blob_storage_context_(blob_storage_context) {} | 53 blob_storage_context_(blob_storage_context) {} |
| 43 | 54 |
| 44 BlobDispatcherHost::~BlobDispatcherHost() { | 55 BlobDispatcherHost::~BlobDispatcherHost() { |
| 45 ClearHostFromBlobStorageContext(); | 56 ClearHostFromBlobStorageContext(); |
| 46 } | 57 } |
| 47 | 58 |
| 48 void BlobDispatcherHost::OnChannelClosing() { | 59 void BlobDispatcherHost::OnChannelClosing() { |
| 49 ClearHostFromBlobStorageContext(); | 60 ClearHostFromBlobStorageContext(); |
| 50 public_blob_urls_.clear(); | 61 public_blob_urls_.clear(); |
| 51 blobs_inuse_map_.clear(); | 62 blobs_inuse_map_.clear(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 context); | 140 context); |
| 130 Send(new BlobStorageMsg_CancelBuildingBlob( | 141 Send(new BlobStorageMsg_CancelBuildingBlob( |
| 131 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING)); | 142 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING)); |
| 132 } | 143 } |
| 133 return; | 144 return; |
| 134 } | 145 } |
| 135 if (!async_builder_.IsBeingBuilt(uuid)) { | 146 if (!async_builder_.IsBeingBuilt(uuid)) { |
| 136 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); | 147 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); |
| 137 return; | 148 return; |
| 138 } | 149 } |
| 150 | |
| 151 for (const DataElement& item : descriptions) { | |
| 152 if (item.type() == storage::DataElement::TYPE_FILE_FILESYSTEM) { | |
| 153 FileSystemURL filesystem_url( | |
| 154 file_system_context_->CrackURL(item.filesystem_url())); | |
| 155 if (!FileSystemURLIsValid(file_system_context_, filesystem_url) || | |
| 156 !security_policy_->CanReadFileSystemFile(process_id_, | |
| 157 filesystem_url)) { | |
| 158 async_builder_.CancelBuildingBlob( | |
| 159 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context); | |
| 160 Send(new BlobStorageMsg_CancelBuildingBlob( | |
| 161 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED)); | |
|
kinuko
2016/08/05 15:27:30
(I think we were previously just ignoring such ite
dmurph
2016/08/05 19:12:45
Well, strangely this is the same. We now need to c
| |
| 162 return; | |
| 163 } | |
| 164 } | |
| 165 if (item.type() == storage::DataElement::TYPE_FILE && | |
| 166 !security_policy_->CanReadFile(process_id_, item.path())) { | |
| 167 async_builder_.CancelBuildingBlob( | |
| 168 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context); | |
| 169 Send(new BlobStorageMsg_CancelBuildingBlob( | |
| 170 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED)); | |
| 171 return; | |
| 172 } | |
| 173 } | |
| 174 | |
| 139 // |this| owns async_builder_ so using base::Unretained(this) is safe. | 175 // |this| owns async_builder_ so using base::Unretained(this) is safe. |
| 140 BlobTransportResult result = async_builder_.StartBuildingBlob( | 176 BlobTransportResult result = async_builder_.StartBuildingBlob( |
| 141 uuid, descriptions, context->memory_available(), context, | 177 uuid, descriptions, context->memory_available(), context, |
| 142 base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this), | 178 base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this), |
| 143 uuid)); | 179 uuid)); |
| 144 SendIPCResponse(uuid, result); | 180 SendIPCResponse(uuid, result); |
| 145 } | 181 } |
| 146 | 182 |
| 147 void BlobDispatcherHost::OnMemoryItemResponse( | 183 void BlobDispatcherHost::OnMemoryItemResponse( |
| 148 const std::string& uuid, | 184 const std::string& uuid, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 context->RevokePublicBlobURL(url); | 397 context->RevokePublicBlobURL(url); |
| 362 } | 398 } |
| 363 for (const auto& uuid_refnum_pair : blobs_inuse_map_) { | 399 for (const auto& uuid_refnum_pair : blobs_inuse_map_) { |
| 364 for (int i = 0; i < uuid_refnum_pair.second; ++i) | 400 for (int i = 0; i < uuid_refnum_pair.second; ++i) |
| 365 context->DecrementBlobRefCount(uuid_refnum_pair.first); | 401 context->DecrementBlobRefCount(uuid_refnum_pair.first); |
| 366 } | 402 } |
| 367 async_builder_.CancelAll(context); | 403 async_builder_.CancelAll(context); |
| 368 } | 404 } |
| 369 | 405 |
| 370 } // namespace content | 406 } // namespace content |
| OLD | NEW |