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

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

Issue 1165753004: Implement a simple image cache for Sky in Dart (no eviction) (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase origin/master Created 5 years, 7 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/sdk/BUILD.gn ('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
new file mode 100644
index 0000000000000000000000000000000000000000..dcb2ac2e9d63b4eda154d832cf23b35ccd5479b7
--- /dev/null
+++ b/sky/sdk/lib/framework/net/image_cache.dart
@@ -0,0 +1,33 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+import 'dart:sky' as sky;
+import 'dart:collection';
+
+final HashMap<String, List<sky.ImageLoaderCallback>> _pendingRequests =
+ new HashMap<String, List<sky.ImageLoaderCallback>>();
+
+final HashMap<String, sky.Image> _completedRequests =
+ new HashMap<String, sky.Image>();
+
+void load(String url, sky.ImageLoaderCallback callback) {
+ sky.Image result = _completedRequests[url];
+ if (result != null) {
+ callback(_completedRequests[url]);
+ return;
+ }
+
+ bool newRequest = false;
+ _pendingRequests.putIfAbsent(url, () {
+ newRequest = true;
+ return new List<sky.ImageLoaderCallback>();
+ }).add(callback);
+ if (newRequest) {
+ new sky.ImageLoader(url, (image) {
+ _completedRequests[url] = image;
+ _pendingRequests[url].forEach((c) => c(image));
+ _pendingRequests.remove(url);
+ });
+ }
+}
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698