Commit a01bcbd3 authored by Michael van Ouwerkerk's avatar Michael van Ouwerkerk Committed by Commit Bot

Unload CCT module when activity is destroyed.

Bug: 853732
Change-Id: I82029d1dd7067ab6d615b8cb77797f6edd5fe65a
Reviewed-on: https://chromium-review.googlesource.com/1113752
Commit-Queue: Michael van Ouwerkerk <mvanouwerkerk@chromium.org>
Reviewed-by: default avatarBernhard Bauer <bauerb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571084}
parent 9eeaba4e
...@@ -823,6 +823,8 @@ public class CustomTabActivity extends ChromeActivity { ...@@ -823,6 +823,8 @@ public class CustomTabActivity extends ChromeActivity {
protected void onDestroyInternal() { protected void onDestroyInternal() {
super.onDestroyInternal(); super.onDestroyInternal();
if (mActivityDelegate != null) mActivityDelegate.onDestroy(isChangingConfigurations()); if (mActivityDelegate != null) mActivityDelegate.onDestroy(isChangingConfigurations());
mConnection.maybeUnloadModule(mIntentDataProvider.getModulePackageName(),
mIntentDataProvider.getModuleClassName());
} }
@Override @Override
......
...@@ -235,6 +235,7 @@ public class CustomTabsConnection { ...@@ -235,6 +235,7 @@ public class CustomTabsConnection {
/** The module package name and class name. */ /** The module package name and class name. */
private Pair<String, String> mModuleNames; private Pair<String, String> mModuleNames;
private int mModuleUseCount;
/** The module entry point. */ /** The module entry point. */
private ModuleEntryPoint mModuleEntryPoint; private ModuleEntryPoint mModuleEntryPoint;
...@@ -1432,12 +1433,27 @@ public class CustomTabsConnection { ...@@ -1432,12 +1433,27 @@ public class CustomTabsConnection {
|| !mModuleNames.second.equals(className))) { || !mModuleNames.second.equals(className))) {
throw new IllegalStateException("Only one module can be loaded at a time."); throw new IllegalStateException("Only one module can be loaded at a time.");
} }
mModuleUseCount++;
return mModuleEntryPoint; return mModuleEntryPoint;
} }
// TODO(https://crbug.com/853732): Add cleanup mechanism to unload the module.
mModuleNames = new Pair<>(packageName, className); mModuleNames = new Pair<>(packageName, className);
mModuleEntryPoint = ModuleLoader.loadModule(packageName, className); mModuleEntryPoint = ModuleLoader.loadModule(packageName, className);
if (mModuleEntryPoint != null) mModuleUseCount++;
return mModuleEntryPoint; return mModuleEntryPoint;
} }
public void maybeUnloadModule(String packageName, String className) {
if (mModuleEntryPoint == null || mModuleNames == null) return;
if ((!mModuleNames.first.equals(packageName) || !mModuleNames.second.equals(className))) {
throw new IllegalStateException(
"There is no module for package " + packageName + " and class " + className);
}
mModuleUseCount--;
if (mModuleUseCount == 0) {
mModuleEntryPoint.onDestroy();
mModuleEntryPoint = null;
mModuleNames = null;
}
}
} }
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