Commit ca69fde3 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

PlzWorker: Factor out loader setup code from SharedWorkerServiceImpl to WorkerScriptFetchInitiator

As a preparation of PlzDedicatedWorker, this CL makes browser-side loader
classes for PlzSharedWorker reusable for PlzDedicatedWorker. Specifically, this
CL introduces WorkerScriptFetchInitiator that is a static class to abstract
SharedWorkerScriptFetcher and SharedWorkerScriptLoader. This doesn't change
functional behavior.

WorkerScriptFetchInitiator is now used only by SharedWorkerServiceImpl, but it
will also be used by DedicatedWorkerHost in a follow-up CL.

Next plan: Rename SharedWorkerScriptFetcher and SharedWorkerScriptLoader to
WorkerScriptFetcher and WorkerScriptLoader respectively, and remove shared
worker specific code from WorkerScriptFetchInitiator. See the design doc for
details:
https://docs.google.com/document/d/1fWsD0oIa5sNDfUFWGJZ41pDo3zzsbFGyQSNdV8nOG4I/edit?usp=sharing

Change-Id: Iae37ebb8fec6f0843df4c11fac8c9d8abe5b6667
Bug: 906991
Reviewed-on: https://chromium-review.googlesource.com/c/1345704
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610790}
parent 9edd0867
......@@ -1708,6 +1708,8 @@ jumbo_source_set("browser") {
"shared_worker/shared_worker_script_loader_factory.h",
"shared_worker/shared_worker_service_impl.cc",
"shared_worker/shared_worker_service_impl.h",
"shared_worker/worker_script_fetch_initiator.cc",
"shared_worker/worker_script_fetch_initiator.h",
"site_instance_impl.cc",
"site_instance_impl.h",
"speech/speech_recognition_dispatcher_host.cc",
......
......@@ -8,12 +8,10 @@
#include <memory>
#include <set>
#include <utility>
#include <vector>
#include "base/compiler_specific.h"
#include "base/containers/unique_ptr_adapters.h"
#include "base/macros.h"
#include "base/memory/singleton.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/shared_worker/shared_worker_host.h"
#include "content/common/service_worker/service_worker_provider.mojom.h"
......@@ -75,10 +73,6 @@ class CONTENT_EXPORT SharedWorkerServiceImpl : public SharedWorkerService {
friend class SharedWorkerHostTest;
FRIEND_TEST_ALL_PREFIXES(NetworkServiceRestartBrowserTest, SharedWorker);
static void AddAdditionalRequestHeaders(
network::ResourceRequest* resource_request,
BrowserContext* browser_context);
void CreateWorker(
std::unique_ptr<SharedWorkerInstance> instance,
mojom::SharedWorkerClientPtr client,
......
This diff is collapsed.
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_SHARED_WORKER_WORKER_SCRIPT_FETCH_INITIATOR_H_
#define CONTENT_BROWSER_SHARED_WORKER_WORKER_SCRIPT_FETCH_INITIATOR_H_
#include <memory>
#include <set>
#include <utility>
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "content/common/service_worker/service_worker_provider.mojom.h"
#include "content/public/browser/shared_worker_service.h"
#include "content/public/common/resource_type.h"
#include "content/public/common/url_loader_throttle.h"
#include "services/network/public/cpp/resource_response.h"
#include "services/network/public/mojom/url_loader_factory.mojom.h"
#include "third_party/blink/public/mojom/shared_worker/shared_worker_main_script_load_params.mojom.h"
namespace network {
class SharedURLLoaderFactory;
class SharedURLLoaderFactoryInfo;
} // namespace network
namespace content {
class AppCacheNavigationHandleCore;
class BrowserContext;
class ServiceWorkerContextWrapper;
class StoragePartitionImpl;
class URLLoaderFactoryBundleInfo;
class URLLoaderFactoryGetter;
struct SubresourceLoaderParams;
// PlzWorker:
// WorkerScriptFetchInitiator is the entry point of browser-side script fetch
// for SharedWorkerScriptFetcher.
class WorkerScriptFetchInitiator {
public:
using CompletionCallback = base::OnceCallback<void(
mojom::ServiceWorkerProviderInfoForSharedWorkerPtr,
network::mojom::URLLoaderFactoryAssociatedPtrInfo,
std::unique_ptr<URLLoaderFactoryBundleInfo>,
blink::mojom::SharedWorkerMainScriptLoadParamsPtr,
base::Optional<SubresourceLoaderParams>,
bool)>;
// Creates a worker script fetcher and starts it. Must be called on the UI
// thread. |callback| will be called with the result on the UI thread.
static void Start(
int process_id,
const GURL& script_url,
const url::Origin& request_initiator,
ResourceType resource_type,
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
AppCacheNavigationHandleCore* appcache_handle_core,
scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory,
StoragePartitionImpl* storage_partition,
CompletionCallback callback);
private:
static std::unique_ptr<URLLoaderFactoryBundleInfo> CreateFactoryBundle(
int process_id,
StoragePartitionImpl* storage_partition,
bool file_support);
static void AddAdditionalRequestHeaders(
network::ResourceRequest* resource_request,
BrowserContext* browser_context);
static void CreateScriptLoaderOnIO(
int process_id,
std::unique_ptr<network::ResourceRequest> resource_request,
scoped_refptr<URLLoaderFactoryGetter> loader_factory_getter,
std::unique_ptr<URLLoaderFactoryBundleInfo>
factory_bundle_for_browser_info,
std::unique_ptr<URLLoaderFactoryBundleInfo> subresource_loader_factories,
scoped_refptr<ServiceWorkerContextWrapper> context,
AppCacheNavigationHandleCore* appcache_handle_core,
std::unique_ptr<network::SharedURLLoaderFactoryInfo>
blob_url_loader_factory_info,
CompletionCallback callback);
static void DidCreateScriptLoaderOnIO(
CompletionCallback callback,
mojom::ServiceWorkerProviderInfoForSharedWorkerPtr
service_worker_provider_info,
network::mojom::URLLoaderFactoryAssociatedPtrInfo
main_script_loader_factory,
std::unique_ptr<URLLoaderFactoryBundleInfo> subresource_loader_factories,
blink::mojom::SharedWorkerMainScriptLoadParamsPtr main_script_load_params,
base::Optional<SubresourceLoaderParams> subresource_loader_params,
bool success);
};
} // namespace content
#endif // CONTENT_BROWSER_SHARED_WORKER_WORKER_SCRIPT_FETCH_INITIATOR_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment