OLD | NEW |
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:async'; | 5 import 'dart:async'; |
6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
| 7 import "dart:sky.internals" as internals; |
7 | 8 |
8 import 'package:mojo/core.dart' as core; | 9 import 'package:mojo/core.dart' as core; |
9 import 'package:mojom/mojo/asset_bundle/asset_bundle.mojom.dart'; | 10 import 'package:mojom/mojo/asset_bundle/asset_bundle.mojom.dart'; |
10 | 11 |
11 import 'net/fetch.dart'; | 12 import 'net/fetch.dart'; |
12 import 'net/image_cache.dart' as image_cache; | 13 import 'net/image_cache.dart' as image_cache; |
13 import 'shell.dart' as shell; | 14 import 'shell.dart' as shell; |
14 | 15 |
15 abstract class AssetBundle { | 16 abstract class AssetBundle { |
16 void close(); | 17 void close(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 Future<sky.Image> loadImage(String name) { | 60 Future<sky.Image> loadImage(String name) { |
60 return _imageCache.putIfAbsent(name, () { | 61 return _imageCache.putIfAbsent(name, () { |
61 Completer<sky.Image> completer = new Completer<sky.Image>(); | 62 Completer<sky.Image> completer = new Completer<sky.Image>(); |
62 _bundle.ptr.getAsStream(name).then((response) { | 63 _bundle.ptr.getAsStream(name).then((response) { |
63 new sky.ImageDecoder(response.assetData.handle.h, completer.complete); | 64 new sky.ImageDecoder(response.assetData.handle.h, completer.complete); |
64 }); | 65 }); |
65 return completer.future; | 66 return completer.future; |
66 }); | 67 }); |
67 } | 68 } |
68 } | 69 } |
| 70 |
| 71 AssetBundle _initRootBundle() { |
| 72 try { |
| 73 AssetBundleProxy bundle = new AssetBundleProxy.fromHandle( |
| 74 new core.MojoHandle(internals.takeRootBundleHandle())); |
| 75 return new MojoAssetBundle(bundle); |
| 76 } catch (e) { |
| 77 return null; |
| 78 } |
| 79 } |
| 80 |
| 81 final AssetBundle rootBundle = _initRootBundle(); |
OLD | NEW |