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

Side by Side Diff: mojo/dart/embedder/vmservice/main.dart

Issue 1480243004: Dart: Lazy observatory asset loading. Option to disable the observatory. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « mojo/dart/embedder/dart_controller.cc ('k') | mojo/tools/data/benchmarks » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart_controller_service_isolate; 5 library dart_controller_service_isolate;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io'; 9 import 'dart:io';
10 import 'dart:isolate'; 10 import 'dart:isolate';
11 import 'dart:_vmservice'; 11 import 'dart:_vmservice';
12 12
13 part 'loader.dart'; 13 part 'loader.dart';
14 part 'server.dart'; 14 part 'server.dart';
15 15
16 // The TCP ip/port that the HTTP server listens on. 16 // The TCP ip/port that the HTTP server listens on.
17 int _port; 17 int _port;
18 String _ip; 18 String _ip;
19 // Should the HTTP server auto start? 19 // Should the HTTP server auto start?
20 bool _autoStart; 20 bool _autoStart;
21 21
22 // HTTP server. 22 // HTTP server.
23 Server server; 23 Server server;
24 Map<String, Asset> assets; 24 Map<String, Asset> _assets;
25 Map<String, Asset> get assets {
26 if (_assets == null) {
27 try {
28 _assets = Asset.request();
29 } catch (e) {
30 print('Could not load Observatory assets: $e');
31 }
32 }
33 return _assets;
34 }
25 35
26 _onShutdown() { 36 _onShutdown() {
27 if (server != null) { 37 if (server != null) {
28 server.close(true).catchError((e, st) { 38 server.close(true).catchError((e, st) {
29 print(e); 39 print(e);
30 }).whenComplete(_shutdown); 40 }).whenComplete(_shutdown);
31 } else { 41 } else {
32 _shutdown(); 42 _shutdown();
33 } 43 }
34 } 44 }
35 45
36 void _bootServer() { 46 void _bootServer() {
37 try {
38 assets = Asset.request();
39 } catch (e) {
40 print('Could not load Observatory assets: $e');
41 }
42 // Lazily create service. 47 // Lazily create service.
43 var service = new VMService(); 48 var service = new VMService();
44 service.onShutdown = _onShutdown; 49 service.onShutdown = _onShutdown;
45 // Lazily create server. 50 // Lazily create server.
46 server = new Server(service, _ip, _port); 51 server = new Server(service, _ip, _port);
47 } 52 }
48 53
49 main() { 54 main() {
50 if (_autoStart) { 55 if (_autoStart) {
51 _bootServer(); 56 _bootServer();
52 if (server != null) { 57 if (server != null) {
53 server.startup(); 58 server.startup();
54 } 59 }
60 // It's just here to push an event on the event loop so that we invoke the
61 // scheduled microtasks.
62 Timer.run(() {});
55 } 63 }
56 scriptLoadPort.handler = _processLoadRequest; 64 scriptLoadPort.handler = _processLoadRequest;
57 // It's just here to push an event on the event loop so that we invoke the
58 // scheduled microtasks.
59 Timer.run(() {});
60 return scriptLoadPort; 65 return scriptLoadPort;
61 } 66 }
62 67
63 _shutdown() native "ServiceIsolate_Shutdown"; 68 _shutdown() native "ServiceIsolate_Shutdown";
OLDNEW
« no previous file with comments | « mojo/dart/embedder/dart_controller.cc ('k') | mojo/tools/data/benchmarks » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698