| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 CHROMEOS_COMPONENTS_TETHER_CONNECT_TETHERING_OPERATION_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_CONNECT_TETHERING_OPERATION_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_CONNECT_TETHERING_OPERATION_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_CONNECT_TETHERING_OPERATION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
| 13 #include "chromeos/components/tether/ble_connection_manager.h" | 13 #include "chromeos/components/tether/ble_connection_manager.h" |
| 14 #include "chromeos/components/tether/message_transfer_operation.h" | 14 #include "chromeos/components/tether/message_transfer_operation.h" |
| 15 #include "components/cryptauth/remote_device.h" | 15 #include "components/cryptauth/remote_device.h" |
| 16 | 16 |
| 17 namespace chromeos { | 17 namespace chromeos { |
| 18 | 18 |
| 19 namespace tether { | 19 namespace tether { |
| 20 | 20 |
| 21 class HostScanDevicePrioritizer; | |
| 22 class MessageWrapper; | 21 class MessageWrapper; |
| 22 class TetherHostResponseRecorder; |
| 23 | 23 |
| 24 // Operation used to request that a tether host share its Internet connection. | 24 // Operation used to request that a tether host share its Internet connection. |
| 25 // Attempts a connection to the RemoteDevice passed to its constructor and | 25 // Attempts a connection to the RemoteDevice passed to its constructor and |
| 26 // notifies observers when the RemoteDevice sends a response. | 26 // notifies observers when the RemoteDevice sends a response. |
| 27 // TODO(khorimoto): Add a timeout which gives up if no response is received in | 27 // TODO(khorimoto): Add a timeout which gives up if no response is received in |
| 28 // a reasonable amount of time. | 28 // a reasonable amount of time. |
| 29 class ConnectTetheringOperation : public MessageTransferOperation { | 29 class ConnectTetheringOperation : public MessageTransferOperation { |
| 30 public: | 30 public: |
| 31 class Factory { | 31 class Factory { |
| 32 public: | 32 public: |
| 33 static std::unique_ptr<ConnectTetheringOperation> NewInstance( | 33 static std::unique_ptr<ConnectTetheringOperation> NewInstance( |
| 34 const cryptauth::RemoteDevice& device_to_connect, | 34 const cryptauth::RemoteDevice& device_to_connect, |
| 35 BleConnectionManager* connection_manager, | 35 BleConnectionManager* connection_manager, |
| 36 HostScanDevicePrioritizer* host_scan_device_prioritizer); | 36 TetherHostResponseRecorder* tether_host_response_recorder); |
| 37 | 37 |
| 38 static void SetInstanceForTesting(Factory* factory); | 38 static void SetInstanceForTesting(Factory* factory); |
| 39 | 39 |
| 40 protected: | 40 protected: |
| 41 virtual std::unique_ptr<ConnectTetheringOperation> BuildInstance( | 41 virtual std::unique_ptr<ConnectTetheringOperation> BuildInstance( |
| 42 const cryptauth::RemoteDevice& devices_to_connect, | 42 const cryptauth::RemoteDevice& devices_to_connect, |
| 43 BleConnectionManager* connection_manager, | 43 BleConnectionManager* connection_manager, |
| 44 HostScanDevicePrioritizer* host_scan_device_prioritizer); | 44 TetherHostResponseRecorder* tether_host_response_recorder); |
| 45 | 45 |
| 46 private: | 46 private: |
| 47 static Factory* factory_instance_; | 47 static Factory* factory_instance_; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 class Observer { | 50 class Observer { |
| 51 public: | 51 public: |
| 52 virtual void OnSuccessfulConnectTetheringResponse( | 52 virtual void OnSuccessfulConnectTetheringResponse( |
| 53 const cryptauth::RemoteDevice& remote_device, | 53 const cryptauth::RemoteDevice& remote_device, |
| 54 const std::string& ssid, | 54 const std::string& ssid, |
| 55 const std::string& password) = 0; | 55 const std::string& password) = 0; |
| 56 virtual void OnConnectTetheringFailure( | 56 virtual void OnConnectTetheringFailure( |
| 57 const cryptauth::RemoteDevice& remote_device, | 57 const cryptauth::RemoteDevice& remote_device, |
| 58 ConnectTetheringResponse_ResponseCode error_code) = 0; | 58 ConnectTetheringResponse_ResponseCode error_code) = 0; |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 ConnectTetheringOperation( | 61 ConnectTetheringOperation( |
| 62 const cryptauth::RemoteDevice& device_to_connect, | 62 const cryptauth::RemoteDevice& device_to_connect, |
| 63 BleConnectionManager* connection_manager, | 63 BleConnectionManager* connection_manager, |
| 64 HostScanDevicePrioritizer* host_scan_device_prioritizer); | 64 TetherHostResponseRecorder* tether_host_response_recorder); |
| 65 ~ConnectTetheringOperation() override; | 65 ~ConnectTetheringOperation() override; |
| 66 | 66 |
| 67 void AddObserver(Observer* observer); | 67 void AddObserver(Observer* observer); |
| 68 void RemoveObserver(Observer* observer); | 68 void RemoveObserver(Observer* observer); |
| 69 | 69 |
| 70 protected: | 70 protected: |
| 71 // MessageTransferOperation: | 71 // MessageTransferOperation: |
| 72 void OnDeviceAuthenticated( | 72 void OnDeviceAuthenticated( |
| 73 const cryptauth::RemoteDevice& remote_device) override; | 73 const cryptauth::RemoteDevice& remote_device) override; |
| 74 void OnMessageReceived(std::unique_ptr<MessageWrapper> message_wrapper, | 74 void OnMessageReceived(std::unique_ptr<MessageWrapper> message_wrapper, |
| 75 const cryptauth::RemoteDevice& remote_device) override; | 75 const cryptauth::RemoteDevice& remote_device) override; |
| 76 void OnOperationFinished() override; | 76 void OnOperationFinished() override; |
| 77 MessageType GetMessageTypeForConnection() override; | 77 MessageType GetMessageTypeForConnection() override; |
| 78 void NotifyObserversOfSuccessfulResponse(const std::string& ssid, | 78 void NotifyObserversOfSuccessfulResponse(const std::string& ssid, |
| 79 const std::string& password); | 79 const std::string& password); |
| 80 void NotifyObserversOfConnectionFailure( | 80 void NotifyObserversOfConnectionFailure( |
| 81 ConnectTetheringResponse_ResponseCode error_code); | 81 ConnectTetheringResponse_ResponseCode error_code); |
| 82 | 82 |
| 83 private: | 83 private: |
| 84 friend class ConnectTetheringOperationTest; | 84 friend class ConnectTetheringOperationTest; |
| 85 | 85 |
| 86 cryptauth::RemoteDevice remote_device_; | 86 cryptauth::RemoteDevice remote_device_; |
| 87 HostScanDevicePrioritizer* host_scan_device_prioritizer_; | 87 TetherHostResponseRecorder* tether_host_response_recorder_; |
| 88 | 88 |
| 89 // These values are saved in OnMessageReceived() and returned in | 89 // These values are saved in OnMessageReceived() and returned in |
| 90 // OnOperationFinished(). | 90 // OnOperationFinished(). |
| 91 std::string ssid_to_return_; | 91 std::string ssid_to_return_; |
| 92 std::string password_to_return_; | 92 std::string password_to_return_; |
| 93 ConnectTetheringResponse_ResponseCode error_code_to_return_; | 93 ConnectTetheringResponse_ResponseCode error_code_to_return_; |
| 94 | 94 |
| 95 base::ObserverList<Observer> observer_list_; | 95 base::ObserverList<Observer> observer_list_; |
| 96 | 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(ConnectTetheringOperation); | 97 DISALLOW_COPY_AND_ASSIGN(ConnectTetheringOperation); |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 } // namespace tether | 100 } // namespace tether |
| 101 | 101 |
| 102 } // namespace chromeos | 102 } // namespace chromeos |
| 103 | 103 |
| 104 #endif // CHROMEOS_COMPONENTS_TETHER_CONNECT_TETHERING_OPERATION_H_ | 104 #endif // CHROMEOS_COMPONENTS_TETHER_CONNECT_TETHERING_OPERATION_H_ |
| OLD | NEW |