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

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

Issue 2587783003: [CrOS Tether] Fix miscellaneous issues with HostScanScheduler. (Closed)
Patch Set: Created 4 years 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/dbus/power_manager_client.h"
9 #include "chromeos/login/login_state.h" 9 #include "chromeos/login/login_state.h"
10 #include "chromeos/network/network_state_handler_observer.h" 10 #include "chromeos/network/network_state_handler_observer.h"
(...skipping 12 matching lines...) Expand all
23 class LoginState; 23 class LoginState;
24 class PowerManagerClient; 24 class PowerManagerClient;
25 25
26 namespace tether { 26 namespace tether {
27 27
28 class HostScanner; 28 class HostScanner;
29 29
30 // Schedules scans for tether hosts. To start a scan attempt, three conditions 30 // Schedules scans for tether hosts. To start a scan attempt, three conditions
31 // must be true: 31 // must be true:
32 // 32 //
33 // (1) The user has just started using the device; specifically, the user has 33 // (1) The user has just logged in or has just resumed using the device after
34 // just logged in or has just resumed using the device after it had been 34 // it had been sleeping/suspended.
35 // sleeping/suspended.
36 // (2) The device does not have an Internet connection. 35 // (2) The device does not have an Internet connection.
37 // (3) The device has synced data about other devices belonging to the user's 36 // (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 37 // account, and at least one of those devices is capable of being a tether
39 // host (i.e., it has a mobile data connection). 38 // host (i.e., it has a mobile data connection).
40 // 39 //
41 // When one of those conditions changes, this class checks the conditions and 40 // When one of those conditions changes, this class checks the conditions and
42 // starts a scan automatically. Alternatively, a scan can be explicitly 41 // starts a scan automatically. Alternatively, a scan can be explicitly
43 // triggered via ScheduleScanNowIfPossible(). 42 // triggered via ScheduleScanNowIfPossible().
44 class HostScanScheduler : public LoginState::Observer, 43 class HostScanScheduler : public LoginState::Observer,
45 public PowerManagerClient::Observer, 44 public PowerManagerClient::Observer,
(...skipping 22 matching lines...) Expand all
68 void NetworkConnectionStateChanged(const NetworkState* network) override; 67 void NetworkConnectionStateChanged(const NetworkState* network) override;
69 68
70 // cryptauth::CryptAuthDeviceManager::Observer 69 // cryptauth::CryptAuthDeviceManager::Observer
71 void OnSyncFinished(cryptauth::CryptAuthDeviceManager::SyncResult sync_result, 70 void OnSyncFinished(cryptauth::CryptAuthDeviceManager::SyncResult sync_result,
72 cryptauth::CryptAuthDeviceManager::DeviceChangeResult 71 cryptauth::CryptAuthDeviceManager::DeviceChangeResult
73 device_change_result) override; 72 device_change_result) override;
74 73
75 private: 74 private:
76 friend class HostScanSchedulerTest; 75 friend class HostScanSchedulerTest;
77 76
78 class Context { 77 class Delegate {
79 public: 78 public:
80 virtual void AddObserver(HostScanScheduler* host_scan_scheduler) = 0; 79 virtual void AddObserver(HostScanScheduler* host_scan_scheduler) = 0;
81 virtual void RemoveObserver(HostScanScheduler* host_scan_scheduler) = 0; 80 virtual void RemoveObserver(HostScanScheduler* host_scan_scheduler) = 0;
82 virtual bool IsAuthenticatedUserLoggedIn() const = 0; 81 virtual bool IsAuthenticatedUserLoggedIn() const = 0;
83 virtual bool IsNetworkConnectedOrConnecting() const = 0; 82 virtual bool IsNetworkConnectedOrConnecting() const = 0;
84 virtual bool AreTetherHostsSynced() const = 0; 83 virtual bool AreTetherHostsSynced() const = 0;
85 }; 84 };
86 85
87 class ContextImpl : public Context { 86 class DelegateImpl : public Delegate {
88 public: 87 public:
89 ContextImpl(const content::BrowserContext* browser_context); 88 DelegateImpl(const content::BrowserContext* browser_context);
90 89
91 void AddObserver(HostScanScheduler* host_scan_scheduler) override; 90 void AddObserver(HostScanScheduler* host_scan_scheduler) override;
92 void RemoveObserver(HostScanScheduler* host_scan_scheduler) override; 91 void RemoveObserver(HostScanScheduler* host_scan_scheduler) override;
93 bool IsAuthenticatedUserLoggedIn() const override; 92 bool IsAuthenticatedUserLoggedIn() const override;
94 bool IsNetworkConnectedOrConnecting() const override; 93 bool IsNetworkConnectedOrConnecting() const override;
95 bool AreTetherHostsSynced() const override; 94 bool AreTetherHostsSynced() const override;
96 }; 95 };
97 96
98 HostScanScheduler(std::unique_ptr<Context> context_, 97 HostScanScheduler(std::unique_ptr<Delegate> delegate,
99 std::unique_ptr<HostScanner> host_scanner); 98 std::unique_ptr<HostScanner> host_scanner);
100 99
101 std::unique_ptr<Context> context_; 100 std::unique_ptr<Delegate> delegate_;
102 std::unique_ptr<HostScanner> host_scanner_; 101 std::unique_ptr<HostScanner> host_scanner_;
103 bool initialized_; 102 bool initialized_;
104 103
105 DISALLOW_COPY_AND_ASSIGN(HostScanScheduler); 104 DISALLOW_COPY_AND_ASSIGN(HostScanScheduler);
106 }; 105 };
107 106
108 } // namespace tether 107 } // namespace tether
109 108
110 } // namespace chromeos 109 } // namespace chromeos
111 110
112 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_SCHEDULER_H 111 #endif // CHROMEOS_COMPONENTS_TETHER_HOST_SCAN_SCHEDULER_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698