Chromium Code Reviews| 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_MESSAGE_TRANSFER_OPERATION_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_MESSAGE_TRANSFER_OPERATION_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_MESSAGE_TRANSFER_OPERATION_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_MESSAGE_TRANSFER_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/timer/timer.h" | |
| 12 #include "chromeos/components/tether/ble_connection_manager.h" | 13 #include "chromeos/components/tether/ble_connection_manager.h" |
| 13 | 14 |
| 14 namespace chromeos { | 15 namespace chromeos { |
| 15 | 16 |
| 16 namespace tether { | 17 namespace tether { |
| 17 | 18 |
| 18 class MessageWrapper; | 19 class MessageWrapper; |
| 20 class TimerFactory; | |
| 19 | 21 |
| 20 // Abstract base class used for operations which send and/or receive messages | 22 // Abstract base class used for operations which send and/or receive messages |
| 21 // from remote devices. | 23 // from remote devices. |
| 22 class MessageTransferOperation : public BleConnectionManager::Observer { | 24 class MessageTransferOperation : public BleConnectionManager::Observer { |
| 23 public: | 25 public: |
| 24 MessageTransferOperation( | 26 MessageTransferOperation( |
| 25 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, | 27 const std::vector<cryptauth::RemoteDevice>& devices_to_connect, |
| 26 BleConnectionManager* connection_manager); | 28 BleConnectionManager* connection_manager); |
| 27 virtual ~MessageTransferOperation(); | 29 virtual ~MessageTransferOperation(); |
| 28 | 30 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 // Callback executed when the operation has started (i.e., in Initialize()). | 65 // Callback executed when the operation has started (i.e., in Initialize()). |
| 64 virtual void OnOperationStarted() {} | 66 virtual void OnOperationStarted() {} |
| 65 | 67 |
| 66 // Callback executed when the operation has finished (i.e., when all devices | 68 // Callback executed when the operation has finished (i.e., when all devices |
| 67 // have been unregistered). | 69 // have been unregistered). |
| 68 virtual void OnOperationFinished() {} | 70 virtual void OnOperationFinished() {} |
| 69 | 71 |
| 70 // Returns the type of message that this operation intends to send. | 72 // Returns the type of message that this operation intends to send. |
| 71 virtual MessageType GetMessageTypeForConnection() = 0; | 73 virtual MessageType GetMessageTypeForConnection() = 0; |
| 72 | 74 |
| 75 // Returns true if we should wait for a response from the host device. | |
|
Kyle Horimoto
2017/05/31 21:55:33
Also describe what the consequences of this are (i
Ryan Hansberry
2017/06/01 00:31:58
Done.
| |
| 76 virtual bool ShouldWaitForResponse(); | |
| 77 | |
| 78 // The number of seconds that we should wait for a response from the host. If | |
| 79 // ShouldWaitForResponse() returns false, this method is never used. | |
| 80 virtual uint32_t GetResponseTimeoutSeconds(); | |
| 81 | |
| 73 std::vector<cryptauth::RemoteDevice>& remote_devices() { | 82 std::vector<cryptauth::RemoteDevice>& remote_devices() { |
| 74 return remote_devices_; | 83 return remote_devices_; |
| 75 } | 84 } |
| 76 | 85 |
| 86 void SetTimerFactoryForTest( | |
| 87 std::unique_ptr<TimerFactory> timer_factory_for_test); | |
| 88 | |
| 77 private: | 89 private: |
| 78 friend class ConnectTetheringOperationTest; | 90 friend class ConnectTetheringOperationTest; |
| 79 friend class DisconnectTetheringOperationTest; | 91 friend class DisconnectTetheringOperationTest; |
| 80 friend class HostScannerOperationTest; | 92 friend class HostScannerOperationTest; |
| 81 friend class MessageTransferOperationTest; | 93 friend class MessageTransferOperationTest; |
| 82 | 94 |
| 83 static uint32_t kMaxConnectionAttemptsPerDevice; | 95 static uint32_t kMaxConnectionAttemptsPerDevice; |
| 84 | 96 |
| 97 // The number of seconds the client should generally wait for a response from | |
| 98 // the host once an authenticated connection is established. Once this amount | |
| 99 // of time passes, the connection will be closed. Subclasses of | |
| 100 // MessageTransferOperation should override GetResponseTimeoutSeconds() | |
| 101 // if they desire a shorter or longer duration. | |
| 102 static uint32_t kResponseTimeoutSeconds; | |
|
Kyle Horimoto
2017/05/31 21:55:33
Name this kDefaultResponseTimeoutSeconds and edit
Ryan Hansberry
2017/06/01 00:31:58
Done.
| |
| 103 | |
| 104 void StartResponseTimerForDevice( | |
| 105 const cryptauth::RemoteDevice& remote_device); | |
| 106 void StopResponseTimerForDevice(const cryptauth::RemoteDevice& remote_device); | |
| 107 void OnResponseTimeout(const cryptauth::RemoteDevice& remote_device); | |
| 108 | |
| 109 // Exposed for testing. | |
| 110 base::Timer* GetResponseTimerForDevice( | |
| 111 const cryptauth::RemoteDevice& remote_device) { | |
| 112 return remote_device_to_timer_map_[remote_device].get(); | |
| 113 } | |
| 114 | |
| 85 std::vector<cryptauth::RemoteDevice> remote_devices_; | 115 std::vector<cryptauth::RemoteDevice> remote_devices_; |
| 86 BleConnectionManager* connection_manager_; | 116 BleConnectionManager* connection_manager_; |
| 117 std::unique_ptr<TimerFactory> timer_factory_; | |
| 87 | 118 |
| 88 bool initialized_; | 119 bool initialized_; |
| 89 std::map<cryptauth::RemoteDevice, uint32_t> | 120 std::map<cryptauth::RemoteDevice, uint32_t> |
| 90 remote_device_to_num_attempts_map_; | 121 remote_device_to_num_attempts_map_; |
| 122 std::map<cryptauth::RemoteDevice, std::unique_ptr<base::Timer>> | |
| 123 remote_device_to_timer_map_; | |
| 124 base::WeakPtrFactory<MessageTransferOperation> weak_ptr_factory_; | |
| 91 | 125 |
| 92 DISALLOW_COPY_AND_ASSIGN(MessageTransferOperation); | 126 DISALLOW_COPY_AND_ASSIGN(MessageTransferOperation); |
| 93 }; | 127 }; |
| 94 | 128 |
| 95 } // namespace tether | 129 } // namespace tether |
| 96 | 130 |
| 97 } // namespace chromeos | 131 } // namespace chromeos |
| 98 | 132 |
| 99 #endif // CHROMEOS_COMPONENTS_TETHER_MESSAGE_TRANSFER_OPERATION_H_ | 133 #endif // CHROMEOS_COMPONENTS_TETHER_MESSAGE_TRANSFER_OPERATION_H_ |
| OLD | NEW |