Chromium Code Reviews| Index: chromeos/components/tether/active_host.h |
| diff --git a/chromeos/components/tether/active_host.h b/chromeos/components/tether/active_host.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..38e850a7dac96adf847a8217ac9b63b6e3bd4277 |
| --- /dev/null |
| +++ b/chromeos/components/tether/active_host.h |
| @@ -0,0 +1,98 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROMEOS_COMPONENTS_TETHER_ACTIVE_HOST_H_ |
| +#define CHROMEOS_COMPONENTS_TETHER_ACTIVE_HOST_H_ |
| + |
| +#include <string> |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/weak_ptr.h" |
| + |
| +class PrefRegistrySimple; |
| +class PrefService; |
| + |
| +namespace cryptauth { |
| +struct RemoteDevice; |
| +} // namespace cryptauth |
| + |
| +namespace chromeos { |
| + |
| +namespace tether { |
| + |
| +class TetherHostFetcher; |
| + |
| +// ActiveHost tracks metadata about the current connection to a tether host. |
| +// This data is persisted to user preferences. |
| +class ActiveHost { |
| + public: |
| + // Enumeration used to describe the state of the active connection to a tether |
| + // host. |
| + enum class ActiveHostStatus { |
| + DISCONNECTED = 0, |
| + CONNECTING = 1, |
| + CONNECTED = 2 |
| + }; |
| + |
| + ActiveHost(TetherHostFetcher* tether_host_fetcher, PrefService* pref_service); |
| + virtual ~ActiveHost(); |
| + |
| + // Registers the prefs used by this class to the given |registry|. |
| + static void RegisterPrefs(PrefRegistrySimple* registry); |
| + |
| + // Sets the active host to be no host at all (i.e., the local device is not |
| + // connecting or connected to a tether host). |
| + void SetActiveHostDisconnected(); |
| + |
| + // Sets the active host to be the device with ID |active_host_device_id| and |
| + // records that the there is an active attempt to connect to that host (i.e., |
| + // the host is not yet connected but it is in the process of connecting). |
| + void SetActiveHostConnecting(const std::string& active_host_device_id); |
| + |
| + // Sets the active host to be the device with ID |active_host_device_id| and |
| + // that the local device is connected to that device on the mobile hotspot |
| + // with SSID |tether_network_ssid|. |
| + void SetActiveHostConnected(const std::string& active_host_device_id, |
| + const std::string& tether_network_ssid); |
| + |
| + // Gets the active host and associated metadata asynchronously. If |
| + // the active host status is... |
| + // DISCONNECTED: The callback's |active_host| parameter will be nullptr |
| + // and |tether_network_ssid| parameter will be "". |
| + // CONNECTING: The callback's |tether_network_ssid| will be "". |
| + // CONNECTED: All three parameter will be present. |
| + using ActiveHostCallback = |
| + base::Callback<void(ActiveHostStatus active_host_status, |
| + std::unique_ptr<cryptauth::RemoteDevice> active_host, |
| + 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.
|
| + void GetActiveHost(const ActiveHostCallback& active_host_callback); |
| + |
| + // Synchronous getter methods which do not return a full RemoteDevice object. |
| + ActiveHostStatus GetActiveHostStatus() const; |
| + const std::string GetActiveHostDeviceId() const; |
| + const std::string GetTetherNetworkSsid() const; |
| + |
| + private: |
| + void SetActiveHost(ActiveHostStatus active_host_status, |
| + const std::string& active_host_device_id, |
| + const std::string& tether_network_ssid); |
| + |
| + void OnTetherHostFetched( |
| + const ActiveHostCallback& active_host_callback, |
| + std::unique_ptr<cryptauth::RemoteDevice> remote_device); |
| + |
| + TetherHostFetcher* tether_host_fetcher_; |
| + PrefService* pref_service_; |
| + |
| + base::WeakPtrFactory<ActiveHost> weak_ptr_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(ActiveHost); |
| +}; |
| + |
| +} // namespace tether |
| + |
| +} // namespace chromeos |
| + |
| +#endif // CHROMEOS_COMPONENTS_TETHER_ACTIVE_HOST_H_ |