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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/loader/modulescript/WorkletModuleScriptFetcher.cpp
diff --git a/third_party/WebKit/Source/core/loader/modulescript/WorkletModuleScriptFetcher.cpp b/third_party/WebKit/Source/core/loader/modulescript/WorkletModuleScriptFetcher.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..2f3c6e9be920bf2ed10fe535efc49c71124d300f
--- /dev/null
+++ b/third_party/WebKit/Source/core/loader/modulescript/WorkletModuleScriptFetcher.cpp
@@ -0,0 +1,54 @@
+// Copyright 2017 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.
+
+#include "core/loader/modulescript/WorkletModuleScriptFetcher.h"
+
+#include "platform/CrossThreadFunctional.h"
+
+namespace blink {
+
+WorkletModuleScriptFetcher::WorkletModuleScriptFetcher(
+ FetchParameters fetch_params,
+ ResourceFetcher* fetcher,
+ Modulator* modulator,
+ WorkletModuleResponsesMapProxy* module_responses_map_proxy)
+ : ModuleScriptFetcher(fetch_params, fetcher, modulator),
+ module_responses_map_proxy_(module_responses_map_proxy) {}
+
+DEFINE_TRACE(WorkletModuleScriptFetcher) {
+ visitor->Trace(module_responses_map_proxy_);
+ ModuleScriptFetcher::Trace(visitor);
+}
+
+void WorkletModuleScriptFetcher::FetchInternal() {
+ module_responses_map_proxy_->ReadEntry(GetRequestUrl(), this);
+}
+
+void WorkletModuleScriptFetcher::OnRead(
+ const ModuleScriptCreationParams& params) {
+ Finalize(params);
+}
+
+void WorkletModuleScriptFetcher::OnFetchNeeded() {
+ // A target module hasn't been fetched yet. Fallback to the regular module
+ // loading path. The module will be cached in NotifyFinished().
+ was_fetched_via_network_ = true;
+ ModuleScriptFetcher::FetchInternal();
+}
+
+void WorkletModuleScriptFetcher::OnFailed() {
+ Finalize(WTF::nullopt);
+}
+
+void WorkletModuleScriptFetcher::Finalize(
+ WTF::Optional<ModuleScriptCreationParams> params) {
+ if (!params.has_value()) {
+ module_responses_map_proxy_->InvalidateEntry(GetRequestUrl());
+ } else if (was_fetched_via_network_) {
+ module_responses_map_proxy_->UpdateEntry(GetRequestUrl(), *params);
+ }
+ ModuleScriptFetcher::Finalize(params);
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698