Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 channel; | 5 library channel; |
| 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 | 10 |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 195 .transform(new ResponseConverter()) | 195 .transform(new ResponseConverter()) |
| 196 .asBroadcastStream(); | 196 .asBroadcastStream(); |
| 197 notificationStream = jsonStream | 197 notificationStream = jsonStream |
| 198 .where((json) => json[Notification.EVENT] != null) | 198 .where((json) => json[Notification.EVENT] != null) |
| 199 .transform(new NotificationConverter()) | 199 .transform(new NotificationConverter()) |
| 200 .asBroadcastStream(); | 200 .asBroadcastStream(); |
| 201 } | 201 } |
| 202 | 202 |
| 203 @override | 203 @override |
| 204 Future close() { | 204 Future close() { |
| 205 // TODO: implement close | 205 return output.close(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 @override | 208 @override |
| 209 Future<Response> sendRequest(Request request) { | 209 Future<Response> sendRequest(Request request) { |
| 210 String id = request.id; | 210 String id = request.id; |
| 211 output.writeln(JSON.encode(request.toJson())); | 211 output.writeln(JSON.encode(request.toJson())); |
| 212 return responseStream.firstWhere((Response response) => response.id == id); | 212 return responseStream.firstWhere((Response response) => response.id == id); |
| 213 } | 213 } |
| 214 } | 214 } |
| 215 | 215 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 onRequest(request); | 272 onRequest(request); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 /** | 276 /** |
| 277 * Instances of the class [JsonStreamDecoder] convert JSON strings to JSON | 277 * Instances of the class [JsonStreamDecoder] convert JSON strings to JSON |
| 278 * maps. | 278 * maps. |
| 279 */ | 279 */ |
| 280 class JsonStreamDecoder extends Converter<String, Map> { | 280 class JsonStreamDecoder extends Converter<String, Map> { |
| 281 @override | 281 @override |
| 282 Map convert(String text) => JSON.decode(text); | 282 Map convert(String text) { |
| 283 if (text == null || text.isEmpty || text[0] != '{') { | |
|
Paul Berry
2014/05/16 18:01:27
Is this an intentional part of the CL? What's the
danrubel
2014/05/19 17:32:25
This is to allow stack traces from the analysis se
| |
| 284 return null; | |
| 285 } | |
| 286 return JSON.decode(text); | |
| 287 } | |
| 283 | 288 |
| 284 @override | 289 @override |
| 285 ChunkedConversionSink startChunkedConversion(Sink sink) => | 290 ChunkedConversionSink startChunkedConversion(Sink sink) => |
| 286 new ChannelChunkSink<String, Map>(this, sink); | 291 new ChannelChunkSink<String, Map>(this, sink); |
| 287 } | 292 } |
| 288 | 293 |
| 289 /** | 294 /** |
| 290 * Instances of the class [ResponseConverter] convert JSON maps to [Response]s. | 295 * Instances of the class [ResponseConverter] convert JSON maps to [Response]s. |
| 291 */ | 296 */ |
| 292 class ResponseConverter extends Converter<Map, Response> { | 297 class ResponseConverter extends Converter<Map, Response> { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 } | 351 } |
| 347 } | 352 } |
| 348 } | 353 } |
| 349 | 354 |
| 350 @override | 355 @override |
| 351 void close() { | 356 void close() { |
| 352 closed = true; | 357 closed = true; |
| 353 sink.close(); | 358 sink.close(); |
| 354 } | 359 } |
| 355 } | 360 } |
| OLD | NEW |