-
Notifications
You must be signed in to change notification settings - Fork 6k
Persist DartCallbackCache contents across launches #5947
Changes from 6 commits
dc0dc6b
8c9321a
4b3db40
04a6053
77bae66
e27d219
52981cc
c86a4cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| #include "flutter/fml/message_loop.h" | ||
| #include "flutter/fml/paths.h" | ||
| #include "flutter/fml/platform/android/jni_util.h" | ||
| #include "flutter/lib/ui/plugins/callback_cache.h" | ||
| #include "flutter/runtime/dart_vm.h" | ||
| #include "flutter/runtime/start_up.h" | ||
| #include "flutter/shell/common/shell.h" | ||
|
|
@@ -44,7 +45,8 @@ void FlutterMain::Init(JNIEnv* env, | |
| jclass clazz, | ||
| jobject context, | ||
| jobjectArray jargs, | ||
| jstring bundlePath) { | ||
| jstring bundlePath, | ||
| jstring appRootPath) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who has write access to
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parameter is only visible to the internals of |
||
| std::vector<std::string> args; | ||
| args.push_back("flutter"); | ||
| for (auto& arg : fml::jni::StringArrayToVector(env, jargs)) { | ||
|
|
@@ -56,6 +58,11 @@ void FlutterMain::Init(JNIEnv* env, | |
|
|
||
| settings.assets_path = fml::jni::JavaStringToString(env, bundlePath); | ||
|
|
||
| // Restore the callback cache. | ||
| blink::DartCallbackCache::SetCachePath( | ||
| fml::jni::JavaStringToString(env, appRootPath)); | ||
| blink::DartCallbackCache::LoadCacheFromDisk(); | ||
|
|
||
| if (!blink::DartVM::IsRunningPrecompiledCode()) { | ||
| // Check to see if the appropriate kernel files are present and configure | ||
| // settings accordingly. | ||
|
|
@@ -97,7 +104,7 @@ bool FlutterMain::Register(JNIEnv* env) { | |
| { | ||
| .name = "nativeInit", | ||
| .signature = "(Landroid/content/Context;[Ljava/lang/String;Ljava/" | ||
| "lang/String;)V", | ||
| "lang/String;Ljava/lang/String;)V", | ||
| .fnPtr = reinterpret_cast<void*>(&Init), | ||
| }, | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,8 +219,9 @@ public static void ensureInitializationComplete(Context applicationContext, Stri | |
| } | ||
|
|
||
| String appBundlePath = findAppBundlePath(applicationContext); | ||
| String appRootPath = PathUtils.getFilesDir(applicationContext); | ||
| nativeInit(applicationContext, shellArgs.toArray(new String[0]), | ||
| appBundlePath); | ||
| appBundlePath, appRootPath); | ||
|
|
||
| sInitialized = true; | ||
| } catch (Exception e) { | ||
|
|
@@ -229,7 +230,7 @@ public static void ensureInitializationComplete(Context applicationContext, Stri | |
| } | ||
| } | ||
|
|
||
| private static native void nativeInit(Context context, String[] args, String bundlePath); | ||
| private static native void nativeInit(Context context, String[] args, String bundlePath, String appRootPath); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change appRootPath to something reflecting that this path is writable (e.g. "storagePath" or "writablePath"?) imho appRootPath sounds like a path where the app's own assets would live, inviting confusion with bundlePath
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SGTM, will do. |
||
| private static native void nativeRecordStartTimestamp(long initTimeMillis); | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the lifecycle of the cache file? Is the cache file or any of its entries ever deleted?
Would anything within the cache become stale if the application's code is updated but the cache is not purged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the cache is persistent and entries aren't deleted, although we could verify all the callbacks in the cache actually exist when we restore and remove the stale entries.