Provides a mechanism to create Custom Tabs modules from an external dex.
So far the module code was loaded directly from the APK of the module provider. This was causing memory issues if the module APK is 64 bit, as the APK of the module provider is mapped in the memory twice (once for 32-bit Chrome usage and once for 64-bit self usage). As the module APK contains much more code than the loaded module code, this was a wasteful use of memory.
This change introduces an alternative way of loading the module code using an extra dex file contained in the module APK. When a dexResourceId is provided, ModuleLoader retrieves the dex file at that resource and loads the module code from that dex file directly. To do that, the dex file is saved into the local storage of Chrome when the module is first being loaded.
This approach ensures that the whole APK of the module provider is not mapped into the memory just to load the module code. It also doesn't force the module provider APK to become a shared APK, which means Android can still perform profiling optimization on the APK and not do full compilation.
Currently, the locally stored dex file is only updated if the version of the module changes. This doesn't work well for development purposes as the module version stays constant. Therefore, the CL also introduces a way to force the ModuleLoader to update the dex file.
The local dex file is removed if the module is ever loaded again without a dex resource ID. A follow-up CL will also introduce logic to remove the dex from local storage if it isn't used for a certain amount of time.
The CL is guarded behind the CCT_MODULE_DEX_LOADING flag to provide a steady launch.
Change-Id: I5e3c5cddce93e5592d50143623d5aa9463eba36d
Reviewed-on: https://chromium-review.googlesource.com/c/1370176
Commit-Queue: Alihan Livdumlu <[email protected]>
Reviewed-by: Elly Fong-Jones <[email protected]>
Reviewed-by: Michael van Ouwerkerk <[email protected]>
Reviewed-by: Benoit L <[email protected]>
Cr-Commit-Position: refs/heads/master@{#623740}
diff --git a/chrome/browser/flag_descriptions.cc b/chrome/browser/flag_descriptions.cc
index 71f1dce..111b51f 100644
--- a/chrome/browser/flag_descriptions.cc
+++ b/chrome/browser/flag_descriptions.cc
@@ -2229,6 +2229,11 @@
"Enables header customization by dynamically loaded modules in "
"Chrome Custom Tabs.";
+const char kCCTModuleDexLoadingName[] = "Chrome Custom Tabs Module Dex Loading";
+const char kCCTModuleDexLoadingDescription[] =
+ "Enables loading Chrome Custom Tabs module code from a dex file "
+ "provided by the module.";
+
const char kCCTModulePostMessageName[] =
"Chrome Custom Tabs Module postMessage API";
const char kCCTModulePostMessageDescription[] =