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

Side by Side Diff: chromeos/components/tether/host_scan_scheduler.h

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

Powered by Google App Engine
This is Rietveld 408576698