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

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

Issue 2448353002: [BlobAsync] Moving async handling into BlobStorageContext & quota out. (Closed)
Patch Set: hopefully fixed android/windows compile, and comments 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"
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
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 async_builder_.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 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 92
150 ChildProcessSecurityPolicyImpl* security_policy = 93 ChildProcessSecurityPolicyImpl* security_policy =
151 ChildProcessSecurityPolicyImpl::GetInstance(); 94 ChildProcessSecurityPolicyImpl::GetInstance();
152 for (const DataElement& item : descriptions) { 95 for (const DataElement& item : descriptions) {
153 // For each source object that provides the data for the blob, ensure that 96 // For each source object that provides the data for the blob, ensure that
154 // this process has permission to read it. 97 // this process has permission to read it.
155 switch (item.type()) { 98 switch (item.type()) {
156 case storage::DataElement::TYPE_FILE_FILESYSTEM: { 99 case storage::DataElement::TYPE_FILE_FILESYSTEM: {
157 FileSystemURL filesystem_url( 100 FileSystemURL filesystem_url(
158 file_system_context_->CrackURL(item.filesystem_url())); 101 file_system_context_->CrackURL(item.filesystem_url()));
159 if (!FileSystemURLIsValid(file_system_context_.get(), filesystem_url) || 102 if (!FileSystemURLIsValid(file_system_context_.get(), filesystem_url) ||
160 !security_policy->CanReadFileSystemFile(process_id_, 103 !security_policy->CanReadFileSystemFile(process_id_,
161 filesystem_url)) { 104 filesystem_url)) {
162 async_builder_.CancelBuildingBlob( 105 SendFinalBlobStatus(uuid, BlobStatus::ERR_FILE_WRITE_FAILED);
163 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context);
164 Send(new BlobStorageMsg_CancelBuildingBlob(
165 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
166 return; 106 return;
167 } 107 }
168 break; 108 break;
169 } 109 }
170 case storage::DataElement::TYPE_FILE: { 110 case storage::DataElement::TYPE_FILE: {
171 if (!security_policy->CanReadFile(process_id_, item.path())) { 111 if (!security_policy->CanReadFile(process_id_, item.path())) {
172 async_builder_.CancelBuildingBlob( 112 SendFinalBlobStatus(uuid, BlobStatus::ERR_FILE_WRITE_FAILED);
173 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED, context);
174 Send(new BlobStorageMsg_CancelBuildingBlob(
175 uuid, IPCBlobCreationCancelCode::FILE_WRITE_FAILED));
176 return; 113 return;
177 } 114 }
178 break; 115 break;
179 } 116 }
180 case storage::DataElement::TYPE_BLOB: 117 case storage::DataElement::TYPE_BLOB:
181 case storage::DataElement::TYPE_BYTES_DESCRIPTION: 118 case storage::DataElement::TYPE_BYTES_DESCRIPTION:
182 case storage::DataElement::TYPE_BYTES: { 119 case storage::DataElement::TYPE_BYTES: {
183 // Bytes are already in hand; no need to check read permission. 120 // Bytes are already in hand; no need to check read permission.
184 // TODO(nick): For TYPE_BLOB, can we actually get here for blobs 121 // TODO(nick): For TYPE_BLOB, can we actually get here for blobs
185 // originally created by other processes? If so, is that cool? 122 // originally created by other processes? If so, is that cool?
186 break; 123 break;
187 } 124 }
188 case storage::DataElement::TYPE_UNKNOWN: 125 case storage::DataElement::TYPE_UNKNOWN:
189 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: { 126 case storage::DataElement::TYPE_DISK_CACHE_ENTRY: {
190 NOTREACHED(); // Should have been caught by IPC deserialization. 127 NOTREACHED(); // Should have been caught by IPC deserialization.
191 break; 128 break;
192 } 129 }
193 } 130 }
194 } 131 }
132 DCHECK(!base::ContainsKey(blobs_inuse_map_, uuid));
133 blobs_inuse_map_[uuid] = 1;
195 134
196 // |this| owns async_builder_ so using base::Unretained(this) is safe. 135 async_builder_.StartBuildingBlob(
197 BlobTransportResult result = async_builder_.StartBuildingBlob( 136 uuid, content_type, content_disposition, descriptions, context,
198 uuid, descriptions, context->memory_available(), context,
199 base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this), 137 base::Bind(&BlobDispatcherHost::SendMemoryRequest, base::Unretained(this),
200 uuid)); 138 uuid),
201 SendIPCResponse(uuid, result); 139 base::Bind(&BlobDispatcherHost::SendFinalBlobStatus,
140 base::Unretained(this), uuid));
202 } 141 }
203 142
204 void BlobDispatcherHost::OnMemoryItemResponse( 143 void BlobDispatcherHost::OnMemoryItemResponse(
205 const std::string& uuid, 144 const std::string& uuid,
206 const std::vector<storage::BlobItemBytesResponse>& responses) { 145 const std::vector<storage::BlobItemBytesResponse>& responses) {
207 DCHECK_CURRENTLY_ON(BrowserThread::IO); 146 DCHECK_CURRENTLY_ON(BrowserThread::IO);
208 if (uuid.empty()) { 147 if (uuid.empty()) {
209 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); 148 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
210 return; 149 return;
211 } 150 }
212 BlobStorageContext* context = this->context(); 151 BlobStorageContext* context = this->context();
213 const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid); 152 const storage::BlobEntry* entry = context->registry().GetEntry(uuid);
214 if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) { 153 if (!entry || BlobStatusIsError(entry->status())) {
215 // We ignore messages for blobs that don't exist to handle the case where 154 // 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 155 // 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 156 // 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. 157 // 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. 158 // 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, 159 // 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 160 // 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. 161 // host. So we call cancel, and send the message just in case that happens.
223 if (async_builder_.IsBeingBuilt(uuid)) { 162 if (async_builder_.IsBeingBuilt(uuid)) {
224 async_builder_.CancelBuildingBlob( 163 async_builder_.CancelBuildingBlob(
225 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, 164 uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context);
226 context); 165 SendFinalBlobStatus(uuid,
227 Send(new BlobStorageMsg_CancelBuildingBlob( 166 BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING);
228 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING));
229 } 167 }
230 return; 168 return;
231 } 169 }
232 if (!async_builder_.IsBeingBuilt(uuid)) { 170 if (!async_builder_.IsBeingBuilt(uuid)) {
233 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); 171 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
234 return; 172 return;
235 } 173 }
236 BlobTransportResult result = 174 BlobStatus result =
237 async_builder_.OnMemoryResponses(uuid, responses, context); 175 async_builder_.OnMemoryResponses(uuid, responses, context);
238 SendIPCResponse(uuid, result); 176 if (BlobStatusIsPending(result))
177 return;
178 SendFinalBlobStatus(uuid, result);
239 } 179 }
240 180
241 void BlobDispatcherHost::OnCancelBuildingBlob( 181 void BlobDispatcherHost::OnCancelBuildingBlob(const std::string& uuid,
242 const std::string& uuid, 182 const storage::BlobStatus code) {
243 const storage::IPCBlobCreationCancelCode code) {
244 DCHECK_CURRENTLY_ON(BrowserThread::IO); 183 DCHECK_CURRENTLY_ON(BrowserThread::IO);
245 if (uuid.empty()) { 184 if (uuid.empty()) {
246 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); 185 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
247 return; 186 return;
248 } 187 }
249 BlobStorageContext* context = this->context(); 188 BlobStorageContext* context = this->context();
250 const BlobStorageRegistry::Entry* entry = context->registry().GetEntry(uuid); 189 const storage::BlobEntry* entry = context->registry().GetEntry(uuid);
251 if (!entry || entry->state == BlobStorageRegistry::BlobState::BROKEN) { 190 if (!entry || BlobStatusIsError(entry->status())) {
252 // We ignore messages for blobs that don't exist to handle the case where 191 // 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 192 // 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 193 // 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. 194 // 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. 195 // 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, 196 // 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 197 // 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. 198 // host. So we call cancel just in case this happens.
260 if (async_builder_.IsBeingBuilt(uuid)) { 199 if (async_builder_.IsBeingBuilt(uuid)) {
261 async_builder_.CancelBuildingBlob( 200 async_builder_.CancelBuildingBlob(
262 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, 201 uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context);
263 context);
264 } 202 }
265 return; 203 return;
266 } 204 }
267 if (!async_builder_.IsBeingBuilt(uuid)) { 205 if (!async_builder_.IsBeingBuilt(uuid) || !storage::BlobStatusIsError(code)) {
268 SendIPCResponse(uuid, BlobTransportResult::BAD_IPC); 206 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
269 return; 207 return;
270 } 208 }
271 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. " 209 VLOG(1) << "Blob construction of " << uuid << " cancelled by renderer. "
272 << " Reason: " << static_cast<int>(code) << "."; 210 << " Reason: " << static_cast<int>(code) << ".";
273 async_builder_.CancelBuildingBlob(uuid, code, context); 211 async_builder_.CancelBuildingBlob(uuid, code, context);
274 } 212 }
275 213
276 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) { 214 void BlobDispatcherHost::OnIncrementBlobRefCount(const std::string& uuid) {
277 DCHECK_CURRENTLY_ON(BrowserThread::IO); 215 DCHECK_CURRENTLY_ON(BrowserThread::IO);
278 BlobStorageContext* context = this->context(); 216 BlobStorageContext* context = this->context();
(...skipping 27 matching lines...) Expand all
306 context->DecrementBlobRefCount(uuid); 244 context->DecrementBlobRefCount(uuid);
307 blobs_inuse_map_[uuid] -= 1; 245 blobs_inuse_map_[uuid] -= 1;
308 if (blobs_inuse_map_[uuid] == 0) { 246 if (blobs_inuse_map_[uuid] == 0) {
309 blobs_inuse_map_.erase(uuid); 247 blobs_inuse_map_.erase(uuid);
310 // If the blob has been deleted in the context and we're still building it, 248 // 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 249 // this means we have no references waiting to read it. Clear the building
312 // state and send a cancel message to the renderer. 250 // state and send a cancel message to the renderer.
313 if (async_builder_.IsBeingBuilt(uuid) && 251 if (async_builder_.IsBeingBuilt(uuid) &&
314 !context->registry().HasEntry(uuid)) { 252 !context->registry().HasEntry(uuid)) {
315 async_builder_.CancelBuildingBlob( 253 async_builder_.CancelBuildingBlob(
316 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING, 254 uuid, BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING, context);
317 context); 255 SendFinalBlobStatus(uuid,
318 Send(new BlobStorageMsg_CancelBuildingBlob( 256 BlobStatus::ERR_BLOB_DEREFERENCED_WHILE_BUILDING);
319 uuid, IPCBlobCreationCancelCode::BLOB_DEREFERENCED_WHILE_BUILDING));
320 } 257 }
321 } 258 }
322 } 259 }
323 260
324 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url, 261 void BlobDispatcherHost::OnRegisterPublicBlobURL(const GURL& public_url,
325 const std::string& uuid) { 262 const std::string& uuid) {
326 DCHECK_CURRENTLY_ON(BrowserThread::IO); 263 DCHECK_CURRENTLY_ON(BrowserThread::IO);
327 ChildProcessSecurityPolicyImpl* security_policy = 264 ChildProcessSecurityPolicyImpl* security_policy =
328 ChildProcessSecurityPolicyImpl::GetInstance(); 265 ChildProcessSecurityPolicyImpl::GetInstance();
329 266
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 context()->RevokePublicBlobURL(public_url); 302 context()->RevokePublicBlobURL(public_url);
366 public_blob_urls_.erase(public_url); 303 public_blob_urls_.erase(public_url);
367 } 304 }
368 305
369 storage::BlobStorageContext* BlobDispatcherHost::context() { 306 storage::BlobStorageContext* BlobDispatcherHost::context() {
370 return blob_storage_context_->context(); 307 return blob_storage_context_->context();
371 } 308 }
372 309
373 void BlobDispatcherHost::SendMemoryRequest( 310 void BlobDispatcherHost::SendMemoryRequest(
374 const std::string& uuid, 311 const std::string& uuid,
375 std::unique_ptr<std::vector<storage::BlobItemBytesRequest>> requests, 312 std::vector<storage::BlobItemBytesRequest> requests,
376 std::unique_ptr<std::vector<base::SharedMemoryHandle>> memory_handles, 313 std::vector<base::SharedMemoryHandle> memory_handles,
377 std::unique_ptr<std::vector<base::File>> files) { 314 std::vector<base::File> files) {
378 DCHECK_CURRENTLY_ON(BrowserThread::IO); 315 DCHECK_CURRENTLY_ON(BrowserThread::IO);
379 std::vector<IPC::PlatformFileForTransit> file_handles; 316 std::vector<IPC::PlatformFileForTransit> file_handles;
380 // TODO(dmurph): Support file-backed blob transportation. 317 for (base::File& file : files) {
381 DCHECK(files->empty()); 318 file_handles.push_back(IPC::TakePlatformFileForTransit(std::move(file)));
382 Send(new BlobStorageMsg_RequestMemoryItem(uuid, *requests, *memory_handles, 319 }
320 Send(new BlobStorageMsg_RequestMemoryItem(uuid, requests, memory_handles,
383 file_handles)); 321 file_handles));
384 } 322 }
385 323
386 void BlobDispatcherHost::SendIPCResponse(const std::string& uuid, 324 void BlobDispatcherHost::SendFinalBlobStatus(const std::string& uuid,
387 storage::BlobTransportResult result) { 325 BlobStatus status) {
388 switch (result) { 326 if (storage::BlobStatusIsBadIPC(status)) {
389 case BlobTransportResult::BAD_IPC: 327 blobs_inuse_map_.erase(uuid);
390 bad_message::ReceivedBadMessage(this, 328 bad_message::ReceivedBadMessage(this, bad_message::BDH_CONSTRUCTION_FAILED);
391 bad_message::BDH_CONSTRUCTION_FAILED); 329 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 } 330 }
415 NOTREACHED(); 331 DCHECK(!BlobStatusIsPending(status));
332 Send(new BlobStorageMsg_SendBlobStatus(uuid, status));
416 } 333 }
417 334
418 bool BlobDispatcherHost::IsInUseInHost(const std::string& uuid) { 335 bool BlobDispatcherHost::IsInUseInHost(const std::string& uuid) {
419 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end(); 336 return blobs_inuse_map_.find(uuid) != blobs_inuse_map_.end();
420 } 337 }
421 338
422 bool BlobDispatcherHost::IsUrlRegisteredInHost(const GURL& blob_url) { 339 bool BlobDispatcherHost::IsUrlRegisteredInHost(const GURL& blob_url) {
423 return public_blob_urls_.find(blob_url) != public_blob_urls_.end(); 340 return public_blob_urls_.find(blob_url) != public_blob_urls_.end();
424 } 341 }
425 342
426 void BlobDispatcherHost::ClearHostFromBlobStorageContext() { 343 void BlobDispatcherHost::ClearHostFromBlobStorageContext() {
427 BlobStorageContext* context = this->context(); 344 BlobStorageContext* context = this->context();
428 for (const auto& url : public_blob_urls_) { 345 for (const auto& url : public_blob_urls_) {
429 context->RevokePublicBlobURL(url); 346 context->RevokePublicBlobURL(url);
430 } 347 }
431 for (const auto& uuid_refnum_pair : blobs_inuse_map_) { 348 for (const auto& uuid_refnum_pair : blobs_inuse_map_) {
432 for (int i = 0; i < uuid_refnum_pair.second; ++i) 349 for (int i = 0; i < uuid_refnum_pair.second; ++i)
433 context->DecrementBlobRefCount(uuid_refnum_pair.first); 350 context->DecrementBlobRefCount(uuid_refnum_pair.first);
434 } 351 }
435 async_builder_.CancelAll(context); 352 async_builder_.CancelAll(context);
436 } 353 }
437 354
438 } // namespace content 355 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698