| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_NET_CLIENT_CONNECTION_MANAGER_H_ | 5 #ifndef BLIMP_NET_CLIENT_CONNECTION_MANAGER_H_ |
| 6 #define BLIMP_NET_CLIENT_CONNECTION_MANAGER_H_ | 6 #define BLIMP_NET_CLIENT_CONNECTION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 void AddTransport(std::unique_ptr<BlimpTransport> transport); | 39 void AddTransport(std::unique_ptr<BlimpTransport> transport); |
| 40 | 40 |
| 41 // Attempts to create a connection using any of the BlimpTransports in | 41 // Attempts to create a connection using any of the BlimpTransports in |
| 42 // |transports_|. | 42 // |transports_|. |
| 43 // This will result in the handler being called back at-most-once. | 43 // This will result in the handler being called back at-most-once. |
| 44 // | 44 // |
| 45 // This is also a placeholder for automatic reconnection logic for common | 45 // This is also a placeholder for automatic reconnection logic for common |
| 46 // cases such as network switches, online/offline changes. | 46 // cases such as network switches, online/offline changes. |
| 47 void Connect(); | 47 void Connect(); |
| 48 | 48 |
| 49 // Sets the client token to use in the authentication message. | 49 // Sets the client auth token to use in the authentication message. |
| 50 void set_client_token(const std::string& client_token) { | 50 void set_client_auth_token(const std::string& client_auth_token) { |
| 51 client_token_ = client_token; | 51 client_auth_token_ = client_auth_token; |
| 52 } | 52 } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 // Tries to connect using the BlimpTransport specified at |transport_index|. | 55 // Tries to connect using the BlimpTransport specified at |transport_index|. |
| 56 void Connect(int transport_index); | 56 void Connect(int transport_index); |
| 57 | 57 |
| 58 // Callback invoked by transports_[transport_index] to indicate that it has a | 58 // Callback invoked by transports_[transport_index] to indicate that it has a |
| 59 // connection ready to be authenticated or there is an error. | 59 // connection ready to be authenticated or there is an error. |
| 60 void OnConnectResult(int transport_index, int result); | 60 void OnConnectResult(int transport_index, int result); |
| 61 | 61 |
| 62 // Sends authentication message to the engine via |connection|. | 62 // Sends authentication message to the engine via |connection|. |
| 63 void SendAuthenticationMessage(std::unique_ptr<BlimpConnection> connection); | 63 void SendAuthenticationMessage(std::unique_ptr<BlimpConnection> connection); |
| 64 | 64 |
| 65 // Invoked after the authentication message is sent to |connection|. | 65 // Invoked after the authentication message is sent to |connection|. |
| 66 // The result of the write operation is passed via |result|. | 66 // The result of the write operation is passed via |result|. |
| 67 void OnAuthenticationMessageSent(std::unique_ptr<BlimpConnection> connection, | 67 void OnAuthenticationMessageSent(std::unique_ptr<BlimpConnection> connection, |
| 68 int result); | 68 int result); |
| 69 | 69 |
| 70 // ConnectionErrorObserver implementation. | 70 // ConnectionErrorObserver implementation. |
| 71 void OnConnectionError(int error) override; | 71 void OnConnectionError(int error) override; |
| 72 | 72 |
| 73 std::string client_token_; | 73 std::string client_auth_token_; |
| 74 ConnectionHandler* connection_handler_; | 74 ConnectionHandler* connection_handler_; |
| 75 std::vector<std::unique_ptr<BlimpTransport>> transports_; | 75 std::vector<std::unique_ptr<BlimpTransport>> transports_; |
| 76 base::WeakPtrFactory<ClientConnectionManager> weak_factory_; | 76 base::WeakPtrFactory<ClientConnectionManager> weak_factory_; |
| 77 | 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(ClientConnectionManager); | 78 DISALLOW_COPY_AND_ASSIGN(ClientConnectionManager); |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 } // namespace blimp | 81 } // namespace blimp |
| 82 | 82 |
| 83 #endif // BLIMP_NET_CLIENT_CONNECTION_MANAGER_H_ | 83 #endif // BLIMP_NET_CLIENT_CONNECTION_MANAGER_H_ |
| OLD | NEW |