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

[CrOS MultiDevice] Add ability to remove a multi-device host.

This CL:
(1) Displays a confirmation dialog when users request that the host
    device be removed.
(2) Actually removes the device as a host if the user confirms their
    intention to forget the current device.

Note: As part of this change, I've moved some strings from
chromeos_strings.grdp to settings_strings.grdp, since the strings are
displayed in the settings page.

Bug: 870069, 824568
Change-Id: Ifd9fb275fa385d4fcc45cd4d8000c4534cd3c14b
Reviewed-on: https://chromium-review.googlesource.com/1191523Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586421}
parent 1da75893
...@@ -196,14 +196,6 @@ ...@@ -196,14 +196,6 @@
Offer new features that use your phone's connection to your Chromebook Offer new features that use your phone's connection to your Chromebook
</message> </message>
<!-- MultiDevice 'Forget device' dialog -->
<message name="IDS_MULTIDEVICE_FORGET_DEVICE_DIALOG_HEADING" desc="Heading for a dialog that lets the user choose if their Chromebook should forget their phone. This means they will no longer have access to multidevice features.">
Forget device
</message>
<message name="IDS_MULTIDEVICE_FORGET_DEVICE_DIALOG_MESSAGE" desc="Text of a dialog that lets the user choose if their Chromebook should forget their phone. This means they will no longer have access to multidevice features.">
Remove your phone and disable Better Together
</message>
<!-- File Manager --> <!-- File Manager -->
<message name="IDS_FILE_BROWSER_ANDROID_FILES_ROOT_LABEL" desc="A label for the 'Play files' root which shows Android files. 'Play' in this label is an abbreviation of 'Google Play', so it should not be translated. Use sentence case."> <message name="IDS_FILE_BROWSER_ANDROID_FILES_ROOT_LABEL" desc="A label for the 'Play files' root which shows Android files. 'Play' in this label is an abbreviation of 'Google Play', so it should not be translated. Use sentence case.">
Play files Play files
......
...@@ -4264,6 +4264,12 @@ ...@@ -4264,6 +4264,12 @@
<message name="IDS_SETTINGS_MULTIDEVICE_FORGET_THIS_DEVICE_EXPLANATION" desc="Explanation on a clickable menu item that makes the Chromebook forget the user's phone. It tells the user that the menu item will cause their phone to stop acting as a partner for their Chromebook for multidevice features."> <message name="IDS_SETTINGS_MULTIDEVICE_FORGET_THIS_DEVICE_EXPLANATION" desc="Explanation on a clickable menu item that makes the Chromebook forget the user's phone. It tells the user that the menu item will cause their phone to stop acting as a partner for their Chromebook for multidevice features.">
Remove from Better Together Remove from Better Together
</message> </message>
<message name="IDS_SETTINGS_MULTIDEVICE_FORGET_DEVICE_DIALOG_HEADING" desc="Heading for a dialog that lets the user choose if their Chromebook should forget their phone. This means they will no longer have access to multidevice features.">
Forget device
</message>
<message name="IDS_SETTINGS_MULTIDEVICE_FORGET_DEVICE_DIALOG_MESSAGE" desc="Text of a dialog that lets the user choose if their Chromebook should forget their phone. This means they will no longer have access to multidevice features.">
Remove your phone and disable Better Together
</message>
</if> </if>
<!-- Password protection --> <!-- Password protection -->
......
...@@ -21,6 +21,8 @@ cr.define('settings', function() { ...@@ -21,6 +21,8 @@ cr.define('settings', function() {
*/ */
setFeatureEnabledState(feature, enabled, opt_authToken) {} setFeatureEnabledState(feature, enabled, opt_authToken) {}
removeHostDevice() {}
retryPendingHostSetup() {} retryPendingHostSetup() {}
} }
...@@ -44,6 +46,11 @@ cr.define('settings', function() { ...@@ -44,6 +46,11 @@ cr.define('settings', function() {
'setFeatureEnabledState', feature, enabled, opt_authToken); 'setFeatureEnabledState', feature, enabled, opt_authToken);
} }
/** @override */
removeHostDevice() {
chrome.send('removeHostDevice');
}
/** @override */ /** @override */
retryPendingHostSetup() { retryPendingHostSetup() {
chrome.send('retryPendingHostSetup'); chrome.send('retryPendingHostSetup');
......
...@@ -56,6 +56,7 @@ Polymer({ ...@@ -56,6 +56,7 @@ Polymer({
listeners: { listeners: {
'feature-toggle-clicked': 'onFeatureToggleClicked_', 'feature-toggle-clicked': 'onFeatureToggleClicked_',
'forget-device-requested': 'onForgetDeviceRequested_',
}, },
/** @private {?settings.MultiDeviceBrowserProxy} */ /** @private {?settings.MultiDeviceBrowserProxy} */
...@@ -226,6 +227,12 @@ Polymer({ ...@@ -226,6 +227,12 @@ Polymer({
this.browserProxy_.setFeatureEnabledState(feature, enabled); this.browserProxy_.setFeatureEnabledState(feature, enabled);
}, },
/** @private */
onForgetDeviceRequested_: function() {
this.browserProxy_.removeHostDevice();
settings.navigateTo(settings.routes.MULTIDEVICE);
},
/** /**
* Called when the authToken_ changes. If the authToken is valid, that * Called when the authToken_ changes. If the authToken is valid, that
* indicates the user authenticated successfully. If not, cancel the pending * indicates the user authenticated successfully. If not, cancel the pending
......
...@@ -95,6 +95,26 @@ ...@@ -95,6 +95,26 @@
</paper-icon-button-light> </paper-icon-button-light>
</div> </div>
</div> </div>
<cr-dialog id="forgetDeviceDialog" show-close-button="false">
<div slot="title">$i18n{multideviceForgetDeviceDialogHeading}</div>
<div slot="body">
<div class="settings-box first">
$i18n{multideviceForgetDeviceDialogMessage}
</div>
</div>
<div slot="button-container">
<paper-button class="cancel-button"
on-click="onForgetDeviceDialogCancelClick_">
$i18n{cancel}
</paper-button>
<paper-button id="confirmButton"
class="action-button"
on-click="onForgetDeviceDialogConfirmClick_">
$i18n{confirm}
</paper-button>
</div>
</cr-dialog>
</template> </template>
<script src="multidevice_subpage.js"></script> <script src="multidevice_subpage.js"></script>
</dom-module> </dom-module>
...@@ -82,8 +82,18 @@ Polymer({ ...@@ -82,8 +82,18 @@ Polymer({
/** @private */ /** @private */
handleForgetDeviceClick_: function() { handleForgetDeviceClick_: function() {
// TODO(khorimoto): Have this navigate to the route for dialog once it is this.$.forgetDeviceDialog.showModal();
// built. },
/** @private */
onForgetDeviceDialogCancelClick_: function() {
this.$.forgetDeviceDialog.close();
},
/** @private */
onForgetDeviceDialogConfirmClick_: function() {
this.fire('forget-device-requested');
this.$.forgetDeviceDialog.close();
}, },
/** /**
......
...@@ -55,6 +55,10 @@ void MultideviceHandler::RegisterMessages() { ...@@ -55,6 +55,10 @@ void MultideviceHandler::RegisterMessages() {
"setFeatureEnabledState", "setFeatureEnabledState",
base::BindRepeating(&MultideviceHandler::HandleSetFeatureEnabledState, base::BindRepeating(&MultideviceHandler::HandleSetFeatureEnabledState,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"removeHostDevice",
base::BindRepeating(&MultideviceHandler::HandleRemoveHostDevice,
base::Unretained(this)));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"retryPendingHostSetup", "retryPendingHostSetup",
base::BindRepeating(&MultideviceHandler::HandleRetryPendingHostSetup, base::BindRepeating(&MultideviceHandler::HandleRetryPendingHostSetup,
...@@ -163,6 +167,11 @@ void MultideviceHandler::HandleSetFeatureEnabledState( ...@@ -163,6 +167,11 @@ void MultideviceHandler::HandleSetFeatureEnabledState(
callback_weak_ptr_factory_.GetWeakPtr(), callback_id)); callback_weak_ptr_factory_.GetWeakPtr(), callback_id));
} }
void MultideviceHandler::HandleRemoveHostDevice(const base::ListValue* args) {
DCHECK(args->empty());
multidevice_setup_client_->RemoveHostDevice();
}
void MultideviceHandler::HandleRetryPendingHostSetup( void MultideviceHandler::HandleRetryPendingHostSetup(
const base::ListValue* args) { const base::ListValue* args) {
DCHECK(args->empty()); DCHECK(args->empty());
......
...@@ -54,6 +54,7 @@ class MultideviceHandler ...@@ -54,6 +54,7 @@ class MultideviceHandler
void HandleShowMultiDeviceSetupDialog(const base::ListValue* args); void HandleShowMultiDeviceSetupDialog(const base::ListValue* args);
void HandleGetPageContent(const base::ListValue* args); void HandleGetPageContent(const base::ListValue* args);
void HandleSetFeatureEnabledState(const base::ListValue* args); void HandleSetFeatureEnabledState(const base::ListValue* args);
void HandleRemoveHostDevice(const base::ListValue* args);
void HandleRetryPendingHostSetup(const base::ListValue* args); void HandleRetryPendingHostSetup(const base::ListValue* args);
void OnHostStatusFetched( void OnHostStatusFetched(
......
...@@ -113,7 +113,6 @@ class MultideviceHandlerTest : public testing::Test { ...@@ -113,7 +113,6 @@ class MultideviceHandlerTest : public testing::Test {
void CallGetPageContentData(bool expected_to_request_data_from_device_sync) { void CallGetPageContentData(bool expected_to_request_data_from_device_sync) {
EXPECT_TRUE(current_host_status_with_device_); EXPECT_TRUE(current_host_status_with_device_);
EXPECT_TRUE(current_host_status_with_device_);
size_t call_data_count_before_call = test_web_ui()->call_data().size(); size_t call_data_count_before_call = test_web_ui()->call_data().size();
...@@ -147,6 +146,15 @@ class MultideviceHandlerTest : public testing::Test { ...@@ -147,6 +146,15 @@ class MultideviceHandlerTest : public testing::Test {
VerifyPageContent(call_data.arg3()); VerifyPageContent(call_data.arg3());
} }
void CallRemoveHostDevice() {
size_t num_remote_host_device_calls_before_call =
fake_multidevice_setup_client()->num_remove_host_device_called();
base::ListValue empty_args;
test_web_ui()->HandleReceivedMessage("removeHostDevice", &empty_args);
EXPECT_EQ(num_remote_host_device_calls_before_call + 1u,
fake_multidevice_setup_client()->num_remove_host_device_called());
}
void SimulateHostStatusUpdate( void SimulateHostStatusUpdate(
multidevice_setup::mojom::HostStatus host_status, multidevice_setup::mojom::HostStatus host_status,
const base::Optional<cryptauth::RemoteDeviceRef>& host_device) { const base::Optional<cryptauth::RemoteDeviceRef>& host_device) {
...@@ -313,6 +321,12 @@ TEST_F(MultideviceHandlerTest, SetFeatureEnabledState) { ...@@ -313,6 +321,12 @@ TEST_F(MultideviceHandlerTest, SetFeatureEnabledState) {
false /* enabled */, "authToken" /* auth_token */, true /* success */); false /* enabled */, "authToken" /* auth_token */, true /* success */);
} }
TEST_F(MultideviceHandlerTest, RemoveHostDevice) {
CallRemoveHostDevice();
CallRemoveHostDevice();
CallRemoveHostDevice();
}
} // namespace settings } // namespace settings
} // namespace chromeos } // namespace chromeos
...@@ -2601,6 +2601,10 @@ void AddMultideviceStrings(content::WebUIDataSource* html_source) { ...@@ -2601,6 +2601,10 @@ void AddMultideviceStrings(content::WebUIDataSource* html_source) {
{"multideviceForgetDevice", IDS_SETTINGS_MULTIDEVICE_FORGET_THIS_DEVICE}, {"multideviceForgetDevice", IDS_SETTINGS_MULTIDEVICE_FORGET_THIS_DEVICE},
{"multideviceForgetDeviceSummary", {"multideviceForgetDeviceSummary",
IDS_SETTINGS_MULTIDEVICE_FORGET_THIS_DEVICE_EXPLANATION}, IDS_SETTINGS_MULTIDEVICE_FORGET_THIS_DEVICE_EXPLANATION},
{"multideviceForgetDeviceDialogHeading",
IDS_SETTINGS_MULTIDEVICE_FORGET_DEVICE_DIALOG_HEADING},
{"multideviceForgetDeviceDialogMessage",
IDS_SETTINGS_MULTIDEVICE_FORGET_DEVICE_DIALOG_MESSAGE},
}; };
AddLocalizedStringsBulk(html_source, localized_strings, AddLocalizedStringsBulk(html_source, localized_strings,
arraysize(localized_strings)); arraysize(localized_strings));
......
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