Unverified Commit a21f33e7 authored by Dan Field's avatar Dan Field Committed by GitHub

avoid incorrect usage of TimelineTask (#127527)

This code was added based on a misunderstanding of the API surface.
parent c05a05e6
......@@ -34,11 +34,18 @@ void main() {
<Map<String, dynamic>>[
<String, dynamic>{
'name': 'ImageCache.putIfAbsent',
'args': <String, dynamic>{'key': 'Test', 'isolateId': isolateId},
'args': <String, dynamic>{
'key': 'Test',
'isolateId': isolateId,
'parentId': null,
},
},
<String, dynamic>{
'name': 'listener',
'args': <String, dynamic>{'isolateId': isolateId},
'args': <String, dynamic>{
'isolateId': isolateId,
'parentId': null,
},
},
<String, dynamic>{
'name': 'ImageCache.clear',
......@@ -48,15 +55,24 @@ void main() {
'liveImages': 1,
'currentSizeInBytes': 0,
'isolateId': isolateId,
'parentId': null,
},
},
<String, dynamic>{
'name': 'ImageCache.putIfAbsent',
'args': <String, dynamic>{'key': 'Test2', 'isolateId': isolateId},
'args': <String, dynamic>{
'key': 'Test2',
'isolateId': isolateId,
'parentId': null,
},
},
<String, dynamic>{
'name': 'ImageCache.evict',
'args': <String, dynamic>{'sizeInBytes': 4, 'isolateId': isolateId},
'args': <String, dynamic>{
'sizeInBytes': 4,
'isolateId': isolateId,
'parentId': null,
},
},
],
);
......
......@@ -325,7 +325,6 @@ class ImageCache {
/// cause other images in the cache to be evicted.
ImageStreamCompleter? putIfAbsent(Object key, ImageStreamCompleter Function() loader, { ImageErrorListener? onError }) {
TimelineTask? timelineTask;
TimelineTask? listenerTask;
if (!kReleaseMode) {
timelineTask = TimelineTask()..start(
'ImageCache.putIfAbsent',
......@@ -398,7 +397,7 @@ class ImageCache {
}
if (!kReleaseMode) {
listenerTask = TimelineTask(parent: timelineTask)..start('listener');
timelineTask!.start('listener');
}
// A multi-frame provider may call the listener more than once. We need do make
// sure that some cleanup works won't run multiple times, such as finishing the
......@@ -425,7 +424,7 @@ class ImageCache {
// Only touch if the cache was enabled when resolve was initially called.
if (trackPendingImage) {
_touch(key, image, listenerTask);
_touch(key, image, timelineTask);
} else {
image.dispose();
}
......@@ -435,11 +434,12 @@ class ImageCache {
pendingImage.removeListener();
}
if (!kReleaseMode && !listenedOnce) {
listenerTask!.finish(arguments: <String, dynamic>{
timelineTask!
..finish(arguments: <String, dynamic>{
'syncCall': syncCall,
'sizeInBytes': sizeBytes,
});
timelineTask!.finish(arguments: <String, dynamic>{
})
..finish(arguments: <String, dynamic>{
'currentSizeBytes': currentSizeBytes,
'currentSize': currentSize,
});
......@@ -504,9 +504,8 @@ class ImageCache {
// maximum, or the cache is empty.
void _checkCacheSize(TimelineTask? timelineTask) {
final Map<String, dynamic> finishArgs = <String, dynamic>{};
TimelineTask? checkCacheTask;
if (!kReleaseMode) {
checkCacheTask = TimelineTask(parent: timelineTask)..start('checkCacheSize');
timelineTask!.start('checkCacheSize');
finishArgs['evictedKeys'] = <String>[];
finishArgs['currentSize'] = currentSize;
finishArgs['currentSizeBytes'] = currentSizeBytes;
......@@ -524,7 +523,7 @@ class ImageCache {
if (!kReleaseMode) {
finishArgs['endSize'] = currentSize;
finishArgs['endSizeBytes'] = currentSizeBytes;
checkCacheTask!.finish(arguments: finishArgs);
timelineTask!.finish(arguments: finishArgs);
}
assert(_currentSizeBytes >= 0);
assert(_cache.length <= maximumSize);
......
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