Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_context_wrapper.h" | 5 #include "content/browser/service_worker/service_worker_context_wrapper.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/barrier_closure.h" | 13 #include "base/barrier_closure.h" |
| 14 #include "base/bind.h" | 14 #include "base/bind.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/location.h" | 17 #include "base/location.h" |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "base/profiler/scoped_tracker.h" | 19 #include "base/profiler/scoped_tracker.h" |
| 20 #include "base/single_thread_task_runner.h" | 20 #include "base/single_thread_task_runner.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 21 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "content/browser/renderer_host/render_process_host_impl.h" | |
| 23 #include "content/browser/service_worker/embedded_worker_status.h" | 24 #include "content/browser/service_worker/embedded_worker_status.h" |
| 24 #include "content/browser/service_worker/service_worker_context_core.h" | 25 #include "content/browser/service_worker/service_worker_context_core.h" |
| 25 #include "content/browser/service_worker/service_worker_context_observer.h" | 26 #include "content/browser/service_worker/service_worker_context_observer.h" |
| 26 #include "content/browser/service_worker/service_worker_process_manager.h" | 27 #include "content/browser/service_worker/service_worker_process_manager.h" |
| 27 #include "content/browser/service_worker/service_worker_quota_client.h" | 28 #include "content/browser/service_worker/service_worker_quota_client.h" |
| 28 #include "content/browser/service_worker/service_worker_version.h" | 29 #include "content/browser/service_worker/service_worker_version.h" |
| 29 #include "content/browser/storage_partition_impl.h" | 30 #include "content/browser/storage_partition_impl.h" |
| 30 #include "content/common/service_worker/service_worker_utils.h" | 31 #include "content/common/service_worker/service_worker_utils.h" |
| 31 #include "content/public/browser/browser_context.h" | 32 #include "content/public/browser/browser_context.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 context_core_.reset(); | 820 context_core_.reset(); |
| 820 return; | 821 return; |
| 821 } | 822 } |
| 822 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); | 823 context_core_.reset(new ServiceWorkerContextCore(context_core_.get(), this)); |
| 823 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; | 824 DVLOG(1) << "Restarted ServiceWorkerContextCore successfully."; |
| 824 | 825 |
| 825 observer_list_->Notify(FROM_HERE, | 826 observer_list_->Notify(FROM_HERE, |
| 826 &ServiceWorkerContextObserver::OnStorageWiped); | 827 &ServiceWorkerContextObserver::OnStorageWiped); |
| 827 } | 828 } |
| 828 | 829 |
| 830 void ServiceWorkerContextWrapper::StartServiceWorkerForNavigationPreconnect( | |
| 831 const GURL& document_url, | |
| 832 RenderProcessHost* host, | |
| 833 const ResultCallback& callback) { | |
| 834 TRACE_EVENT1("ServiceWorker", "StartServiceWorkerForNavigationPreconnect", | |
| 835 "document_url", document_url.spec()); | |
| 836 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 837 if (!host || !RenderProcessHostImpl::IsSuitableHost( | |
| 838 host, host->GetBrowserContext(), document_url)) { | |
| 839 callback.Run(false); | |
| 840 return; | |
| 841 } | |
| 842 | |
| 843 BrowserThread::PostTask( | |
| 844 BrowserThread::IO, FROM_HERE, | |
| 845 base::Bind(&ServiceWorkerContextWrapper:: | |
| 846 DidCheckRenderProcessForNavigationPreconnect, | |
| 847 this, document_url, host->GetID(), callback)); | |
| 848 } | |
| 849 | |
| 850 void ServiceWorkerContextWrapper::DidCheckRenderProcessForNavigationPreconnect( | |
| 851 const GURL& document_url, | |
| 852 int render_process_id, | |
| 853 const ResultCallback& callback) { | |
| 854 TRACE_EVENT1("ServiceWorker", "DidCheckRenderProcessForNavigationPreconnect", | |
| 855 "document_url", document_url.spec()); | |
| 856 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 857 if (!context_core_) { | |
| 858 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 859 base::Bind(callback, false)); | |
| 860 return; | |
| 861 } | |
| 862 FindReadyRegistrationForDocument( | |
| 863 document_url, base::Bind(&ServiceWorkerContextWrapper:: | |
| 864 DidFindRegistrationForNavigationPreconnect, | |
| 865 this, render_process_id, callback)); | |
| 866 } | |
| 867 | |
| 868 void ServiceWorkerContextWrapper::DidFindRegistrationForNavigationPreconnect( | |
| 869 int render_process_id, | |
| 870 const ResultCallback& callback, | |
| 871 ServiceWorkerStatusCode status, | |
| 872 scoped_refptr<ServiceWorkerRegistration> registration) { | |
| 873 TRACE_EVENT0("ServiceWorker", "DidFindRegistrationForNavigationPreconnect"); | |
| 874 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 875 if (status != SERVICE_WORKER_OK || !registration->active_version()) { | |
| 876 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 877 base::Bind(callback, false)); | |
| 878 return; | |
| 879 } | |
| 880 | |
| 881 if (registration->active_version()->fetch_handler_existence() == | |
| 882 ServiceWorkerVersion::FetchHandlerExistence::DOES_NOT_EXIST) { | |
| 883 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 884 base::Bind(callback, false)); | |
| 885 return; | |
| 886 } | |
| 887 | |
| 888 // Add the process reference of |render_process_id| not to launch a new | |
| 889 // renderer process for the service worker. | |
| 890 context_core_->process_manager()->AddProcessReferenceToPattern( | |
| 891 registration->pattern(), render_process_id); | |
|
falken
2017/06/01 06:54:17
Have you tested this with PlzNavigate? Is it still
horo
2017/06/01 11:15:07
Added tests for PlzNavigate.
I think we still nee
falken
2017/06/01 23:24:14
To be clear, the plan was to remove ServiceWorkerP
| |
| 892 | |
| 893 registration->active_version()->StartWorker( | |
| 894 ServiceWorkerMetrics::EventType::PRECONNECT, | |
| 895 base::Bind(&ServiceWorkerContextWrapper:: | |
| 896 DidStartServiceWorkerForNavigationPreconnect, | |
| 897 this, registration->pattern(), render_process_id, callback)); | |
| 898 } | |
| 899 | |
| 900 void ServiceWorkerContextWrapper::DidStartServiceWorkerForNavigationPreconnect( | |
| 901 const GURL& pattern, | |
| 902 int render_process_id, | |
| 903 const ResultCallback& callback, | |
| 904 ServiceWorkerStatusCode code) { | |
| 905 TRACE_EVENT1("ServiceWorker", "DidStartServiceWorkerForNavigationPreconnect", | |
| 906 "url", pattern.spec()); | |
| 907 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
| 908 | |
| 909 // Remove the process reference added in | |
| 910 // DidFindRegistrationForNavigationPreconnect. | |
| 911 context_core_->process_manager()->RemoveProcessReferenceFromPattern( | |
| 912 pattern, render_process_id); | |
| 913 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 914 base::Bind(callback, code == SERVICE_WORKER_OK)); | |
| 915 } | |
| 916 | |
| 829 void ServiceWorkerContextWrapper::BindWorkerFetchContext( | 917 void ServiceWorkerContextWrapper::BindWorkerFetchContext( |
| 830 int render_process_id, | 918 int render_process_id, |
| 831 int service_worker_provider_id, | 919 int service_worker_provider_id, |
| 832 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info) { | 920 mojom::ServiceWorkerWorkerClientAssociatedPtrInfo client_ptr_info) { |
| 833 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 921 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 834 context()->BindWorkerFetchContext(render_process_id, | 922 context()->BindWorkerFetchContext(render_process_id, |
| 835 service_worker_provider_id, | 923 service_worker_provider_id, |
| 836 std::move(client_ptr_info)); | 924 std::move(client_ptr_info)); |
| 837 } | 925 } |
| 838 | 926 |
| 839 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { | 927 ServiceWorkerContextCore* ServiceWorkerContextWrapper::context() { |
| 840 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 928 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 841 return context_core_.get(); | 929 return context_core_.get(); |
| 842 } | 930 } |
| 843 | 931 |
| 844 } // namespace content | 932 } // namespace content |
| OLD | NEW |