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

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

Issue 1217083009: Add a NetworkAssetBundle that is backed by the network (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: 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 | no next file » | 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 e0312d144ac75c9e72fd06f18dc86868b6806d51..58a76501c71962042bb73610dbc8d1b15ad99177 100644
--- a/sky/sdk/lib/mojo/asset_bundle.dart
+++ b/sky/sdk/lib/mojo/asset_bundle.dart
@@ -17,31 +17,52 @@ Future<sky.Image> _decodeImage(core.MojoDataPipeConsumer assetData) {
return completer.future;
}
-class AssetBundle {
- AssetBundle(AssetBundleProxy this._bundle);
+abstract class AssetBundle {
+ void close();
+ Future<sky.Image> fetchImage(String key);
+}
- void close() {
- _bundle.close();
- _bundle = null;
- }
+class NetworkAssetBundle extends AssetBundle {
+ NetworkAssetBundle(Uri base_url) : _base_url = base_url;
- Future<sky.Image> fetchImage(String path) async {
- core.MojoDataPipeConsumer assetData =
- (await _bundle.ptr.getAsStream(path)).assetData;
+ final Uri _base_url;
+
+ 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);
}
-
- AssetBundleProxy _bundle;
}
-Future<AssetBundle> fetchAssetBundle(String url) async {
+Future _fetchAndUnpackBundle(String relativeUrl, AssetBundleProxy bundle) async {
core.MojoDataPipeConsumer bundleData = (await fetchUrl(url)).body;
-
AssetUnpackerProxy unpacker = new AssetUnpackerProxy.unbound();
shell.requestService("mojo:asset_bundle", unpacker);
- AssetBundleProxy bundle = new AssetBundleProxy.unbound();
unpacker.ptr.unpackZipStream(bundleData, bundle);
unpacker.close();
+}
+
+class MojoAssetBundle extends AssetBundle {
+ MojoAssetBundle(AssetBundleProxy this._bundle);
- return new AssetBundle(bundle);
+ factory MojoAssetBundle.fromNetwork(String relativeUrl) {
+ AssetBundleProxy bundle = new AssetBundleProxy.unbound();
+ _fetchAndUnpackBundle(relativeUrl, bundle);
+ return new AssetBundle(bundle);
+ }
+
+ AssetBundleProxy _bundle;
+
+ void close() {
+ _bundle.close();
+ _bundle = null;
+ }
+
+ Future<sky.Image> fetchImage(String name) async {
+ core.MojoDataPipeConsumer assetData =
+ (await _bundle.ptr.getAsStream(name)).assetData;
+ return await _decodeImage(assetData);
+ }
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698