OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BLIMP_CLIENT_CORE_SESSION_CONNECTION_STATUS_H_ | 5 #ifndef BLIMP_CLIENT_CORE_SESSION_CONNECTION_STATUS_H_ |
6 #define BLIMP_CLIENT_CORE_SESSION_CONNECTION_STATUS_H_ | 6 #define BLIMP_CLIENT_CORE_SESSION_CONNECTION_STATUS_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "blimp/client/core/session/network_event_observer.h" | 11 #include "blimp/client/core/session/network_event_observer.h" |
12 #include "blimp/client/public/session/assignment.h" | 12 #include "blimp/client/public/session/assignment.h" |
| 13 #include "blimp/common/public/session/assignment_options.h" |
13 #include "net/base/ip_endpoint.h" | 14 #include "net/base/ip_endpoint.h" |
14 | 15 |
15 namespace blimp { | 16 namespace blimp { |
16 namespace client { | 17 namespace client { |
17 | 18 |
18 // Provides Blimp engine connection status, and also broadcasts connection | 19 // Provides Blimp engine connection status, and also broadcasts connection |
19 // events to observers on main thread. | 20 // events to observers on main thread. |
20 class ConnectionStatus : public NetworkEventObserver { | 21 class ConnectionStatus : public NetworkEventObserver { |
21 public: | 22 public: |
22 ConnectionStatus(); | 23 ConnectionStatus(); |
23 ~ConnectionStatus() override; | 24 ~ConnectionStatus() override; |
24 | 25 |
25 // Return if we connected to the engine. | 26 // Return if we connected to the engine. |
26 bool is_connected() const { return is_connected_; } | 27 bool is_connected() const { return is_connected_; } |
27 | 28 |
28 // Get engine IP and port. | 29 // Get engine IP and port. |
29 const net::IPEndPoint& engine_endpoint() const { return engine_endpoint_; } | 30 const net::IPEndPoint& engine_endpoint() const { |
| 31 return assignment_options_.engine_endpoint; |
| 32 } |
30 | 33 |
31 // Broadcast network events. | 34 // Broadcast network events. |
32 void AddObserver(NetworkEventObserver* observer); | 35 void AddObserver(NetworkEventObserver* observer); |
33 void RemoveObserver(NetworkEventObserver* observer); | 36 void RemoveObserver(NetworkEventObserver* observer); |
34 | 37 |
35 // Set connection states. | 38 // Set connection states. |
36 void OnAssignmentResult(int result, const Assignment& assignment); | 39 void OnAssignmentResult(int result, const Assignment& assignment); |
37 | 40 |
38 base::WeakPtr<ConnectionStatus> GetWeakPtr(); | 41 base::WeakPtr<ConnectionStatus> GetWeakPtr(); |
39 | 42 |
40 private: | 43 private: |
41 // NetworkEventObserver implementation. | 44 // NetworkEventObserver implementation. |
42 void OnConnected() override; | 45 void OnConnected() override; |
43 void OnDisconnected(int result) override; | 46 void OnDisconnected(int result) override; |
44 | 47 |
45 // Observers listen to session events. | 48 // Observers listen to session events. |
46 base::ObserverList<NetworkEventObserver> connection_observers_; | 49 base::ObserverList<NetworkEventObserver> connection_observers_; |
47 | 50 |
48 // IP address and port of the engine. | 51 // Engine assignment specific to the given transport. |
49 net::IPEndPoint engine_endpoint_; | 52 AssignmentOptions assignment_options_; |
50 | 53 |
51 // If the client is currently connected. | 54 // If the client is currently connected. |
52 bool is_connected_; | 55 bool is_connected_; |
53 | 56 |
54 base::WeakPtrFactory<ConnectionStatus> weak_factory_; | 57 base::WeakPtrFactory<ConnectionStatus> weak_factory_; |
55 | 58 |
56 DISALLOW_COPY_AND_ASSIGN(ConnectionStatus); | 59 DISALLOW_COPY_AND_ASSIGN(ConnectionStatus); |
57 }; | 60 }; |
58 | 61 |
59 } // namespace client | 62 } // namespace client |
60 } // namespace blimp | 63 } // namespace blimp |
61 | 64 |
62 #endif // BLIMP_CLIENT_CORE_SESSION_CONNECTION_STATUS_H_ | 65 #endif // BLIMP_CLIENT_CORE_SESSION_CONNECTION_STATUS_H_ |
OLD | NEW |