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
3 // found in the LICENSE file.
4 
5 #include "content/browser/service_worker/service_worker_main_resource_handle_core.h"
6 
7 #include "content/browser/service_worker/service_worker_context_wrapper.h"
8 #include "content/browser/service_worker/service_worker_main_resource_handle.h"
9 #include "content/common/service_worker/service_worker_utils.h"
10 
11 namespace content {
12 
ServiceWorkerMainResourceHandleCore(base::WeakPtr<ServiceWorkerMainResourceHandle> ui_handle,ServiceWorkerContextWrapper * context_wrapper,ServiceWorkerAccessedCallback service_worker_accessed_callback)13 ServiceWorkerMainResourceHandleCore::ServiceWorkerMainResourceHandleCore(
14     base::WeakPtr<ServiceWorkerMainResourceHandle> ui_handle,
15     ServiceWorkerContextWrapper* context_wrapper,
16     ServiceWorkerAccessedCallback service_worker_accessed_callback)
17     : context_wrapper_(context_wrapper),
18       ui_handle_(ui_handle),
19       service_worker_accessed_callback_(
20           std::move(service_worker_accessed_callback)) {
21   // The ServiceWorkerMainResourceHandleCore is created on the UI thread but
22   // should only be accessed from the core thread afterwards.
23   DCHECK_CURRENTLY_ON(BrowserThread::UI);
24 }
25 
~ServiceWorkerMainResourceHandleCore()26 ServiceWorkerMainResourceHandleCore::~ServiceWorkerMainResourceHandleCore() {
27   DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
28 }
29 
OnBeginNavigationCommit(int render_process_id,int render_frame_id,const network::CrossOriginEmbedderPolicy & cross_origin_embedder_policy,mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter> coep_reporter,ukm::SourceId document_ukm_source_id)30 void ServiceWorkerMainResourceHandleCore::OnBeginNavigationCommit(
31     int render_process_id,
32     int render_frame_id,
33     const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy,
34     mojo::PendingRemote<network::mojom::CrossOriginEmbedderPolicyReporter>
35         coep_reporter,
36     ukm::SourceId document_ukm_source_id) {
37   DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
38   if (container_host_) {
39     container_host_->OnBeginNavigationCommit(
40         render_process_id, render_frame_id, cross_origin_embedder_policy,
41         std::move(coep_reporter), document_ukm_source_id);
42   }
43 }
OnEndNavigationCommit()44 void ServiceWorkerMainResourceHandleCore::OnEndNavigationCommit() {
45   DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
46   if (container_host_)
47     container_host_->OnEndNavigationCommit();
48 }
49 
OnBeginWorkerCommit(const network::CrossOriginEmbedderPolicy & cross_origin_embedder_policy,ukm::SourceId worker_ukm_source_id)50 void ServiceWorkerMainResourceHandleCore::OnBeginWorkerCommit(
51     const network::CrossOriginEmbedderPolicy& cross_origin_embedder_policy,
52     ukm::SourceId worker_ukm_source_id) {
53   DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
54   if (container_host_) {
55     container_host_->CompleteWebWorkerPreparation(cross_origin_embedder_policy,
56                                                   worker_ukm_source_id);
57   }
58 }
59 
60 }  // namespace content
61