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

Side by Side 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: 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 unified diff | Download patch
« no previous file with comments | « sky/sdk/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 import 'dart:sky' as sky;
6 import 'dart:collection';
7
8 class ImageCache {
abarth-chromium 2015/06/02 00:52:47 There's no need for this class. You can just put
jackson 2015/06/02 01:18:25 Acknowledged.
9 static final ImageCache _sharedCache = new ImageCache();
10 static ImageCache shared() { return _sharedCache; }
11
12 final HashMap pendingRequests = new HashMap<String, List<sky.ImageLoaderCallba ck>>();
13 final HashMap completedRequests = new HashMap<String, sky.Image>();
abarth-chromium 2015/06/02 00:52:47 It's more important to put the types on the declar
jackson 2015/06/02 01:18:25 Acknowledged.
14
15 void load(String url, sky.ImageLoaderCallback callback) {
16 if (completedRequests.containsKey(url)) {
17 callback(completedRequests[url]);
18 } else if (pendingRequests.containsKey(url)) {
abarth-chromium 2015/06/02 00:52:47 Using putIfAbsent [1] is the idiomatic (and faster
jackson 2015/06/02 01:18:25 Acknowledged.
19 pendingRequests[url].add(callback);
20 } else {
21 pendingRequests[url] = new List();
22 pendingRequests[url].add(callback);
23 new sky.ImageLoader(url, (image) {
24 completedRequests[url] = image;
25 pendingRequests[url].forEach((c) => c(image));
26 pendingRequests[url].remove(url);
27 }).load();
28 }
29 }
30 }
OLDNEW
« 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