OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_SCHEDULER_H_ |
| 6 #define CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_SCHEDULER_H_ |
| 7 |
| 8 #include <memory> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/weak_ptr.h" |
| 12 #include "base/timer/timer.h" |
| 13 #include "chromeos/components/tether/active_host.h" |
| 14 #include "chromeos/components/tether/keep_alive_operation.h" |
| 15 |
| 16 namespace chromeos { |
| 17 |
| 18 namespace tether { |
| 19 |
| 20 // 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 |
| 22 // is sent immediately, then another one is scheduled every 4 minutes until the |
| 23 // device disconnects. |
| 24 class KeepAliveScheduler : public ActiveHost::Observer, |
| 25 public KeepAliveOperation::Observer { |
| 26 public: |
| 27 KeepAliveScheduler(ActiveHost* active_host, |
| 28 BleConnectionManager* connection_manager); |
| 29 virtual ~KeepAliveScheduler(); |
| 30 |
| 31 // ActiveHost::Observer: |
| 32 void OnActiveHostChanged(ActiveHost::ActiveHostStatus active_host_status, |
| 33 std::unique_ptr<cryptauth::RemoteDevice> active_host, |
| 34 const std::string& wifi_network_id) override; |
| 35 |
| 36 // KeepAliveOperation::Observer: |
| 37 void OnOperationFinished() override; |
| 38 |
| 39 private: |
| 40 friend class KeepAliveSchedulerTest; |
| 41 |
| 42 KeepAliveScheduler(ActiveHost* active_host, |
| 43 BleConnectionManager* connection_manager, |
| 44 std::unique_ptr<base::Timer> timer); |
| 45 |
| 46 void SendKeepAliveTickle(); |
| 47 |
| 48 static const uint32_t kKeepAliveIntervalMinutes; |
| 49 |
| 50 ActiveHost* active_host_; |
| 51 BleConnectionManager* connection_manager_; |
| 52 |
| 53 std::unique_ptr<base::Timer> timer_; |
| 54 std::unique_ptr<cryptauth::RemoteDevice> active_host_device_; |
| 55 std::unique_ptr<KeepAliveOperation> keep_alive_operation_; |
| 56 |
| 57 base::WeakPtrFactory<KeepAliveScheduler> weak_ptr_factory_; |
| 58 |
| 59 DISALLOW_COPY_AND_ASSIGN(KeepAliveScheduler); |
| 60 }; |
| 61 |
| 62 } // namespace tether |
| 63 |
| 64 } // namespace chromeos |
| 65 |
| 66 #endif // CHROMEOS_COMPONENTS_TETHER_KEEP_ALIVE_SCHEDULER_H_ |
OLD | NEW |