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

Side by Side Diff: sky/sdk/lib/framework/net/image_cache.dart

Issue 1173703002: Move image loading out of C++ into Dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rename fetchMojo to fetchUrl 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/lib/framework/net/fetch.dart ('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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:sky' as sky; 5 import 'dart:sky';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'fetch.dart';
8 import 'package:mojom/mojo/url_response.mojom.dart';
7 9
8 final HashMap<String, List<sky.ImageLoaderCallback>> _pendingRequests = 10 final HashMap<String, List<ImageDecoderCallback>> _pendingRequests =
9 new HashMap<String, List<sky.ImageLoaderCallback>>(); 11 new HashMap<String, List<ImageDecoderCallback>>();
10 12
11 final HashMap<String, sky.Image> _completedRequests = 13 final HashMap<String, Image> _completedRequests =
12 new HashMap<String, sky.Image>(); 14 new HashMap<String, Image>();
13 15
14 void load(String url, sky.ImageLoaderCallback callback) { 16 void load(String url, ImageDecoderCallback callback) {
15 sky.Image result = _completedRequests[url]; 17 Image result = _completedRequests[url];
16 if (result != null) { 18 if (result != null) {
17 callback(_completedRequests[url]); 19 callback(_completedRequests[url]);
18 return; 20 return;
19 } 21 }
20 22
21 bool newRequest = false; 23 bool newRequest = false;
22 _pendingRequests.putIfAbsent(url, () { 24 _pendingRequests.putIfAbsent(url, () {
23 newRequest = true; 25 newRequest = true;
24 return new List<sky.ImageLoaderCallback>(); 26 return new List<ImageDecoderCallback>();
25 }).add(callback); 27 }).add(callback);
26 if (newRequest) { 28 if (newRequest) {
27 new sky.ImageLoader(url, (image) { 29 fetchUrl(url).then((UrlResponse response) {
28 _completedRequests[url] = image; 30 new ImageDecoder(response.body.handle.h, (image) {
29 _pendingRequests[url].forEach((c) => c(image)); 31 _completedRequests[url] = image;
30 _pendingRequests.remove(url); 32 _pendingRequests[url].forEach((c) => c(image));
33 _pendingRequests.remove(url);
34 });
31 }); 35 });
32 } 36 }
33 } 37 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/net/fetch.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698