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_SCHEDULER_H_ | 5 #ifndef CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_SCHEDULER_H_ |
6 #define CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_SCHEDULER_H_ | 6 #define CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_SCHEDULER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
12 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
13 #include "chromeos/components/tether/active_host.h" | 13 #include "chromeos/components/tether/active_host.h" |
| 14 #include "chromeos/components/tether/device_status_util.h" |
14 #include "chromeos/components/tether/keep_alive_operation.h" | 15 #include "chromeos/components/tether/keep_alive_operation.h" |
15 | 16 |
16 namespace chromeos { | 17 namespace chromeos { |
17 | 18 |
18 namespace tether { | 19 namespace tether { |
19 | 20 |
| 21 class HostScanCache; |
| 22 class DeviceIdTetherNetworkGuidMap; |
| 23 |
20 // Schedules keep-alive messages to be sent when this device is connected to a | 24 // Schedules keep-alive messages to be sent when this device is connected to a |
21 // remote device's tether hotspot. When a device connects, a keep-alive message | 25 // remote device's tether hotspot. When a device connects, a keep-alive message |
22 // is sent immediately, then another one is scheduled every 4 minutes until the | 26 // is sent immediately, then another one is scheduled every 4 minutes until the |
23 // device disconnects. | 27 // device disconnects. |
24 class KeepAliveScheduler : public ActiveHost::Observer, | 28 class KeepAliveScheduler : public ActiveHost::Observer, |
25 public KeepAliveOperation::Observer { | 29 public KeepAliveOperation::Observer { |
26 public: | 30 public: |
27 KeepAliveScheduler(ActiveHost* active_host, | 31 KeepAliveScheduler( |
28 BleConnectionManager* connection_manager); | 32 ActiveHost* active_host, |
| 33 BleConnectionManager* connection_manager, |
| 34 HostScanCache* host_scan_cache, |
| 35 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map); |
29 virtual ~KeepAliveScheduler(); | 36 virtual ~KeepAliveScheduler(); |
30 | 37 |
31 // ActiveHost::Observer: | 38 // ActiveHost::Observer: |
32 void OnActiveHostChanged( | 39 void OnActiveHostChanged( |
33 const ActiveHost::ActiveHostChangeInfo& change_info) override; | 40 const ActiveHost::ActiveHostChangeInfo& change_info) override; |
34 | 41 |
35 // KeepAliveOperation::Observer: | 42 // KeepAliveOperation::Observer: |
36 void OnOperationFinished() override; | 43 void OnOperationFinished( |
| 44 const cryptauth::RemoteDevice& remote_device, |
| 45 std::unique_ptr<DeviceStatus> device_status) override; |
37 | 46 |
38 private: | 47 private: |
39 friend class KeepAliveSchedulerTest; | 48 friend class KeepAliveSchedulerTest; |
40 | 49 |
41 KeepAliveScheduler(ActiveHost* active_host, | 50 KeepAliveScheduler( |
42 BleConnectionManager* connection_manager, | 51 ActiveHost* active_host, |
43 std::unique_ptr<base::Timer> timer); | 52 BleConnectionManager* connection_manager, |
| 53 HostScanCache* host_scan_cache, |
| 54 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map, |
| 55 std::unique_ptr<base::Timer> timer); |
44 | 56 |
45 void SendKeepAliveTickle(); | 57 void SendKeepAliveTickle(); |
46 | 58 |
47 static const uint32_t kKeepAliveIntervalMinutes; | 59 static const uint32_t kKeepAliveIntervalMinutes; |
48 | 60 |
49 ActiveHost* active_host_; | 61 ActiveHost* active_host_; |
50 BleConnectionManager* connection_manager_; | 62 BleConnectionManager* connection_manager_; |
| 63 HostScanCache* host_scan_cache_; |
| 64 DeviceIdTetherNetworkGuidMap* device_id_tether_network_guid_map_; |
51 | 65 |
52 std::unique_ptr<base::Timer> timer_; | 66 std::unique_ptr<base::Timer> timer_; |
53 std::shared_ptr<cryptauth::RemoteDevice> active_host_device_; | 67 std::shared_ptr<cryptauth::RemoteDevice> active_host_device_; |
54 std::unique_ptr<KeepAliveOperation> keep_alive_operation_; | 68 std::unique_ptr<KeepAliveOperation> keep_alive_operation_; |
55 | 69 |
56 base::WeakPtrFactory<KeepAliveScheduler> weak_ptr_factory_; | 70 base::WeakPtrFactory<KeepAliveScheduler> weak_ptr_factory_; |
57 | 71 |
58 DISALLOW_COPY_AND_ASSIGN(KeepAliveScheduler); | 72 DISALLOW_COPY_AND_ASSIGN(KeepAliveScheduler); |
59 }; | 73 }; |
60 | 74 |
61 } // namespace tether | 75 } // namespace tether |
62 | 76 |
63 } // namespace chromeos | 77 } // namespace chromeos |
64 | 78 |
65 #endif // CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_SCHEDULER_H_ | 79 #endif // CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_SCHEDULER_H_ |
OLD | NEW |