-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BestEffortServiceWorker] Dedupe main resource
This CL is a part of efforts that achieve the dedupe function to BestEffortServiceWorker. At a high-level, the dedupe is achieved by reusing the RaceNetworkRequest response as a response of the corresponding request in the fetch handler, and do not send a new fetch request. We can split into some smaller steps to implement this. 1. Generates a token of RaceNetworkRequest, and pass it to the blink side to make the corresponding request in the fetch handler discoverable. 2. Adds a map of the token and URLLoaderFactory in ServiceWorkerGlobalScope, and replaces the default URLLoader when the fetch request is same as the one called in RaceNetworkRequest which is outside of the fetch handler. 3. (This CL) Fuses two message pipes into one in a custom URLLoaderClient so that we can reuse the RaceNetworkRequest result and don't dispatch duplicated requests in the fetch handler. This CL introduces one new class. `ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory` is the URLLoaderFactory that fuses the RaceNetworkRequest URLLoaderClient mojo message pipe and the other URLLoaderClient pipe for the corresponding fetch request in the ServiceWorker fetch handler in blink side. By fusing them into one message pipe, the request in the fetch handler never creates a new URLLoader and thus no duplicated request, and reuses the response of RaceNetworkRequest. `ServiceWorkerRaceNetworkRequestDataPipeManager` is the class managing the dedicated data pipe and buffering data from RaceNetworkRequset. We use this class to create new data pipes and pass the response of original RaceNetworkRequset to the RaceNetworkRequest itself and the fetch handler, respectively. `ServiceWorkerRaceNetworkRequestURLLoaderClient` is changed to send the response data to newly created two mojo data pipes, one is for the RaceNetworkRequest itself, and the other one is for the fetch handler. This CL adds the dedupe feature to the main resource only. For subresoureces, we don't support it at least for now due to the complexity of redirect case, but the ActiveEntry in net layer would dedupe requests in most cases in reality. Here is a design doc including diagram how mojo pipes work. https://docs.google.com/document/d/1eotFetBW9RUE2sYjCnVl7P8rbvIsWBJcy3NOswC5kek/edit#bookmark=id.umdo7cpwavad Change-Id: Ia524f69a81335528a66db5df2488a1f8190f2024 Bug: 1420517 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4560732 Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Commit-Queue: Shunya Shishido <sisidovski@chromium.org> Reviewed-by: Minoru Chikamune <chikamune@chromium.org> Reviewed-by: Yoshisato Yanagisawa <yyanagisawa@chromium.org> Reviewed-by: Tsuyoshi Horo <horo@chromium.org> Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Cr-Commit-Position: refs/heads/main@{#1158698}
- Loading branch information
1 parent
a18c634
commit 9c857cb
Showing
15 changed files
with
1,113 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
content/common/service_worker/forwarded_race_network_request_url_loader_factory.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "content/common/service_worker/forwarded_race_network_request_url_loader_factory.h" | ||
|
||
namespace content { | ||
|
||
ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory:: | ||
ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory( | ||
mojo::PendingReceiver<network::mojom::URLLoaderClient> client_receiver, | ||
const GURL& url) | ||
: client_receiver_(std::move(client_receiver)), url_(url) {} | ||
|
||
ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory:: | ||
~ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory() = default; | ||
|
||
void ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory:: | ||
CreateLoaderAndStart( | ||
mojo::PendingReceiver<network::mojom::URLLoader> receiver, | ||
int32_t request_id, | ||
uint32_t options, | ||
const network::ResourceRequest& resource_request, | ||
mojo::PendingRemote<network::mojom::URLLoaderClient> client, | ||
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { | ||
CHECK_EQ(url_, resource_request.url); | ||
bool result = mojo::FusePipes(std::move(client_receiver_), std::move(client)); | ||
CHECK(result); | ||
} | ||
|
||
void ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory::Clone( | ||
mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) { | ||
receiver_.Bind(std::move(receiver)); | ||
} | ||
} // namespace content |
55 changes: 55 additions & 0 deletions
55
content/common/service_worker/forwarded_race_network_request_url_loader_factory.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2023 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef CONTENT_COMMON_SERVICE_WORKER_FORWARDED_RACE_NETWORK_REQUEST_URL_LOADER_FACTORY_H_ | ||
#define CONTENT_COMMON_SERVICE_WORKER_FORWARDED_RACE_NETWORK_REQUEST_URL_LOADER_FACTORY_H_ | ||
|
||
#include "mojo/public/cpp/bindings/pending_receiver.h" | ||
#include "mojo/public/cpp/bindings/receiver.h" | ||
#include "mojo/public/cpp/bindings/remote.h" | ||
#include "services/network/public/cpp/resource_request.h" | ||
#include "services/network/public/cpp/shared_url_loader_factory.h" | ||
#include "services/network/public/mojom/url_loader.mojom.h" | ||
#include "services/network/public/mojom/url_loader_factory.mojom.h" | ||
|
||
namespace content { | ||
// A URLLoaderFactory for BestEffortServiceWorker (crbug.com/1420517). | ||
// RaceNetworkRequest is initiated outside of ServiceWorker, but the response | ||
// will be reused as a corresponding fetch event result in ServiceWorker in | ||
// order to avoid sending duplicated requests. | ||
// This URLLoaderFactory fuses two different message pipes into a single pipe by | ||
// passing |client_receiver| in the constructor and calling | ||
// CreateLoaderAndStart(). | ||
class ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory | ||
: network::mojom::URLLoaderFactory { | ||
public: | ||
ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory( | ||
mojo::PendingReceiver<network::mojom::URLLoaderClient> client_receiver, | ||
const GURL& url); | ||
ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory( | ||
const ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory&) = delete; | ||
ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory& operator=( | ||
const ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory&) = delete; | ||
~ServiceWorkerForwardedRaceNetworkRequestURLLoaderFactory() override; | ||
|
||
// network::mojom::URLLoaderFactory: | ||
void CreateLoaderAndStart( | ||
mojo::PendingReceiver<network::mojom::URLLoader> receiver, | ||
int32_t request_id, | ||
uint32_t options, | ||
const network::ResourceRequest& resource_request, | ||
mojo::PendingRemote<network::mojom::URLLoaderClient> client, | ||
const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) | ||
override; | ||
void Clone(mojo::PendingReceiver<network::mojom::URLLoaderFactory> receiver) | ||
override; | ||
|
||
private: | ||
mojo::Receiver<network::mojom::URLLoaderFactory> receiver_{this}; | ||
mojo::PendingReceiver<network::mojom::URLLoaderClient> client_receiver_; | ||
GURL url_; | ||
}; | ||
} // namespace content | ||
|
||
#endif // CONTENT_COMMON_SERVICE_WORKER_FORWARDED_RACE_NETWORK_REQUEST_URL_LOADER_FACTORY_H_ |
Oops, something went wrong.