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