Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: third_party/WebKit/Source/core/loader/modulescript/WorkletModuleScriptFetcher.cpp

Issue 2939773005: [POC] Implement "module responses map" concept (Closed)
Patch Set: rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "core/loader/modulescript/WorkletModuleScriptFetcher.h"
6
7 #include "platform/CrossThreadFunctional.h"
8
9 namespace blink {
10
11 WorkletModuleScriptFetcher::WorkletModuleScriptFetcher(
12 FetchParameters fetch_params,
13 ResourceFetcher* fetcher,
14 Modulator* modulator,
15 WorkletModuleResponsesMapProxy* module_responses_map_proxy)
16 : ModuleScriptFetcher(fetch_params, fetcher, modulator),
17 module_responses_map_proxy_(module_responses_map_proxy) {}
18
19 DEFINE_TRACE(WorkletModuleScriptFetcher) {
20 visitor->Trace(module_responses_map_proxy_);
21 ModuleScriptFetcher::Trace(visitor);
22 }
23
24 void WorkletModuleScriptFetcher::FetchInternal() {
25 module_responses_map_proxy_->ReadEntry(GetRequestUrl(), this);
26 }
27
28 void WorkletModuleScriptFetcher::OnRead(
29 const ModuleScriptCreationParams& params) {
30 Finalize(params);
31 }
32
33 void WorkletModuleScriptFetcher::OnFetchNeeded() {
34 // A target module hasn't been fetched yet. Fallback to the regular module
35 // loading path. The module will be cached in NotifyFinished().
36 was_fetched_via_network_ = true;
37 ModuleScriptFetcher::FetchInternal();
38 }
39
40 void WorkletModuleScriptFetcher::OnFailed() {
41 Finalize(WTF::nullopt);
42 }
43
44 void WorkletModuleScriptFetcher::Finalize(
45 WTF::Optional<ModuleScriptCreationParams> params) {
46 if (!params.has_value()) {
47 module_responses_map_proxy_->InvalidateEntry(GetRequestUrl());
48 } else if (was_fetched_via_network_) {
49 module_responses_map_proxy_->UpdateEntry(GetRequestUrl(), *params);
50 }
51 ModuleScriptFetcher::Finalize(params);
52 }
53
54 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698