Commit 4d028f12 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[WebAssembly] Add blink::feature kWasmCodeCache.

- Adds kWasmCodeCache to blink::features.
- Checks if enabled before creating the cache in the browser.
- Checks if enabled before fetching from cache in renderer.

This is patterned after the Javascript IsolatedCodeCache feature.

Bug: chromium:719172
Change-Id: I1ffea5d8029b2b550c45e3ba25821889c7c2183c
Reviewed-on: https://chromium-review.googlesource.com/c/1341071
Commit-Queue: Bill Budge <bbudge@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarMythri Alle <mythria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609705}
parent 7cff94fe
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "content/browser/code_cache/generated_code_cache.h" #include "content/browser/code_cache/generated_code_cache.h"
#include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "third_party/blink/public/common/features.h"
namespace content { namespace content {
...@@ -29,9 +30,13 @@ void GeneratedCodeCacheContext::InitializeOnIO(const base::FilePath& path, ...@@ -29,9 +30,13 @@ void GeneratedCodeCacheContext::InitializeOnIO(const base::FilePath& path,
generated_js_code_cache_.reset( generated_js_code_cache_.reset(
new GeneratedCodeCache(path.AppendASCII("js"), max_bytes, new GeneratedCodeCache(path.AppendASCII("js"), max_bytes,
GeneratedCodeCache::CodeCacheType::kJavaScript)); GeneratedCodeCache::CodeCacheType::kJavaScript));
generated_wasm_code_cache_.reset(
new GeneratedCodeCache(path.AppendASCII("wasm"), max_bytes, // Only create the Wasm cache if it's enabled.
GeneratedCodeCache::CodeCacheType::kWebAssembly)); if (base::FeatureList::IsEnabled(blink::features::kWasmCodeCache)) {
generated_wasm_code_cache_.reset(new GeneratedCodeCache(
path.AppendASCII("wasm"), max_bytes,
GeneratedCodeCache::CodeCacheType::kWebAssembly));
}
} }
GeneratedCodeCache* GeneratedCodeCacheContext::generated_js_code_cache() const { GeneratedCodeCache* GeneratedCodeCacheContext::generated_js_code_cache() const {
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
#include "storage/browser/test/mock_quota_manager.h" #include "storage/browser/test/mock_quota_manager.h"
#include "storage/browser/test/mock_special_storage_policy.h" #include "storage/browser/test/mock_special_storage_policy.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#if BUILDFLAG(ENABLE_PLUGINS) #if BUILDFLAG(ENABLE_PLUGINS)
#include "ppapi/shared_impl/ppapi_constants.h" // nogncheck #include "ppapi/shared_impl/ppapi_constants.h" // nogncheck
...@@ -1305,16 +1306,10 @@ TEST_F(StoragePartitionImplTest, ClearCodeCache) { ...@@ -1305,16 +1306,10 @@ TEST_F(StoragePartitionImplTest, ClearCodeCache) {
GURL origin = GURL(kTestOrigin1); GURL origin = GURL(kTestOrigin1);
std::string data("SomeData"); std::string data("SomeData");
std::string data2("SomeData.wasm");
tester.AddEntry(RemoveCodeCacheTester::kJs, kResourceURL, origin, data); tester.AddEntry(RemoveCodeCacheTester::kJs, kResourceURL, origin, data);
tester.AddEntry(RemoveCodeCacheTester::kWebAssembly, kResourceURL, origin,
data2);
EXPECT_TRUE( EXPECT_TRUE(
tester.ContainsEntry(RemoveCodeCacheTester::kJs, kResourceURL, origin)); tester.ContainsEntry(RemoveCodeCacheTester::kJs, kResourceURL, origin));
EXPECT_EQ(tester.received_data(), data); EXPECT_EQ(tester.received_data(), data);
EXPECT_TRUE(tester.ContainsEntry(RemoveCodeCacheTester::kWebAssembly,
kResourceURL, origin));
EXPECT_EQ(tester.received_data(), data2);
base::RunLoop run_loop; base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
...@@ -1323,6 +1318,42 @@ TEST_F(StoragePartitionImplTest, ClearCodeCache) { ...@@ -1323,6 +1318,42 @@ TEST_F(StoragePartitionImplTest, ClearCodeCache) {
EXPECT_FALSE( EXPECT_FALSE(
tester.ContainsEntry(RemoveCodeCacheTester::kJs, kResourceURL, origin)); tester.ContainsEntry(RemoveCodeCacheTester::kJs, kResourceURL, origin));
// Make sure there isn't a second invalid callback sitting in the queue.
// (this used to be a bug).
base::RunLoop().RunUntilIdle();
}
TEST_F(StoragePartitionImplTest, ClearWasmCodeCache) {
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures(
std::vector<base::Feature>(
{net::features::kIsolatedCodeCache, blink::features::kWasmCodeCache}),
std::vector<base::Feature>());
ASSERT_TRUE(base::FeatureList::IsEnabled(net::features::kIsolatedCodeCache));
ASSERT_TRUE(base::FeatureList::IsEnabled(blink::features::kWasmCodeCache));
StoragePartitionImpl* partition = static_cast<StoragePartitionImpl*>(
BrowserContext::GetDefaultStoragePartition(browser_context()));
// Ensure code cache is initialized.
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(partition->GetGeneratedCodeCacheContext() != nullptr);
RemoveCodeCacheTester tester(partition->GetGeneratedCodeCacheContext());
GURL origin = GURL(kTestOrigin1);
std::string data("SomeData.wasm");
tester.AddEntry(RemoveCodeCacheTester::kWebAssembly, kResourceURL, origin,
data);
EXPECT_TRUE(tester.ContainsEntry(RemoveCodeCacheTester::kWebAssembly,
kResourceURL, origin));
EXPECT_EQ(tester.received_data(), data);
base::RunLoop run_loop;
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&ClearCodeCache, partition, &run_loop));
run_loop.Run();
EXPECT_FALSE(tester.ContainsEntry(RemoveCodeCacheTester::kWebAssembly, EXPECT_FALSE(tester.ContainsEntry(RemoveCodeCacheTester::kWebAssembly,
kResourceURL, origin)); kResourceURL, origin));
......
...@@ -436,6 +436,8 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs( ...@@ -436,6 +436,8 @@ void SetRuntimeFeaturesDefaultsAndUpdateFromArgs(
WebRuntimeFeatures::EnableIsolatedCodeCache( WebRuntimeFeatures::EnableIsolatedCodeCache(
base::FeatureList::IsEnabled(net::features::kIsolatedCodeCache)); base::FeatureList::IsEnabled(net::features::kIsolatedCodeCache));
WebRuntimeFeatures::EnableWasmCodeCache(
base::FeatureList::IsEnabled(blink::features::kWasmCodeCache));
if (base::FeatureList::IsEnabled(features::kSignedHTTPExchange)) { if (base::FeatureList::IsEnabled(features::kSignedHTTPExchange)) {
WebRuntimeFeatures::EnableSignedHTTPExchange(true); WebRuntimeFeatures::EnableSignedHTTPExchange(true);
......
...@@ -107,6 +107,12 @@ const base::Feature kJankTracking{"JankTracking", ...@@ -107,6 +107,12 @@ const base::Feature kJankTracking{"JankTracking",
const base::Feature kRTCUnifiedPlanByDefault{"RTCUnifiedPlanByDefault", const base::Feature kRTCUnifiedPlanByDefault{"RTCUnifiedPlanByDefault",
base::FEATURE_DISABLED_BY_DEFAULT}; base::FEATURE_DISABLED_BY_DEFAULT};
// Enables the site isolated Wasm code cache that is keyed on the resource URL
// and the origin lock of the renderer that is requesting the resource. When
// this flag is enabled, content/GeneratedCodeCache handles code cache requests.
const base::Feature kWasmCodeCache = {"WasmCodeCache",
base::FEATURE_DISABLED_BY_DEFAULT};
const char kAutofillPreviewStyleExperimentBgColorParameterName[] = "bg_color"; const char kAutofillPreviewStyleExperimentBgColorParameterName[] = "bg_color";
const char kAutofillPreviewStyleExperimentColorParameterName[] = "color"; const char kAutofillPreviewStyleExperimentColorParameterName[] = "color";
......
...@@ -34,6 +34,7 @@ BLINK_COMMON_EXPORT extern const base::Feature kWritableFilesAPI; ...@@ -34,6 +34,7 @@ BLINK_COMMON_EXPORT extern const base::Feature kWritableFilesAPI;
BLINK_COMMON_EXPORT extern const base::Feature kMixedContentAutoupgrade; BLINK_COMMON_EXPORT extern const base::Feature kMixedContentAutoupgrade;
BLINK_COMMON_EXPORT extern const base::Feature kJankTracking; BLINK_COMMON_EXPORT extern const base::Feature kJankTracking;
BLINK_COMMON_EXPORT extern const base::Feature kRTCUnifiedPlanByDefault; BLINK_COMMON_EXPORT extern const base::Feature kRTCUnifiedPlanByDefault;
BLINK_COMMON_EXPORT extern const base::Feature kWasmCodeCache;
BLINK_COMMON_EXPORT extern const char BLINK_COMMON_EXPORT extern const char
kAutofillPreviewStyleExperimentBgColorParameterName[]; kAutofillPreviewStyleExperimentBgColorParameterName[];
......
...@@ -91,6 +91,7 @@ class WebRuntimeFeatures { ...@@ -91,6 +91,7 @@ class WebRuntimeFeatures {
BLINK_PLATFORM_EXPORT static void EnableBloatedRendererDetection(bool); BLINK_PLATFORM_EXPORT static void EnableBloatedRendererDetection(bool);
BLINK_PLATFORM_EXPORT static void EnableCacheInlineScriptCode(bool); BLINK_PLATFORM_EXPORT static void EnableCacheInlineScriptCode(bool);
BLINK_PLATFORM_EXPORT static void EnableIsolatedCodeCache(bool); BLINK_PLATFORM_EXPORT static void EnableIsolatedCodeCache(bool);
BLINK_PLATFORM_EXPORT static void EnableWasmCodeCache(bool);
BLINK_PLATFORM_EXPORT static void EnableCanvas2dImageChromium(bool); BLINK_PLATFORM_EXPORT static void EnableCanvas2dImageChromium(bool);
BLINK_PLATFORM_EXPORT static void EnableCSSHexAlphaColor(bool); BLINK_PLATFORM_EXPORT static void EnableCSSHexAlphaColor(bool);
BLINK_PLATFORM_EXPORT static void EnableCSSFragmentIdentifiers(bool); BLINK_PLATFORM_EXPORT static void EnableCSSFragmentIdentifiers(bool);
......
...@@ -116,6 +116,10 @@ void WebRuntimeFeatures::EnableIsolatedCodeCache(bool enable) { ...@@ -116,6 +116,10 @@ void WebRuntimeFeatures::EnableIsolatedCodeCache(bool enable) {
RuntimeEnabledFeatures::SetIsolatedCodeCacheEnabled(enable); RuntimeEnabledFeatures::SetIsolatedCodeCacheEnabled(enable);
} }
void WebRuntimeFeatures::EnableWasmCodeCache(bool enable) {
RuntimeEnabledFeatures::SetWasmCodeCacheEnabled(enable);
}
void WebRuntimeFeatures::EnableCanvas2dImageChromium(bool enable) { void WebRuntimeFeatures::EnableCanvas2dImageChromium(bool enable) {
RuntimeEnabledFeatures::SetCanvas2dImageChromiumEnabled(enable); RuntimeEnabledFeatures::SetCanvas2dImageChromiumEnabled(enable);
} }
......
...@@ -327,6 +327,9 @@ void ResourceLoader::Trace(blink::Visitor* visitor) { ...@@ -327,6 +327,9 @@ void ResourceLoader::Trace(blink::Visitor* visitor) {
bool ResourceLoader::ShouldFetchCodeCache() { bool ResourceLoader::ShouldFetchCodeCache() {
if (!RuntimeEnabledFeatures::IsolatedCodeCacheEnabled()) if (!RuntimeEnabledFeatures::IsolatedCodeCacheEnabled())
return false; return false;
if (resource_->GetType() == ResourceType::kRaw &&
!RuntimeEnabledFeatures::WasmCodeCacheEnabled())
return false;
// TODO(crbug.com/867347): Enable fetching of code caches on non-main threads // TODO(crbug.com/867347): Enable fetching of code caches on non-main threads
// once code cache has its own mojo interface. Currently it is using // once code cache has its own mojo interface. Currently it is using
......
...@@ -1278,6 +1278,10 @@ ...@@ -1278,6 +1278,10 @@
name: "WakeLockNavigator", name: "WakeLockNavigator",
status: "experimental", status: "experimental",
}, },
{
name: "WasmCodeCache",
status: "experimental",
},
{ {
name: "WebAnimationsAPI", name: "WebAnimationsAPI",
status: "experimental", status: "experimental",
......
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