|
| 1 | +// Copyright (c) 2019, 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 dart.io; |
| 6 | + |
| 7 | +@pragma('vm:entry-point') |
| 8 | +abstract class _NetworkProfiling { |
| 9 | + static const _kGetHttpProfileRPC = 'ext.dart.io.getHttpProfile'; |
| 10 | + static const _kGetSocketProfileRPC = 'ext.dart.io.getSocketProfile'; |
| 11 | + |
| 12 | + @pragma('vm:entry-point') |
| 13 | + static void _registerServiceExtension() { |
| 14 | + registerExtension(_kGetHttpProfileRPC, _serviceExtensionHandler); |
| 15 | + registerExtension(_kGetSocketProfileRPC, _serviceExtensionHandler); |
| 16 | + } |
| 17 | + |
| 18 | + static Future<ServiceExtensionResponse> _serviceExtensionHandler( |
| 19 | + String method, Map<String, String> parameters) { |
| 20 | + String responseJson; |
| 21 | + switch (method) { |
| 22 | + case _kGetHttpProfileRPC: |
| 23 | + responseJson = _HttpProfile.toJSON(); |
| 24 | + break; |
| 25 | + case _kGetSocketProfileRPC: |
| 26 | + responseJson = _SocketProfile.toJSON(); |
| 27 | + break; |
| 28 | + default: |
| 29 | + return Future.value(ServiceExtensionResponse.error( |
| 30 | + ServiceExtensionResponse.extensionError, |
| 31 | + 'Method $method does not exist')); |
| 32 | + } |
| 33 | + return Future.value(ServiceExtensionResponse.result(responseJson)); |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +abstract class _HttpProfile { |
| 38 | + static const _kType = 'HttpProfile'; |
| 39 | + // TODO(bkonyi): implement. |
| 40 | + static String toJSON() { |
| 41 | + final response = <String, dynamic>{ |
| 42 | + 'type': _kType, |
| 43 | + }; |
| 44 | + return json.encode(response); |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +abstract class _SocketProfile { |
| 49 | + static const _kType = 'SocketProfile'; |
| 50 | + // TODO(bkonyi): implement. |
| 51 | + static String toJSON() { |
| 52 | + final response = <String, dynamic>{ |
| 53 | + 'type': _kType, |
| 54 | + }; |
| 55 | + return json.encode(response); |
| 56 | + } |
| 57 | +} |
0 commit comments