The flow of the new code appears correct to me.

The rest of this comment is geared more to the future. I'm not a big fan of lines 254-256; It seems a little like duplicated code since the same steps are needed for the non-jpeg case as well. Admittedly, when to execute those steps is not straightforward in the non-jpeg case so I'm not sure how to share that logic. It just seems it would be worth considering some refactoring to keep the code complexity down (perhaps using a kind of strategy pattern abstracting the behavior of 'previewable' vs. 'non-previewable' images) -- clearly not for 1.3t. Also, perhaps my threshold for complexity is low as I'm not as fluent in the code as you.