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

Unified Diff: runtime/observatory/lib/src/repositories/target.dart

Issue 2340973002: Improve VM connection flow in Observatory (Closed)
Patch Set: ... Created 4 years, 3 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/observatory/lib/src/repositories/target.dart
diff --git a/runtime/observatory/lib/src/repositories/target.dart b/runtime/observatory/lib/src/repositories/target.dart
index ec52128d96ea272456ef43d399590a9d9e8057fb..bb011600039f690113782b79570a3276326593bf 100644
--- a/runtime/observatory/lib/src/repositories/target.dart
+++ b/runtime/observatory/lib/src/repositories/target.dart
@@ -6,7 +6,8 @@ part of repositories;
class TargetChangeEvent implements M.TargetChangeEvent {
final TargetRepository repository;
- TargetChangeEvent(this.repository);
+ final bool disconnected;
+ TargetChangeEvent(this.repository, [this.disconnected = false]);
}
class TargetRepository implements M.TargetRepository {
@@ -28,14 +29,18 @@ class TargetRepository implements M.TargetRepository {
TargetRepository._(this._onChange, this.onChange) {
_restore();
- if (_list.isEmpty) {
- _list.add(new SC.WebSocketVMTarget(_networkAddressOfDefaultTarget()));
+ // Add the default address if it doesn't already exist.
+ if (_find(_networkAddressOfDefaultTarget()) == null) {
+ add(_networkAddressOfDefaultTarget());
}
- current = _list.first;
+ // Set the current target to the default target.
+ current = _find(_networkAddressOfDefaultTarget());
}
void add(String address) {
- if (_find(address) != null) return;
+ if (_find(address) != null) {
+ return;
+ }
_list.insert(0, new SC.WebSocketVMTarget(address));
_onChange.add(new TargetChangeEvent(this));
_store();
@@ -45,13 +50,19 @@ class TargetRepository implements M.TargetRepository {
void setCurrent(M.Target t) {
SC.WebSocketVMTarget target = t as SC.WebSocketVMTarget;
- if (!_list.contains(target)) return;
+ if (!_list.contains(target)) {
+ return;
+ }
current = target;
current.lastConnectionTime = new DateTime.now().millisecondsSinceEpoch;
_onChange.add(new TargetChangeEvent(this));
_store();
}
+ void emitDisconnectEvent() {
+ _onChange.add(new TargetChangeEvent(this, true));
+ }
+
void delete(o) {
if (_list.remove(o)) {
if (o == current) {
« no previous file with comments | « runtime/observatory/lib/src/repositories/isolate.dart ('k') | runtime/observatory/lib/src/service/object.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698