| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:http/http.dart' as http; | 8 import 'package:http/http.dart' as http; |
| 9 import 'package:stack_trace/stack_trace.dart'; | 9 import 'package:stack_trace/stack_trace.dart'; |
| 10 import 'package:usage/usage.dart'; | 10 import 'package:usage/usage.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 /// it must be supplied in the request. | 25 /// it must be supplied in the request. |
| 26 const String _stackTraceFilename = 'stacktrace_file'; | 26 const String _stackTraceFilename = 'stacktrace_file'; |
| 27 | 27 |
| 28 /// Sends crash reports to Google. | 28 /// Sends crash reports to Google. |
| 29 /// | 29 /// |
| 30 /// Clients shouldn't extend, mixin or implement this class. | 30 /// Clients shouldn't extend, mixin or implement this class. |
| 31 class CrashReportSender { | 31 class CrashReportSender { |
| 32 static final Uri _baseUri = new Uri( | 32 static final Uri _baseUri = new Uri( |
| 33 scheme: 'https', host: _crashServerHost, path: _crashEndpointPath); | 33 scheme: 'https', host: _crashServerHost, path: _crashEndpointPath); |
| 34 | 34 |
| 35 final String crashProductId; |
| 35 final Analytics analytics; | 36 final Analytics analytics; |
| 36 final http.Client _httpClient; | 37 final http.Client _httpClient; |
| 37 | 38 |
| 38 /// Create a new [CrashReportSender], using the data from the given | 39 /// Create a new [CrashReportSender], using the data from the given |
| 39 /// [Analytics] instance. | 40 /// [Analytics] instance. |
| 40 CrashReportSender(this.analytics, {http.Client httpClient}) | 41 CrashReportSender(this.crashProductId, this.analytics, |
| 42 {http.Client httpClient}) |
| 41 : _httpClient = httpClient ?? new http.Client(); | 43 : _httpClient = httpClient ?? new http.Client(); |
| 42 | 44 |
| 43 /// Sends one crash report. | 45 /// Sends one crash report. |
| 44 /// | 46 /// |
| 45 /// The report is populated from data in [error] and [stackTrace]. | 47 /// The report is populated from data in [error] and [stackTrace]. |
| 46 Future sendReport(dynamic error, {StackTrace stackTrace}) async { | 48 Future sendReport(dynamic error, {StackTrace stackTrace}) async { |
| 47 if (!analytics.enabled) { | 49 if (!analytics.enabled) { |
| 48 return; | 50 return; |
| 49 } | 51 } |
| 50 | 52 |
| 51 try { | 53 try { |
| 52 final Uri uri = _baseUri.replace( | 54 final Uri uri = _baseUri.replace( |
| 53 queryParameters: <String, String>{ | 55 queryParameters: <String, String>{ |
| 54 'product': analytics.trackingId, | 56 'product': analytics.trackingId, |
| 55 'version': analytics.applicationVersion, | 57 'version': analytics.applicationVersion, |
| 56 }, | 58 }, |
| 57 ); | 59 ); |
| 58 | 60 |
| 59 final http.MultipartRequest req = new http.MultipartRequest('POST', uri); | 61 final http.MultipartRequest req = new http.MultipartRequest('POST', uri); |
| 60 req.fields['uuid'] = analytics.clientId; | 62 req.fields['uuid'] = analytics.clientId; |
| 61 req.fields['product'] = analytics.trackingId; | 63 req.fields['product'] = crashProductId; |
| 62 req.fields['version'] = analytics.applicationVersion; | 64 req.fields['version'] = analytics.applicationVersion; |
| 63 req.fields['osName'] = Platform.operatingSystem; | 65 req.fields['osName'] = Platform.operatingSystem; |
| 64 // TODO(devoncarew): Report the operating system version when we're able. | 66 // TODO(devoncarew): Report the operating system version when we're able. |
| 65 //req.fields['osVersion'] = Platform.operatingSystemVersion; | 67 //req.fields['osVersion'] = Platform.operatingSystemVersion; |
| 66 req.fields['type'] = 'DartError'; | 68 req.fields['type'] = 'DartError'; |
| 67 req.fields['error_runtime_type'] = '${error.runtimeType}'; | 69 req.fields['error_runtime_type'] = '${error.runtimeType}'; |
| 68 | 70 |
| 69 final Chain chain = new Chain.parse(stackTrace.toString()); | 71 final Chain chain = new Chain.parse(stackTrace.toString()); |
| 70 req.files.add(new http.MultipartFile.fromString( | 72 req.files.add(new http.MultipartFile.fromString( |
| 71 _stackTraceFileField, chain.terse.toString(), | 73 _stackTraceFileField, chain.terse.toString(), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 83 throw 'exception while sending crash report: $error\n$stackTrace'; | 85 throw 'exception while sending crash report: $error\n$stackTrace'; |
| 84 } | 86 } |
| 85 } | 87 } |
| 86 | 88 |
| 87 /// Closes the client and cleans up any resources associated with it. This | 89 /// Closes the client and cleans up any resources associated with it. This |
| 88 /// will close the associated [http.Client]. | 90 /// will close the associated [http.Client]. |
| 89 void dispose() { | 91 void dispose() { |
| 90 _httpClient.close(); | 92 _httpClient.close(); |
| 91 } | 93 } |
| 92 } | 94 } |
| OLD | NEW |