Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Unified Diff: sky/sdk/lib/framework/net/image_cache.dart

Issue 1170413002: Make Sky not crash when an image 404s. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/engine/core/loader/CanvasImageDecoder.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/framework/net/image_cache.dart
diff --git a/sky/sdk/lib/framework/net/image_cache.dart b/sky/sdk/lib/framework/net/image_cache.dart
index ccd69996e022b2d5bd161788674fd8de34583bf1..1ec669866ae476be20818a05b2526fecdf54a9ec 100644
--- a/sky/sdk/lib/framework/net/image_cache.dart
+++ b/sky/sdk/lib/framework/net/image_cache.dart
@@ -13,6 +13,12 @@ final HashMap<String, List<ImageDecoderCallback>> _pendingRequests =
final HashMap<String, Image> _completedRequests =
new HashMap<String, Image>();
+void _loadComplete(url, image) {
+ _completedRequests[url] = image;
+ _pendingRequests[url].forEach((c) => c(image));
+ _pendingRequests.remove(url);
+}
+
void load(String url, ImageDecoderCallback callback) {
Image result = _completedRequests[url];
if (result != null) {
@@ -27,11 +33,12 @@ void load(String url, ImageDecoderCallback callback) {
}).add(callback);
if (newRequest) {
fetchUrl(url).then((UrlResponse response) {
- new ImageDecoder(response.body.handle.h, (image) {
- _completedRequests[url] = image;
- _pendingRequests[url].forEach((c) => c(image));
- _pendingRequests.remove(url);
- });
+ if (response.statusCode >= 400) {
+ _loadComplete(url, null);
+ return;
+ }
+ new ImageDecoder(response.body.handle.h,
+ (image) => _loadComplete(url, image));
});
}
}
« no previous file with comments | « sky/engine/core/loader/CanvasImageDecoder.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698