Commit 0a49f46b authored by Clemens Arbesser's avatar Clemens Arbesser Committed by Commit Bot

[Autofill Assistant] Moved towards ValueReferences where it makes sense.

Also changed IntegerSum from two operands to N operands. Not sure why it
wasn't set up like that in the first place.

Bug: b/145043394
Change-Id: I81bf164b7fd10e76c0741889b479f04061fd5e87
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2130552
Commit-Queue: Clemens Arbesser <arbesser@google.com>
Reviewed-by: default avatarMarian Fechete <marianfe@google.com>
Cr-Commit-Position: refs/heads/master@{#755368}
parent 65009b69
...@@ -340,7 +340,7 @@ bool CreateImplicitInteractionsForView( ...@@ -340,7 +340,7 @@ bool CreateImplicitInteractionsForView(
->mutable_on_value_changed() ->mutable_on_value_changed()
->set_model_identifier(proto.text_input_view().model_identifier()); ->set_model_identifier(proto.text_input_view().model_identifier());
SetTextProto set_text_callback; SetTextProto set_text_callback;
set_text_callback.set_model_identifier( set_text_callback.mutable_text()->set_model_identifier(
proto.text_input_view().model_identifier()); proto.text_input_view().model_identifier());
set_text_callback.set_view_identifier(proto.identifier()); set_text_callback.set_view_identifier(proto.identifier());
*implicit_set_text_interaction.add_callbacks()->mutable_set_text() = *implicit_set_text_interaction.add_callbacks()->mutable_set_text() =
...@@ -364,7 +364,7 @@ bool CreateImplicitInteractionsForView( ...@@ -364,7 +364,7 @@ bool CreateImplicitInteractionsForView(
->mutable_on_value_changed() ->mutable_on_value_changed()
->set_model_identifier(proto.text_view().model_identifier()); ->set_model_identifier(proto.text_view().model_identifier());
SetTextProto set_text_callback; SetTextProto set_text_callback;
set_text_callback.set_model_identifier( set_text_callback.mutable_text()->set_model_identifier(
proto.text_view().model_identifier()); proto.text_view().model_identifier());
set_text_callback.set_view_identifier(proto.identifier()); set_text_callback.set_view_identifier(proto.identifier());
*implicit_set_text_interaction.add_callbacks()->mutable_set_text() = *implicit_set_text_interaction.add_callbacks()->mutable_set_text() =
......
...@@ -71,24 +71,23 @@ void ShowListPopup(base::WeakPtr<UserModel> user_model, ...@@ -71,24 +71,23 @@ void ShowListPopup(base::WeakPtr<UserModel> user_model,
return; return;
} }
auto item_names = user_model->GetValue(proto.item_names_model_identifier()); auto item_names = user_model->GetValue(proto.item_names());
if (!item_names.has_value()) { if (!item_names.has_value()) {
DVLOG(2) << "Failed to show list popup: '" DVLOG(2) << "Failed to show list popup: '" << proto.item_names()
<< proto.item_names_model_identifier() << "' not found in model."; << "' not found in model.";
return; return;
} }
if (item_names->strings().values().size() == 0) { if (item_names->strings().values().size() == 0) {
DVLOG(2) << "Failed to show list popup: the list of item names in '" DVLOG(2) << "Failed to show list popup: the list of item names in '"
<< proto.item_names_model_identifier() << "' was empty."; << proto.item_names() << "' was empty.";
return; return;
} }
base::Optional<ValueProto> item_types; base::Optional<ValueProto> item_types;
if (proto.has_item_types_model_identifier()) { if (proto.has_item_types()) {
item_types = user_model->GetValue(proto.item_types_model_identifier()); item_types = user_model->GetValue(proto.item_types());
if (!item_types.has_value()) { if (!item_types.has_value()) {
DVLOG(2) << "Failed to show list popup: '" DVLOG(2) << "Failed to show list popup: '" << proto.item_types()
<< proto.item_types_model_identifier()
<< "' not found in the model."; << "' not found in the model.";
return; return;
} }
...@@ -177,19 +176,19 @@ void ShowCalendarPopup(base::WeakPtr<UserModel> user_model, ...@@ -177,19 +176,19 @@ void ShowCalendarPopup(base::WeakPtr<UserModel> user_model,
return; return;
} }
auto min_date = user_model->GetValue(proto.min_date_model_identifier()); auto min_date = user_model->GetValue(proto.min_date());
if (!min_date.has_value() || min_date->dates().values().size() != 1) { if (!min_date.has_value() || min_date->dates().values().size() != 1) {
DVLOG(2) << "Failed to show calendar popup: min_date not found or invalid " DVLOG(2) << "Failed to show calendar popup: min_date not found or invalid "
"in user model at " "in user model at "
<< proto.min_date_model_identifier(); << proto.min_date();
return; return;
} }
auto max_date = user_model->GetValue(proto.max_date_model_identifier()); auto max_date = user_model->GetValue(proto.max_date());
if (!max_date.has_value() || max_date->dates().values().size() != 1) { if (!max_date.has_value() || max_date->dates().values().size() != 1) {
DVLOG(2) << "Failed to show calendar popup: max_date not found or invalid " DVLOG(2) << "Failed to show calendar popup: max_date not found or invalid "
"in user model at " "in user model at "
<< proto.max_date_model_identifier(); << proto.max_date();
return; return;
} }
...@@ -217,15 +216,15 @@ void SetViewText( ...@@ -217,15 +216,15 @@ void SetViewText(
return; return;
} }
auto text = user_model->GetValue(proto.model_identifier()); auto text = user_model->GetValue(proto.text());
if (!text.has_value()) { if (!text.has_value()) {
DVLOG(2) << "Failed to set text for " << proto.view_identifier() << ": " DVLOG(2) << "Failed to set text for " << proto.view_identifier() << ": "
<< proto.model_identifier() << " not found in model"; << proto.text() << " not found in model";
return; return;
} }
if (text->strings().values_size() != 1) { if (text->strings().values_size() != 1) {
DVLOG(2) << "Failed to set text for " << proto.view_identifier() DVLOG(2) << "Failed to set text for " << proto.view_identifier()
<< ": expected " << proto.model_identifier() << ": expected " << proto.text()
<< " to contain single string, but was instead " << *text; << " to contain single string, but was instead " << *text;
return; return;
} }
...@@ -259,12 +258,11 @@ void SetViewVisibility( ...@@ -259,12 +258,11 @@ void SetViewVisibility(
return; return;
} }
auto visible_value = user_model->GetValue(proto.model_identifier()); auto visible_value = user_model->GetValue(proto.visible());
if (!visible_value.has_value() || if (!visible_value.has_value() ||
visible_value->booleans().values_size() != 1) { visible_value->booleans().values_size() != 1) {
DVLOG(2) << "Failed to set view visibility for " << proto.view_identifier() DVLOG(2) << "Failed to set view visibility for " << proto.view_identifier()
<< ": " << proto.model_identifier() << ": " << proto.visible() << " did not contain single boolean";
<< " did not contain single boolean";
return; return;
} }
......
...@@ -76,8 +76,8 @@ CreateInteractionCallbackFromProto( ...@@ -76,8 +76,8 @@ CreateInteractionCallbackFromProto(
base::android::ScopedJavaGlobalRef<jobject> jdelegate) { base::android::ScopedJavaGlobalRef<jobject> jdelegate) {
switch (proto.kind_case()) { switch (proto.kind_case()) {
case CallbackProto::kSetValue: case CallbackProto::kSetValue:
if (proto.set_value().model_identifier().empty()) { if (!proto.set_value().has_value()) {
VLOG(1) << "Error creating SetValue interaction: model_identifier " VLOG(1) << "Error creating SetValue interaction: value "
"not set"; "not set";
return base::nullopt; return base::nullopt;
} }
...@@ -91,9 +91,9 @@ CreateInteractionCallbackFromProto( ...@@ -91,9 +91,9 @@ CreateInteractionCallbackFromProto(
proto.show_info_popup().info_popup(), jcontext)); proto.show_info_popup().info_popup(), jcontext));
} }
case CallbackProto::kShowListPopup: case CallbackProto::kShowListPopup:
if (proto.show_list_popup().item_names_model_identifier().empty()) { if (!proto.show_list_popup().has_item_names()) {
VLOG(1) << "Error creating ShowListPopup interaction: " VLOG(1) << "Error creating ShowListPopup interaction: "
"items_list_model_identifier not set"; "item_names not set";
return base::nullopt; return base::nullopt;
} }
if (proto.show_list_popup() if (proto.show_list_popup()
...@@ -118,9 +118,9 @@ CreateInteractionCallbackFromProto( ...@@ -118,9 +118,9 @@ CreateInteractionCallbackFromProto(
basic_interactions->GetWeakPtr(), basic_interactions->GetWeakPtr(),
proto.compute_value())); proto.compute_value()));
case CallbackProto::kSetUserActions: case CallbackProto::kSetUserActions:
if (proto.set_user_actions().model_identifier().empty()) { if (!proto.set_user_actions().has_user_actions()) {
VLOG(1) << "Error creating SetUserActions interaction: " VLOG(1) << "Error creating SetUserActions interaction: "
"model_identifier not set"; "user_actions not set";
return base::nullopt; return base::nullopt;
} }
return base::Optional<InteractionHandlerAndroid::InteractionCallback>( return base::Optional<InteractionHandlerAndroid::InteractionCallback>(
...@@ -145,9 +145,9 @@ CreateInteractionCallbackFromProto( ...@@ -145,9 +145,9 @@ CreateInteractionCallbackFromProto(
proto.show_calendar_popup(), jcontext, proto.show_calendar_popup(), jcontext,
jdelegate)); jdelegate));
case CallbackProto::kSetText: case CallbackProto::kSetText:
if (proto.set_text().model_identifier().empty()) { if (!proto.set_text().has_text()) {
VLOG(1) << "Error creating SetText interaction: " VLOG(1) << "Error creating SetText interaction: "
"model_identifier not set"; "text not set";
return base::nullopt; return base::nullopt;
} }
if (proto.set_text().view_identifier().empty()) { if (proto.set_text().view_identifier().empty()) {
...@@ -170,9 +170,9 @@ CreateInteractionCallbackFromProto( ...@@ -170,9 +170,9 @@ CreateInteractionCallbackFromProto(
"user_action_identifier not set"; "user_action_identifier not set";
return base::nullopt; return base::nullopt;
} }
if (proto.toggle_user_action().enabled_model_identifier().empty()) { if (!proto.toggle_user_action().has_enabled()) {
VLOG(1) << "Error creating ToggleUserAction interaction: " VLOG(1) << "Error creating ToggleUserAction interaction: "
"enabled_model_identifier not set"; "enabled not set";
return base::nullopt; return base::nullopt;
} }
return base::Optional<InteractionHandlerAndroid::InteractionCallback>( return base::Optional<InteractionHandlerAndroid::InteractionCallback>(
...@@ -185,9 +185,9 @@ CreateInteractionCallbackFromProto( ...@@ -185,9 +185,9 @@ CreateInteractionCallbackFromProto(
"view_identifier not set"; "view_identifier not set";
return base::nullopt; return base::nullopt;
} }
if (proto.set_view_visibility().model_identifier().empty()) { if (!proto.set_view_visibility().has_visible()) {
VLOG(1) << "Error creating SetViewVisibility interaction: " VLOG(1) << "Error creating SetViewVisibility interaction: "
"model_identifier not set"; "visible not set";
return base::nullopt; return base::nullopt;
} }
return base::Optional<InteractionHandlerAndroid::InteractionCallback>( return base::Optional<InteractionHandlerAndroid::InteractionCallback>(
......
...@@ -40,24 +40,24 @@ class BasicInteractionsTest : public testing::Test { ...@@ -40,24 +40,24 @@ class BasicInteractionsTest : public testing::Test {
TEST_F(BasicInteractionsTest, SetValue) { TEST_F(BasicInteractionsTest, SetValue) {
SetModelValueProto proto; SetModelValueProto proto;
*proto.mutable_value() = SimpleValue(std::string("success")); *proto.mutable_value()->mutable_value() = SimpleValue(std::string("success"));
// Model identifier not set. // Model identifier not set.
EXPECT_FALSE(basic_interactions_.SetValue(proto)); EXPECT_FALSE(basic_interactions_.SetValue(proto));
proto.set_model_identifier("output"); proto.set_model_identifier("output");
EXPECT_TRUE(basic_interactions_.SetValue(proto)); EXPECT_TRUE(basic_interactions_.SetValue(proto));
EXPECT_EQ(user_model_.GetValue("output"), proto.value()); EXPECT_EQ(user_model_.GetValue("output"), proto.value().value());
} }
TEST_F(BasicInteractionsTest, ComputeValueBooleanAnd) { TEST_F(BasicInteractionsTest, ComputeValueBooleanAnd) {
ComputeValueProto proto; ComputeValueProto proto;
proto.mutable_boolean_and()->add_model_identifiers("value_1"); proto.mutable_boolean_and()->add_values()->set_model_identifier("value_1");
proto.mutable_boolean_and()->add_model_identifiers("value_2"); *proto.mutable_boolean_and()->add_values()->mutable_value() =
proto.mutable_boolean_and()->add_model_identifiers("value_3"); SimpleValue(true);
proto.mutable_boolean_and()->add_values()->set_model_identifier("value_3");
user_model_.SetValue("value_1", SimpleValue(true)); user_model_.SetValue("value_1", SimpleValue(true));
user_model_.SetValue("value_2", SimpleValue(true));
user_model_.SetValue("value_3", SimpleValue(false)); user_model_.SetValue("value_3", SimpleValue(false));
// Result model identifier not set. // Result model identifier not set.
...@@ -79,19 +79,19 @@ TEST_F(BasicInteractionsTest, ComputeValueBooleanAnd) { ...@@ -79,19 +79,19 @@ TEST_F(BasicInteractionsTest, ComputeValueBooleanAnd) {
ValueProto multi_bool; ValueProto multi_bool;
multi_bool.mutable_booleans()->add_values(true); multi_bool.mutable_booleans()->add_values(true);
multi_bool.mutable_booleans()->add_values(false); multi_bool.mutable_booleans()->add_values(false);
user_model_.SetValue("value_2", multi_bool); user_model_.SetValue("value_3", multi_bool);
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
} }
TEST_F(BasicInteractionsTest, ComputeValueBooleanOr) { TEST_F(BasicInteractionsTest, ComputeValueBooleanOr) {
ComputeValueProto proto; ComputeValueProto proto;
proto.mutable_boolean_or()->add_model_identifiers("value_1"); proto.mutable_boolean_or()->add_values()->set_model_identifier("value_1");
proto.mutable_boolean_or()->add_model_identifiers("value_2"); proto.mutable_boolean_or()->add_values()->set_model_identifier("value_2");
proto.mutable_boolean_or()->add_model_identifiers("value_3"); *proto.mutable_boolean_or()->add_values()->mutable_value() =
SimpleValue(false);
user_model_.SetValue("value_1", SimpleValue(false)); user_model_.SetValue("value_1", SimpleValue(false));
user_model_.SetValue("value_2", SimpleValue(false)); user_model_.SetValue("value_2", SimpleValue(false));
user_model_.SetValue("value_3", SimpleValue(false));
// Result model identifier not set. // Result model identifier not set.
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
...@@ -118,7 +118,7 @@ TEST_F(BasicInteractionsTest, ComputeValueBooleanOr) { ...@@ -118,7 +118,7 @@ TEST_F(BasicInteractionsTest, ComputeValueBooleanOr) {
TEST_F(BasicInteractionsTest, ComputeValueBooleanNot) { TEST_F(BasicInteractionsTest, ComputeValueBooleanNot) {
ComputeValueProto proto; ComputeValueProto proto;
proto.mutable_boolean_not()->set_model_identifier("value"); proto.mutable_boolean_not()->mutable_value()->set_model_identifier("value");
user_model_.SetValue("value", SimpleValue(false)); user_model_.SetValue("value", SimpleValue(false));
// Result model identifier not set. // Result model identifier not set.
...@@ -145,7 +145,7 @@ TEST_F(BasicInteractionsTest, ComputeValueBooleanNot) { ...@@ -145,7 +145,7 @@ TEST_F(BasicInteractionsTest, ComputeValueBooleanNot) {
TEST_F(BasicInteractionsTest, ComputeValueToString) { TEST_F(BasicInteractionsTest, ComputeValueToString) {
ComputeValueProto proto; ComputeValueProto proto;
proto.mutable_to_string()->set_model_identifier("value"); proto.mutable_to_string()->mutable_value()->set_model_identifier("value");
user_model_.SetValue("value", SimpleValue(1)); user_model_.SetValue("value", SimpleValue(1));
// Result model identifier not set. // Result model identifier not set.
...@@ -209,9 +209,9 @@ TEST_F(BasicInteractionsTest, ComputeValueIntegerSum) { ...@@ -209,9 +209,9 @@ TEST_F(BasicInteractionsTest, ComputeValueIntegerSum) {
// Missing fields. // Missing fields.
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
proto.mutable_integer_sum()->set_model_identifier_a("value_a"); proto.mutable_integer_sum()->add_values()->set_model_identifier("value_a");
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
proto.mutable_integer_sum()->set_model_identifier_b("value_b"); proto.mutable_integer_sum()->add_values()->set_model_identifier("value_b");
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
proto.set_result_model_identifier("result"); proto.set_result_model_identifier("result");
EXPECT_TRUE(basic_interactions_.ComputeValue(proto)); EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
...@@ -231,8 +231,9 @@ TEST_F(BasicInteractionsTest, ComputeValueIntegerSum) { ...@@ -231,8 +231,9 @@ TEST_F(BasicInteractionsTest, ComputeValueIntegerSum) {
user_model_.SetValue("value_a", SimpleValue(-1)); user_model_.SetValue("value_a", SimpleValue(-1));
user_model_.SetValue("value_b", SimpleValue(5)); user_model_.SetValue("value_b", SimpleValue(5));
*proto.mutable_integer_sum()->add_values()->mutable_value() = SimpleValue(3);
EXPECT_TRUE(basic_interactions_.ComputeValue(proto)); EXPECT_TRUE(basic_interactions_.ComputeValue(proto));
EXPECT_EQ(user_model_.GetValue("result"), SimpleValue(4)); EXPECT_EQ(user_model_.GetValue("result"), SimpleValue(7));
} }
TEST_F(BasicInteractionsTest, EndActionWithoutCallbackFails) { TEST_F(BasicInteractionsTest, EndActionWithoutCallbackFails) {
...@@ -262,9 +263,11 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) { ...@@ -262,9 +263,11 @@ TEST_F(BasicInteractionsTest, ComputeValueCompare) {
// Fields are missing. // Fields are missing.
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
proto.mutable_comparison()->set_model_identifier_a("value_a"); proto.mutable_comparison()->mutable_value_a()->set_model_identifier(
"value_a");
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
proto.mutable_comparison()->set_model_identifier_b("value_b"); proto.mutable_comparison()->mutable_value_b()->set_model_identifier(
"value_b");
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
proto.set_result_model_identifier("result"); proto.set_result_model_identifier("result");
EXPECT_FALSE(basic_interactions_.ComputeValue(proto)); EXPECT_FALSE(basic_interactions_.ComputeValue(proto));
...@@ -371,7 +374,7 @@ TEST_F(BasicInteractionsTest, ToggleUserAction) { ...@@ -371,7 +374,7 @@ TEST_F(BasicInteractionsTest, ToggleUserAction) {
EXPECT_FALSE(basic_interactions_.ToggleUserAction(proto)); EXPECT_FALSE(basic_interactions_.ToggleUserAction(proto));
proto.set_user_actions_model_identifier("chips"); proto.set_user_actions_model_identifier("chips");
EXPECT_FALSE(basic_interactions_.ToggleUserAction(proto)); EXPECT_FALSE(basic_interactions_.ToggleUserAction(proto));
proto.set_enabled_model_identifier("enabled"); proto.mutable_enabled()->set_model_identifier("enabled");
EXPECT_FALSE(basic_interactions_.ToggleUserAction(proto)); EXPECT_FALSE(basic_interactions_.ToggleUserAction(proto));
proto.set_user_action_identifier("done_identifier"); proto.set_user_action_identifier("done_identifier");
EXPECT_TRUE(basic_interactions_.ToggleUserAction(proto)); EXPECT_TRUE(basic_interactions_.ToggleUserAction(proto));
......
...@@ -83,7 +83,8 @@ message SetModelValueProto { ...@@ -83,7 +83,8 @@ message SetModelValueProto {
// The model identifier to write to. // The model identifier to write to.
optional string model_identifier = 1; optional string model_identifier = 1;
// The value to write. // The value to write.
optional ValueProto value = 2; optional ValueReferenceProto value = 3;
reserved 2;
} }
// Computes a value and stores the result to |result_model_identifier|. // Computes a value and stores the result to |result_model_identifier|.
...@@ -109,31 +110,33 @@ message ComputeValueProto { ...@@ -109,31 +110,33 @@ message ComputeValueProto {
// Performs a logical AND on all specified values. // Performs a logical AND on all specified values.
message BooleanAndProto { message BooleanAndProto {
// The model identifiers to logically AND. All identifiers must point to // The values to logically AND. All values must be single booleans.
// boolean ValueProtos. repeated ValueReferenceProto values = 2;
repeated string model_identifiers = 1; reserved 1;
} }
// Performs a logical OR on all specified values. // Performs a logical OR on all specified values.
message BooleanOrProto { message BooleanOrProto {
// The model identifiers to logically OR. All identifiers must point to // The values to logically OR. All values must be single booleans.
// boolean ValueProtos. repeated ValueReferenceProto values = 2;
repeated string model_identifiers = 1; reserved 1;
} }
// Performs a logical NOT on the specified value. // Performs a logical NOT on the specified value.
message BooleanNotProto { message BooleanNotProto {
// The model identifier to logically invert. Must point to a boolean value. // The value to logically invert. Must be a single boolean.
optional string model_identifier = 1; optional ValueReferenceProto value = 2;
reserved 1;
} }
// Creates a string representation of the specified value. // Creates a string representation of the specified value.
message ToStringProto { message ToStringProto {
// The model identifier to stringify. // The value to stringify.
optional string model_identifier = 1; optional ValueReferenceProto value = 3;
// Optional format options. // Optional format options.
oneof format_options { DateFormatProto date_format = 2; } oneof format_options { DateFormatProto date_format = 2; }
reserved 1;
} }
// A format string for a date, such as "EEE, MMM d". See // A format string for a date, such as "EEE, MMM d". See
...@@ -156,19 +159,21 @@ message ValueComparisonProto { ...@@ -156,19 +159,21 @@ message ValueComparisonProto {
} }
// The first value to compare. // The first value to compare.
optional string model_identifier_a = 1; optional ValueReferenceProto value_a = 4;
// The second value to compare. // The second value to compare.
optional string model_identifier_b = 2; optional ValueReferenceProto value_b = 5;
// The comparison mode. // The comparison mode.
optional Mode mode = 3; optional Mode mode = 3;
reserved 1, 2;
} }
// Computes the sum of two single integers. // Computes the sum of all input integers.
message IntegerSumProto { message IntegerSumProto {
// The first model identifier. Must point to an integer value. // The values to sum. All values must be single integers.
optional string model_identifier_a = 1; repeated ValueReferenceProto values = 3;
// The second model identifier. Must point to an integer value.
optional string model_identifier_b = 2; reserved 1, 2;
} }
// Displays a standard info popup. // Displays a standard info popup.
...@@ -187,12 +192,12 @@ message ShowListPopupProto { ...@@ -187,12 +192,12 @@ message ShowListPopupProto {
DISABLED = 1; DISABLED = 1;
ENABLED = 2; ENABLED = 2;
} }
// The item names to show in the list. Must be a list of strings. // The item names to show in the list. Must be a StringList.
optional string item_names_model_identifier = 1; optional ValueReferenceProto item_names = 6;
// Optional, must be the same length as the list stored at // Optional, must be the same length as the list stored at
// |items_list_model_identifier| if specified. Will default to ENABLED for all // |items_list_model_identifier| if specified. Will default to ENABLED for all
// items if not specified. Must be a list of int32 |ItemType| if specified. // items if not specified. Must be a list of int32 |ItemType| if specified.
optional string item_types_model_identifier = 2; optional ValueReferenceProto item_types = 7;
// The indices of the selected items (both input and output). Must be a list // The indices of the selected items (both input and output). Must be a list
// of integers. // of integers.
optional string selected_item_indices_model_identifier = 3; optional string selected_item_indices_model_identifier = 3;
...@@ -201,14 +206,17 @@ message ShowListPopupProto { ...@@ -201,14 +206,17 @@ message ShowListPopupProto {
// Optional output model identifier to store the names of the selected items // Optional output model identifier to store the names of the selected items
// in a StringList. // in a StringList.
optional string selected_item_names_model_identifier = 5; optional string selected_item_names_model_identifier = 5;
reserved 1, 2;
} }
// Sets the list of available user actions. User actions are either direct // Sets the list of available user actions. User actions are either direct
// actions performed via assistant and/or chips that users can tap. // actions performed via assistant and/or chips that users can tap.
message SetUserActionsProto { message SetUserActionsProto {
// The model identifier containing the user actions. Must point to a // The user actions to set. Must contain a UserActionList value.
// UserActionList value. optional ValueReferenceProto user_actions = 2;
optional string model_identifier = 1;
reserved 1;
} }
// Enables or disables a single user action. Modifies the value in-place. // Enables or disables a single user action. Modifies the value in-place.
...@@ -217,9 +225,11 @@ message ToggleUserActionProto { ...@@ -217,9 +225,11 @@ message ToggleUserActionProto {
optional string user_actions_model_identifier = 1; optional string user_actions_model_identifier = 1;
// The identifier of the specific user action to modify. // The identifier of the specific user action to modify.
optional string user_action_identifier = 2; optional string user_action_identifier = 2;
// Whether the user action should be enabled or disabled. Should point to a // Whether the user action should be enabled or disabled. Should be a single
// single boolean. // boolean.
optional string enabled_model_identifier = 3; optional ValueReferenceProto enabled = 4;
reserved 3;
} }
// Ends the generic Ui action (this is usually tied to a chip). // Ends the generic Ui action (this is usually tied to a chip).
...@@ -235,24 +245,25 @@ message EndActionProto { ...@@ -235,24 +245,25 @@ message EndActionProto {
// Displays a calendar popup that lets the user select a date. // Displays a calendar popup that lets the user select a date.
message ShowCalendarPopupProto { message ShowCalendarPopupProto {
// The date model identifier (both input and output). Must point to a single // The date model identifier (both input and output). Must point to a single
// DateList. If not set, the calendar will default to the current date. // Date. If not set, the calendar will default to the current date.
optional string date_model_identifier = 1; optional string date_model_identifier = 1;
// The model identifier for the minimum allowed date. Must point to a single // The minimum allowed date. Must point to a single Date.
// DateList. optional ValueReferenceProto min_date = 4;
optional string min_date_model_identifier = 2; // The maximum allowed date. Must point to a single Date.
// The model identifier for the minimum allowed date. Must point to a single optional ValueReferenceProto max_date = 5;
// DateList.
optional string max_date_model_identifier = 3; reserved 2, 3;
} }
// Modifies the displayed text of a text view or a text input view. // Modifies the displayed text of a text view or a text input view.
message SetTextProto { message SetTextProto {
// The model identifier containing the text to set. Must point to a single // The text to set. Must be a single string.
// string. optional ValueReferenceProto text = 3;
optional string model_identifier = 1;
// The text view to modify. Must point to a text view or a text input // The text view to modify. Must point to a text view or a text input
// view. // view.
optional string view_identifier = 2; optional string view_identifier = 2;
reserved 1;
} }
// Modifies a view's visibiliy. // Modifies a view's visibiliy.
...@@ -260,7 +271,8 @@ message SetViewVisibilityProto { ...@@ -260,7 +271,8 @@ message SetViewVisibilityProto {
// The view to modify. // The view to modify.
optional string view_identifier = 1; optional string view_identifier = 1;
// The model identifier containing the visibility flag. Must point to a single // The visibility flag. Must be a single boolean.
// bool. optional ValueReferenceProto visible = 3;
optional string model_identifier = 2;
reserved 2;
} }
...@@ -31,6 +31,13 @@ message ValueProto { ...@@ -31,6 +31,13 @@ message ValueProto {
} }
} }
message ValueReferenceProto {
oneof kind {
ValueProto value = 1;
string model_identifier = 2;
}
}
message StringList { message StringList {
repeated string values = 1; repeated string values = 1;
} }
......
...@@ -42,6 +42,18 @@ base::Optional<ValueProto> UserModel::GetValue( ...@@ -42,6 +42,18 @@ base::Optional<ValueProto> UserModel::GetValue(
return base::nullopt; return base::nullopt;
} }
base::Optional<ValueProto> UserModel::GetValue(
const ValueReferenceProto& reference) const {
switch (reference.kind_case()) {
case ValueReferenceProto::kValue:
return reference.value();
case ValueReferenceProto::kModelIdentifier:
return GetValue(reference.model_identifier());
case ValueReferenceProto::KIND_NOT_SET:
return base::nullopt;
}
}
void UserModel::MergeWithProto(const ModelProto& another, void UserModel::MergeWithProto(const ModelProto& another,
bool force_notifications) { bool force_notifications) {
for (const auto& another_value : another.values()) { for (const auto& another_value : another.values()) {
......
...@@ -49,15 +49,18 @@ class UserModel { ...@@ -49,15 +49,18 @@ class UserModel {
// Returns the value for |identifier| or nullopt if there is no such value. // Returns the value for |identifier| or nullopt if there is no such value.
base::Optional<ValueProto> GetValue(const std::string& identifier) const; base::Optional<ValueProto> GetValue(const std::string& identifier) const;
// Returns the value for |reference| or nullopt if there is no such value.
base::Optional<ValueProto> GetValue(
const ValueReferenceProto& reference) const;
// Returns all specified values in a new std::vector. Returns nullopt if any // Returns all specified values in a new std::vector. Returns nullopt if any
// of the requested values was not found. |model_identifiers| must be // of the requested values was not found.
// a std::string iterable.
template <class T> template <class T>
base::Optional<std::vector<ValueProto>> GetValues( base::Optional<std::vector<ValueProto>> GetValues(
const T& model_identifiers) const { const T& value_references) const {
std::vector<ValueProto> values; std::vector<ValueProto> values;
for (const auto& identifier : model_identifiers) { for (const auto& reference : value_references) {
auto value = GetValue(identifier); auto value = GetValue(reference);
if (!value.has_value()) { if (!value.has_value()) {
return base::nullopt; return base::nullopt;
} }
......
...@@ -205,6 +205,18 @@ std::ostream& operator<<(std::ostream& out, const ValueProto& value) { ...@@ -205,6 +205,18 @@ std::ostream& operator<<(std::ostream& out, const ValueProto& value) {
return out; return out;
} }
std::ostream& operator<<(std::ostream& out,
const ValueReferenceProto& reference) {
switch (reference.kind_case()) {
case ValueReferenceProto::kValue:
return out << reference.value();
case ValueReferenceProto::kModelIdentifier:
return out << reference.model_identifier();
case ValueReferenceProto::KIND_NOT_SET:
return out;
}
}
// Intended for debugging. Writes a string representation of |value| to |out|. // Intended for debugging. Writes a string representation of |value| to |out|.
std::ostream& operator<<(std::ostream& out, std::ostream& operator<<(std::ostream& out,
const ModelProto::ModelValue& value) { const ModelProto::ModelValue& value) {
......
...@@ -40,6 +40,8 @@ bool operator<(const DateProto& value_a, const DateProto& value_b); ...@@ -40,6 +40,8 @@ bool operator<(const DateProto& value_a, const DateProto& value_b);
// Intended for debugging. // Intended for debugging.
std::ostream& operator<<(std::ostream& out, const ValueProto& value); std::ostream& operator<<(std::ostream& out, const ValueProto& value);
std::ostream& operator<<(std::ostream& out,
const ValueReferenceProto& reference);
std::ostream& operator<<(std::ostream& out, std::ostream& operator<<(std::ostream& out,
const ModelProto::ModelValue& value); const ModelProto::ModelValue& value);
std::ostream& operator<<(std::ostream& out, const UserActionProto& value); std::ostream& operator<<(std::ostream& out, const UserActionProto& value);
......
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