Commit 9543366e authored by John McCutchan's avatar John McCutchan Committed by GitHub

Send asset evictions notices to Flutter framework (#5303)

parent 95f2e981
...@@ -27,6 +27,7 @@ class DevFSEntry { ...@@ -27,6 +27,7 @@ class DevFSEntry {
final String devicePath; final String devicePath;
final AssetBundleEntry bundleEntry; final AssetBundleEntry bundleEntry;
String get assetPath => bundleEntry.archivePath;
final File file; final File file;
FileStat _fileStat; FileStat _fileStat;
...@@ -71,6 +72,8 @@ class DevFSEntry { ...@@ -71,6 +72,8 @@ class DevFSEntry {
bool get _isSourceEntry => file == null; bool get _isSourceEntry => file == null;
bool get _isAssetEntry => bundleEntry != null;
Future<List<int>> contentsAsBytes() async { Future<List<int>> contentsAsBytes() async {
if (_isSourceEntry) if (_isSourceEntry)
return bundleEntry.contentsAsBytes(); return bundleEntry.contentsAsBytes();
...@@ -246,6 +249,7 @@ class DevFS { ...@@ -246,6 +249,7 @@ class DevFS {
final Map<String, DevFSEntry> _entries = <String, DevFSEntry>{}; final Map<String, DevFSEntry> _entries = <String, DevFSEntry>{};
final Set<DevFSEntry> _dirtyEntries = new Set<DevFSEntry>(); final Set<DevFSEntry> _dirtyEntries = new Set<DevFSEntry>();
final Set<DevFSEntry> _deletedEntries = new Set<DevFSEntry>(); final Set<DevFSEntry> _deletedEntries = new Set<DevFSEntry>();
final Set<DevFSEntry> dirtyAssetEntries = new Set<DevFSEntry>();
final List<Future<Response>> _pendingOperations = new List<Future<Response>>(); final List<Future<Response>> _pendingOperations = new List<Future<Response>>();
...@@ -276,6 +280,8 @@ class DevFS { ...@@ -276,6 +280,8 @@ class DevFS {
_dirtyEntries.clear(); _dirtyEntries.clear();
// Clear the deleted entries list. // Clear the deleted entries list.
_deletedEntries.clear(); _deletedEntries.clear();
// Clear the dirty asset entries.
dirtyAssetEntries.clear();
} }
Future<dynamic> update({ DevFSProgressReporter progressReporter, Future<dynamic> update({ DevFSProgressReporter progressReporter,
...@@ -422,8 +428,11 @@ class DevFS { ...@@ -422,8 +428,11 @@ class DevFS {
} }
bool needsWrite = entry.isModified; bool needsWrite = entry.isModified;
if (needsWrite) { if (needsWrite) {
if (_dirtyEntries.add(entry)) if (_dirtyEntries.add(entry)) {
_bytes += entry.size; _bytes += entry.size;
if (entry._isAssetEntry)
dirtyAssetEntries.add(entry);
}
} }
} }
......
...@@ -272,6 +272,21 @@ class HotRunner extends ResidentRunner { ...@@ -272,6 +272,21 @@ class HotRunner extends ResidentRunner {
return true; return true;
} }
Future<Null> _evictDirtyAssets() async {
if (_devFS == null) {
return;
}
if (_devFS.dirtyAssetEntries.length == 0) {
return;
}
if (serviceProtocol.firstIsolateId == null)
throw 'Application isolate not found';
for (DevFSEntry entry in _devFS.dirtyAssetEntries) {
await serviceProtocol.flutterEvictAsset(serviceProtocol.firstIsolateId,
entry.assetPath);
}
}
Future<Null> _cleanupDevFS() async { Future<Null> _cleanupDevFS() async {
if (_devFS != null) { if (_devFS != null) {
// Cleanup the devFS. // Cleanup the devFS.
...@@ -384,6 +399,7 @@ class HotRunner extends ResidentRunner { ...@@ -384,6 +399,7 @@ class HotRunner extends ResidentRunner {
printError('Hot reload failed:\n$errorMessage'); printError('Hot reload failed:\n$errorMessage');
return false; return false;
} }
await _evictDirtyAssets();
Status reassembleStatus = Status reassembleStatus =
logger.startProgress('Reassembling application...'); logger.startProgress('Reassembling application...');
try { try {
......
...@@ -267,6 +267,13 @@ class Observatory { ...@@ -267,6 +267,13 @@ class Observatory {
}).then((dynamic result) => new Response(result)); }).then((dynamic result) => new Response(result));
} }
Future<Response> flutterEvictAsset(String isolateId, String assetPath) {
return peer.sendRequest('ext.flutter.evict', <String, dynamic>{
'isolateId': isolateId,
'value': assetPath
}).then((dynamic result) => new Response(result));
}
Future<Response> flutterExit(String isolateId) { Future<Response> flutterExit(String isolateId) {
return peer return peer
.sendRequest('ext.flutter.exit', <String, dynamic>{ 'isolateId': isolateId }) .sendRequest('ext.flutter.exit', <String, dynamic>{ 'isolateId': isolateId })
......
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