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

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

Issue 192443004: Complete the switch to ServiceObject (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 side-by-side diff with in-line comments
Download patch
Index: runtime/bin/vmservice/client/lib/src/app/location_manager.dart
diff --git a/runtime/bin/vmservice/client/lib/src/app/location_manager.dart b/runtime/bin/vmservice/client/lib/src/app/location_manager.dart
index 29fc0747ac44e91c002897e5f20614edaf9bded4..7826e7d6beaefaf09a919a010e9b067ae3435fa3 100644
--- a/runtime/bin/vmservice/client/lib/src/app/location_manager.dart
+++ b/runtime/bin/vmservice/client/lib/src/app/location_manager.dart
@@ -8,24 +8,18 @@ part of app;
/// URL in window.location. The text after the '#' is used as the request
/// string for the VM service.
class LocationManager extends Observable {
- static const int InvalidIsolateId = 0;
static const String defaultHash = '#/isolates/';
- static final RegExp currentIsolateMatcher = new RegExp(r"#/isolates/\d+");
-
+ static final RegExp _currentIsolateMatcher = new RegExp(r'#/isolates/\d+');
+ static final RegExp _currentObjectMatcher = new RegExp(r'#/isolates/\d+/');
ObservatoryApplication _app;
- ObservatoryApplication get app => _app;
-
- @observable bool profile = false;
@observable String currentHash = '';
- @observable Uri currentHashUri;
+
void init() {
window.onHashChange.listen((event) {
if (setDefaultHash()) {
// We just triggered another onHashChange event.
return;
}
- notifyPropertyChange(#hasCurrentIsolate, !hasCurrentIsolate,
- hasCurrentIsolate);
// Request the current anchor.
requestCurrentHash();
});
@@ -36,40 +30,23 @@ class LocationManager extends Observable {
}
}
-
- /// Returns the current isolate prefix, i.e. '#/isolates/XX/' if one
- /// is present and null otherwise.
- String currentIsolateAnchorPrefix() {
- Match m = currentIsolateMatcher.matchAsPrefix(currentHash);
- if (m == null) {
- return null;
- }
- return m.input.substring(m.start, m.end);
- }
-
- /// Returns the current object id.
- String currentObjectId() {
- Match m = currentIsolateMatcher.matchAsPrefix(currentHash);
+ /// Parses the location entry and extracts the id for the object
+ /// inside the current isolate.
+ String currentIsolateObjectId() {
+ Match m = _currentObjectMatcher.matchAsPrefix(currentHash);
if (m == null) {
return null;
}
return m.input.substring(m.end);
}
- /// Predicate, does the current URL have a current isolate ID in it?
- @observable bool get hasCurrentIsolate {
- return currentIsolateAnchorPrefix() != null;
- }
-
- /// Extract the current isolate id as an integer. Returns [InvalidIsolateId]
- /// if none is present in window.location.
+ /// Parses the location entry and extracts the id for the current isolate.
String currentIsolateId() {
- var prefix = currentIsolateAnchorPrefix();
- if (prefix == null) {
+ Match m = _currentIsolateMatcher.matchAsPrefix(currentHash);
+ if (m == null) {
return '';
}
- // Chop off the '/#'.
- return prefix.substring(2);
+ return m.input.substring(2, m.end);
}
/// Returns the current isolate.
@@ -78,7 +55,7 @@ class LocationManager extends Observable {
if (id == '') {
return null;
}
- return app.vm.getIsolate(id);
+ return _app.vm.isolates.getIsolate(id);
}
/// If no anchor is set, set the default anchor and return true.
@@ -92,23 +69,21 @@ class LocationManager extends Observable {
return false;
}
- /// Take the current request string from window.location and submit the
- /// request to the request manager.
+ void _setResponse(ServiceObject so) {
turnidge 2014/03/10 21:03:28 Consider using "obj" instead of "so" - I always re
Cutch 2014/03/11 03:17:48 Done.
+ _app.response = so;
+ }
+
+ /// Refresh the service object reference in the location entry.
void requestCurrentHash() {
currentHash = window.location.hash;
- // Chomp off the #
- String requestUrl = currentHash.substring(1);
- app.isolate = currentIsolate();
- currentHashUri = Uri.parse(requestUrl);
- if (app.isolate == null) {
- Logger.root.warning('Refreshing isolates.');
- app.vm.refreshIsolates();
+ _app.isolate = currentIsolate();
+ if (_app.isolate == null) {
+ // No current isolate, refresh the isolate list.
+ _app.vm.isolates.refresh().then(_setResponse);
return;
}
- var objectId = currentObjectId();
- Logger.root.info('Asking ${app.isolate.id} for ${objectId}');
- app.isolate.get(objectId).then((so) {
- app.response = so;
- });
+ // Have a current isolate, request object.
+ var objectId = currentIsolateObjectId();
+ _app.isolate.get(objectId).then(_setResponse);
}
}

Powered by Google App Engine
This is Rietveld 408576698