Commit bdccbaa8 authored by Regan Hsu's avatar Regan Hsu Committed by Commit Bot

[CrOS PhoneHub] Fire a host status change when device sync event occurs

When a new device sync event occurs, the phone sends its encrypted
metadata to the Chromebook. Previously, this wasn't considered a status
change, since the same device is still set as the host. However, the
encrypted metadata stores the PII device name, which is needed by
Browser tabs. This CL ensures that when OnNewDevicesSynced() is called,
a host status change is fired so that MultiDeviceSetup is aware of
the decrypted PII name.

Bug: 1143045, 1106937
Change-Id: I543c97b06185570755632b23adfea192f090376a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536055
Commit-Queue: Regan Hsu <hsuregan@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#827084}
parent 7044601b
......@@ -67,7 +67,8 @@ HostStatusProviderImpl::HostStatusProviderImpl(
host_verifier_->AddObserver(this);
device_sync_client_->AddObserver(this);
CheckForUpdatedStatusAndNotifyIfChanged();
CheckForUpdatedStatusAndNotifyIfChanged(
/*force_notify_host_status_change=*/false);
RecordMultiDeviceHostStatus(current_status_and_device_.host_status());
}
......@@ -83,25 +84,38 @@ HostStatusProviderImpl::GetHostWithStatus() const {
}
void HostStatusProviderImpl::OnHostChangedOnBackend() {
CheckForUpdatedStatusAndNotifyIfChanged();
CheckForUpdatedStatusAndNotifyIfChanged(
/*force_notify_host_status_change=*/false);
}
void HostStatusProviderImpl::OnPendingHostRequestChange() {
CheckForUpdatedStatusAndNotifyIfChanged();
CheckForUpdatedStatusAndNotifyIfChanged(
/*force_notify_host_status_change=*/false);
}
void HostStatusProviderImpl::OnHostVerified() {
CheckForUpdatedStatusAndNotifyIfChanged();
CheckForUpdatedStatusAndNotifyIfChanged(
/*force_notify_host_status_change=*/false);
}
void HostStatusProviderImpl::OnNewDevicesSynced() {
CheckForUpdatedStatusAndNotifyIfChanged();
CheckForUpdatedStatusAndNotifyIfChanged(
/*force_notify_host_status_change=*/true);
}
void HostStatusProviderImpl::CheckForUpdatedStatusAndNotifyIfChanged() {
void HostStatusProviderImpl::CheckForUpdatedStatusAndNotifyIfChanged(
bool force_notify_host_status_change) {
HostStatusWithDevice current_status_and_device = GetCurrentStatus();
if (current_status_and_device == current_status_and_device_)
if (current_status_and_device == current_status_and_device_) {
if (force_notify_host_status_change) {
// If the RemoteDevice the host device references has changed, but not its
// contents, fire a host status change. Note that since the status doesn't
// actually change, neither logging nor metric collection should occur.
NotifyHostStatusChange(current_status_and_device_.host_status(),
current_status_and_device_.host_device());
}
return;
}
PA_LOG(VERBOSE) << "HostStatusProviderImpl::"
<< "CheckForUpdatedStatusAndNotifyIfChanged(): Host status "
......
......@@ -70,7 +70,9 @@ class HostStatusProviderImpl : public HostStatusProvider,
// device_sync::DeviceSyncClient::Observer:
void OnNewDevicesSynced() override;
void CheckForUpdatedStatusAndNotifyIfChanged();
void CheckForUpdatedStatusAndNotifyIfChanged(
bool force_notify_host_status_change);
HostStatusWithDevice GetCurrentStatus();
EligibleHostDevicesProvider* eligible_host_devices_provider_;
......
......@@ -92,6 +92,10 @@ class MultiDeviceSetupHostStatusProviderImplTest : public testing::Test {
FakeHostVerifier* fake_host_verifier() { return fake_host_verifier_.get(); }
device_sync::FakeDeviceSyncClient* fake_device_sync_client() {
return fake_device_sync_client_.get();
}
private:
multidevice::RemoteDeviceRefList test_devices_;
......@@ -145,6 +149,14 @@ TEST_F(MultiDeviceSetupHostStatusProviderImplTest,
3u /* expected_observer_index */);
}
TEST_F(MultiDeviceSetupHostStatusProviderImplTest,
OnNewDevicesSyncedNotifiesHostStatusChange) {
MakeDevicesEligibleHosts();
EXPECT_EQ(1u, GetNumChangeEvents());
fake_device_sync_client()->NotifyNewDevicesSynced();
EXPECT_EQ(2u, GetNumChangeEvents());
}
TEST_F(MultiDeviceSetupHostStatusProviderImplTest, SetHostThenForget) {
MakeDevicesEligibleHosts();
EXPECT_EQ(1u, GetNumChangeEvents());
......
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