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 get.handler; | 5 library get.handler; |
| 6 | 6 |
| 7 import 'dart:convert'; | 7 import 'dart:convert'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:math'; | 9 import 'dart:math'; |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 * state. | 38 * state. |
| 39 */ | 39 */ |
| 40 static const String CACHE_STATE_PATH = '/cache_state'; | 40 static const String CACHE_STATE_PATH = '/cache_state'; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * The path used to request code completion information. | 43 * The path used to request code completion information. |
| 44 */ | 44 */ |
| 45 static const String COMPLETION_PATH = '/completion'; | 45 static const String COMPLETION_PATH = '/completion'; |
| 46 | 46 |
| 47 /** | 47 /** |
| 48 * The path used to request overlays information. | |
| 49 */ | |
| 50 static const String OVERLAYS_PATH = '/overlays'; | |
| 51 | |
| 52 /** | |
| 48 * Query parameter used to represent the cache state to search for, when | 53 * Query parameter used to represent the cache state to search for, when |
| 49 * accessing [CACHE_STATE_PATH]. | 54 * accessing [CACHE_STATE_PATH]. |
| 50 */ | 55 */ |
| 51 static const String STATE_QUERY_PARAM = 'state'; | 56 static const String STATE_QUERY_PARAM = 'state'; |
| 52 | 57 |
| 53 /** | 58 /** |
| 54 * Query parameter used to represent the context to search for, when | 59 * Query parameter used to represent the context to search for, when |
| 55 * accessing [CACHE_ENTRY_PATH] or [CACHE_STATE_PATH]. | 60 * accessing [CACHE_ENTRY_PATH] or [CACHE_STATE_PATH]. |
| 56 */ | 61 */ |
| 57 static const String CONTEXT_QUERY_PARAM = 'context'; | 62 static const String CONTEXT_QUERY_PARAM = 'context'; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 89 void handleGetRequest(HttpRequest request) { | 94 void handleGetRequest(HttpRequest request) { |
| 90 String path = request.uri.path; | 95 String path = request.uri.path; |
| 91 if (path == STATUS_PATH) { | 96 if (path == STATUS_PATH) { |
| 92 _returnServerStatus(request); | 97 _returnServerStatus(request); |
| 93 } else if (path == CACHE_STATE_PATH) { | 98 } else if (path == CACHE_STATE_PATH) { |
| 94 _returnCacheState(request); | 99 _returnCacheState(request); |
| 95 } else if (path == CACHE_ENTRY_PATH) { | 100 } else if (path == CACHE_ENTRY_PATH) { |
| 96 _returnCacheEntry(request); | 101 _returnCacheEntry(request); |
| 97 } else if (path == COMPLETION_PATH) { | 102 } else if (path == COMPLETION_PATH) { |
| 98 _returnCompletionInfo(request); | 103 _returnCompletionInfo(request); |
| 104 } else if (path == OVERLAYS_PATH) { | |
| 105 _returnOverlaysInfo(request); | |
| 99 } else { | 106 } else { |
| 100 _returnUnknownRequest(request); | 107 _returnUnknownRequest(request); |
| 101 } | 108 } |
| 102 } | 109 } |
| 103 | 110 |
| 104 /** | 111 /** |
| 105 * Create a link to [path] with query parameters [params], with inner HTML | 112 * Create a link to [path] with query parameters [params], with inner HTML |
| 106 * [innerHtml]. | 113 * [innerHtml]. |
| 107 */ | 114 */ |
| 108 String _makeLink(String path, Map<String, String> params, String innerHtml) { | 115 String _makeLink(String path, Map<String, String> params, String innerHtml) { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 response.write('<title>Dart Analysis Server - Failure</title>'); | 372 response.write('<title>Dart Analysis Server - Failure</title>'); |
| 366 response.write('</head>'); | 373 response.write('</head>'); |
| 367 response.write('<body>'); | 374 response.write('<body>'); |
| 368 response.write(HTML_ESCAPE.convert(message)); | 375 response.write(HTML_ESCAPE.convert(message)); |
| 369 response.write('</body>'); | 376 response.write('</body>'); |
| 370 response.write('</html>'); | 377 response.write('</html>'); |
| 371 response.close(); | 378 response.close(); |
| 372 } | 379 } |
| 373 | 380 |
| 374 /** | 381 /** |
| 382 * Return a response displaying overlays information. | |
| 383 */ | |
| 384 void _returnOverlaysInfo(HttpRequest request) { | |
| 385 AnalysisServer analysisServer = _server.analysisServer; | |
| 386 if (analysisServer == null) { | |
| 387 return _returnFailure(request, 'Analysis server is not running'); | |
| 388 } | |
| 389 HttpResponse response = request.response; | |
| 390 response.statusCode = HttpStatus.OK; | |
| 391 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/html"); | |
| 392 response.write('<html>'); | |
| 393 response.write('<head>'); | |
| 394 response.write('<title>Dart Analysis Server - Overlays</title>'); | |
| 395 response.write('</head>'); | |
| 396 response.write('<body>'); | |
| 397 response.write('<h1>Dart Analysis Server - Overlays</h1>'); | |
| 398 response.write('<table border="1">'); | |
| 399 int count = 0; | |
| 400 analysisServer.folderMap.forEach((_, AnalysisContextImpl context) { | |
| 401 context.visitContentCache((Source source, int stamp, String contents) { | |
| 402 count++; | |
| 403 response.write('<tr>'); | |
| 404 response.write('<td>${HTML_ESCAPE.convert('$source')}</td>'); | |
|
Paul Berry
2015/01/15 00:07:06
Maybe enclose this in <pre> so it gets monospaced?
scheglov
2015/01/15 00:22:15
Done.
| |
| 405 response.write( | |
| 406 '<td>${new DateTime.fromMillisecondsSinceEpoch(stamp)}</td>'); | |
| 407 response.write('</tr>'); | |
| 408 }); | |
| 409 }); | |
| 410 response.write('<tr><td colspan="2">Total: $count entries.</td></tr>'); | |
| 411 response.write('</table>'); | |
| 412 response.write('</body>'); | |
| 413 response.write('</html>'); | |
| 414 response.close(); | |
| 415 } | |
| 416 | |
| 417 /** | |
| 375 * Return a response indicating the status of the analysis server. | 418 * Return a response indicating the status of the analysis server. |
| 376 */ | 419 */ |
| 377 void _returnServerStatus(HttpRequest request) { | 420 void _returnServerStatus(HttpRequest request) { |
| 378 HttpResponse response = request.response; | 421 HttpResponse response = request.response; |
| 379 response.statusCode = HttpStatus.OK; | 422 response.statusCode = HttpStatus.OK; |
| 380 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/html"); | 423 response.headers.add(HttpHeaders.CONTENT_TYPE, "text/html"); |
| 381 response.write('<html>'); | 424 response.write('<html>'); |
| 382 response.write('<head>'); | 425 response.write('<head>'); |
| 383 response.write('<title>Dart Analysis Server - Status</title>'); | 426 response.write('<title>Dart Analysis Server - Status</title>'); |
| 384 response.write('<style>'); | 427 response.write('<style>'); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 532 if (op != null) { | 575 if (op != null) { |
| 533 _writeRow(response, [' ', ' ', ' ']); | 576 _writeRow(response, [' ', ' ', ' ']); |
| 534 String elapsed = op.elapsed != null ? op.elapsed.toString() : '???'; | 577 String elapsed = op.elapsed != null ? op.elapsed.toString() : '???'; |
| 535 _writeRow(response, [elapsed, ' ', op.name]); | 578 _writeRow(response, [elapsed, ' ', op.name]); |
| 536 } | 579 } |
| 537 } | 580 } |
| 538 } | 581 } |
| 539 response.write('</table>'); | 582 response.write('</table>'); |
| 540 if (handler.performanceList.length > 0) { | 583 if (handler.performanceList.length > 0) { |
| 541 response.write('<table>'); | 584 response.write('<table>'); |
| 542 _writeRow(response, ['Milliseconds', '', '# Notifications', '', '# Suggest ions', '', 'Snippet'], header: true); | 585 _writeRow( |
| 586 response, | |
| 587 ['Milliseconds', '', '# Notifications', '', '# Suggestions', '', 'Snip pet'], | |
| 588 header: true); | |
| 543 handler.performanceList.forEach((CompletionPerformance performance) { | 589 handler.performanceList.forEach((CompletionPerformance performance) { |
| 544 _writeRow( | 590 _writeRow( |
| 545 response, | 591 response, |
| 546 [ | 592 [ |
| 547 performance.elapsedInMilliseconds, | 593 performance.elapsedInMilliseconds, |
| 548 ' ', | 594 ' ', |
| 549 performance.notificationCount, | 595 performance.notificationCount, |
| 550 ' ', | 596 ' ', |
| 551 performance.suggestionCount, | 597 performance.suggestionCount, |
| 552 ' ', | 598 ' ', |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 583 if (header) { | 629 if (header) { |
| 584 response.write('</th>'); | 630 response.write('</th>'); |
| 585 } else { | 631 } else { |
| 586 response.write('</td>'); | 632 response.write('</td>'); |
| 587 } | 633 } |
| 588 } | 634 } |
| 589 | 635 |
| 590 response.write('</tr>'); | 636 response.write('</tr>'); |
| 591 } | 637 } |
| 592 } | 638 } |
| OLD | NEW |