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

Side by Side 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: Created 3 years, 6 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 unified diff | Download patch
OLDNEW
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
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 void SetWaitForResponse(bool wait_for_response) {
khorimoto 2017/05/31 17:26:35 Instead, please use the protected function pattern
Ryan Hansberry 2017/05/31 21:19:04 Done. Same done for response_timeout_seconds.
76 wait_for_response_ = wait_for_response;
77 }
78
73 std::vector<cryptauth::RemoteDevice>& remote_devices() { 79 std::vector<cryptauth::RemoteDevice>& remote_devices() {
74 return remote_devices_; 80 return remote_devices_;
75 } 81 }
76 82
83 void SetTimerFactoryForTest(
khorimoto 2017/05/31 17:26:35 Please make this private. You can add a friend rel
Kyle Horimoto 2017/05/31 21:55:33 Ping.
Ryan Hansberry 2017/06/01 00:31:58 Done.
84 std::unique_ptr<TimerFactory> timer_factory_for_test);
85
77 private: 86 private:
78 friend class ConnectTetheringOperationTest; 87 friend class ConnectTetheringOperationTest;
79 friend class DisconnectTetheringOperationTest; 88 friend class DisconnectTetheringOperationTest;
80 friend class HostScannerOperationTest; 89 friend class HostScannerOperationTest;
81 friend class MessageTransferOperationTest; 90 friend class MessageTransferOperationTest;
82 91
83 static uint32_t kMaxConnectionAttemptsPerDevice; 92 static uint32_t kMaxConnectionAttemptsPerDevice;
84 93
94 // The number of seconds the client should generally wait for a response from
95 // the host once an authenticated connection is established. Once this amount
96 // of time passes, the connection will be closed. Subclasses of
97 // MessageTransferOperation may desire a shorter or longer duration; see
98 // SetResponseTimeout().
khorimoto 2017/05/31 17:26:35 There is no SetResponseTimeout() - I think you for
Ryan Hansberry 2017/05/31 21:19:04 Done.
99 static uint32_t kResponseTimeoutSeconds;
khorimoto 2017/05/31 17:26:35 Actually, this is probably more easily expressed u
Ryan Hansberry 2017/05/31 21:19:04 Discussed offline; skipping over this due to linki
100
101 void StartResponseTimerForDevice(
102 const cryptauth::RemoteDevice& remote_device);
103 void StopResponseTimerForDevice(const cryptauth::RemoteDevice& remote_device);
104 void OnResponseTimeout(const cryptauth::RemoteDevice& remote_device);
105
106 // Exposed for testing.
107 base::Timer* GetResponseTimerForDevice(
khorimoto 2017/05/31 17:26:35 Please avoid exposing private fields via getters l
Ryan Hansberry 2017/05/31 21:19:03 I'd prefer not to emulate the logic in host_scan_c
Kyle Horimoto 2017/05/31 21:55:33 Sorry - I'd still like you to change this. The rea
Ryan Hansberry 2017/06/01 00:31:58 Resolved offline -- Done.
108 const cryptauth::RemoteDevice& remote_device) {
109 return remote_device_to_timer_map_[remote_device].get();
110 }
111
85 std::vector<cryptauth::RemoteDevice> remote_devices_; 112 std::vector<cryptauth::RemoteDevice> remote_devices_;
86 BleConnectionManager* connection_manager_; 113 BleConnectionManager* connection_manager_;
114 std::unique_ptr<TimerFactory> timer_factory_;
87 115
88 bool initialized_; 116 bool initialized_;
117 bool wait_for_response_;
118 uint32_t response_timeout_seconds_;
89 std::map<cryptauth::RemoteDevice, uint32_t> 119 std::map<cryptauth::RemoteDevice, uint32_t>
90 remote_device_to_num_attempts_map_; 120 remote_device_to_num_attempts_map_;
121 std::map<cryptauth::RemoteDevice, std::unique_ptr<base::Timer>>
122 remote_device_to_timer_map_;
123 base::WeakPtrFactory<MessageTransferOperation> weak_ptr_factory_;
91 124
92 DISALLOW_COPY_AND_ASSIGN(MessageTransferOperation); 125 DISALLOW_COPY_AND_ASSIGN(MessageTransferOperation);
93 }; 126 };
94 127
95 } // namespace tether 128 } // namespace tether
96 129
97 } // namespace chromeos 130 } // namespace chromeos
98 131
99 #endif // CHROMEOS_COMPONENTS_TETHER_MESSAGE_TRANSFER_OPERATION_H_ 132 #endif // CHROMEOS_COMPONENTS_TETHER_MESSAGE_TRANSFER_OPERATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698