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

Side by Side Diff: runtime/bin/vmservice/loader.dart

Issue 584023004: Service isolate rework (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « runtime/bin/vmservice.h ('k') | runtime/bin/vmservice/resources.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of vmservice_io;
6
7 var _httpClient;
8
9 void _loadHttp(sendPort, uri) {
10 if (_httpClient == null) {
11 _httpClient = new HttpClient()..maxConnectionsPerHost = 6;
12 }
13 _httpClient.getUrl(uri)
14 .then((HttpClientRequest request) => request.close())
15 .then((HttpClientResponse response) {
16 var builder = new BytesBuilder(copy: false);
17 response.listen(
18 builder.add,
19 onDone: () {
20 if (response.statusCode != 200) {
21 var msg = 'Failure getting $uri: '
22 '${response.statusCode} ${response.reasonPhrase}';
23 sendPort.send(msg);
24 } else {
25 sendPort.send(builder.takeBytes());
26 }
27 },
28 onError: (e) {
29 sendPort.send(e.toString());
30 });
31 })
32 .catchError((e) {
33 sendPort.send(e.toString());
34 });
35 // It's just here to push an event on the event loop so that we invoke the
36 // scheduled microtasks.
37 Timer.run(() {});
38 }
39
40 void _loadFile(sendPort, path) {
41 var sourceFile = new File(path);
42 sourceFile.readAsBytes().then((data) {
43 sendPort.send(data);
44 },
45 onError: (e) {
46 sendPort.send(e.toString());
47 });
48 }
49
50 _processLoadRequest(request) {
51 var sp = request[0];
52 var uri = Uri.parse(request[1]);
53 if (uri.scheme == 'file') {
54 _loadFile(sp, uri.toFilePath());
55 } else if ((uri.scheme == 'http') || (uri.scheme == 'https')) {
56 _loadHttp(sp, uri);
57 } else {
58 sp.send('Unknown scheme for $uri');
59 }
60 }
OLDNEW
« no previous file with comments | « runtime/bin/vmservice.h ('k') | runtime/bin/vmservice/resources.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698