Chromium Code Reviews| 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 7d7059dae620140b63ab1237da375a218f7c7373..71ac10d7f65c99d0f59153aaa8af300ffe8f0634 100644 |
| --- a/sky/sdk/lib/mojo/asset_bundle.dart |
| +++ b/sky/sdk/lib/mojo/asset_bundle.dart |
| @@ -4,7 +4,8 @@ |
| import 'dart:async'; |
| import 'dart:sky' as sky; |
| -import "dart:sky.internals" as internals; |
| +import 'dart:sky.internals' as internals; |
| +import 'dart:typed_data'; |
| import 'package:mojo/core.dart' as core; |
| import 'package:mojom/mojo/asset_bundle/asset_bundle.mojom.dart'; |
| @@ -16,6 +17,7 @@ import 'shell.dart' as shell; |
| abstract class AssetBundle { |
| void close(); |
| Future<sky.Image> loadImage(String key); |
| + Future<String> loadString(String key); |
| } |
| class NetworkAssetBundle extends AssetBundle { |
| @@ -25,9 +27,12 @@ class NetworkAssetBundle extends AssetBundle { |
| void close() { } |
| - Future<sky.Image> loadImage(String name) { |
| - Uri url = _baseUrl.resolve(name); |
| - return image_cache.load(url.toString()); |
| + Future<sky.Image> loadImage(String key) { |
| + return image_cache.load(_baseUrl.resolve(key).toString()); |
| + } |
| + |
| + Future<String> loadString(String key) { |
|
viktorl
2015/07/10 16:39:37
It may be worth thinking of calling this loadText
abarth-chromium
2015/07/10 16:42:28
Yeah, that might be worthwhile. I was hoping to s
|
| + return fetchString(_baseUrl.resolve(key).toString()); |
| } |
| } |
| @@ -48,8 +53,9 @@ class MojoAssetBundle extends AssetBundle { |
| return new MojoAssetBundle(bundle); |
| } |
| - AssetBundleProxy _bundle; |
| + final AssetBundleProxy _bundle; |
| Map<String, Future<sky.Image>> _imageCache = new Map<String, Future<sky.Image>>(); |
| + Map<String, Future<String>> _stringCache = new Map<String, Future<String>>(); |
| void close() { |
| _bundle.close(); |
| @@ -57,15 +63,25 @@ class MojoAssetBundle extends AssetBundle { |
| _imageCache = null; |
| } |
| - Future<sky.Image> loadImage(String name) { |
| - return _imageCache.putIfAbsent(name, () { |
| + Future<sky.Image> loadImage(String key) { |
| + return _imageCache.putIfAbsent(key, () { |
| Completer<sky.Image> completer = new Completer<sky.Image>(); |
| - _bundle.ptr.getAsStream(name).then((response) { |
| + _bundle.ptr.getAsStream(key).then((response) { |
| new sky.ImageDecoder(response.assetData.handle.h, completer.complete); |
| }); |
| return completer.future; |
| }); |
| } |
| + |
| + Future<String> _fetchString(String key) async { |
| + core.MojoDataPipeConsumer pipe = (await _bundle.ptr.getAsStream(key)).assetData; |
| + ByteData data = await core.DataPipeDrainer.drainHandle(pipe); |
| + return new String.fromCharCodes(new Uint8List.view(data.buffer)); |
| + } |
| + |
| + Future<String> loadString(String key) { |
| + return _stringCache.putIfAbsent(key, () => _fetchString(key)); |
| + } |
| } |
| AssetBundle _initRootBundle() { |