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_CLIENT_NETWORK_COMPONENTS_H_ |
| 6 #define BLIMP_CLIENT_CORE_SESSION_CLIENT_NETWORK_COMPONENTS_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/threading/thread_checker.h" |
| 11 #include "blimp/client/core/session/assignment_source.h" |
| 12 #include "blimp/client/core/session/network_event_observer.h" |
| 13 #include "blimp/net/blimp_connection.h" |
| 14 #include "blimp/net/blimp_connection_statistics.h" |
| 15 #include "blimp/net/browser_connection_handler.h" |
| 16 #include "blimp/net/client_connection_manager.h" |
| 17 |
| 18 namespace blimp { |
| 19 namespace client { |
| 20 |
| 21 // This class's functions and destruction must all be invoked on the IO thread |
| 22 // by the owner. It is OK to construct the object on the main thread. The |
| 23 // ThreadChecker is initialized in the call to Initialize. |
| 24 class ClientNetworkComponents : public ConnectionHandler, |
| 25 public ConnectionErrorObserver { |
| 26 public: |
| 27 // Can be created on any thread. |
| 28 ClientNetworkComponents( |
| 29 std::unique_ptr<NetworkEventObserver> observer, |
| 30 std::unique_ptr<BlimpConnectionStatistics> blimp_connection_statistics); |
| 31 ~ClientNetworkComponents() override; |
| 32 |
| 33 // Sets up network components. |
| 34 void Initialize(); |
| 35 |
| 36 // Starts the connection to the engine using the given |assignment|. |
| 37 // It is required to first call Initialize. |
| 38 void ConnectWithAssignment(const Assignment& assignment); |
| 39 |
| 40 BrowserConnectionHandler* GetBrowserConnectionHandler(); |
| 41 |
| 42 private: |
| 43 // ConnectionHandler implementation. |
| 44 void HandleConnection(std::unique_ptr<BlimpConnection> connection) override; |
| 45 |
| 46 // ConnectionErrorObserver implementation. |
| 47 void OnConnectionError(int error) override; |
| 48 |
| 49 // The ThreadChecker is reset during the call to Initialize. |
| 50 base::ThreadChecker io_thread_checker_; |
| 51 |
| 52 BrowserConnectionHandler connection_handler_; |
| 53 std::unique_ptr<ClientConnectionManager> connection_manager_; |
| 54 std::unique_ptr<NetworkEventObserver> network_observer_; |
| 55 std::unique_ptr<BlimpConnectionStatistics> connection_statistics_; |
| 56 |
| 57 DISALLOW_COPY_AND_ASSIGN(ClientNetworkComponents); |
| 58 }; |
| 59 |
| 60 } // namespace client |
| 61 } // namespace blimp |
| 62 |
| 63 #endif // BLIMP_CLIENT_CORE_SESSION_CLIENT_NETWORK_COMPONENTS_H_ |
OLD | NEW |