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

[CrOS MultiDevice] Add setFeatureStateEnabled() to MultiDevice proxy.

This allows the settings page to request that multi-device features be
enabled or disabled via clicks on a toggle.

Bug: 824568
Change-Id: I7edf3991036d5119a1bed8cf67f82b2138594b13
Reviewed-on: https://chromium-review.googlesource.com/1176870
Commit-Queue: Kyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583839}
parent 11a2b625
...@@ -10,6 +10,14 @@ cr.define('settings', function() { ...@@ -10,6 +10,14 @@ cr.define('settings', function() {
/** @return {!Promise<!MultiDevicePageContentData>} */ /** @return {!Promise<!MultiDevicePageContentData>} */
getPageContentData() {} getPageContentData() {}
/**
* @param {!settings.MultiDeviceFeature} feature The feature whose state
* should be set.
* @param {boolean} enabled Whether the feature should be turned off or on.
* @return {!Promise<boolean>} Whether the operation was successful.
*/
setFeatureEnabledState(feature, enabled) {}
retryPendingHostSetup() {} retryPendingHostSetup() {}
} }
...@@ -27,6 +35,11 @@ cr.define('settings', function() { ...@@ -27,6 +35,11 @@ cr.define('settings', function() {
return cr.sendWithPromise('getPageContentData'); return cr.sendWithPromise('getPageContentData');
} }
/** @override */
setFeatureEnabledState(feature, enabled) {
return cr.sendWithPromise('setFeatureEnabledState');
}
/** @override */ /** @override */
retryPendingHostSetup() { retryPendingHostSetup() {
chrome.send('retryPendingHostSetup'); chrome.send('retryPendingHostSetup');
......
...@@ -18,6 +18,19 @@ cr.define('settings', function() { ...@@ -18,6 +18,19 @@ cr.define('settings', function() {
HOST_SET_VERIFIED: 4, HOST_SET_VERIFIED: 4,
}; };
/**
* Enum of MultiDevice features. Note that this is copied from (and must
* include an analog of all values in) the Feature enum in
* //chromeos/services/multidevice_setup/public/mojom/multidevice_setup.mojom.
* @enum {number}
*/
MultiDeviceFeature = {
BETTER_TOGETHER_SUITE: 0,
INSTANT_TETHERING: 1,
MESSAGES: 2,
SMART_LOCK: 3,
};
/** /**
* Possible states of MultiDevice features. Note that this is copied from (and * Possible states of MultiDevice features. Note that this is copied from (and
* must include an analog of all values in) the FeatureState enum in * must include an analog of all values in) the FeatureState enum in
...@@ -36,6 +49,7 @@ cr.define('settings', function() { ...@@ -36,6 +49,7 @@ cr.define('settings', function() {
return { return {
MultiDeviceSettingsMode: MultiDeviceSettingsMode, MultiDeviceSettingsMode: MultiDeviceSettingsMode,
MultiDeviceFeature: MultiDeviceFeature,
MultiDeviceFeatureState: MultiDeviceFeatureState, MultiDeviceFeatureState: MultiDeviceFeatureState,
}; };
}); });
......
...@@ -51,6 +51,10 @@ void MultideviceHandler::RegisterMessages() { ...@@ -51,6 +51,10 @@ void MultideviceHandler::RegisterMessages() {
"getPageContentData", "getPageContentData",
base::BindRepeating(&MultideviceHandler::HandleGetPageContent, base::BindRepeating(&MultideviceHandler::HandleGetPageContent,
base::Unretained(this))); base::Unretained(this)));
web_ui()->RegisterMessageCallback(
"setFeatureEnabledState",
base::BindRepeating(&MultideviceHandler::HandleSetFeatureEnabledState,
base::Unretained(this)));
web_ui()->RegisterMessageCallback( web_ui()->RegisterMessageCallback(
"retryPendingHostSetup", "retryPendingHostSetup",
base::BindRepeating(&MultideviceHandler::HandleRetryPendingHostSetup, base::BindRepeating(&MultideviceHandler::HandleRetryPendingHostSetup,
...@@ -131,6 +135,29 @@ void MultideviceHandler::HandleGetPageContent(const base::ListValue* args) { ...@@ -131,6 +135,29 @@ void MultideviceHandler::HandleGetPageContent(const base::ListValue* args) {
callback_weak_ptr_factory_.GetWeakPtr(), callback_id)); callback_weak_ptr_factory_.GetWeakPtr(), callback_id));
} }
void MultideviceHandler::HandleSetFeatureEnabledState(
const base::ListValue* args) {
std::string callback_id;
bool result = args->GetString(0, &callback_id);
DCHECK(result);
int feature_as_int;
result = args->GetInteger(1, &feature_as_int);
DCHECK(result);
auto feature = static_cast<multidevice_setup::mojom::Feature>(feature_as_int);
DCHECK(multidevice_setup::mojom::IsKnownEnumValue(feature));
bool enabled;
result = args->GetBoolean(2, &enabled);
DCHECK(result);
multidevice_setup_client_->SetFeatureEnabledState(
feature, enabled,
base::BindOnce(&MultideviceHandler::OnSetFeatureStateEnabledResult,
callback_weak_ptr_factory_.GetWeakPtr(), callback_id));
}
void MultideviceHandler::HandleRetryPendingHostSetup( void MultideviceHandler::HandleRetryPendingHostSetup(
const base::ListValue* args) { const base::ListValue* args) {
DCHECK(args->empty()); DCHECK(args->empty());
...@@ -154,6 +181,12 @@ void MultideviceHandler::OnFeatureStatesFetched( ...@@ -154,6 +181,12 @@ void MultideviceHandler::OnFeatureStatesFetched(
AttemptGetPageContentResponse(js_callback_id); AttemptGetPageContentResponse(js_callback_id);
} }
void MultideviceHandler::OnSetFeatureStateEnabledResult(
const std::string& js_callback_id,
bool success) {
ResolveJavascriptCallback(base::Value(js_callback_id), base::Value(success));
}
std::unique_ptr<base::DictionaryValue> std::unique_ptr<base::DictionaryValue>
MultideviceHandler::GeneratePageContentDataDictionary() { MultideviceHandler::GeneratePageContentDataDictionary() {
// Cannot generate page contents without all required data. // Cannot generate page contents without all required data.
......
...@@ -53,6 +53,7 @@ class MultideviceHandler ...@@ -53,6 +53,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 HandleRetryPendingHostSetup(const base::ListValue* args); void HandleRetryPendingHostSetup(const base::ListValue* args);
void OnHostStatusFetched( void OnHostStatusFetched(
...@@ -63,6 +64,8 @@ class MultideviceHandler ...@@ -63,6 +64,8 @@ class MultideviceHandler
const std::string& js_callback_id, const std::string& js_callback_id,
const multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap& const multidevice_setup::MultiDeviceSetupClient::FeatureStatesMap&
feature_states_map); feature_states_map);
void OnSetFeatureStateEnabledResult(const std::string& js_callback_id,
bool success);
// Returns null if requisite data has not yet been fetched (i.e., if one or // Returns null if requisite data has not yet been fetched (i.e., if one or
// both of |last_host_status_update_| and |last_feature_states_update_| is // both of |last_host_status_update_| and |last_feature_states_update_| is
......
...@@ -192,6 +192,33 @@ class MultideviceHandlerTest : public testing::Test { ...@@ -192,6 +192,33 @@ class MultideviceHandlerTest : public testing::Test {
success); success);
} }
void CallSetFeatureEnabledState(multidevice_setup::mojom::Feature feature,
bool enabled,
bool success) {
size_t call_data_count_before_call = test_web_ui()->call_data().size();
base::ListValue args;
args.AppendString("handlerFunctionName");
args.AppendInteger(static_cast<int>(feature));
args.AppendBoolean(enabled);
base::ListValue empty_args;
test_web_ui()->HandleReceivedMessage("setFeatureEnabledState", &args);
fake_multidevice_setup_client()
->InvokePendingSetFeatureEnabledStateCallback(
feature /* expected_feature */, enabled /* expected_enabled */,
success);
EXPECT_EQ(call_data_count_before_call + 1u,
test_web_ui()->call_data().size());
const content::TestWebUI::CallData& call_data =
CallDataAtIndex(call_data_count_before_call);
EXPECT_EQ("cr.webUIResponse", call_data.function_name());
EXPECT_EQ("handlerFunctionName", call_data.arg1()->GetString());
EXPECT_TRUE(call_data.arg2()->GetBool());
EXPECT_EQ(success, call_data.arg3()->GetBool());
}
const content::TestWebUI::CallData& CallDataAtIndex(size_t index) { const content::TestWebUI::CallData& CallDataAtIndex(size_t index) {
return *test_web_ui_->call_data()[index]; return *test_web_ui_->call_data()[index];
} }
...@@ -271,6 +298,18 @@ TEST_F(MultideviceHandlerTest, RetryPendingHostSetup) { ...@@ -271,6 +298,18 @@ TEST_F(MultideviceHandlerTest, RetryPendingHostSetup) {
CallRetryPendingHostSetup(false /* success */); CallRetryPendingHostSetup(false /* success */);
} }
TEST_F(MultideviceHandlerTest, SetFeatureEnabledState) {
CallSetFeatureEnabledState(
multidevice_setup::mojom::Feature::kBetterTogetherSuite,
true /* enabled */, true /* success */);
CallSetFeatureEnabledState(
multidevice_setup::mojom::Feature::kBetterTogetherSuite,
false /* enabled */, false /* success */);
CallSetFeatureEnabledState(
multidevice_setup::mojom::Feature::kBetterTogetherSuite,
false /* enabled */, true /* success */);
}
} // namespace settings } // namespace settings
} // namespace chromeos } // namespace chromeos
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