Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/renderer/service_worker/worker_fetch_context_impl.h" | |
| 6 | |
| 7 #include "content/child/request_extra_data.h" | |
| 8 #include "content/child/resource_dispatcher.h" | |
| 9 #include "content/child/web_url_loader_impl.h" | |
| 10 #include "mojo/public/cpp/bindings/associated_binding.h" | |
| 11 | |
| 12 namespace content { | |
| 13 | |
| 14 WorkerFetchContextImpl::WorkerFetchContextImpl( | |
| 15 mojom::WorkerURLLoaderFactoryProviderPtrInfo provider_info) | |
| 16 : provider_info_(std::move(provider_info)) {} | |
| 17 | |
| 18 WorkerFetchContextImpl::~WorkerFetchContextImpl() {} | |
| 19 | |
| 20 void WorkerFetchContextImpl::InitializeOnWorkerThread( | |
| 21 base::SingleThreadTaskRunner* loading_task_runner) { | |
| 22 DCHECK(loading_task_runner->RunsTasksOnCurrentThread()); | |
| 23 DCHECK(!resource_dispatcher_); | |
| 24 DCHECK(!binding_); | |
| 25 resource_dispatcher_ = | |
| 26 base::MakeUnique<ResourceDispatcher>(nullptr, loading_task_runner); | |
| 27 binding_ = base::MakeUnique< | |
| 28 mojo::AssociatedBinding<mojom::ServiceWorkerWorkerClient>>(this); | |
| 29 DCHECK(provider_info_.is_valid()); | |
| 30 provider_.Bind(std::move(provider_info_)); | |
| 31 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo ptr_info; | |
| 32 binding_->Bind(&ptr_info); | |
| 33 provider_->GetURLLoaderFactoryAndRegisterClient( | |
| 34 mojo::MakeRequest(&url_loader_factory_), std::move(ptr_info), | |
| 35 service_worker_provider_id_); | |
| 36 } | |
| 37 | |
| 38 std::unique_ptr<blink::WebURLLoader> WorkerFetchContextImpl::CreateURLLoader() { | |
| 39 return base::MakeUnique<content::WebURLLoaderImpl>(resource_dispatcher_.get(), | |
| 40 url_loader_factory_.get()); | |
| 41 } | |
| 42 | |
| 43 void WorkerFetchContextImpl::WillSendRequest(blink::WebURLRequest& request) { | |
| 44 RequestExtraData* extra_data = new RequestExtraData(); | |
| 45 extra_data->set_service_worker_provider_id(service_worker_provider_id_); | |
| 46 request.SetExtraData(extra_data); | |
| 47 | |
| 48 if (!IsControlledByServiceWorker() && | |
| 49 request.GetServiceWorkerMode() != | |
| 50 blink::WebURLRequest::ServiceWorkerMode::kNone) { | |
| 51 request.SetServiceWorkerMode( | |
| 52 blink::WebURLRequest::ServiceWorkerMode::kForeign); | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 bool WorkerFetchContextImpl::IsControlledByServiceWorker() const { | |
| 57 return is_controlled_by_service_worker_ || | |
| 58 (controller_version_id_ != kInvalidServiceWorkerVersionId); | |
| 59 } | |
| 60 | |
| 61 void WorkerFetchContextImpl::set_service_worker_provider_id(int id) { | |
| 62 service_worker_provider_id_ = id; | |
| 63 } | |
| 64 | |
| 65 void WorkerFetchContextImpl::set_is_controlled_by_service_worker(bool flag) { | |
| 66 is_controlled_by_service_worker_ = flag; | |
| 67 } | |
| 68 | |
| 69 void WorkerFetchContextImpl::SetControllerServiceWorker( | |
| 70 int64_t controller_version_id) { | |
| 71 controller_version_id_ = controller_version_id; | |
|
estark
2017/04/25 06:41:08
Is there any reason to send the id rather than jus
horo
2017/04/25 08:43:44
We are using the service worker version ID as a ke
estark
2017/04/25 20:26:56
Thanks for the explanation. LGTM but please wait f
| |
| 72 } | |
| 73 | |
| 74 } // namespace content | |
| OLD | NEW |