Commit 26dc78e6 authored by Anna Malova's avatar Anna Malova Committed by Commit Bot

Dynamic module: If the module loader setup is changed, create a module loader...

Dynamic module: If the module loader setup is changed, create a module loader with a new settings instead of crashing.
Destroy an old dynamic module and load a new one.

Bug: 924118
Change-Id: Iea1af7ced5f379ff9eb7e6bca2b737d8a12a05fa
Reviewed-on: https://chromium-review.googlesource.com/c/1429962
Commit-Queue: Anna Malova <amalova@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625308}
parent 880dfbd3
......@@ -56,6 +56,7 @@ import org.chromium.chrome.browser.browserservices.BrowserSessionContentUtils;
import org.chromium.chrome.browser.browserservices.Origin;
import org.chromium.chrome.browser.browserservices.PostMessageHandler;
import org.chromium.chrome.browser.customtabs.dynamicmodule.ModuleLoader;
import org.chromium.chrome.browser.customtabs.dynamicmodule.ModuleMetrics;
import org.chromium.chrome.browser.device.DeviceClassManager;
import org.chromium.chrome.browser.init.ChainedTasks;
import org.chromium.chrome.browser.init.ChromeBrowserInitializer;
......@@ -1455,17 +1456,15 @@ public class CustomTabsConnection {
resourceId = 0;
}
if (mModuleLoader == null) mModuleLoader = new ModuleLoader(componentName, resourceId);
if (!componentName.equals(mModuleLoader.getComponentName())) {
throw new IllegalStateException("The given component name " + componentName
+ " does not match the initialized component name "
+ mModuleLoader.getComponentName());
}
if (resourceId != mModuleLoader.getDexResourceId()) {
throw new IllegalStateException("The given resource ID " + resourceId
+ " does not match the initialized resource ID "
+ mModuleLoader.getDexResourceId());
if (mModuleLoader != null &&
(!componentName.equals(mModuleLoader.getComponentName()) ||
resourceId != mModuleLoader.getDexResourceId())) {
mModuleLoader.destroyModule(ModuleMetrics.DestructionReason.MODULE_LOADER_CHANGED);
mModuleLoader = null;
}
if (mModuleLoader == null) mModuleLoader = new ModuleLoader(componentName, resourceId);
return mModuleLoader;
}
......
......@@ -232,7 +232,7 @@ public class ModuleLoader {
return ModuleMetrics.now() - mModuleUnusedTimeMs > limit;
}
private void destroyModule(@DestructionReason int reason) {
public void destroyModule(@DestructionReason int reason) {
assert mModuleEntryPoint != null;
ModuleMetrics.recordDestruction(reason);
......
......@@ -79,12 +79,13 @@ public final class ModuleMetrics {
/**
* Possible reasons for destroying a dynamic module. Keep in sync with the
* CustomTabs.DynamicModule.DestructionReason enum in histograms.xml. Do not remove
* or change existing values other than NUM_ENTRIES.
* CustomTabs.DynamicModule.DestructionReason enum in tools/metrics/histograms/enums.xml.
* Do not remove or change existing values other than NUM_ENTRIES.
*/
@IntDef({DestructionReason.NO_CACHING_UNUSED, DestructionReason.CACHED_SEVERE_MEMORY_PRESSURE,
DestructionReason.CACHED_MILD_MEMORY_PRESSURE_TIME_EXCEEDED,
DestructionReason.CACHED_UI_HIDDEN_TIME_EXCEEDED})
DestructionReason.CACHED_UI_HIDDEN_TIME_EXCEEDED,
DestructionReason.MODULE_LOADER_CHANGED})
@Retention(RetentionPolicy.SOURCE)
public @interface DestructionReason {
/** No caching enabled and the module is unused. */
......@@ -95,8 +96,10 @@ public final class ModuleMetrics {
int CACHED_MILD_MEMORY_PRESSURE_TIME_EXCEEDED = 2;
/** Cached and app hidden and time exceeded. */
int CACHED_UI_HIDDEN_TIME_EXCEEDED = 3;
/** Module loader setup is changed. */
int MODULE_LOADER_CHANGED = 4;
/** Upper bound for legal sample values - all sample values have to be strictly lower. */
int NUM_ENTRIES = 4;
int NUM_ENTRIES = 5;
}
/**
......
......@@ -9984,6 +9984,7 @@ Called by update_net_error_codes.py.-->
<int value="1" label="Cached and severe memory pressure"/>
<int value="2" label="Cached and mild memory pressure and time exceeded"/>
<int value="3" label="Cached and app hidden and time exceeded"/>
<int value="4" label="Module loader setup changed"/>
</enum>
<enum name="CustomTabsDynamicModuleLoadResult">
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