| 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_KEEP_ALIVE_OPERATION_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_OPERATION_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_OPERATION_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_OPERATION_H_ |
| 7 | 7 |
| 8 #include "base/observer_list.h" | 8 #include "base/observer_list.h" |
| 9 #include "chromeos/components/tether/message_transfer_operation.h" | 9 #include "chromeos/components/tether/message_transfer_operation.h" |
| 10 | 10 |
| 11 namespace chromeos { | 11 namespace chromeos { |
| 12 | 12 |
| 13 namespace tether { | 13 namespace tether { |
| 14 | 14 |
| 15 class BleConnectionManager; | 15 class BleConnectionManager; |
| 16 | 16 |
| 17 // Operation which sends a keep-alive message to a tether host. | 17 // Operation which sends a keep-alive message to a tether host and receives an |
| 18 // TODO(khorimoto/hansberry): Change protocol to receive a DeviceStatus update | 18 // update about the host's status. |
| 19 // after sending the KeepAliveTickle message. | |
| 20 class KeepAliveOperation : public MessageTransferOperation { | 19 class KeepAliveOperation : public MessageTransferOperation { |
| 21 public: | 20 public: |
| 22 class Factory { | 21 class Factory { |
| 23 public: | 22 public: |
| 24 static std::unique_ptr<KeepAliveOperation> NewInstance( | 23 static std::unique_ptr<KeepAliveOperation> NewInstance( |
| 25 const cryptauth::RemoteDevice& device_to_connect, | 24 const cryptauth::RemoteDevice& device_to_connect, |
| 26 BleConnectionManager* connection_manager); | 25 BleConnectionManager* connection_manager); |
| 27 | 26 |
| 28 static void SetInstanceForTesting(Factory* factory); | 27 static void SetInstanceForTesting(Factory* factory); |
| 29 | 28 |
| 30 protected: | 29 protected: |
| 31 virtual std::unique_ptr<KeepAliveOperation> BuildInstance( | 30 virtual std::unique_ptr<KeepAliveOperation> BuildInstance( |
| 32 const cryptauth::RemoteDevice& device_to_connect, | 31 const cryptauth::RemoteDevice& device_to_connect, |
| 33 BleConnectionManager* connection_manager); | 32 BleConnectionManager* connection_manager); |
| 34 | 33 |
| 35 private: | 34 private: |
| 36 static Factory* factory_instance_; | 35 static Factory* factory_instance_; |
| 37 }; | 36 }; |
| 38 | 37 |
| 39 class Observer { | 38 class Observer { |
| 40 public: | 39 public: |
| 41 // TODO(khorimoto): This function should take a DeviceStatus once there is | 40 // |device_status| points to a valid DeviceStatus if the operation completed |
| 42 // keep-alive tickle response. | 41 // successfully and is null if the operation was not successful. |
| 43 virtual void OnOperationFinished() = 0; | 42 virtual void OnOperationFinished( |
| 43 const cryptauth::RemoteDevice& remote_device, |
| 44 std::unique_ptr<DeviceStatus> device_status) = 0; |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 KeepAliveOperation(const cryptauth::RemoteDevice& device_to_connect, | 47 KeepAliveOperation(const cryptauth::RemoteDevice& device_to_connect, |
| 47 BleConnectionManager* connection_manager); | 48 BleConnectionManager* connection_manager); |
| 48 ~KeepAliveOperation() override; | 49 ~KeepAliveOperation() override; |
| 49 | 50 |
| 50 void AddObserver(Observer* observer); | 51 void AddObserver(Observer* observer); |
| 51 void RemoveObserver(Observer* observer); | 52 void RemoveObserver(Observer* observer); |
| 52 | 53 |
| 53 protected: | 54 protected: |
| 54 // MessageTransferOperation: | 55 // MessageTransferOperation: |
| 55 void OnDeviceAuthenticated( | 56 void OnDeviceAuthenticated( |
| 56 const cryptauth::RemoteDevice& remote_device) override; | 57 const cryptauth::RemoteDevice& remote_device) override; |
| 58 void OnMessageReceived(std::unique_ptr<MessageWrapper> message_wrapper, |
| 59 const cryptauth::RemoteDevice& remote_device) override; |
| 57 void OnOperationFinished() override; | 60 void OnOperationFinished() override; |
| 58 MessageType GetMessageTypeForConnection() override; | 61 MessageType GetMessageTypeForConnection() override; |
| 59 | 62 |
| 63 std::unique_ptr<DeviceStatus> device_status_; |
| 64 |
| 60 private: | 65 private: |
| 61 friend class KeepAliveOperationTest; | 66 friend class KeepAliveOperationTest; |
| 62 | 67 |
| 68 cryptauth::RemoteDevice remote_device_; |
| 63 base::ObserverList<Observer> observer_list_; | 69 base::ObserverList<Observer> observer_list_; |
| 64 bool has_authenticated_; | |
| 65 | 70 |
| 66 DISALLOW_COPY_AND_ASSIGN(KeepAliveOperation); | 71 DISALLOW_COPY_AND_ASSIGN(KeepAliveOperation); |
| 67 }; | 72 }; |
| 68 | 73 |
| 69 } // namespace tether | 74 } // namespace tether |
| 70 | 75 |
| 71 } // namespace chromeos | 76 } // namespace chromeos |
| 72 | 77 |
| 73 #endif // CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_OPERATION_H_ | 78 #endif // CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_OPERATION_H_ |
| OLD | NEW |