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

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

Issue 184233007: Refactor Observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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) 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 app;
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 =
15 new RegExp(r'#/isolates/\d+/profile');
16 14
17 ObservatoryApplication _application; 15 ObservatoryApplication _app;
18 ObservatoryApplication get application => _application; 16 ObservatoryApplication get app => _app;
19 17
20 @observable bool profile = false; 18 @observable bool profile = false;
21 @observable String currentHash = ''; 19 @observable String currentHash = '';
22 @observable Uri currentHashUri; 20 @observable Uri currentHashUri;
23 void init() { 21 void init() {
24 window.onHashChange.listen((event) { 22 window.onHashChange.listen((event) {
25 if (setDefaultHash()) { 23 if (setDefaultHash()) {
26 // We just triggered another onHashChange event. 24 // We just triggered another onHashChange event.
27 return; 25 return;
28 } 26 }
(...skipping 13 matching lines...) Expand all
42 /// Returns the current isolate prefix, i.e. '#/isolates/XX/' if one 40 /// Returns the current isolate prefix, i.e. '#/isolates/XX/' if one
43 /// is present and null otherwise. 41 /// is present and null otherwise.
44 String currentIsolateAnchorPrefix() { 42 String currentIsolateAnchorPrefix() {
45 Match m = currentIsolateMatcher.matchAsPrefix(currentHash); 43 Match m = currentIsolateMatcher.matchAsPrefix(currentHash);
46 if (m == null) { 44 if (m == null) {
47 return null; 45 return null;
48 } 46 }
49 return m.input.substring(m.start, m.end); 47 return m.input.substring(m.start, m.end);
50 } 48 }
51 49
50 /// Returns the current object id.
51 String currentObjectId() {
52 Match m = currentIsolateMatcher.matchAsPrefix(currentHash);
53 if (m == null) {
54 return null;
55 }
56 return m.input.substring(m.end);
57 }
58
52 /// Predicate, does the current URL have a current isolate ID in it? 59 /// Predicate, does the current URL have a current isolate ID in it?
53 @observable bool get hasCurrentIsolate { 60 @observable bool get hasCurrentIsolate {
54 return currentIsolateAnchorPrefix() != null; 61 return currentIsolateAnchorPrefix() != null;
55 } 62 }
56 63
57 /// Extract the current isolate id as an integer. Returns [InvalidIsolateId] 64 /// Extract the current isolate id as an integer. Returns [InvalidIsolateId]
58 /// if none is present in window.location. 65 /// if none is present in window.location.
59 String currentIsolateId() { 66 String currentIsolateId() {
60 var prefix = currentIsolateAnchorPrefix(); 67 var prefix = currentIsolateAnchorPrefix();
61 if (prefix == null) { 68 if (prefix == null) {
62 return ''; 69 return '';
63 } 70 }
64 // Chop off the '/#'. 71 // Chop off the '/#'.
65 return prefix.substring(2); 72 return prefix.substring(2);
66 } 73 }
67 74
75 /// Returns the current isolate.
68 @observable Isolate currentIsolate() { 76 @observable Isolate currentIsolate() {
69 var id = currentIsolateId(); 77 var id = currentIsolateId();
70 if (id == '') { 78 if (id == '') {
71 return null; 79 return null;
72 } 80 }
73 return _application.isolateManager.getIsolate(id); 81 return app.vm.getIsolate(id);
74 } 82 }
75 83
76 /// If no anchor is set, set the default anchor and return true. 84 /// If no anchor is set, set the default anchor and return true.
77 /// Return false otherwise. 85 /// Return false otherwise.
78 bool setDefaultHash() { 86 bool setDefaultHash() {
79 currentHash = window.location.hash; 87 currentHash = window.location.hash;
80 if (currentHash == '' || currentHash == '#') { 88 if (currentHash == '' || currentHash == '#') {
81 window.location.hash = defaultHash; 89 window.location.hash = defaultHash;
82 return true; 90 return true;
83 } 91 }
84 return false; 92 return false;
85 } 93 }
86 94
87 /// Take the current request string from window.location and submit the 95 /// Take the current request string from window.location and submit the
88 /// request to the request manager. 96 /// request to the request manager.
89 void requestCurrentHash() { 97 void requestCurrentHash() {
90 currentHash = window.location.hash; 98 currentHash = window.location.hash;
91 // Chomp off the # 99 // Chomp off the #
92 String requestUrl = currentHash.substring(1); 100 String requestUrl = currentHash.substring(1);
101 app.isolate = currentIsolate();
93 currentHashUri = Uri.parse(requestUrl); 102 currentHashUri = Uri.parse(requestUrl);
94 if (currentIsolateProfileMatcher.hasMatch(currentHash)) { 103 if (app.isolate == null) {
95 // We do not automatically fetch profile data. 104 Logger.root.warning('Refreshing isolates.');
96 profile = true; 105 app.vm.refreshIsolates();
97 } else { 106 return;
98 application.requestManager.get(requestUrl);
99 profile = false;
100 } 107 }
101 } 108 var objectId = currentObjectId();
102 109 Logger.root.info('Asking ${app.isolate.id} for ${objectId}');
103 /// Create a request for [l] on the current isolate. 110 app.isolate.get(objectId).then((so) {
104 @observable 111 app.response = so;
105 String currentIsolateRelativeLink(String l) { 112 });
106 var isolateId = currentIsolateId();
107 if (isolateId == LocationManager.InvalidIsolateId) {
108 return defaultHash;
109 }
110 return relativeLink(isolateId, l);
111 }
112
113 /// Create a request for [scriptURL] on the current isolate.
114 @observable
115 String currentIsolateScriptLink(String scriptURL) {
116 var encoded = Uri.encodeComponent(scriptURL);
117 return currentIsolateRelativeLink('scripts/$encoded');
118 }
119
120 /// Create a request for [l] on [isolateId].
121 @observable
122 String relativeLink(String isolateId, String l) {
123 return '#/$isolateId/$l';
124 }
125
126 /// Create a request for [l] on [isolateId].
127 @observable
128 String absoluteLink(String l) {
129 return '#/$l';
130 } 113 }
131 } 114 }
OLDNEW
« no previous file with comments | « runtime/bin/vmservice/client/lib/src/app/isolate.dart ('k') | runtime/bin/vmservice/client/lib/src/app/model.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698