OLD | NEW |
(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 } |
OLD | NEW |