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

Unified Diff: sky/sdk/lib/mojo/asset_bundle.dart

Issue 1217593004: Teach Icon to use an AssetBundle (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: upload again 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/sdk/lib/widgets/basic.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/mojo/asset_bundle.dart
diff --git a/sky/sdk/lib/mojo/asset_bundle.dart b/sky/sdk/lib/mojo/asset_bundle.dart
index b90c06afbd0e099a07f92fdd9a257d778d19f8d2..0a18bdd313b38527f4cbbee5c547082ba5d73457 100644
--- a/sky/sdk/lib/mojo/asset_bundle.dart
+++ b/sky/sdk/lib/mojo/asset_bundle.dart
@@ -8,31 +8,25 @@ import 'dart:sky' as sky;
import 'package:mojo/core.dart' as core;
import 'package:mojom/mojo/asset_bundle/asset_bundle.mojom.dart';
-import 'shell.dart' as shell;
import 'net/fetch.dart';
-
-Future<sky.Image> _decodeImage(core.MojoDataPipeConsumer assetData) {
- Completer<sky.Image> completer = new Completer<sky.Image>();
- new sky.ImageDecoder(assetData.handle.h, completer.complete);
- return completer.future;
-}
+import 'net/image_cache.dart' as image_cache;
+import 'shell.dart' as shell;
abstract class AssetBundle {
void close();
- Future<sky.Image> fetchImage(String key);
+ Future<sky.Image> loadImage(String key);
}
class NetworkAssetBundle extends AssetBundle {
- NetworkAssetBundle(Uri base_url) : _base_url = base_url;
+ NetworkAssetBundle(Uri baseUrl) : _baseUrl = baseUrl;
- final Uri _base_url;
+ final Uri _baseUrl;
void close() { }
- Future<sky.Image> fetchImage(String name) async {
- Uri url = _base_url.resolve(name);
- core.MojoDataPipeConsumer assetData = (await fetchUrl(url.toString())).body;
- return await _decodeImage(assetData);
+ Future<sky.Image> loadImage(String name) {
+ Uri url = _baseUrl.resolve(name);
+ return image_cache.load(url.toString());
}
}
@@ -50,19 +44,25 @@ class MojoAssetBundle extends AssetBundle {
factory MojoAssetBundle.fromNetwork(String relativeUrl) {
AssetBundleProxy bundle = new AssetBundleProxy.unbound();
_fetchAndUnpackBundle(relativeUrl, bundle);
- return new AssetBundle(bundle);
+ return new MojoAssetBundle(bundle);
}
AssetBundleProxy _bundle;
+ Map<String, Future<sky.Image>> _imageCache = new Map<String, Future<sky.Image>>();
void close() {
_bundle.close();
_bundle = null;
+ _imageCache = null;
}
- Future<sky.Image> fetchImage(String name) async {
- core.MojoDataPipeConsumer assetData =
- (await _bundle.ptr.getAsStream(name)).assetData;
- return await _decodeImage(assetData);
+ Future<sky.Image> loadImage(String name) {
+ return _imageCache.putIfAbsent(name, () {
+ Completer<sky.Image> completer = new Completer<sky.Image>();
+ _bundle.ptr.getAsStream(name).then((response) {
+ new sky.ImageDecoder(response.assetData.handle.h, completer.complete);
+ });
+ return completer.future;
+ });
}
}
« no previous file with comments | « no previous file | sky/sdk/lib/widgets/basic.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698