Commit 6a5c2a13 authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

[Layered API] Add UseCounters for each individual modules

Bug: 829084
Change-Id: I699e5e8ac655f1b305fff5985a107d29f2200fce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1506825Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638509}
parent 25294643
...@@ -2255,6 +2255,8 @@ enum WebFeature { ...@@ -2255,6 +2255,8 @@ enum WebFeature {
kCSSValueAppearanceTextarea = 2821, kCSSValueAppearanceTextarea = 2821,
kCSSValueAppearanceTextFieldForOthersRendered = 2822, kCSSValueAppearanceTextFieldForOthersRendered = 2822,
kCSSValueAppearanceTextFieldForTemporalRendered = 2823, kCSSValueAppearanceTextFieldForTemporalRendered = 2823,
kBuiltInModuleKvStorage = 2824,
kBuiltInModuleVirtualScroller = 2825,
// Add new features immediately above this line. Don't change assigned // Add new features immediately above this line. Don't change assigned
// numbers of any item, and don't reuse removed slots. // numbers of any item, and don't reuse removed slots.
......
...@@ -23,18 +23,21 @@ static const char kImportScheme[] = "import"; ...@@ -23,18 +23,21 @@ static const char kImportScheme[] = "import";
constexpr char kBuiltinSpecifierPrefix[] = "@std/"; constexpr char kBuiltinSpecifierPrefix[] = "@std/";
int GetResourceIDFromPath(const Modulator& modulator, const String& path) { constexpr char kTopLevelScriptPostfix[] = "/index.js";
const LayeredAPIResource* GetResourceFromPath(const Modulator& modulator,
const String& path) {
for (size_t i = 0; i < base::size(kLayeredAPIResources); ++i) { for (size_t i = 0; i < base::size(kLayeredAPIResources); ++i) {
if (modulator.BuiltInModuleEnabled(kLayeredAPIResources[i].module) && if (modulator.BuiltInModuleEnabled(kLayeredAPIResources[i].module) &&
path == kLayeredAPIResources[i].path) { path == kLayeredAPIResources[i].path) {
return kLayeredAPIResources[i].resource_id; return &kLayeredAPIResources[i];
} }
} }
return -1; return nullptr;
} }
bool IsImplemented(const Modulator& modulator, const String& name) { bool IsImplemented(const Modulator& modulator, const String& name) {
return GetResourceIDFromPath(modulator, name + "/index.js") >= 0; return GetResourceFromPath(modulator, name + kTopLevelScriptPostfix);
} }
} // namespace } // namespace
...@@ -104,11 +107,15 @@ String GetSourceText(const Modulator& modulator, const KURL& url) { ...@@ -104,11 +107,15 @@ String GetSourceText(const Modulator& modulator, const KURL& url) {
path = path.Substring(2); path = path.Substring(2);
} }
int resource_id = GetResourceIDFromPath(modulator, path); const LayeredAPIResource* resource = GetResourceFromPath(modulator, path);
if (resource_id < 0) if (!resource)
return String(); return String();
return UncompressResourceAsString(resource_id); // Only count the use of top-level scripts of each built-in module.
if (path.EndsWith(kTopLevelScriptPostfix))
modulator.BuiltInModuleUseCount(resource->module);
return UncompressResourceAsString(resource->resource_id);
} }
} // namespace layered_api } // namespace layered_api
......
...@@ -123,6 +123,7 @@ class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>, ...@@ -123,6 +123,7 @@ class CORE_EXPORT Modulator : public GarbageCollectedFinalized<Modulator>,
virtual bool BuiltInModuleInfraEnabled() const = 0; virtual bool BuiltInModuleInfraEnabled() const = 0;
virtual bool BuiltInModuleEnabled(blink::layered_api::Module) const = 0; virtual bool BuiltInModuleEnabled(blink::layered_api::Module) const = 0;
virtual void BuiltInModuleUseCount(blink::layered_api::Module) const = 0;
// https://html.spec.whatwg.org/C/#fetch-a-module-script-tree // https://html.spec.whatwg.org/C/#fetch-a-module-script-tree
// https://html.spec.whatwg.org/C/#fetch-a-module-worker-script-tree // https://html.spec.whatwg.org/C/#fetch-a-module-worker-script-tree
......
...@@ -65,6 +65,24 @@ bool ModulatorImplBase::BuiltInModuleEnabled( ...@@ -65,6 +65,24 @@ bool ModulatorImplBase::BuiltInModuleEnabled(
} }
} }
void ModulatorImplBase::BuiltInModuleUseCount(
blink::layered_api::Module module) const {
DCHECK(BuiltInModuleInfraEnabled());
DCHECK(BuiltInModuleEnabled(module));
switch (module) {
case blink::layered_api::Module::kBlank:
break;
case blink::layered_api::Module::kVirtualScroller:
UseCounter::Count(GetExecutionContext(),
WebFeature::kBuiltInModuleVirtualScroller);
break;
case blink::layered_api::Module::kKvStorage:
UseCounter::Count(GetExecutionContext(),
WebFeature::kBuiltInModuleKvStorage);
break;
}
}
// <specdef label="fetch-a-module-script-tree" // <specdef label="fetch-a-module-script-tree"
// href="https://html.spec.whatwg.org/C/#fetch-a-module-script-tree"> // href="https://html.spec.whatwg.org/C/#fetch-a-module-script-tree">
// <specdef label="fetch-a-module-worker-script-tree" // <specdef label="fetch-a-module-worker-script-tree"
......
...@@ -44,6 +44,7 @@ class ModulatorImplBase : public Modulator { ...@@ -44,6 +44,7 @@ class ModulatorImplBase : public Modulator {
bool BuiltInModuleInfraEnabled() const override; bool BuiltInModuleInfraEnabled() const override;
bool BuiltInModuleEnabled(blink::layered_api::Module) const override; bool BuiltInModuleEnabled(blink::layered_api::Module) const override;
void BuiltInModuleUseCount(blink::layered_api::Module) const override;
ScriptModuleResolver* GetScriptModuleResolver() override { ScriptModuleResolver* GetScriptModuleResolver() override {
return script_module_resolver_.Get(); return script_module_resolver_.Get();
......
...@@ -66,6 +66,8 @@ bool DummyModulator::BuiltInModuleEnabled(blink::layered_api::Module) const { ...@@ -66,6 +66,8 @@ bool DummyModulator::BuiltInModuleEnabled(blink::layered_api::Module) const {
return false; return false;
} }
void DummyModulator::BuiltInModuleUseCount(blink::layered_api::Module) const {}
ScriptModuleResolver* DummyModulator::GetScriptModuleResolver() { ScriptModuleResolver* DummyModulator::GetScriptModuleResolver() {
return resolver_.Get(); return resolver_.Get();
} }
......
...@@ -37,6 +37,7 @@ class DummyModulator : public Modulator { ...@@ -37,6 +37,7 @@ class DummyModulator : public Modulator {
bool BuiltInModuleInfraEnabled() const override; bool BuiltInModuleInfraEnabled() const override;
bool BuiltInModuleEnabled(blink::layered_api::Module) const override; bool BuiltInModuleEnabled(blink::layered_api::Module) const override;
void BuiltInModuleUseCount(blink::layered_api::Module) const override;
void FetchTree(const KURL&, void FetchTree(const KURL&,
ResourceFetcher*, ResourceFetcher*,
......
...@@ -21792,6 +21792,8 @@ Called by update_net_error_codes.py.--> ...@@ -21792,6 +21792,8 @@ Called by update_net_error_codes.py.-->
<int value="2821" label="CSSValueAppearanceTextarea"/> <int value="2821" label="CSSValueAppearanceTextarea"/>
<int value="2822" label="CSSValueAppearanceTextFieldForOthersRendered"/> <int value="2822" label="CSSValueAppearanceTextFieldForOthersRendered"/>
<int value="2823" label="CSSValueAppearanceTextFieldForTemporalRendered"/> <int value="2823" label="CSSValueAppearanceTextFieldForTemporalRendered"/>
<int value="2824" label="BuiltInModuleKvStorage"/>
<int value="2825" label="BuiltInModuleVirtualScroller"/>
</enum> </enum>
<enum name="FeaturePolicyFeature"> <enum name="FeaturePolicyFeature">
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