| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 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_HOST_SCAN_SCHEDULER_H |
| 6 #define CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_SCHEDULER_H |
| 7 |
| 8 #include "chromeos/dbus/power_manager_client.h" |
| 9 #include "chromeos/login/login_state.h" |
| 10 #include "chromeos/network/network_state_handler_observer.h" |
| 11 #include "components/cryptauth/cryptauth_device_manager.h" |
| 12 |
| 13 namespace content { |
| 14 class BrowserContext; |
| 15 } |
| 16 |
| 17 namespace cryptauth { |
| 18 class CryptAuthDeviceManager; |
| 19 } |
| 20 |
| 21 namespace chromeos { |
| 22 |
| 23 class LoginState; |
| 24 class PowerManagerClient; |
| 25 |
| 26 namespace tether { |
| 27 |
| 28 class HostScanner; |
| 29 |
| 30 // Schedules scans for tether hosts. To start a scan attempt, three conditions |
| 31 // must be true: |
| 32 // |
| 33 // (1) The user has just started using the device; specifically, the user has |
| 34 // just logged in or has just resumed using the device after it had been |
| 35 // sleeping/suspended. |
| 36 // (2) The device does not have an Internet connection. |
| 37 // (3) The device has synced data about other devices belonging to the user's |
| 38 // account, and at least one of those devices is capable of being a tether |
| 39 // host (i.e., it has a mobile data connection). |
| 40 // |
| 41 // When one of those conditions changes, this class checks the conditions and |
| 42 // starts a scan automatically. Alternatively, a scan can be explicitly |
| 43 // triggered via ScheduleScanNowIfPossible(). |
| 44 class HostScanScheduler : public LoginState::Observer, |
| 45 public PowerManagerClient::Observer, |
| 46 public NetworkStateHandlerObserver, |
| 47 public cryptauth::CryptAuthDeviceManager::Observer { |
| 48 public: |
| 49 HostScanScheduler(const content::BrowserContext* browser_context, |
| 50 std::unique_ptr<HostScanner> host_scanner); |
| 51 ~HostScanScheduler() override; |
| 52 |
| 53 // Sets up listeners so that scans can be automatically triggered when |
| 54 // needed. |
| 55 void InitializeAutomaticScans(); |
| 56 |
| 57 // Schedules a scan now if the three conditions described above are met and |
| 58 // returns whether the scan was started. |
| 59 bool ScheduleScanNowIfPossible(); |
| 60 |
| 61 // LoginState::Observer |
| 62 void LoggedInStateChanged() override; |
| 63 |
| 64 // PowerManagerClient::Observer |
| 65 void SuspendDone(const base::TimeDelta& sleep_duration) override; |
| 66 |
| 67 // NetworkStateHandlerObserver |
| 68 void NetworkConnectionStateChanged(const NetworkState* network) override; |
| 69 |
| 70 // cryptauth::CryptAuthDeviceManager::Observer |
| 71 void OnSyncFinished(cryptauth::CryptAuthDeviceManager::SyncResult sync_result, |
| 72 cryptauth::CryptAuthDeviceManager::DeviceChangeResult |
| 73 device_change_result) override; |
| 74 |
| 75 private: |
| 76 friend class HostScanSchedulerTest; |
| 77 |
| 78 class Context { |
| 79 public: |
| 80 virtual void AddObserver(HostScanScheduler* host_scan_scheduler) = 0; |
| 81 virtual void RemoveObserver(HostScanScheduler* host_scan_scheduler) = 0; |
| 82 virtual bool IsAuthenticatedUserLoggedIn() const = 0; |
| 83 virtual bool IsNetworkConnectedOrConnecting() const = 0; |
| 84 virtual bool AreTetherHostsSynced() const = 0; |
| 85 }; |
| 86 |
| 87 class ContextImpl : public Context { |
| 88 public: |
| 89 ContextImpl(const content::BrowserContext* browser_context); |
| 90 |
| 91 void AddObserver(HostScanScheduler* host_scan_scheduler) override; |
| 92 void RemoveObserver(HostScanScheduler* host_scan_scheduler) override; |
| 93 bool IsAuthenticatedUserLoggedIn() const override; |
| 94 bool IsNetworkConnectedOrConnecting() const override; |
| 95 bool AreTetherHostsSynced() const override; |
| 96 }; |
| 97 |
| 98 HostScanScheduler(std::unique_ptr<Context> context_, |
| 99 std::unique_ptr<HostScanner> host_scanner); |
| 100 |
| 101 std::unique_ptr<Context> context_; |
| 102 std::unique_ptr<HostScanner> host_scanner_; |
| 103 bool initialized_; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(HostScanScheduler); |
| 106 }; |
| 107 |
| 108 } // namespace tether |
| 109 |
| 110 } // namespace chromeos |
| 111 |
| 112 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_SCHEDULER_H |
| OLD | NEW |