Chromium Code Reviews| 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_ACTIVE_HOST_H_ | |
| 6 #define CHROMEOS_COMPONENTS_TETHER_ACTIVE_HOST_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/callback.h" | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 | |
| 14 class PrefRegistrySimple; | |
| 15 class PrefService; | |
| 16 | |
| 17 namespace cryptauth { | |
| 18 struct RemoteDevice; | |
| 19 } // namespace cryptauth | |
| 20 | |
| 21 namespace chromeos { | |
| 22 | |
| 23 namespace tether { | |
| 24 | |
| 25 class TetherHostFetcher; | |
| 26 | |
| 27 // ActiveHost tracks metadata about the current connection to a tether host. | |
| 28 // This data is persisted to user preferences. | |
| 29 class ActiveHost { | |
| 30 public: | |
| 31 // Enumeration used to describe the state of the active connection to a tether | |
| 32 // host. | |
| 33 enum class ActiveHostStatus { | |
| 34 DISCONNECTED = 0, | |
| 35 CONNECTING = 1, | |
| 36 CONNECTED = 2 | |
| 37 }; | |
| 38 | |
| 39 ActiveHost(TetherHostFetcher* tether_host_fetcher, PrefService* pref_service); | |
| 40 virtual ~ActiveHost(); | |
| 41 | |
| 42 // Registers the prefs used by this class to the given |registry|. | |
| 43 static void RegisterPrefs(PrefRegistrySimple* registry); | |
| 44 | |
| 45 // Sets the active host to be no host at all (i.e., the local device is not | |
| 46 // connecting or connected to a tether host). | |
| 47 void SetActiveHostDisconnected(); | |
| 48 | |
| 49 // Sets the active host to be the device with ID |active_host_device_id| and | |
| 50 // records that the there is an active attempt to connect to that host (i.e., | |
| 51 // the host is not yet connected but it is in the process of connecting). | |
| 52 void SetActiveHostConnecting(const std::string& active_host_device_id); | |
| 53 | |
| 54 // Sets the active host to be the device with ID |active_host_device_id| and | |
| 55 // that the local device is connected to that device on the mobile hotspot | |
| 56 // with SSID |tether_network_ssid|. | |
| 57 void SetActiveHostConnected(const std::string& active_host_device_id, | |
| 58 const std::string& tether_network_ssid); | |
| 59 | |
| 60 // Gets the active host and associated metadata asynchronously. If | |
| 61 // the active host status is... | |
| 62 // DISCONNECTED: The callback's |active_host| parameter will be nullptr | |
| 63 // and |tether_network_ssid| parameter will be "". | |
| 64 // CONNECTING: The callback's |tether_network_ssid| will be "". | |
| 65 // CONNECTED: All three parameter will be present. | |
| 66 using ActiveHostCallback = | |
| 67 base::Callback<void(ActiveHostStatus active_host_status, | |
| 68 std::unique_ptr<cryptauth::RemoteDevice> active_host, | |
| 69 const std::string& tether_network_ssid)>; | |
|
Ryan Hansberry
2017/03/09 17:20:48
We'll be referencing the Wi-Fi network by its netw
Kyle Horimoto
2017/03/09 18:42:00
Done.
| |
| 70 void GetActiveHost(const ActiveHostCallback& active_host_callback); | |
| 71 | |
| 72 // Synchronous getter methods which do not return a full RemoteDevice object. | |
| 73 ActiveHostStatus GetActiveHostStatus() const; | |
| 74 const std::string GetActiveHostDeviceId() const; | |
| 75 const std::string GetTetherNetworkSsid() const; | |
| 76 | |
| 77 private: | |
| 78 void SetActiveHost(ActiveHostStatus active_host_status, | |
| 79 const std::string& active_host_device_id, | |
| 80 const std::string& tether_network_ssid); | |
| 81 | |
| 82 void OnTetherHostFetched( | |
| 83 const ActiveHostCallback& active_host_callback, | |
| 84 std::unique_ptr<cryptauth::RemoteDevice> remote_device); | |
| 85 | |
| 86 TetherHostFetcher* tether_host_fetcher_; | |
| 87 PrefService* pref_service_; | |
| 88 | |
| 89 base::WeakPtrFactory<ActiveHost> weak_ptr_factory_; | |
| 90 | |
| 91 DISALLOW_COPY_AND_ASSIGN(ActiveHost); | |
| 92 }; | |
| 93 | |
| 94 } // namespace tether | |
| 95 | |
| 96 } // namespace chromeos | |
| 97 | |
| 98 #endif // CHROMEOS_COMPONENTS_TETHER_ACTIVE_HOST_H_ | |
| OLD | NEW |