Skip to content

Commit 1a2cfe3

Browse files
sjuddglide-copybara-robot
authored andcommittedAug 16, 2022
Avoid always overwriting RunReason with one specific one in DecodeJob.reschedule.
This seems to have been around for years. I think the only negative impact is that we call into the SourceGenerator and run a few extra lines, which shouldn't materially impact the result of the load or its performance. It's certainly confusing though. PiperOrigin-RevId: 468008961
1 parent 10bffe3 commit 1a2cfe3

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed
 

‎library/src/main/java/com/bumptech/glide/load/engine/DecodeJob.java

+11-7
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ private void runGenerators() {
313313
currentGenerator = getNextGenerator();
314314

315315
if (stage == Stage.SOURCE) {
316-
reschedule();
316+
reschedule(RunReason.SWITCH_TO_SOURCE_SERVICE);
317317
return;
318318
}
319319
}
@@ -369,10 +369,16 @@ private Stage getNextStage(Stage current) {
369369
}
370370
}
371371

372+
private void reschedule(RunReason runReason) {
373+
this.runReason = runReason;
374+
callback.reschedule(this);
375+
}
376+
377+
// This is used by SourceGenerator to ask us to switch back to our thread. Internal methods in
378+
// this class should call reschedule with a specific RunReason.
372379
@Override
373380
public void reschedule() {
374-
runReason = RunReason.SWITCH_TO_SOURCE_SERVICE;
375-
callback.reschedule(this);
381+
reschedule(RunReason.SWITCH_TO_SOURCE_SERVICE);
376382
}
377383

378384
@Override
@@ -386,8 +392,7 @@ public void onDataFetcherReady(
386392
this.isLoadingFromAlternateCacheKey = sourceKey != decodeHelper.getCacheKeys().get(0);
387393

388394
if (Thread.currentThread() != currentThread) {
389-
runReason = RunReason.DECODE_DATA;
390-
callback.reschedule(this);
395+
reschedule(RunReason.DECODE_DATA);
391396
} else {
392397
GlideTrace.beginSection("DecodeJob.decodeFromRetrievedData");
393398
try {
@@ -406,8 +411,7 @@ public void onDataFetcherFailed(
406411
exception.setLoggingDetails(attemptedKey, dataSource, fetcher.getDataClass());
407412
throwables.add(exception);
408413
if (Thread.currentThread() != currentThread) {
409-
runReason = RunReason.SWITCH_TO_SOURCE_SERVICE;
410-
callback.reschedule(this);
414+
reschedule(RunReason.SWITCH_TO_SOURCE_SERVICE);
411415
} else {
412416
runGenerators();
413417
}

‎library/src/main/java/com/bumptech/glide/load/engine/SourceGenerator.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ void onDataReadyInternal(LoadData<?> loadData, Object data) {
204204
if (data != null && diskCacheStrategy.isDataCacheable(loadData.fetcher.getDataSource())) {
205205
dataToCache = data;
206206
// We might be being called back on someone else's thread. Before doing anything, we should
207-
// reschedule to get back onto Glide's thread.
207+
// reschedule to get back onto Glide's thread. Then once we're back on Glide's thread, we'll
208+
// get called again and we can write the retrieved data to cache.
208209
cb.reschedule();
209210
} else {
210211
cb.onDataFetcherReady(

0 commit comments

Comments
 (0)
Please sign in to comment.