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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/observatory/location_manager.dart

Issue 143973005: Code coverage in Observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 part of observatory; 5 part of observatory;
6 6
7 /// The LocationManager class observes and parses the hash ('#') portion of the 7 /// The LocationManager class observes and parses the hash ('#') portion of the
8 /// URL in window.location. The text after the '#' is used as the request 8 /// URL in window.location. The text after the '#' is used as the request
9 /// string for the VM service. 9 /// string for the VM service.
10 class LocationManager extends Observable { 10 class LocationManager extends Observable {
11 static const int InvalidIsolateId = 0; 11 static const int InvalidIsolateId = 0;
12 static const String defaultHash = '#/isolates/'; 12 static const String defaultHash = '#/isolates/';
13 static final RegExp currentIsolateMatcher = new RegExp(r"#/isolates/\d+"); 13 static final RegExp currentIsolateMatcher = new RegExp(r"#/isolates/\d+");
14 static final RegExp currentIsolateProfileMatcher = 14 static final RegExp currentIsolateProfileMatcher =
15 new RegExp(r'#/isolates/\d+/profile'); 15 new RegExp(r'#/isolates/\d+/profile');
16 16
17 ObservatoryApplication _application; 17 ObservatoryApplication _application;
18 ObservatoryApplication get application => _application; 18 ObservatoryApplication get application => _application;
19 19
20 @observable bool profile = false; 20 @observable bool profile = false;
21 @observable String currentHash = ''; 21 @observable String currentHash = '';
22 @observable Uri currentHashUri; 22 @observable Uri currentHashUri;
23 void init() { 23 void init() {
24 window.onHashChange.listen((event) { 24 window.onHashChange.listen((event) {
25 if (setDefaultHash()) { 25 if (setDefaultHash()) {
26 // We just triggered another onHashChange event. 26 // We just triggered another onHashChange event.
27 return; 27 return;
28 } 28 }
29 notifyPropertyChange(#hasCurrentIsolate, !hasCurrentIsolate,
30 hasCurrentIsolate);
29 // Request the current anchor. 31 // Request the current anchor.
30 requestCurrentHash(); 32 requestCurrentHash();
31 }); 33 });
32 34
33 if (!setDefaultHash()) { 35 if (!setDefaultHash()) {
34 // An anchor was already present, trigger a request. 36 // An anchor was already present, trigger a request.
35 requestCurrentHash(); 37 requestCurrentHash();
36 } 38 }
37 } 39 }
38 40
39 41
40 /// Returns the current isolate prefix, i.e. '#/isolates/XX/' if one 42 /// Returns the current isolate prefix, i.e. '#/isolates/XX/' if one
41 /// is present and null otherwise. 43 /// is present and null otherwise.
42 String currentIsolateAnchorPrefix() { 44 String currentIsolateAnchorPrefix() {
43 Match m = currentIsolateMatcher.matchAsPrefix(currentHash); 45 Match m = currentIsolateMatcher.matchAsPrefix(currentHash);
44 if (m == null) { 46 if (m == null) {
45 return null; 47 return null;
46 } 48 }
47 return m.input.substring(m.start, m.end); 49 return m.input.substring(m.start, m.end);
48 } 50 }
49 51
50 /// Predicate, does the current URL have a current isolate ID in it? 52 /// Predicate, does the current URL have a current isolate ID in it?
51 bool get hasCurrentIsolate { 53 @observable bool get hasCurrentIsolate {
52 return currentIsolateAnchorPrefix() != null; 54 return currentIsolateAnchorPrefix() != null;
53 } 55 }
54 56
55 /// Extract the current isolate id as an integer. Returns [InvalidIsolateId] 57 /// Extract the current isolate id as an integer. Returns [InvalidIsolateId]
56 /// if none is present in window.location. 58 /// if none is present in window.location.
57 String currentIsolateId() { 59 String currentIsolateId() {
58 var prefix = currentIsolateAnchorPrefix(); 60 var prefix = currentIsolateAnchorPrefix();
59 if (prefix == null) { 61 if (prefix == null) {
60 return ''; 62 return '';
61 } 63 }
62 // Chop off the '/#'. 64 // Chop off the '/#'.
63 return prefix.substring(2); 65 return prefix.substring(2);
64 } 66 }
65 67
68 Isolate currentIsolate() {
69 var id = currentIsolateId();
70 if (id == '') {
71 return null;
72 }
73 return _application.isolateManager.getIsolate(id);
74 }
75
66 /// If no anchor is set, set the default anchor and return true. 76 /// If no anchor is set, set the default anchor and return true.
67 /// Return false otherwise. 77 /// Return false otherwise.
68 bool setDefaultHash() { 78 bool setDefaultHash() {
69 currentHash = window.location.hash; 79 currentHash = window.location.hash;
70 if (currentHash == '' || currentHash == '#') { 80 if (currentHash == '' || currentHash == '#') {
71 window.location.hash = defaultHash; 81 window.location.hash = defaultHash;
72 return true; 82 return true;
73 } 83 }
74 return false; 84 return false;
75 } 85 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 String relativeLink(String isolateId, String l) { 122 String relativeLink(String isolateId, String l) {
113 return '#/$isolateId/$l'; 123 return '#/$isolateId/$l';
114 } 124 }
115 125
116 /// Create a request for [l] on [isolateId]. 126 /// Create a request for [l] on [isolateId].
117 @observable 127 @observable
118 String absoluteLink(String l) { 128 String absoluteLink(String l) {
119 return '#/$l'; 129 return '#/$l';
120 } 130 }
121 } 131 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698