Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Unified Diff: chromeos/components/tether/message_transfer_operation.h

Issue 2915713002: Tether MessageTransferOperation: Only wait for a response from a host for a certain amount of time … (Closed)
Patch Set: khorimoto@ comments. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chromeos/components/tether/message_transfer_operation.h
diff --git a/chromeos/components/tether/message_transfer_operation.h b/chromeos/components/tether/message_transfer_operation.h
index 3265214002750504c3e40f3c9e71205d82c4d08f..9d9e664e24e443794097b275694a080c7e011c74 100644
--- a/chromeos/components/tether/message_transfer_operation.h
+++ b/chromeos/components/tether/message_transfer_operation.h
@@ -9,6 +9,7 @@
#include <vector>
#include "base/macros.h"
+#include "base/timer/timer.h"
#include "chromeos/components/tether/ble_connection_manager.h"
namespace chromeos {
@@ -16,6 +17,7 @@ namespace chromeos {
namespace tether {
class MessageWrapper;
+class TimerFactory;
// Abstract base class used for operations which send and/or receive messages
// from remote devices.
@@ -70,10 +72,20 @@ class MessageTransferOperation : public BleConnectionManager::Observer {
// Returns the type of message that this operation intends to send.
virtual MessageType GetMessageTypeForConnection() = 0;
+ // 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.
+ virtual bool ShouldWaitForResponse();
+
+ // The number of seconds that we should wait for a response from the host. If
+ // ShouldWaitForResponse() returns false, this method is never used.
+ virtual uint32_t GetResponseTimeoutSeconds();
+
std::vector<cryptauth::RemoteDevice>& remote_devices() {
return remote_devices_;
}
+ void SetTimerFactoryForTest(
+ std::unique_ptr<TimerFactory> timer_factory_for_test);
+
private:
friend class ConnectTetheringOperationTest;
friend class DisconnectTetheringOperationTest;
@@ -82,12 +94,34 @@ class MessageTransferOperation : public BleConnectionManager::Observer {
static uint32_t kMaxConnectionAttemptsPerDevice;
+ // The number of seconds the client should generally wait for a response from
+ // the host once an authenticated connection is established. Once this amount
+ // of time passes, the connection will be closed. Subclasses of
+ // MessageTransferOperation should override GetResponseTimeoutSeconds()
+ // if they desire a shorter or longer duration.
+ 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.
+
+ void StartResponseTimerForDevice(
+ const cryptauth::RemoteDevice& remote_device);
+ void StopResponseTimerForDevice(const cryptauth::RemoteDevice& remote_device);
+ void OnResponseTimeout(const cryptauth::RemoteDevice& remote_device);
+
+ // Exposed for testing.
+ base::Timer* GetResponseTimerForDevice(
+ const cryptauth::RemoteDevice& remote_device) {
+ return remote_device_to_timer_map_[remote_device].get();
+ }
+
std::vector<cryptauth::RemoteDevice> remote_devices_;
BleConnectionManager* connection_manager_;
+ std::unique_ptr<TimerFactory> timer_factory_;
bool initialized_;
std::map<cryptauth::RemoteDevice, uint32_t>
remote_device_to_num_attempts_map_;
+ std::map<cryptauth::RemoteDevice, std::unique_ptr<base::Timer>>
+ remote_device_to_timer_map_;
+ base::WeakPtrFactory<MessageTransferOperation> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(MessageTransferOperation);
};

Powered by Google App Engine
This is Rietveld 408576698