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