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

Side by Side Diff: pkg/analysis_server/lib/src/channel/web_socket_channel.dart

Issue 954013002: Replace try/finally with PerformanceTag.makeCurrentWhile(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months 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 | Annotate | Revision Log
OLDNEW
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.web_socket; 5 library channel.web_socket;
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
11 import 'package:analysis_server/src/analysis_server.dart'; 11 import 'package:analysis_server/src/analysis_server.dart';
12 import 'package:analysis_server/src/channel/channel.dart'; 12 import 'package:analysis_server/src/channel/channel.dart';
13 import 'package:analysis_server/src/protocol.dart'; 13 import 'package:analysis_server/src/protocol.dart';
14 import 'package:analyzer/instrumentation/instrumentation.dart'; 14 import 'package:analyzer/instrumentation/instrumentation.dart';
15 import 'package:analyzer/src/generated/utilities_general.dart';
16 15
17 16
18 /** 17 /**
19 * Instances of the class [WebSocketClientChannel] implement a 18 * Instances of the class [WebSocketClientChannel] implement a
20 * [ClientCommunicationChannel] that uses a [WebSocket] to communicate with 19 * [ClientCommunicationChannel] that uses a [WebSocket] to communicate with
21 * servers. 20 * servers.
22 */ 21 */
23 class WebSocketClientChannel implements ClientCommunicationChannel { 22 class WebSocketClientChannel implements ClientCommunicationChannel {
24 /** 23 /**
25 * The socket being wrapped. 24 * The socket being wrapped.
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 99
101 /** 100 /**
102 * Read a request from the given [data] and use the given function to handle 101 * Read a request from the given [data] and use the given function to handle
103 * the request. 102 * the request.
104 */ 103 */
105 void readRequest(Object data, void onRequest(Request request)) { 104 void readRequest(Object data, void onRequest(Request request)) {
106 if (data is String) { 105 if (data is String) {
107 instrumentationService.logRequest(data); 106 instrumentationService.logRequest(data);
108 // Parse the string as a JSON descriptor and process the resulting 107 // Parse the string as a JSON descriptor and process the resulting
109 // structure as a request. 108 // structure as a request.
110 PerformanceTag prevTag = 109 ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() {
111 ServerPerformanceStatistics.serverChannel.makeCurrent();
112 try {
113 Request request = new Request.fromString(data); 110 Request request = new Request.fromString(data);
114 if (request == null) { 111 if (request == null) {
115 sendResponse(new Response.invalidRequestFormat()); 112 sendResponse(new Response.invalidRequestFormat());
116 return; 113 return;
117 } 114 }
118 onRequest(request); 115 onRequest(request);
119 } finally { 116 });
120 prevTag.makeCurrent();
121 }
122 } else if (data is List<int>) { 117 } else if (data is List<int>) {
123 // TODO(brianwilkerson) Implement a more efficient protocol. 118 // TODO(brianwilkerson) Implement a more efficient protocol.
124 sendResponse(new Response.invalidRequestFormat()); 119 sendResponse(new Response.invalidRequestFormat());
125 } else { 120 } else {
126 sendResponse(new Response.invalidRequestFormat()); 121 sendResponse(new Response.invalidRequestFormat());
127 } 122 }
128 } 123 }
129 124
130 @override 125 @override
131 void sendNotification(Notification notification) { 126 void sendNotification(Notification notification) {
132 PerformanceTag prevTag = 127 ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() {
133 ServerPerformanceStatistics.serverChannel.makeCurrent();
134 try {
135 String jsonEncoding = JSON.encode(notification.toJson()); 128 String jsonEncoding = JSON.encode(notification.toJson());
136 socket.add(jsonEncoding); 129 socket.add(jsonEncoding);
137 instrumentationService.logNotification(jsonEncoding); 130 instrumentationService.logNotification(jsonEncoding);
138 } finally { 131 });
139 prevTag.makeCurrent();
140 }
141 } 132 }
142 133
143 @override 134 @override
144 void sendResponse(Response response) { 135 void sendResponse(Response response) {
145 PerformanceTag prevTag = 136 ServerPerformanceStatistics.serverChannel.makeCurrentWhile(() {
146 ServerPerformanceStatistics.serverChannel.makeCurrent();
147 try {
148 String jsonEncoding = JSON.encode(response.toJson()); 137 String jsonEncoding = JSON.encode(response.toJson());
149 socket.add(jsonEncoding); 138 socket.add(jsonEncoding);
150 instrumentationService.logResponse(jsonEncoding); 139 instrumentationService.logResponse(jsonEncoding);
151 } finally { 140 });
152 prevTag.makeCurrent();
153 }
154 } 141 }
155 } 142 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698