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