Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/service_worker/service_worker_url_request_job.h" | 5 #include "content/browser/service_worker/service_worker_url_request_job.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/memory/scoped_vector.h" | |
| 13 #include "base/profiler/scoped_tracker.h" | 14 #include "base/profiler/scoped_tracker.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 16 #include "content/browser/resource_context_impl.h" | 17 #include "content/browser/resource_context_impl.h" |
| 17 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" | 18 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" |
| 18 #include "content/browser/service_worker/service_worker_provider_host.h" | 19 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 19 #include "content/browser/streams/stream.h" | 20 #include "content/browser/streams/stream.h" |
| 20 #include "content/browser/streams/stream_context.h" | 21 #include "content/browser/streams/stream_context.h" |
| 21 #include "content/browser/streams/stream_registry.h" | 22 #include "content/browser/streams/stream_registry.h" |
| 22 #include "content/common/resource_request_body.h" | 23 #include "content/common/resource_request_body.h" |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 info->GetPageTransition(), ui::PAGE_TRANSITION_RELOAD); | 403 info->GetPageTransition(), ui::PAGE_TRANSITION_RELOAD); |
| 403 } | 404 } |
| 404 return request.Pass(); | 405 return request.Pass(); |
| 405 } | 406 } |
| 406 | 407 |
| 407 bool ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, | 408 bool ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, |
| 408 uint64* blob_size) { | 409 uint64* blob_size) { |
| 409 if (!body_.get() || !blob_storage_context_) | 410 if (!body_.get() || !blob_storage_context_) |
| 410 return false; | 411 return false; |
| 411 | 412 |
| 413 // To ensure the blobs stick around until the end of the reading. | |
| 414 ScopedVector<storage::BlobDataHandle> handles; | |
| 415 ScopedVector<storage::BlobDataSnapshot> snapshots; | |
| 416 // TODO(dmurph): Allow blobs to be added below, so that the context can | |
| 417 // efficiently re-use blob items for the new blob. | |
| 412 std::vector<const ResourceRequestBody::Element*> resolved_elements; | 418 std::vector<const ResourceRequestBody::Element*> resolved_elements; |
| 413 for (size_t i = 0; i < body_->elements()->size(); ++i) { | 419 for (const ResourceRequestBody::Element& element : (*body_->elements())) { |
| 414 const ResourceRequestBody::Element& element = (*body_->elements())[i]; | |
| 415 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) { | 420 if (element.type() != ResourceRequestBody::Element::TYPE_BLOB) { |
| 416 resolved_elements.push_back(&element); | 421 resolved_elements.push_back(&element); |
| 417 continue; | 422 continue; |
| 418 } | 423 } |
| 419 scoped_ptr<storage::BlobDataHandle> handle = | 424 scoped_ptr<storage::BlobDataHandle> handle = |
| 420 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); | 425 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); |
| 421 if (handle->data()->items().empty()) | 426 scoped_ptr<storage::BlobDataSnapshot> snapshot = handle->CreateSnapshot(); |
| 427 if (snapshot->items().empty()) | |
| 422 continue; | 428 continue; |
| 423 for (size_t i = 0; i < handle->data()->items().size(); ++i) { | 429 const auto& items = snapshot->items(); |
| 424 const storage::BlobData::Item& item = handle->data()->items().at(i); | 430 for (const auto& item : items) { |
| 425 DCHECK_NE(storage::BlobData::Item::TYPE_BLOB, item.type()); | 431 DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type()); |
| 426 resolved_elements.push_back(&item); | 432 resolved_elements.push_back(item->data_element_ptr()); |
| 427 } | 433 } |
| 434 handles.push_back(handle.release()); | |
| 435 snapshots.push_back(snapshot.release()); | |
| 428 } | 436 } |
| 429 | 437 |
| 430 const std::string uuid(base::GenerateGUID()); | 438 const std::string uuid(base::GenerateGUID()); |
| 431 uint64 total_size = 0; | 439 uint64 total_size = 0; |
| 432 scoped_refptr<storage::BlobData> blob_data = new storage::BlobData(uuid); | 440 scoped_ptr<storage::BlobDataBuilder> blob_data( |
|
michaeln
2015/01/21 01:46:41
i think BlobDataBuilder can be on the stack here t
dmurph
2015/01/21 22:40:11
Done.
| |
| 441 new storage::BlobDataBuilder(uuid)); | |
| 433 for (size_t i = 0; i < resolved_elements.size(); ++i) { | 442 for (size_t i = 0; i < resolved_elements.size(); ++i) { |
| 434 const ResourceRequestBody::Element& element = *resolved_elements[i]; | 443 const ResourceRequestBody::Element& element = *resolved_elements[i]; |
| 435 if (total_size != kuint64max && element.length() != kuint64max) | 444 if (total_size != kuint64max && element.length() != kuint64max) |
| 436 total_size += element.length(); | 445 total_size += element.length(); |
| 437 else | 446 else |
| 438 total_size = kuint64max; | 447 total_size = kuint64max; |
| 439 switch (element.type()) { | 448 switch (element.type()) { |
| 440 case ResourceRequestBody::Element::TYPE_BYTES: | 449 case ResourceRequestBody::Element::TYPE_BYTES: |
| 441 blob_data->AppendData(element.bytes(), element.length()); | 450 blob_data->AppendData(element.bytes(), element.length()); |
| 442 break; | 451 break; |
| 443 case ResourceRequestBody::Element::TYPE_FILE: | 452 case ResourceRequestBody::Element::TYPE_FILE: |
| 444 blob_data->AppendFile(element.path(), | 453 blob_data->AppendFile(element.path(), element.offset(), |
| 445 element.offset(), | |
| 446 element.length(), | 454 element.length(), |
| 447 element.expected_modification_time()); | 455 element.expected_modification_time()); |
| 448 break; | 456 break; |
| 449 case ResourceRequestBody::Element::TYPE_BLOB: | 457 case ResourceRequestBody::Element::TYPE_BLOB: |
| 450 // Blob elements should be resolved beforehand. | 458 // Blob elements should be resolved beforehand. |
| 451 NOTREACHED(); | 459 NOTREACHED(); |
| 452 break; | 460 break; |
| 453 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: | 461 case ResourceRequestBody::Element::TYPE_FILE_FILESYSTEM: |
| 454 blob_data->AppendFileSystemFile(element.filesystem_url(), | 462 blob_data->AppendFileSystemFile(element.filesystem_url(), |
| 455 element.offset(), | 463 element.offset(), |
| 456 element.length(), | 464 element.length(), |
| 457 element.expected_modification_time()); | 465 element.expected_modification_time()); |
| 458 break; | 466 break; |
| 459 default: | 467 default: |
| 460 NOTIMPLEMENTED(); | 468 NOTIMPLEMENTED(); |
| 461 } | 469 } |
| 462 } | 470 } |
| 463 | 471 |
| 464 request_body_blob_data_handle_ = | 472 request_body_blob_data_handle_ = |
| 465 blob_storage_context_->AddFinishedBlob(blob_data.get()); | 473 blob_storage_context_->AddFinishedBlob(*blob_data.get()); |
| 466 *blob_uuid = uuid; | 474 *blob_uuid = uuid; |
| 467 *blob_size = total_size; | 475 *blob_size = total_size; |
| 468 return true; | 476 return true; |
| 469 } | 477 } |
| 470 | 478 |
| 471 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent() { | 479 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent() { |
| 472 fetch_ready_time_ = base::TimeTicks::Now(); | 480 fetch_ready_time_ = base::TimeTicks::Now(); |
| 473 } | 481 } |
| 474 | 482 |
| 475 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( | 483 void ServiceWorkerURLRequestJob::DidDispatchFetchEvent( |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 619 } | 627 } |
| 620 if (!waiting_stream_url_.is_empty()) { | 628 if (!waiting_stream_url_.is_empty()) { |
| 621 StreamRegistry* stream_registry = | 629 StreamRegistry* stream_registry = |
| 622 GetStreamContextForResourceContext(resource_context_)->registry(); | 630 GetStreamContextForResourceContext(resource_context_)->registry(); |
| 623 stream_registry->RemoveRegisterObserver(waiting_stream_url_); | 631 stream_registry->RemoveRegisterObserver(waiting_stream_url_); |
| 624 stream_registry->AbortPendingStream(waiting_stream_url_); | 632 stream_registry->AbortPendingStream(waiting_stream_url_); |
| 625 } | 633 } |
| 626 } | 634 } |
| 627 | 635 |
| 628 } // namespace content | 636 } // namespace content |
| OLD | NEW |