Commit 46717551 authored by Kyle Horimoto's avatar Kyle Horimoto Committed by Commit Bot

[CrOS MultiDevice] Update HostBackendDelegate description.

The AttemptToSetMultiDeviceHostOnBackend() function will retry any
pending request immediately when called, but that was not explicitly
documented. Likewise, there was no explicit test for this behavior.

This CL addresses both of those issues; a follow-up CL will invoke
this class in the way that I'm describing.

Bug: 824568
Change-Id: I397455528498b3d52f7c505785f0be93dd0ce212
Reviewed-on: https://chromium-review.googlesource.com/1115735
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarRyan Hansberry <hansberry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570600}
parent c2d7b797
...@@ -56,6 +56,9 @@ class HostBackendDelegate { ...@@ -56,6 +56,9 @@ class HostBackendDelegate {
// the OnBackendRequestFailed() observer function is invoked, but this // the OnBackendRequestFailed() observer function is invoked, but this
// object continues to attempt the request until the request succeeds or until // object continues to attempt the request until the request succeeds or until
// AttemptToSetMultiDeviceHostOnBackend() is called with a new device. // AttemptToSetMultiDeviceHostOnBackend() is called with a new device.
//
// If there is already a pending request and this function is called with the
// same request, a retry will be attempted immediately.
virtual void AttemptToSetMultiDeviceHostOnBackend( virtual void AttemptToSetMultiDeviceHostOnBackend(
const base::Optional<cryptauth::RemoteDeviceRef>& host_device) = 0; const base::Optional<cryptauth::RemoteDeviceRef>& host_device) = 0;
......
...@@ -119,6 +119,9 @@ void HostBackendDelegateImpl::AttemptToSetMultiDeviceHostOnBackend( ...@@ -119,6 +119,9 @@ void HostBackendDelegateImpl::AttemptToSetMultiDeviceHostOnBackend(
return; return;
} }
// Stop the timer, since a new attempt is being started.
timer_->Stop();
if (host_device) if (host_device)
SetPendingHostRequest(host_device->GetDeviceId()); SetPendingHostRequest(host_device->GetDeviceId());
else else
......
...@@ -347,7 +347,7 @@ TEST_F(MultiDeviceSetupHostBackendDelegateImplTest, ...@@ -347,7 +347,7 @@ TEST_F(MultiDeviceSetupHostBackendDelegateImplTest,
} }
TEST_F(MultiDeviceSetupHostBackendDelegateImplTest, TEST_F(MultiDeviceSetupHostBackendDelegateImplTest,
StartWithDevice_SimultaneousRequestsToSameDevice) { SimultaneousRequestsToSameDevice) {
CreateDelegate(base::nullopt /* initial_host */); CreateDelegate(base::nullopt /* initial_host */);
// Attempt to set device 0, but do not invoke the callback yet. // Attempt to set device 0, but do not invoke the callback yet.
...@@ -393,6 +393,34 @@ TEST_F(MultiDeviceSetupHostBackendDelegateImplTest, ...@@ -393,6 +393,34 @@ TEST_F(MultiDeviceSetupHostBackendDelegateImplTest,
EXPECT_EQ(test_devices()[0], delegate()->GetMultiDeviceHostFromBackend()); EXPECT_EQ(test_devices()[0], delegate()->GetMultiDeviceHostFromBackend());
} }
TEST_F(MultiDeviceSetupHostBackendDelegateImplTest,
MultipleRequestsToSameDevice_FirstFail_ThenSucceed) {
CreateDelegate(base::nullopt /* initial_host */);
// Attempt to set device 0, but fail.
AttemptToSetMultiDeviceHostOnBackend(test_devices()[0]);
InvokePendingSetSoftwareFeatureStateCallback(
"errorCode1" /* error_code */,
true /* expected_to_notify_observer_and_start_retry_timer */);
EXPECT_TRUE(delegate()->HasPendingHostRequest());
EXPECT_EQ(test_devices()[0], delegate()->GetPendingHostRequest());
EXPECT_EQ(base::nullopt, delegate()->GetMultiDeviceHostFromBackend());
// The retry timer is running; however, instead of relying on that, call
// AttemptToSetMultiDeviceHostOnBackend() again to trigger an immediate retry
// without the timer.
AttemptToSetMultiDeviceHostOnBackend(test_devices()[0]);
InvokePendingSetSoftwareFeatureStateCallback(
base::nullopt /* error_code */,
false /* expected_to_notify_observer_and_start_retry_timer */);
EXPECT_TRUE(delegate()->HasPendingHostRequest());
EXPECT_EQ(test_devices()[0], delegate()->GetPendingHostRequest());
SimulateNewHostDevicesSynced(test_devices()[0] /* host_device_after_sync */,
true /* expected_to_fulfill_pending_request */);
EXPECT_FALSE(delegate()->HasPendingHostRequest());
EXPECT_EQ(test_devices()[0], delegate()->GetMultiDeviceHostFromBackend());
}
TEST_F(MultiDeviceSetupHostBackendDelegateImplTest, TEST_F(MultiDeviceSetupHostBackendDelegateImplTest,
InitialPendingRequestButNoInitialDevice) { InitialPendingRequestButNoInitialDevice) {
CreateDelegate( CreateDelegate(
......
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