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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 repositories; 5 part of repositories;
6 6
7 class TargetChangeEvent implements M.TargetChangeEvent { 7 class TargetChangeEvent implements M.TargetChangeEvent {
8 final TargetRepository repository; 8 final TargetRepository repository;
9 TargetChangeEvent(this.repository); 9 final bool disconnected;
10 TargetChangeEvent(this.repository, [this.disconnected = false]);
10 } 11 }
11 12
12 class TargetRepository implements M.TargetRepository { 13 class TargetRepository implements M.TargetRepository {
13 14
14 static const _historyKey = 'history'; 15 static const _historyKey = 'history';
15 16
16 final StreamController<TargetChangeEvent> _onChange; 17 final StreamController<TargetChangeEvent> _onChange;
17 final Stream<TargetChangeEvent> onChange; 18 final Stream<TargetChangeEvent> onChange;
18 final SettingsRepository _settings = new SettingsRepository('targetManager'); 19 final SettingsRepository _settings = new SettingsRepository('targetManager');
19 20
20 final List<SC.WebSocketVMTarget> _list = <SC.WebSocketVMTarget>[]; 21 final List<SC.WebSocketVMTarget> _list = <SC.WebSocketVMTarget>[];
21 SC.WebSocketVMTarget current; 22 SC.WebSocketVMTarget current;
22 23
23 factory TargetRepository() { 24 factory TargetRepository() {
24 var controller = new StreamController<TargetChangeEvent>(); 25 var controller = new StreamController<TargetChangeEvent>();
25 var stream = controller.stream.asBroadcastStream(); 26 var stream = controller.stream.asBroadcastStream();
26 return new TargetRepository._(controller, stream); 27 return new TargetRepository._(controller, stream);
27 } 28 }
28 29
29 TargetRepository._(this._onChange, this.onChange) { 30 TargetRepository._(this._onChange, this.onChange) {
30 _restore(); 31 _restore();
31 if (_list.isEmpty) { 32 // Add the default address if it doesn't already exist.
32 _list.add(new SC.WebSocketVMTarget(_networkAddressOfDefaultTarget())); 33 if (_find(_networkAddressOfDefaultTarget()) == null) {
34 add(_networkAddressOfDefaultTarget());
33 } 35 }
34 current = _list.first; 36 // Set the current target to the default target.
37 current = _find(_networkAddressOfDefaultTarget());
35 } 38 }
36 39
37 void add(String address) { 40 void add(String address) {
38 if (_find(address) != null) return; 41 if (_find(address) != null) {
42 return;
43 }
39 _list.insert(0, new SC.WebSocketVMTarget(address)); 44 _list.insert(0, new SC.WebSocketVMTarget(address));
40 _onChange.add(new TargetChangeEvent(this)); 45 _onChange.add(new TargetChangeEvent(this));
41 _store(); 46 _store();
42 } 47 }
43 48
44 Iterable<SC.WebSocketVMTarget> list() => _list; 49 Iterable<SC.WebSocketVMTarget> list() => _list;
45 50
46 void setCurrent(M.Target t) { 51 void setCurrent(M.Target t) {
47 SC.WebSocketVMTarget target = t as SC.WebSocketVMTarget; 52 SC.WebSocketVMTarget target = t as SC.WebSocketVMTarget;
48 if (!_list.contains(target)) return; 53 if (!_list.contains(target)) {
54 return;
55 }
49 current = target; 56 current = target;
50 current.lastConnectionTime = new DateTime.now().millisecondsSinceEpoch; 57 current.lastConnectionTime = new DateTime.now().millisecondsSinceEpoch;
51 _onChange.add(new TargetChangeEvent(this)); 58 _onChange.add(new TargetChangeEvent(this));
52 _store(); 59 _store();
53 } 60 }
54 61
62 void emitDisconnectEvent() {
63 _onChange.add(new TargetChangeEvent(this, true));
64 }
65
55 void delete(o) { 66 void delete(o) {
56 if (_list.remove(o)) { 67 if (_list.remove(o)) {
57 if (o == current) { 68 if (o == current) {
58 current = null; 69 current = null;
59 } 70 }
60 _onChange.add(new TargetChangeEvent(this)); 71 _onChange.add(new TargetChangeEvent(this));
61 _store(); 72 _store();
62 } 73 }
63 } 74 }
64 75
(...skipping 30 matching lines...) Expand all
95 // We are running as JavaScript, use the same host that Observatory has 106 // We are running as JavaScript, use the same host that Observatory has
96 // been loaded from. 107 // been loaded from.
97 return 'ws://${window.location.host}/ws'; 108 return 'ws://${window.location.host}/ws';
98 } else { 109 } else {
99 // Otherwise, assume we are running from Dart Editor and want to connect 110 // Otherwise, assume we are running from Dart Editor and want to connect
100 // to the default host. 111 // to the default host.
101 return 'ws://localhost:8181/ws'; 112 return 'ws://localhost:8181/ws';
102 } 113 }
103 } 114 }
104 } 115 }
OLDNEW
« 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