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

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: Rebase origin/master 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 final HashMap<String, List<sky.ImageLoaderCallback>> _pendingRequests =
9 new HashMap<String, List<sky.ImageLoaderCallback>>();
10
11 final HashMap<String, sky.Image> _completedRequests =
12 new HashMap<String, sky.Image>();
13
14 void load(String url, sky.ImageLoaderCallback callback) {
15 sky.Image result = _completedRequests[url];
16 if (result != null) {
17 callback(_completedRequests[url]);
18 return;
19 }
20
21 bool newRequest = false;
22 _pendingRequests.putIfAbsent(url, () {
23 newRequest = true;
24 return new List<sky.ImageLoaderCallback>();
25 }).add(callback);
26 if (newRequest) {
27 new sky.ImageLoader(url, (image) {
28 _completedRequests[url] = image;
29 _pendingRequests[url].forEach((c) => c(image));
30 _pendingRequests.remove(url);
31 });
32 }
33 }
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