Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 vmservice_io; | 5 library vmservice_io; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 if (_registerSignalHandlerTimer != null) { | 55 if (_registerSignalHandlerTimer != null) { |
| 56 _registerSignalHandlerTimer.cancel(); | 56 _registerSignalHandlerTimer.cancel(); |
| 57 _registerSignalHandlerTimer = null; | 57 _registerSignalHandlerTimer = null; |
| 58 } | 58 } |
| 59 // Call out to embedder's shutdown callback. | 59 // Call out to embedder's shutdown callback. |
| 60 _shutdown(); | 60 _shutdown(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 Future<Uri> createTempDirCallback(String base) async { | |
| 64 Directory temp = await Directory.systemTemp.createTemp(base); | |
| 65 return temp.uri; | |
| 66 } | |
| 67 | |
| 68 Future deleteDirCallback(Uri path) async { | |
| 69 Directory dir = new Directory.fromUri(path); | |
| 70 await dir.delete(recursive: true); | |
| 71 } | |
| 72 | |
| 73 Future writeFileCallback(Uri path, List<int> bytes) async { | |
| 74 var file = await new File.fromUri(path); | |
| 75 await file.writeAsBytes(bytes); | |
| 76 } | |
| 77 | |
| 78 Future<List<int>> readFileCallback(Uri path) async { | |
| 79 var file = await new File.fromUri(path); | |
| 80 return await file.readAsBytes(); | |
| 81 } | |
| 82 | |
| 83 Future<List<Map<String,String>>> listFilesCallback(Uri dirPath) async { | |
| 84 var dir = new Directory.fromUri(dirPath); | |
| 85 var dirPathStr = dirPath.path; | |
| 86 var stream = dir.list(recursive: true); | |
| 87 var result = []; | |
| 88 await for (var fileEntity in stream) { | |
| 89 var stat = await fileEntity.stat(); | |
| 90 if (stat.type == FileSystemEntityType.FILE && | |
| 91 fileEntity.path.startsWith(dirPathStr)) { | |
| 92 var map = {}; | |
| 93 map['name'] = '/' + fileEntity.path.substring(dirPathStr.length); | |
| 94 map['size'] = stat.size; | |
|
Cutch
2016/07/01 21:23:17
modification time might be useful here too
| |
| 95 result.add(map); | |
| 96 } | |
| 97 } | |
| 98 return result; | |
| 99 } | |
| 100 | |
| 63 _clearFuture(_) { | 101 _clearFuture(_) { |
| 64 serverFuture = null; | 102 serverFuture = null; |
| 65 } | 103 } |
| 66 | 104 |
| 67 _onSignal(ProcessSignal signal) { | 105 _onSignal(ProcessSignal signal) { |
| 68 if (serverFuture != null) { | 106 if (serverFuture != null) { |
| 69 // Still waiting. | 107 // Still waiting. |
| 70 return; | 108 return; |
| 71 } | 109 } |
| 72 _lazyServerBoot(); | 110 _lazyServerBoot(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 89 if (_isWindows) { | 127 if (_isWindows) { |
| 90 // Cannot register for signals on Windows. | 128 // Cannot register for signals on Windows. |
| 91 return; | 129 return; |
| 92 } | 130 } |
| 93 _signalSubscription = _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); | 131 _signalSubscription = _signalWatch(ProcessSignal.SIGQUIT).listen(_onSignal); |
| 94 } | 132 } |
| 95 | 133 |
| 96 main() { | 134 main() { |
| 97 // Set embedder hooks. | 135 // Set embedder hooks. |
| 98 VMServiceEmbedderHooks.cleanup = cleanupCallback; | 136 VMServiceEmbedderHooks.cleanup = cleanupCallback; |
| 137 VMServiceEmbedderHooks.createTempDir = createTempDirCallback; | |
| 138 VMServiceEmbedderHooks.deleteDir = deleteDirCallback; | |
| 139 VMServiceEmbedderHooks.writeFile = writeFileCallback; | |
| 140 VMServiceEmbedderHooks.readFile = readFileCallback; | |
| 141 VMServiceEmbedderHooks.listFiles = listFilesCallback; | |
| 99 // Always instantiate the vmservice object so that the exit message | 142 // Always instantiate the vmservice object so that the exit message |
| 100 // can be delivered and waiting loaders can be cancelled. | 143 // can be delivered and waiting loaders can be cancelled. |
| 101 var service = new VMService(); | 144 var service = new VMService(); |
| 102 if (_autoStart) { | 145 if (_autoStart) { |
| 103 _lazyServerBoot(); | 146 _lazyServerBoot(); |
| 104 server.startup(); | 147 server.startup(); |
| 105 // It's just here to push an event on the event loop so that we invoke the | 148 // It's just here to push an event on the event loop so that we invoke the |
| 106 // scheduled microtasks. | 149 // scheduled microtasks. |
| 107 Timer.run(() {}); | 150 Timer.run(() {}); |
| 108 } | 151 } |
| 109 scriptLoadPort.handler = _processLoadRequest; | 152 scriptLoadPort.handler = _processLoadRequest; |
| 110 // Register signal handler after a small delay to avoid stalling main | 153 // Register signal handler after a small delay to avoid stalling main |
| 111 // isolate startup. | 154 // isolate startup. |
| 112 _registerSignalHandlerTimer = new Timer(shortDelay, _registerSignalHandler); | 155 _registerSignalHandlerTimer = new Timer(shortDelay, _registerSignalHandler); |
| 113 return scriptLoadPort; | 156 return scriptLoadPort; |
| 114 } | 157 } |
| 115 | 158 |
| 116 _shutdown() native "VMServiceIO_Shutdown"; | 159 _shutdown() native "VMServiceIO_Shutdown"; |
| OLD | NEW |