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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | |
| 11 #include <map> | 10 #include <map> |
| 12 #include <string> | 11 #include <string> |
| 13 #include <utility> | 12 #include <utility> |
| 14 #include <vector> | 13 #include <vector> |
| 15 | 14 |
| 16 #include "base/bind.h" | 15 #include "base/bind.h" |
| 16 #include "base/files/file_util.h" | |
| 17 #include "base/guid.h" | 17 #include "base/guid.h" |
| 18 #include "base/location.h" | 18 #include "base/location.h" |
| 19 #include "base/numerics/safe_conversions.h" | |
| 19 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "base/task_runner.h" | |
| 23 #include "base/task_runner_util.h" | |
| 21 #include "base/threading/thread_task_runner_handle.h" | 24 #include "base/threading/thread_task_runner_handle.h" |
| 22 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 23 #include "content/browser/resource_context_impl.h" | 26 #include "content/browser/resource_context_impl.h" |
| 24 #include "content/browser/service_worker/embedded_worker_instance.h" | 27 #include "content/browser/service_worker/embedded_worker_instance.h" |
| 25 #include "content/browser/service_worker/service_worker_blob_reader.h" | 28 #include "content/browser/service_worker/service_worker_blob_reader.h" |
| 26 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" | 29 #include "content/browser/service_worker/service_worker_fetch_dispatcher.h" |
| 27 #include "content/browser/service_worker/service_worker_provider_host.h" | 30 #include "content/browser/service_worker/service_worker_provider_host.h" |
| 28 #include "content/browser/service_worker/service_worker_response_info.h" | 31 #include "content/browser/service_worker/service_worker_response_info.h" |
| 29 #include "content/browser/service_worker/service_worker_stream_reader.h" | 32 #include "content/browser/service_worker/service_worker_stream_reader.h" |
| 30 #include "content/common/resource_request_body_impl.h" | 33 #include "content/common/resource_request_body_impl.h" |
| 31 #include "content/common/service_worker/service_worker_types.h" | 34 #include "content/common/service_worker/service_worker_types.h" |
| 32 #include "content/common/service_worker/service_worker_utils.h" | 35 #include "content/common/service_worker/service_worker_utils.h" |
| 33 #include "content/public/browser/blob_handle.h" | 36 #include "content/public/browser/blob_handle.h" |
| 37 #include "content/public/browser/browser_thread.h" | |
| 34 #include "content/public/browser/resource_request_info.h" | 38 #include "content/public/browser/resource_request_info.h" |
| 35 #include "content/public/browser/service_worker_context.h" | 39 #include "content/public/browser/service_worker_context.h" |
| 36 #include "content/public/common/referrer.h" | 40 #include "content/public/common/referrer.h" |
| 37 #include "net/base/net_errors.h" | 41 #include "net/base/net_errors.h" |
| 38 #include "net/http/http_request_headers.h" | 42 #include "net/http/http_request_headers.h" |
| 39 #include "net/http/http_response_headers.h" | 43 #include "net/http/http_response_headers.h" |
| 40 #include "net/http/http_response_info.h" | 44 #include "net/http/http_response_info.h" |
| 41 #include "net/http/http_util.h" | 45 #include "net/http/http_util.h" |
| 42 #include "net/log/net_log.h" | 46 #include "net/log/net_log.h" |
| 43 #include "net/log/net_log_event_type.h" | 47 #include "net/log/net_log_event_type.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB: | 101 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_BLOB: |
| 98 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM: | 102 case m::REQUEST_JOB_ERROR_DESTROYED_WITH_STREAM: |
| 99 // Invalid type. | 103 // Invalid type. |
| 100 case m::NUM_REQUEST_JOB_RESULT_TYPES: | 104 case m::NUM_REQUEST_JOB_RESULT_TYPES: |
| 101 NOTREACHED() << result; | 105 NOTREACHED() << result; |
| 102 } | 106 } |
| 103 NOTREACHED() << result; | 107 NOTREACHED() << result; |
| 104 return n::FAILED; | 108 return n::FAILED; |
| 105 } | 109 } |
| 106 | 110 |
| 111 std::vector<int64_t> GetFileSizesOnBlockingPool( | |
| 112 std::vector<base::FilePath> file_paths) { | |
| 113 std::vector<int64_t> sizes; | |
| 114 sizes.reserve(file_paths.size()); | |
| 115 for (const base::FilePath& path : file_paths) { | |
| 116 base::File::Info file_info; | |
| 117 if (!base::GetFileInfo(path, &file_info) || file_info.is_directory) | |
| 118 return std::vector<int64_t>(); | |
| 119 sizes.push_back(file_info.size); | |
| 120 } | |
| 121 return sizes; | |
| 122 } | |
| 123 | |
| 107 } // namespace | 124 } // namespace |
| 108 | 125 |
| 109 class ServiceWorkerURLRequestJob::BlobConstructionWaiter { | 126 // Sets the size on each DataElement in the request body that is a file with |
| 127 // unknown size. This ensures ServiceWorkerURLRequestJob::CreateRequestBodyBlob | |
| 128 // can successfuly create a blob from the data elements, as files with unknown | |
| 129 // sizes are not supported by the blob storage system. | |
| 130 class ServiceWorkerURLRequestJob::FileSizeResolver { | |
| 110 public: | 131 public: |
| 111 explicit BlobConstructionWaiter(ServiceWorkerURLRequestJob* owner) | 132 explicit FileSizeResolver(ServiceWorkerURLRequestJob* owner) |
| 112 : owner_(owner), weak_factory_(this) { | 133 : owner_(owner), weak_factory_(this) { |
| 113 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "BlobConstructionWaiter", this, | 134 TRACE_EVENT_ASYNC_BEGIN1("ServiceWorker", "FileSizeResolver", this, "URL", |
| 114 "URL", owner_->request()->url().spec()); | 135 owner_->request()->url().spec()); |
| 115 owner_->request()->net_log().BeginEvent( | 136 owner_->request()->net_log().BeginEvent( |
| 116 net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_BLOB); | 137 net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_FILES); |
| 117 } | 138 } |
| 118 | 139 |
| 119 ~BlobConstructionWaiter() { | 140 ~FileSizeResolver() { |
| 120 owner_->request()->net_log().EndEvent( | 141 owner_->request()->net_log().EndEvent( |
| 121 net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_BLOB, | 142 net::NetLogEventType::SERVICE_WORKER_WAITING_FOR_REQUEST_BODY_FILES, |
| 122 net::NetLog::BoolCallback("success", phase_ == Phase::SUCCESS)); | 143 net::NetLog::BoolCallback("success", phase_ == Phase::SUCCESS)); |
| 123 TRACE_EVENT_ASYNC_END1("ServiceWorker", "BlobConstructionWaiter", this, | 144 TRACE_EVENT_ASYNC_END1("ServiceWorker", "FileSizeResolver", this, "Success", |
| 124 "Success", phase_ == Phase::SUCCESS); | 145 phase_ == Phase::SUCCESS); |
| 125 } | 146 } |
| 126 | 147 |
| 127 void RunOnComplete(const base::Callback<void(bool)>& callback) { | 148 void Resolve(base::TaskRunner* file_runner, |
| 149 const base::Callback<void(bool)>& callback) { | |
| 128 DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_)); | 150 DCHECK_EQ(static_cast<int>(Phase::INITIAL), static_cast<int>(phase_)); |
| 151 DCHECK(file_elements_.empty()); | |
| 129 phase_ = Phase::WAITING; | 152 phase_ = Phase::WAITING; |
| 130 num_pending_request_body_blobs_ = 0; | 153 body_ = owner_->body_; |
| 131 callback_ = callback; | 154 callback_ = callback; |
| 132 | 155 |
| 133 for (const ResourceRequestBodyImpl::Element& element : | 156 std::vector<base::FilePath> file_paths; |
| 134 *(owner_->body_->elements())) { | 157 for (ResourceRequestBodyImpl::Element& element : |
| 135 if (element.type() != ResourceRequestBodyImpl::Element::TYPE_BLOB) | 158 *body_->elements_mutable()) { |
| 136 continue; | 159 if (element.type() == ResourceRequestBodyImpl::Element::TYPE_FILE && |
| 137 | 160 element.length() == ResourceRequestBodyImpl::Element::kUnknownSize) { |
| 138 std::unique_ptr<storage::BlobDataHandle> handle = | 161 file_elements_.push_back(&element); |
| 139 owner_->blob_storage_context_->GetBlobDataFromUUID( | 162 file_paths.push_back(element.path()); |
| 140 element.blob_uuid()); | |
| 141 if (handle->IsBroken()) { | |
| 142 Complete(false); | |
| 143 return; | |
| 144 } | |
| 145 if (handle->IsBeingBuilt()) { | |
| 146 ++num_pending_request_body_blobs_; | |
| 147 handle->RunOnConstructionComplete( | |
| 148 base::Bind(&BlobConstructionWaiter::OneRequestBodyBlobCompleted, | |
| 149 weak_factory_.GetWeakPtr())); | |
| 150 } | 163 } |
| 151 } | 164 } |
| 165 if (file_elements_.empty()) { | |
| 166 Complete(true); | |
| 167 return; | |
| 168 } | |
| 152 | 169 |
| 153 if (num_pending_request_body_blobs_ == 0) | 170 PostTaskAndReplyWithResult( |
| 154 Complete(true); | 171 file_runner, FROM_HERE, |
| 172 base::Bind(&GetFileSizesOnBlockingPool, base::Passed(&file_paths)), | |
| 173 base::Bind( | |
| 174 &ServiceWorkerURLRequestJob::FileSizeResolver::OnFileSizesResolved, | |
| 175 weak_factory_.GetWeakPtr())); | |
| 155 } | 176 } |
| 156 | 177 |
| 157 private: | 178 private: |
| 158 enum class Phase { INITIAL, WAITING, SUCCESS, FAIL }; | 179 enum class Phase { INITIAL, WAITING, SUCCESS, FAIL }; |
| 159 | 180 |
| 160 void OneRequestBodyBlobCompleted( | 181 void OnFileSizesResolved(std::vector<int64_t> sizes) { |
| 161 bool success, | 182 bool success = !sizes.empty(); |
| 162 storage::IPCBlobCreationCancelCode cancel_code) { | 183 if (success) { |
| 163 DCHECK_GT(num_pending_request_body_blobs_, 0UL); | 184 DCHECK_EQ(sizes.size(), file_elements_.size()); |
| 164 | 185 size_t num_elements = file_elements_.size(); |
| 165 if (success) | 186 for (size_t i = 0; i < num_elements; i++) { |
| 166 --num_pending_request_body_blobs_; | 187 ResourceRequestBodyImpl::Element* element = file_elements_[i]; |
| 167 else | 188 element->SetToFilePathRange(element->path(), element->offset(), |
| 168 num_pending_request_body_blobs_ = 0; | 189 base::checked_cast<uint64_t>(sizes[i]), |
| 169 | 190 element->expected_modification_time()); |
| 170 if (num_pending_request_body_blobs_ == 0) | 191 } |
| 171 Complete(success); | 192 file_elements_.clear(); |
| 193 } | |
| 194 Complete(success); | |
| 172 } | 195 } |
| 173 | 196 |
| 174 void Complete(bool success) { | 197 void Complete(bool success) { |
| 175 DCHECK_EQ(static_cast<int>(Phase::WAITING), static_cast<int>(phase_)); | 198 DCHECK_EQ(static_cast<int>(Phase::WAITING), static_cast<int>(phase_)); |
| 176 phase_ = success ? Phase::SUCCESS : Phase::FAIL; | 199 phase_ = success ? Phase::SUCCESS : Phase::FAIL; |
| 177 // Destroys |this|. | 200 // Destroys |this|, so we make a copy of the callback. |
| 178 callback_.Run(success); | 201 base::Callback<void(bool)> callback = callback_; |
| 202 callback.Run(success); | |
|
kinuko
2016/11/16 03:53:51
nit/optional: recently I learned we can also write
dmurph
2016/11/16 20:05:01
Amazing! I love it.
| |
| 179 } | 203 } |
| 180 | 204 |
| 181 // Owns and must outlive |this|. | 205 // Owns and must outlive |this|. |
| 182 ServiceWorkerURLRequestJob* owner_; | 206 ServiceWorkerURLRequestJob* owner_; |
| 183 | 207 |
| 184 scoped_refptr<ResourceRequestBodyImpl> body_; | 208 scoped_refptr<ResourceRequestBodyImpl> body_; |
| 209 std::vector<ResourceRequestBodyImpl::Element*> file_elements_; | |
| 185 base::Callback<void(bool)> callback_; | 210 base::Callback<void(bool)> callback_; |
| 186 size_t num_pending_request_body_blobs_ = 0; | |
| 187 Phase phase_ = Phase::INITIAL; | 211 Phase phase_ = Phase::INITIAL; |
| 188 base::WeakPtrFactory<BlobConstructionWaiter> weak_factory_; | 212 base::WeakPtrFactory<FileSizeResolver> weak_factory_; |
| 189 | 213 |
| 190 DISALLOW_COPY_AND_ASSIGN(BlobConstructionWaiter); | 214 DISALLOW_COPY_AND_ASSIGN(FileSizeResolver); |
| 191 }; | 215 }; |
| 192 | 216 |
| 193 bool ServiceWorkerURLRequestJob::Delegate::RequestStillValid( | 217 bool ServiceWorkerURLRequestJob::Delegate::RequestStillValid( |
| 194 ServiceWorkerMetrics::URLRequestJobResult* result) { | 218 ServiceWorkerMetrics::URLRequestJobResult* result) { |
| 195 return true; | 219 return true; |
| 196 } | 220 } |
| 197 | 221 |
| 198 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob( | 222 ServiceWorkerURLRequestJob::ServiceWorkerURLRequestJob( |
| 199 net::URLRequest* request, | 223 net::URLRequest* request, |
| 200 net::NetworkDelegate* network_delegate, | 224 net::NetworkDelegate* network_delegate, |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 226 frame_type_(frame_type), | 250 frame_type_(frame_type), |
| 227 fall_back_required_(false), | 251 fall_back_required_(false), |
| 228 body_(body), | 252 body_(body), |
| 229 fetch_type_(fetch_type), | 253 fetch_type_(fetch_type), |
| 230 weak_factory_(this) { | 254 weak_factory_(this) { |
| 231 DCHECK(delegate_) << "ServiceWorkerURLRequestJob requires a delegate"; | 255 DCHECK(delegate_) << "ServiceWorkerURLRequestJob requires a delegate"; |
| 232 } | 256 } |
| 233 | 257 |
| 234 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { | 258 ServiceWorkerURLRequestJob::~ServiceWorkerURLRequestJob() { |
| 235 stream_reader_.reset(); | 259 stream_reader_.reset(); |
| 236 blob_construction_waiter_.reset(); | 260 file_size_resolver_.reset(); |
| 237 | 261 |
| 238 if (!ShouldRecordResult()) | 262 if (!ShouldRecordResult()) |
| 239 return; | 263 return; |
| 240 ServiceWorkerMetrics::URLRequestJobResult result = | 264 ServiceWorkerMetrics::URLRequestJobResult result = |
| 241 ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED; | 265 ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED; |
| 242 if (response_body_type_ == STREAM) | 266 if (response_body_type_ == STREAM) |
| 243 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM; | 267 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_STREAM; |
| 244 else if (response_body_type_ == BLOB) | 268 else if (response_body_type_ == BLOB) |
| 245 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB; | 269 result = ServiceWorkerMetrics::REQUEST_JOB_ERROR_KILLED_WITH_BLOB; |
| 246 RecordResult(result); | 270 RecordResult(result); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 case FALLBACK_TO_NETWORK: | 427 case FALLBACK_TO_NETWORK: |
| 404 FinalizeFallbackToNetwork(); | 428 FinalizeFallbackToNetwork(); |
| 405 return; | 429 return; |
| 406 | 430 |
| 407 case FALLBACK_TO_RENDERER: | 431 case FALLBACK_TO_RENDERER: |
| 408 FinalizeFallbackToRenderer(); | 432 FinalizeFallbackToRenderer(); |
| 409 return; | 433 return; |
| 410 | 434 |
| 411 case FORWARD_TO_SERVICE_WORKER: | 435 case FORWARD_TO_SERVICE_WORKER: |
| 412 if (HasRequestBody()) { | 436 if (HasRequestBody()) { |
| 413 DCHECK(!blob_construction_waiter_); | 437 DCHECK(!file_size_resolver_); |
| 414 blob_construction_waiter_.reset(new BlobConstructionWaiter(this)); | 438 file_size_resolver_.reset(new FileSizeResolver(this)); |
| 415 blob_construction_waiter_->RunOnComplete( | 439 file_size_resolver_->Resolve( |
| 416 base::Bind(&ServiceWorkerURLRequestJob::RequestBodyBlobsCompleted, | 440 BrowserThread::GetBlockingPool(), |
| 417 GetWeakPtr())); | 441 base::Bind( |
| 442 &ServiceWorkerURLRequestJob::RequestBodyFileSizesResolved, | |
| 443 GetWeakPtr())); | |
| 418 return; | 444 return; |
| 419 } | 445 } |
| 420 | 446 |
| 421 RequestBodyBlobsCompleted(true); | 447 RequestBodyFileSizesResolved(true); |
| 422 return; | 448 return; |
| 423 } | 449 } |
| 424 | 450 |
| 425 NOTREACHED(); | 451 NOTREACHED(); |
| 426 } | 452 } |
| 427 | 453 |
| 428 std::unique_ptr<ServiceWorkerFetchRequest> | 454 std::unique_ptr<ServiceWorkerFetchRequest> |
| 429 ServiceWorkerURLRequestJob::CreateFetchRequest() { | 455 ServiceWorkerURLRequestJob::CreateFetchRequest() { |
| 430 std::string blob_uuid; | 456 std::string blob_uuid; |
| 431 uint64_t blob_size = 0; | 457 uint64_t blob_size = 0; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 request->referrer = | 489 request->referrer = |
| 464 Referrer(GURL(request_->referrer()), blink::WebReferrerPolicyDefault); | 490 Referrer(GURL(request_->referrer()), blink::WebReferrerPolicyDefault); |
| 465 } | 491 } |
| 466 request->fetch_type = fetch_type_; | 492 request->fetch_type = fetch_type_; |
| 467 return request; | 493 return request; |
| 468 } | 494 } |
| 469 | 495 |
| 470 void ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, | 496 void ServiceWorkerURLRequestJob::CreateRequestBodyBlob(std::string* blob_uuid, |
| 471 uint64_t* blob_size) { | 497 uint64_t* blob_size) { |
| 472 DCHECK(HasRequestBody()); | 498 DCHECK(HasRequestBody()); |
| 473 // To ensure the blobs stick around until the end of the reading. | 499 storage::BlobDataBuilder blob_builder(base::GenerateGUID()); |
| 474 std::vector<std::unique_ptr<storage::BlobDataHandle>> handles; | |
| 475 std::vector<std::unique_ptr<storage::BlobDataSnapshot>> snapshots; | |
| 476 // TODO(dmurph): Allow blobs to be added below, so that the context can | |
| 477 // efficiently re-use blob items for the new blob. | |
| 478 std::vector<const ResourceRequestBodyImpl::Element*> resolved_elements; | |
| 479 for (const ResourceRequestBodyImpl::Element& element : (*body_->elements())) { | 500 for (const ResourceRequestBodyImpl::Element& element : (*body_->elements())) { |
| 480 if (element.type() != ResourceRequestBodyImpl::Element::TYPE_BLOB) { | 501 blob_builder.AppendIPCDataElement(element); |
| 481 resolved_elements.push_back(&element); | |
| 482 continue; | |
| 483 } | |
| 484 std::unique_ptr<storage::BlobDataHandle> handle = | |
| 485 blob_storage_context_->GetBlobDataFromUUID(element.blob_uuid()); | |
| 486 std::unique_ptr<storage::BlobDataSnapshot> snapshot = | |
| 487 handle->CreateSnapshot(); | |
| 488 if (snapshot->items().empty()) | |
| 489 continue; | |
| 490 const auto& items = snapshot->items(); | |
| 491 for (const auto& item : items) { | |
| 492 DCHECK_NE(storage::DataElement::TYPE_BLOB, item->type()); | |
| 493 resolved_elements.push_back(item->data_element_ptr()); | |
| 494 } | |
| 495 handles.push_back(std::move(handle)); | |
| 496 snapshots.push_back(std::move(snapshot)); | |
| 497 } | |
| 498 | |
| 499 const std::string uuid(base::GenerateGUID()); | |
| 500 uint64_t total_size = 0; | |
| 501 | |
| 502 storage::BlobDataBuilder blob_builder(uuid); | |
| 503 for (size_t i = 0; i < resolved_elements.size(); ++i) { | |
| 504 const ResourceRequestBodyImpl::Element& element = *resolved_elements[i]; | |
| 505 if (total_size != std::numeric_limits<uint64_t>::max() && | |
| 506 element.length() != std::numeric_limits<uint64_t>::max()) | |
| 507 total_size += element.length(); | |
| 508 else | |
| 509 total_size = std::numeric_limits<uint64_t>::max(); | |
| 510 switch (element.type()) { | |
| 511 case ResourceRequestBodyImpl::Element::TYPE_BYTES: | |
| 512 blob_builder.AppendData(element.bytes(), element.length()); | |
| 513 break; | |
| 514 case ResourceRequestBodyImpl::Element::TYPE_FILE: | |
| 515 blob_builder.AppendFile(element.path(), element.offset(), | |
| 516 element.length(), | |
| 517 element.expected_modification_time()); | |
| 518 break; | |
| 519 case ResourceRequestBodyImpl::Element::TYPE_BLOB: | |
| 520 // Blob elements should be resolved beforehand. | |
| 521 NOTREACHED(); | |
| 522 break; | |
| 523 case ResourceRequestBodyImpl::Element::TYPE_FILE_FILESYSTEM: | |
| 524 blob_builder.AppendFileSystemFile(element.filesystem_url(), | |
| 525 element.offset(), element.length(), | |
| 526 element.expected_modification_time()); | |
| 527 break; | |
| 528 default: | |
| 529 NOTIMPLEMENTED(); | |
| 530 } | |
| 531 } | 502 } |
| 532 | 503 |
| 533 request_body_blob_data_handle_ = | 504 request_body_blob_data_handle_ = |
| 534 blob_storage_context_->AddFinishedBlob(&blob_builder); | 505 blob_storage_context_->AddFinishedBlob(&blob_builder); |
| 535 *blob_uuid = uuid; | 506 *blob_uuid = blob_builder.uuid(); |
| 536 *blob_size = total_size; | 507 *blob_size = request_body_blob_data_handle_->size(); |
| 537 } | 508 } |
| 538 | 509 |
| 539 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent( | 510 void ServiceWorkerURLRequestJob::DidPrepareFetchEvent( |
| 540 scoped_refptr<ServiceWorkerVersion> version) { | 511 scoped_refptr<ServiceWorkerVersion> version) { |
| 541 worker_ready_time_ = base::TimeTicks::Now(); | 512 worker_ready_time_ = base::TimeTicks::Now(); |
| 542 load_timing_info_.send_start = worker_ready_time_; | 513 load_timing_info_.send_start = worker_ready_time_; |
| 543 | 514 |
| 544 // Record the time taken for the browser to find and possibly start an active | 515 // Record the time taken for the browser to find and possibly start an active |
| 545 // worker to which to dispatch a FetchEvent for a main frame resource request. | 516 // worker to which to dispatch a FetchEvent for a main frame resource request. |
| 546 // For context, a FetchEvent can only be dispatched to an ACTIVATED worker | 517 // For context, a FetchEvent can only be dispatched to an ACTIVATED worker |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 844 bool ServiceWorkerURLRequestJob::IsMainResourceLoad() const { | 815 bool ServiceWorkerURLRequestJob::IsMainResourceLoad() const { |
| 845 return ServiceWorkerUtils::IsMainResourceType(resource_type_); | 816 return ServiceWorkerUtils::IsMainResourceType(resource_type_); |
| 846 } | 817 } |
| 847 | 818 |
| 848 bool ServiceWorkerURLRequestJob::HasRequestBody() { | 819 bool ServiceWorkerURLRequestJob::HasRequestBody() { |
| 849 // URLRequest::has_upload() must be checked since its upload data may have | 820 // URLRequest::has_upload() must be checked since its upload data may have |
| 850 // been cleared while handling a redirect. | 821 // been cleared while handling a redirect. |
| 851 return request_->has_upload() && body_.get() && blob_storage_context_; | 822 return request_->has_upload() && body_.get() && blob_storage_context_; |
| 852 } | 823 } |
| 853 | 824 |
| 854 void ServiceWorkerURLRequestJob::RequestBodyBlobsCompleted(bool success) { | 825 void ServiceWorkerURLRequestJob::RequestBodyFileSizesResolved(bool success) { |
| 855 blob_construction_waiter_.reset(); | 826 file_size_resolver_.reset(); |
| 856 if (!success) { | 827 if (!success) { |
| 857 RecordResult( | 828 RecordResult( |
| 858 ServiceWorkerMetrics::REQUEST_JOB_ERROR_REQUEST_BODY_BLOB_FAILED); | 829 ServiceWorkerMetrics::REQUEST_JOB_ERROR_REQUEST_BODY_BLOB_FAILED); |
| 859 // TODO(falken): This and below should probably be NotifyStartError, not | 830 // TODO(falken): This and below should probably be NotifyStartError, not |
| 860 // DeliverErrorResponse. But changing it causes | 831 // DeliverErrorResponse. But changing it causes |
| 861 // ServiceWorkerURLRequestJobTest.DeletedProviderHostBeforeFetchEvent to | 832 // ServiceWorkerURLRequestJobTest.DeletedProviderHostBeforeFetchEvent to |
| 862 // fail. | 833 // fail. |
| 863 DeliverErrorResponse(); | 834 DeliverErrorResponse(); |
| 864 return; | 835 return; |
| 865 } | 836 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 884 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, | 855 base::Bind(&ServiceWorkerURLRequestJob::DidPrepareFetchEvent, |
| 885 weak_factory_.GetWeakPtr(), active_worker), | 856 weak_factory_.GetWeakPtr(), active_worker), |
| 886 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, | 857 base::Bind(&ServiceWorkerURLRequestJob::DidDispatchFetchEvent, |
| 887 weak_factory_.GetWeakPtr()))); | 858 weak_factory_.GetWeakPtr()))); |
| 888 worker_start_time_ = base::TimeTicks::Now(); | 859 worker_start_time_ = base::TimeTicks::Now(); |
| 889 fetch_dispatcher_->MaybeStartNavigationPreload(request()); | 860 fetch_dispatcher_->MaybeStartNavigationPreload(request()); |
| 890 fetch_dispatcher_->Run(); | 861 fetch_dispatcher_->Run(); |
| 891 } | 862 } |
| 892 | 863 |
| 893 } // namespace content | 864 } // namespace content |
| OLD | NEW |