Commit 64bfdde2 authored by Claude van der Merwe's avatar Claude van der Merwe Committed by Commit Bot

Enable Wifi Sync after Multidevice Setup

Wifi Sync is enabled from a Chrome OS device if the multidevice setup
is complete and the Wifi Sync flag is enabled on the Chrome OS device.

This CL adds a pending state kEnableOnVerify that gets set when
the Multidevice setup is complete on a Chrome OS device with the
Wifi Sync flag enabled. The kEnableOnVerify state listens for the
host to become verified and enables Wifi Sync if it is not already
enabled.

The kEnableOnVerify state gets cleared if the host device is removed.

Bug: 1117619
Change-Id: I34070149b963629aa0ff0dc2da8c3022c2fcef5c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2457047
Commit-Queue: Claude van der Merwe <cvandermerwe@google.com>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarJon Mann <jonmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816209}
parent cf6352bf
...@@ -84,17 +84,36 @@ WifiSyncFeatureManagerImpl::WifiSyncFeatureManagerImpl( ...@@ -84,17 +84,36 @@ WifiSyncFeatureManagerImpl::WifiSyncFeatureManagerImpl(
if (GetCurrentState() == CurrentState::kValidPendingRequest) { if (GetCurrentState() == CurrentState::kValidPendingRequest) {
AttemptSetWifiSyncHostStateNetworkRequest(false /* is_retry */); AttemptSetWifiSyncHostStateNetworkRequest(false /* is_retry */);
} }
if (ShouldEnableOnVerify()) {
ProcessEnableOnVerifyAttempt();
}
} }
void WifiSyncFeatureManagerImpl::OnHostStatusChange( void WifiSyncFeatureManagerImpl::OnHostStatusChange(
const HostStatusProvider::HostStatusWithDevice& host_status_with_device) { const HostStatusProvider::HostStatusWithDevice& host_status_with_device) {
if (GetCurrentState() == CurrentState::kNoVerifiedHost) { if (GetCurrentState() == CurrentState::kNoVerifiedHost &&
!ShouldEnableOnVerify()) {
ResetPendingWifiSyncHostNetworkRequest(); ResetPendingWifiSyncHostNetworkRequest();
} }
// kHostSetLocallyButWaitingForBackendConfirmation is only possible if the
// setup flow has been completed on the local device.
if (host_status_with_device.host_status() ==
mojom::HostStatus::kHostSetLocallyButWaitingForBackendConfirmation &&
features::IsWifiSyncAndroidEnabled()) {
SetPendingWifiSyncHostNetworkRequest(
PendingState::kSetPendingEnableOnVerify);
return;
}
if (ShouldEnableOnVerify()) {
ProcessEnableOnVerifyAttempt();
}
} }
void WifiSyncFeatureManagerImpl::OnNewDevicesSynced() { void WifiSyncFeatureManagerImpl::OnNewDevicesSynced() {
if (GetCurrentState() != CurrentState::kValidPendingRequest) { if (GetCurrentState() != CurrentState::kValidPendingRequest &&
!ShouldEnableOnVerify()) {
ResetPendingWifiSyncHostNetworkRequest(); ResetPendingWifiSyncHostNetworkRequest();
} }
} }
...@@ -151,7 +170,13 @@ WifiSyncFeatureManagerImpl::GetCurrentState() { ...@@ -151,7 +170,13 @@ WifiSyncFeatureManagerImpl::GetCurrentState() {
return CurrentState::kNoVerifiedHost; return CurrentState::kNoVerifiedHost;
} }
if (GetPendingState() == PendingState::kPendingNone) { PendingState pending_state = GetPendingState();
// If the pending request is kSetPendingEnableOnVerify then there is no
// actionable pending equest. The pending request will be changed from
// kSetPendingEnableOnVerify when the host has been verified.
if (pending_state == PendingState::kPendingNone ||
pending_state == PendingState::kSetPendingEnableOnVerify) {
return CurrentState::kNoPendingRequest; return CurrentState::kNoPendingRequest;
} }
...@@ -161,7 +186,7 @@ WifiSyncFeatureManagerImpl::GetCurrentState() { ...@@ -161,7 +186,7 @@ WifiSyncFeatureManagerImpl::GetCurrentState() {
->GetSoftwareFeatureState( ->GetSoftwareFeatureState(
multidevice::SoftwareFeature::kWifiSyncHost) == multidevice::SoftwareFeature::kWifiSyncHost) ==
multidevice::SoftwareFeatureState::kEnabled); multidevice::SoftwareFeatureState::kEnabled);
bool pending_enabled = (GetPendingState() == PendingState::kPendingEnable); bool pending_enabled = (pending_state == PendingState::kPendingEnable);
if (pending_enabled == enabled_on_host) { if (pending_enabled == enabled_on_host) {
return CurrentState::kPendingMatchesBackend; return CurrentState::kPendingMatchesBackend;
...@@ -265,6 +290,33 @@ void WifiSyncFeatureManagerImpl::OnSetWifiSyncHostStateNetworkRequestFinished( ...@@ -265,6 +290,33 @@ void WifiSyncFeatureManagerImpl::OnSetWifiSyncHostStateNetworkRequestFinished(
} }
} }
bool WifiSyncFeatureManagerImpl::ShouldEnableOnVerify() {
return (GetPendingState() == PendingState::kSetPendingEnableOnVerify);
}
void WifiSyncFeatureManagerImpl::ProcessEnableOnVerifyAttempt() {
mojom::HostStatus host_status =
host_status_provider_->GetHostWithStatus().host_status();
// If host is not set.
if (host_status == mojom::HostStatus::kNoEligibleHosts ||
host_status == mojom::HostStatus::kEligibleHostExistsButNoHostSet) {
ResetPendingWifiSyncHostNetworkRequest();
return;
}
if (host_status != mojom::HostStatus::kHostVerified) {
return;
}
if (IsWifiSyncEnabled()) {
ResetPendingWifiSyncHostNetworkRequest();
return;
}
SetIsWifiSyncEnabled(true);
}
} // namespace multidevice_setup } // namespace multidevice_setup
} // namespace chromeos } // namespace chromeos
\ No newline at end of file
...@@ -102,7 +102,8 @@ class WifiSyncFeatureManagerImpl ...@@ -102,7 +102,8 @@ class WifiSyncFeatureManagerImpl
enum class PendingState { enum class PendingState {
kPendingNone = 0, kPendingNone = 0,
kPendingEnable = 1, kPendingEnable = 1,
kPendingDisable = 2 kPendingDisable = 2,
kSetPendingEnableOnVerify = 3
}; };
enum class CurrentState { enum class CurrentState {
...@@ -120,6 +121,8 @@ class WifiSyncFeatureManagerImpl ...@@ -120,6 +121,8 @@ class WifiSyncFeatureManagerImpl
void OnSetWifiSyncHostStateNetworkRequestFinished( void OnSetWifiSyncHostStateNetworkRequestFinished(
bool attempted_to_enable, bool attempted_to_enable,
device_sync::mojom::NetworkRequestResult result_code); device_sync::mojom::NetworkRequestResult result_code);
bool ShouldEnableOnVerify();
void ProcessEnableOnVerifyAttempt();
HostStatusProvider* host_status_provider_; HostStatusProvider* host_status_provider_;
PrefService* pref_service_; PrefService* pref_service_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment