| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "storage/browser/blob/blob_async_builder_host.h" | 5 #include "storage/browser/blob/blob_async_builder_host.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 return BlobTransportResult::CANCEL_MEMORY_FULL; | 284 return BlobTransportResult::CANCEL_MEMORY_FULL; |
| 285 } | 285 } |
| 286 state->num_fulfilled_requests++; | 286 state->num_fulfilled_requests++; |
| 287 } | 287 } |
| 288 return ContinueBlobMemoryRequests(uuid, context); | 288 return ContinueBlobMemoryRequests(uuid, context); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void BlobAsyncBuilderHost::CancelBuildingBlob(const std::string& uuid, | 291 void BlobAsyncBuilderHost::CancelBuildingBlob(const std::string& uuid, |
| 292 IPCBlobCreationCancelCode code, | 292 IPCBlobCreationCancelCode code, |
| 293 BlobStorageContext* context) { | 293 BlobStorageContext* context) { |
| 294 LOG(ERROR) << "Cancelling blob " << uuid; |
| 294 DCHECK(context); | 295 DCHECK(context); |
| 295 auto state_it = async_blob_map_.find(uuid); | 296 auto state_it = async_blob_map_.find(uuid); |
| 296 if (state_it == async_blob_map_.end()) { | 297 if (state_it == async_blob_map_.end()) { |
| 297 return; | 298 return; |
| 298 } | 299 } |
| 299 // We can have the blob dereferenced by the renderer, but have it still being | 300 // We can have the blob dereferenced by the renderer, but have it still being |
| 300 // 'built'. In this case, it's destructed in the context, but we still have | 301 // 'built'. In this case, it's destructed in the context, but we still have |
| 301 // it in our map. Hence we make sure the context has the entry before | 302 // it in our map. Hence we make sure the context has the entry before |
| 302 // calling cancel. | 303 // calling cancel. |
| 303 if (context->registry().HasEntry(uuid)) | 304 if (context->registry().HasEntry(uuid)) |
| 304 context->CancelPendingBlob(uuid, code); | 305 context->CancelPendingBlob(uuid, code); |
| 305 async_blob_map_.erase(state_it); | 306 async_blob_map_.erase(state_it); |
| 306 } | 307 } |
| 307 | 308 |
| 309 |
| 310 |
| 308 void BlobAsyncBuilderHost::CancelAll(BlobStorageContext* context) { | 311 void BlobAsyncBuilderHost::CancelAll(BlobStorageContext* context) { |
| 309 DCHECK(context); | 312 DCHECK(context); |
| 310 // If the blob still exists in the context (and is being built), then we know | 313 // If the blob still exists in the context (and is being built), then we know |
| 311 // that someone else is expecting our blob, and we need to cancel it to let | 314 // that someone else is expecting our blob, and we need to cancel it to let |
| 312 // the dependency know it's gone. | 315 // the dependency know it's gone. |
| 313 std::vector<std::unique_ptr<BlobDataHandle>> referenced_pending_blobs; | 316 std::vector<std::unique_ptr<BlobDataHandle>> referenced_pending_blobs; |
| 314 for (const auto& uuid_state_pair : async_blob_map_) { | 317 for (const auto& uuid_state_pair : async_blob_map_) { |
| 315 if (context->IsBeingBuilt(uuid_state_pair.first)) { | 318 if (context->IsBeingBuilt(uuid_state_pair.first)) { |
| 319 auto* state = uuid_state_pair.second.get(); |
| 320 state->LogState(); |
| 316 referenced_pending_blobs.emplace_back( | 321 referenced_pending_blobs.emplace_back( |
| 317 context->GetBlobDataFromUUID(uuid_state_pair.first)); | 322 context->GetBlobDataFromUUID(uuid_state_pair.first)); |
| 318 } | 323 } |
| 319 } | 324 } |
| 320 // We clear the map before canceling them to prevent any strange reentry into | 325 // We clear the map before canceling them to prevent any strange reentry into |
| 321 // our class (see ReferencedBlobFinished) if any blobs were waiting for others | 326 // our class (see ReferencedBlobFinished) if any blobs were waiting for others |
| 322 // to construct. | 327 // to construct. |
| 323 async_blob_map_.clear(); | 328 async_blob_map_.clear(); |
| 324 for (const std::unique_ptr<BlobDataHandle>& handle : | 329 for (const std::unique_ptr<BlobDataHandle>& handle : |
| 325 referenced_pending_blobs) { | 330 referenced_pending_blobs) { |
| 331 LOG(ERROR) << "cancelling blob " << handle->uuid() |
| 332 << " which is being expected by someone"; |
| 326 context->CancelPendingBlob( | 333 context->CancelPendingBlob( |
| 327 handle->uuid(), IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT); | 334 handle->uuid(), IPCBlobCreationCancelCode::SOURCE_DIED_IN_TRANSIT); |
| 328 } | 335 } |
| 329 } | 336 } |
| 330 | 337 |
| 331 BlobTransportResult BlobAsyncBuilderHost::ContinueBlobMemoryRequests( | 338 BlobTransportResult BlobAsyncBuilderHost::ContinueBlobMemoryRequests( |
| 332 const std::string& uuid, | 339 const std::string& uuid, |
| 333 BlobStorageContext* context) { | 340 BlobStorageContext* context) { |
| 334 AsyncBlobMap::const_iterator state_it = async_blob_map_.find(uuid); | 341 AsyncBlobMap::const_iterator state_it = async_blob_map_.find(uuid); |
| 335 DCHECK(state_it != async_blob_map_.end()); | 342 DCHECK(state_it != async_blob_map_.end()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 if (!state->shared_memory_block->CreateAnonymous(size)) { | 390 if (!state->shared_memory_block->CreateAnonymous(size)) { |
| 384 DVLOG(1) << "Unable to allocate shared memory for blob transfer."; | 391 DVLOG(1) << "Unable to allocate shared memory for blob transfer."; |
| 385 return BlobTransportResult::CANCEL_MEMORY_FULL; | 392 return BlobTransportResult::CANCEL_MEMORY_FULL; |
| 386 } | 393 } |
| 387 } | 394 } |
| 388 shared_memory->push_back(state->shared_memory_block->handle()); | 395 shared_memory->push_back(state->shared_memory_block->handle()); |
| 389 byte_requests->push_back(request.message); | 396 byte_requests->push_back(request.message); |
| 390 // Since we are only using one handle at a time, transform our handle | 397 // Since we are only using one handle at a time, transform our handle |
| 391 // index correctly back to 0. | 398 // index correctly back to 0. |
| 392 byte_requests->back().handle_index = 0; | 399 byte_requests->back().handle_index = 0; |
| 400 LOG(ERROR) << uuid << " sending shared memory request"; |
| 393 break; | 401 break; |
| 394 case IPCBlobItemRequestStrategy::FILE: | 402 case IPCBlobItemRequestStrategy::FILE: |
| 395 case IPCBlobItemRequestStrategy::UNKNOWN: | 403 case IPCBlobItemRequestStrategy::UNKNOWN: |
| 396 NOTREACHED() << "Not implemented yet."; | 404 NOTREACHED() << "Not implemented yet."; |
| 397 break; | 405 break; |
| 398 } | 406 } |
| 399 if (stop_accumulating) { | 407 if (stop_accumulating) { |
| 400 break; | 408 break; |
| 401 } | 409 } |
| 402 } | 410 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 if (state->num_referenced_blobs_building > 0) { | 464 if (state->num_referenced_blobs_building > 0) { |
| 457 // We wait until referenced blobs are done. | 465 // We wait until referenced blobs are done. |
| 458 return; | 466 return; |
| 459 } | 467 } |
| 460 } | 468 } |
| 461 context->CompletePendingBlob(state->data_builder); | 469 context->CompletePendingBlob(state->data_builder); |
| 462 async_blob_map_.erase(state->data_builder.uuid()); | 470 async_blob_map_.erase(state->data_builder.uuid()); |
| 463 } | 471 } |
| 464 | 472 |
| 465 } // namespace storage | 473 } // namespace storage |
| OLD | NEW |