Commit c245a507 authored by Joshua Pawlicki's avatar Joshua Pawlicki Committed by Commit Bot

Revert "[Autofill Assistant] Added ShowCalendarPopup to UI framework."

This reverts commit f440b571.

Reason for revert: Breaks compile:

[8419/52202] CXX obj/chrome/browser/browser/ui_controller_android_utils.o
FAILED: obj/chrome/browser/browser/ui_controller_android_utils.o
/b/s/w/ir/cache/goma/client/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF...(too long)
../../chrome/browser/android/autofill_assistant/ui_controller_android_utils.cc:135:53: error: calling a private constructor of class 'JniIntWrapper'
Java_AssistantDateTime_Constructor(env, value.year(), value.month(),
^
../../base/android/jni_int_wrapper.h:46:3: note: declared private here
JniIntWrapper(long);
^
1 error generated.

Original change's description:
> [Autofill Assistant] Added ShowCalendarPopup to UI framework.
> 
> This adds a new interaction to the framework, which shows a calendar
> popup and lets the user set or clear a date from the specified range.
> 
> Bug: b/145043394
> Change-Id: I739e6b5ccb5821352b1ce63e63d8573bdde74f8f
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2093224
> Commit-Queue: Clemens Arbesser <arbesser@google.com>
> Reviewed-by: Sandro Maggi <sandromaggi@google.com>
> Cr-Commit-Position: refs/heads/master@{#748718}

TBR=arbesser@google.com,marianfe@google.com,sandromaggi@google.com

Change-Id: I3f9bfc40d3c3f7cec4118eb189fdf48709a6e62e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: b/145043394
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2094710Reviewed-by: default avatarJoshua Pawlicki <waffles@chromium.org>
Commit-Queue: Joshua Pawlicki <waffles@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748783}
parent b422cf9f
...@@ -196,7 +196,6 @@ generate_jni("jni_headers") { ...@@ -196,7 +196,6 @@ generate_jni("jni_headers") {
"java/src/org/chromium/chrome/browser/autofill_assistant/overlay/AssistantOverlayModel.java", "java/src/org/chromium/chrome/browser/autofill_assistant/overlay/AssistantOverlayModel.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/user_data/AssistantCollectUserDataModel.java", "java/src/org/chromium/chrome/browser/autofill_assistant/user_data/AssistantCollectUserDataModel.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/user_data/AssistantCollectUserDataNativeDelegate.java", "java/src/org/chromium/chrome/browser/autofill_assistant/user_data/AssistantCollectUserDataNativeDelegate.java",
"java/src/org/chromium/chrome/browser/autofill_assistant/user_data/AssistantDateTime.java",
] ]
} }
......
...@@ -35,13 +35,6 @@ public class AssistantGenericUiDelegate { ...@@ -35,13 +35,6 @@ public class AssistantGenericUiDelegate {
value); value);
} }
void onCalendarPopupDateChanged(String identifier, AssistantValue value) {
assert mNativeAssistantGenericUiDelegate != 0;
AssistantGenericUiDelegateJni.get().onCalendarPopupDateChanged(
mNativeAssistantGenericUiDelegate, AssistantGenericUiDelegate.this, identifier,
value);
}
@CalledByNative @CalledByNative
private void clearNativePtr() { private void clearNativePtr() {
mNativeAssistantGenericUiDelegate = 0; mNativeAssistantGenericUiDelegate = 0;
...@@ -53,7 +46,5 @@ public class AssistantGenericUiDelegate { ...@@ -53,7 +46,5 @@ public class AssistantGenericUiDelegate {
String identifier); String identifier);
void onListPopupSelectionChanged(long nativeAssistantGenericUiDelegate, void onListPopupSelectionChanged(long nativeAssistantGenericUiDelegate,
AssistantGenericUiDelegate caller, String identifier, AssistantValue value); AssistantGenericUiDelegate caller, String identifier, AssistantValue value);
void onCalendarPopupDateChanged(long nativeAssistantGenericUiDelegate,
AssistantGenericUiDelegate caller, String identifier, AssistantValue value);
} }
} }
...@@ -8,11 +8,8 @@ import androidx.annotation.Nullable; ...@@ -8,11 +8,8 @@ import androidx.annotation.Nullable;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.autofill_assistant.user_data.AssistantDateTime;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
/** The Java equivalent to {@code ValueProto}. */ /** The Java equivalent to {@code ValueProto}. */
@JNINamespace("autofill_assistant") @JNINamespace("autofill_assistant")
...@@ -20,41 +17,29 @@ public class AssistantValue { ...@@ -20,41 +17,29 @@ public class AssistantValue {
private final String[] mStrings; private final String[] mStrings;
private final boolean[] mBooleans; private final boolean[] mBooleans;
private final int[] mIntegers; private final int[] mIntegers;
private final List<AssistantDateTime> mDateTimes;
AssistantValue() { AssistantValue() {
mStrings = null; mStrings = null;
mBooleans = null; mBooleans = null;
mIntegers = null; mIntegers = null;
mDateTimes = null;
} }
public AssistantValue(String[] strings) { public AssistantValue(String[] strings) {
mStrings = strings; mStrings = strings;
mBooleans = null; mBooleans = null;
mIntegers = null; mIntegers = null;
mDateTimes = null;
} }
public AssistantValue(boolean[] booleans) { public AssistantValue(boolean[] booleans) {
mStrings = null; mStrings = null;
mBooleans = booleans; mBooleans = booleans;
mIntegers = null; mIntegers = null;
mDateTimes = null;
} }
public AssistantValue(int[] integers) { public AssistantValue(int[] integers) {
mStrings = null; mStrings = null;
mBooleans = null; mBooleans = null;
mIntegers = integers; mIntegers = integers;
mDateTimes = null;
}
public AssistantValue(List<AssistantDateTime> dateTimes) {
mStrings = null;
mBooleans = null;
mIntegers = null;
mDateTimes = dateTimes;
} }
@CalledByNative @CalledByNative
...@@ -77,21 +62,6 @@ public class AssistantValue { ...@@ -77,21 +62,6 @@ public class AssistantValue {
return new AssistantValue(values); return new AssistantValue(values);
} }
@CalledByNative
public static AssistantValue createForDateTimes(List<AssistantDateTime> values) {
return new AssistantValue(values);
}
@CalledByNative
private static List<AssistantDateTime> createDateTimeList() {
return new ArrayList<>();
}
@CalledByNative
private static void addDateTimeToList(List<AssistantDateTime> list, AssistantDateTime value) {
list.add(value);
}
@CalledByNative @CalledByNative
public String[] getStrings() { public String[] getStrings() {
return mStrings; return mStrings;
...@@ -107,25 +77,6 @@ public class AssistantValue { ...@@ -107,25 +77,6 @@ public class AssistantValue {
return mIntegers; return mIntegers;
} }
@CalledByNative
public List<AssistantDateTime> getDateTimes() {
return mDateTimes;
}
public static boolean isDateSingleton(AssistantValue value) {
return value != null && value.mDateTimes != null && value.mDateTimes.size() == 1;
}
@CalledByNative
private static int getListSize(List list) {
return list.size();
}
@CalledByNative
private static Object getListAt(List list, int index) {
return list.get(index);
}
@Override @Override
public boolean equals(@Nullable Object obj) { public boolean equals(@Nullable Object obj) {
if (obj == this) { if (obj == this) {
......
...@@ -4,22 +4,16 @@ ...@@ -4,22 +4,16 @@
package org.chromium.chrome.browser.autofill_assistant.generic_ui; package org.chromium.chrome.browser.autofill_assistant.generic_ui;
import static org.chromium.chrome.browser.autofill_assistant.generic_ui.AssistantValue.isDateSingleton;
import android.content.Context; import android.content.Context;
import android.support.annotation.Nullable;
import android.view.View; import android.view.View;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.autofill_assistant.user_data.AssistantDateTime;
import org.chromium.content.browser.input.PopupItemType; import org.chromium.content.browser.input.PopupItemType;
import org.chromium.content.browser.input.SelectPopupDialog; import org.chromium.content.browser.input.SelectPopupDialog;
import org.chromium.content.browser.input.SelectPopupItem; import org.chromium.content.browser.input.SelectPopupItem;
import org.chromium.content.browser.picker.InputDialogContainer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/** JNI bridge between {@code interaction_handler_android} and Java. */ /** JNI bridge between {@code interaction_handler_android} and Java. */
...@@ -48,41 +42,4 @@ public class AssistantViewInteractions { ...@@ -48,41 +42,4 @@ public class AssistantViewInteractions {
popupItems, multiple, selectedItems); popupItems, multiple, selectedItems);
dialog.show(); dialog.show();
} }
@CalledByNative
private static boolean showCalendarPopup(Context context, @Nullable AssistantValue initialDate,
AssistantValue minDate, AssistantValue maxDate, String outputIdentifier,
AssistantGenericUiDelegate delegate) {
if ((initialDate != null && !isDateSingleton(initialDate)) || !isDateSingleton(minDate)
|| !isDateSingleton(maxDate)) {
return false;
}
InputDialogContainer inputDialogContainer =
new InputDialogContainer(context, new InputDialogContainer.InputActionDelegate() {
@Override
public void cancelDateTimeDialog() {
// Do nothing.
}
@Override
public void replaceDateTime(double value) {
// User tapped the 'clear' button.
if (Double.isNaN(value)) {
delegate.onCalendarPopupDateChanged(outputIdentifier, null);
} else {
delegate.onCalendarPopupDateChanged(outputIdentifier,
AssistantValue.createForDateTimes(Collections.singletonList(
new AssistantDateTime((long) value))));
}
}
});
inputDialogContainer.showDialog(org.chromium.ui.base.ime.TextInputType.DATE,
initialDate != null ? initialDate.getDateTimes().get(0).getTimeInUtcMillis()
: Double.NaN,
minDate.getDateTimes().get(0).getTimeInUtcMillis(),
maxDate.getDateTimes().get(0).getTimeInUtcMillis(), -1, null);
return true;
}
} }
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
package org.chromium.chrome.browser.autofill_assistant.user_data; package org.chromium.chrome.browser.autofill_assistant.user_data;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
...@@ -20,7 +17,6 @@ import java.util.TimeZone; ...@@ -20,7 +17,6 @@ import java.util.TimeZone;
* Note that this class does not make any guarantees with respect to the validity of the represented * Note that this class does not make any guarantees with respect to the validity of the represented
* date/time. * date/time.
*/ */
@JNINamespace("autofill_assistant")
public class AssistantDateTime { public class AssistantDateTime {
/** Year, e.g., 2019. */ /** Year, e.g., 2019. */
private int mYear; private int mYear;
...@@ -35,7 +31,6 @@ public class AssistantDateTime { ...@@ -35,7 +31,6 @@ public class AssistantDateTime {
/** Second in [0-59]. */ /** Second in [0-59]. */
private int mSecond; private int mSecond;
@CalledByNative
public AssistantDateTime(int year, int month, int day, int hour, int minute, int second) { public AssistantDateTime(int year, int month, int day, int hour, int minute, int second) {
set(year, month, day, hour, minute, second); set(year, month, day, hour, minute, second);
} }
...@@ -80,17 +75,14 @@ public class AssistantDateTime { ...@@ -80,17 +75,14 @@ public class AssistantDateTime {
return calendar.getTimeInMillis(); return calendar.getTimeInMillis();
} }
@CalledByNative
public int getYear() { public int getYear() {
return mYear; return mYear;
} }
@CalledByNative
public int getMonth() { public int getMonth() {
return mMonth; return mMonth;
} }
@CalledByNative
public int getDay() { public int getDay() {
return mDay; return mDay;
} }
......
...@@ -57,26 +57,6 @@ void AssistantGenericUiDelegate::OnListPopupSelectionChanged( ...@@ -57,26 +57,6 @@ void AssistantGenericUiDelegate::OnListPopupSelectionChanged(
ui_controller_->OnValueChanged(identifier, value); ui_controller_->OnValueChanged(identifier, value);
} }
// TODO(b/145043394): refactor delegate methods into a single SetValue() where
// possible.
void AssistantGenericUiDelegate::OnCalendarPopupDateChanged(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
const base::android::JavaParamRef<jstring>& jmodel_identifier,
const base::android::JavaParamRef<jobject>& jvalue) {
std::string identifier;
if (jmodel_identifier) {
base::android::ConvertJavaStringToUTF8(env, jmodel_identifier, &identifier);
}
ValueProto value;
if (jvalue) {
value = ui_controller_android_utils::ToNativeValue(env, jvalue);
}
ui_controller_->OnValueChanged(identifier, value);
}
base::android::ScopedJavaGlobalRef<jobject> base::android::ScopedJavaGlobalRef<jobject>
AssistantGenericUiDelegate::GetJavaObject() { AssistantGenericUiDelegate::GetJavaObject() {
return java_assistant_generic_ui_delegate_; return java_assistant_generic_ui_delegate_;
......
...@@ -32,16 +32,6 @@ class AssistantGenericUiDelegate { ...@@ -32,16 +32,6 @@ class AssistantGenericUiDelegate {
const base::android::JavaParamRef<jstring>& jmodel_identifier, const base::android::JavaParamRef<jstring>& jmodel_identifier,
const base::android::JavaParamRef<jobject>& jvalue); const base::android::JavaParamRef<jobject>& jvalue);
// The date in a calendar popup has changed. |jmodel_identifier| is the model
// identifier that the new date should be written to. |jvalue| is a Java
// AssistantValue containing a single AssistantDateTime with the new date, or
// nullptr if the date was cleared.
void OnCalendarPopupDateChanged(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller,
const base::android::JavaParamRef<jstring>& jmodel_identifier,
const base::android::JavaParamRef<jobject>& jvalue);
base::android::ScopedJavaGlobalRef<jobject> GetJavaObject(); base::android::ScopedJavaGlobalRef<jobject> GetJavaObject();
private: private:
......
...@@ -154,54 +154,6 @@ void ShowListPopup(base::WeakPtr<UserModel> user_model, ...@@ -154,54 +154,6 @@ void ShowListPopup(base::WeakPtr<UserModel> user_model,
proto.allow_multiselect(), jidentifier, jdelegate); proto.allow_multiselect(), jidentifier, jdelegate);
} }
void ShowCalendarPopup(base::WeakPtr<UserModel> user_model,
const ShowCalendarPopupProto& proto,
base::android::ScopedJavaGlobalRef<jobject> jcontext,
base::android::ScopedJavaGlobalRef<jobject> jdelegate) {
if (!user_model) {
return;
}
JNIEnv* env = base::android::AttachCurrentThread();
auto initial_date = user_model->GetValue(proto.date_model_identifier());
if (initial_date.has_value() && initial_date->dates().values_size() != 1) {
DVLOG(2) << "Failed to show calendar popup: date_model_identifier must be "
"empty or contain single date, but was "
<< *initial_date;
return;
}
auto min_date = user_model->GetValue(proto.min_date_model_identifier());
if (!min_date.has_value() || min_date->dates().values_size() != 1) {
DVLOG(2) << "Failed to show calendar popup: min_date not found or invalid "
"in user model at "
<< proto.min_date_model_identifier();
return;
}
auto max_date = user_model->GetValue(proto.max_date_model_identifier());
if (!max_date.has_value() || max_date->dates().values_size() != 1) {
DVLOG(2) << "Failed to show calendar popup: max_date not found or invalid "
"in user model at "
<< proto.max_date_model_identifier();
return;
}
jboolean jsuccess = Java_AssistantViewInteractions_showCalendarPopup(
env, jcontext,
initial_date.has_value()
? ui_controller_android_utils::ToJavaValue(env, *initial_date)
: nullptr,
ui_controller_android_utils::ToJavaValue(env, *min_date),
ui_controller_android_utils::ToJavaValue(env, *max_date),
base::android::ConvertUTF8ToJavaString(env,
proto.date_model_identifier()),
jdelegate);
if (!jsuccess) {
DVLOG(2) << "Failed to show calendar popup: JNI call failed";
}
}
base::Optional<EventHandler::EventKey> CreateEventKeyFromProto( base::Optional<EventHandler::EventKey> CreateEventKeyFromProto(
const EventProto& proto, const EventProto& proto,
JNIEnv* env, JNIEnv* env,
...@@ -300,17 +252,6 @@ CreateInteractionCallbackFromProto( ...@@ -300,17 +252,6 @@ CreateInteractionCallbackFromProto(
return base::Optional<InteractionHandlerAndroid::InteractionCallback>( return base::Optional<InteractionHandlerAndroid::InteractionCallback>(
base::BindRepeating(&TryEndAction, basic_interactions->GetWeakPtr(), base::BindRepeating(&TryEndAction, basic_interactions->GetWeakPtr(),
proto.end_action())); proto.end_action()));
case CallbackProto::kShowCalendarPopup:
if (proto.show_calendar_popup().date_model_identifier().empty()) {
VLOG(1) << "Error creating ShowCalendarPopup interaction: "
"date_model_identifier not set";
return base::nullopt;
}
return base::Optional<InteractionHandlerAndroid::InteractionCallback>(
base::BindRepeating(&ShowCalendarPopup, user_model->GetWeakPtr(),
proto.show_calendar_popup(), jcontext,
jdelegate));
break;
case CallbackProto::KIND_NOT_SET: case CallbackProto::KIND_NOT_SET:
VLOG(1) << "Error creating interaction: kind not set"; VLOG(1) << "Error creating interaction: kind not set";
return base::nullopt; return base::nullopt;
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/android/jni_array.h" #include "base/android/jni_array.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
#include "chrome/android/features/autofill_assistant/jni_headers/AssistantColor_jni.h" #include "chrome/android/features/autofill_assistant/jni_headers/AssistantColor_jni.h"
#include "chrome/android/features/autofill_assistant/jni_headers/AssistantDateTime_jni.h"
#include "chrome/android/features/autofill_assistant/jni_headers/AssistantDialogButton_jni.h" #include "chrome/android/features/autofill_assistant/jni_headers/AssistantDialogButton_jni.h"
#include "chrome/android/features/autofill_assistant/jni_headers/AssistantDimension_jni.h" #include "chrome/android/features/autofill_assistant/jni_headers/AssistantDimension_jni.h"
#include "chrome/android/features/autofill_assistant/jni_headers/AssistantInfoPopup_jni.h" #include "chrome/android/features/autofill_assistant/jni_headers/AssistantInfoPopup_jni.h"
...@@ -127,16 +126,6 @@ base::android::ScopedJavaLocalRef<jobject> ToJavaValue( ...@@ -127,16 +126,6 @@ base::android::ScopedJavaLocalRef<jobject> ToJavaValue(
NOTREACHED(); NOTREACHED();
return nullptr; return nullptr;
} }
case ValueProto::kDates: {
auto jlist = Java_AssistantValue_createDateTimeList(env);
for (const auto& value : proto.dates().values()) {
Java_AssistantValue_addDateTimeToList(
env, jlist,
Java_AssistantDateTime_Constructor(env, value.year(), value.month(),
value.day(), 0, 0, 0));
}
return Java_AssistantValue_createForDateTimes(env, jlist);
}
case ValueProto::KIND_NOT_SET: case ValueProto::KIND_NOT_SET:
return Java_AssistantValue_create(env); return Java_AssistantValue_create(env);
} }
...@@ -147,47 +136,33 @@ ValueProto ToNativeValue(JNIEnv* env, ...@@ -147,47 +136,33 @@ ValueProto ToNativeValue(JNIEnv* env,
ValueProto proto; ValueProto proto;
auto jints = Java_AssistantValue_getIntegers(env, jvalue); auto jints = Java_AssistantValue_getIntegers(env, jvalue);
if (jints) { if (jints) {
auto* mutable_ints = proto.mutable_ints();
std::vector<int> ints; std::vector<int> ints;
base::android::JavaIntArrayToIntVector(env, jints, &ints); base::android::JavaIntArrayToIntVector(env, jints, &ints);
proto.mutable_ints();
for (int i : ints) { for (int i : ints) {
mutable_ints->add_values(i); proto.mutable_ints()->add_values(i);
} }
return proto; return proto;
} }
auto jbooleans = Java_AssistantValue_getBooleans(env, jvalue); auto jbooleans = Java_AssistantValue_getBooleans(env, jvalue);
if (jbooleans) { if (jbooleans) {
auto* mutable_booleans = proto.mutable_booleans();
std::vector<bool> booleans; std::vector<bool> booleans;
base::android::JavaBooleanArrayToBoolVector(env, jbooleans, &booleans); base::android::JavaBooleanArrayToBoolVector(env, jbooleans, &booleans);
proto.mutable_booleans();
for (auto b : booleans) { for (auto b : booleans) {
mutable_booleans->add_values(b); proto.mutable_booleans()->add_values(b);
} }
return proto; return proto;
} }
auto jstrings = Java_AssistantValue_getStrings(env, jvalue); auto jstrings = Java_AssistantValue_getStrings(env, jvalue);
if (jstrings) { if (jstrings) {
auto* mutable_strings = proto.mutable_strings();
std::vector<std::string> strings; std::vector<std::string> strings;
base::android::AppendJavaStringArrayToStringVector(env, jstrings, &strings); base::android::AppendJavaStringArrayToStringVector(env, jstrings, &strings);
proto.mutable_strings();
for (const auto& string : strings) { for (const auto& string : strings) {
mutable_strings->add_values(string); proto.mutable_strings()->add_values(string);
}
return proto;
}
auto jdatetimes = Java_AssistantValue_getDateTimes(env, jvalue);
if (jdatetimes) {
auto* mutable_dates = proto.mutable_dates();
for (int i = 0; i < Java_AssistantValue_getListSize(env, jdatetimes); ++i) {
auto jvalue = Java_AssistantValue_getListAt(env, jdatetimes, i);
DateProto date;
date.set_year(Java_AssistantDateTime_getYear(env, jvalue));
date.set_month(Java_AssistantDateTime_getMonth(env, jvalue));
date.set_day(Java_AssistantDateTime_getDay(env, jvalue));
*mutable_dates->add_values() = date;
} }
return proto; return proto;
} }
......
...@@ -34,7 +34,6 @@ message CallbackProto { ...@@ -34,7 +34,6 @@ message CallbackProto {
ComputeValueProto compute_value = 4; ComputeValueProto compute_value = 4;
SetUserActionsProto set_user_actions = 5; SetUserActionsProto set_user_actions = 5;
EndActionProto end_action = 6; EndActionProto end_action = 6;
ShowCalendarPopupProto show_calendar_popup = 7;
} }
} }
...@@ -153,16 +152,3 @@ message EndActionProto { ...@@ -153,16 +152,3 @@ message EndActionProto {
// The status to report to the backend. // The status to report to the backend.
optional ProcessedActionStatusProto status = 1; optional ProcessedActionStatusProto status = 1;
} }
// Displays a calendar popup that lets the user select a date.
message ShowCalendarPopupProto {
// 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.
optional string date_model_identifier = 1;
// The model identifier for the minimum allowed date. Must point to a single
// DateList.
optional string min_date_model_identifier = 2;
// The model identifier for the minimum allowed date. Must point to a single
// DateList.
optional string max_date_model_identifier = 3;
}
...@@ -27,7 +27,6 @@ message ValueProto { ...@@ -27,7 +27,6 @@ message ValueProto {
BooleanList booleans = 2; BooleanList booleans = 2;
IntList ints = 3; IntList ints = 3;
UserActionList user_actions = 4; UserActionList user_actions = 4;
DateList dates = 5;
} }
} }
...@@ -47,10 +46,6 @@ message UserActionList { ...@@ -47,10 +46,6 @@ message UserActionList {
repeated UserActionProto values = 1; repeated UserActionProto values = 1;
} }
message DateList {
repeated DateProto values = 1;
}
// Next: 22 // Next: 22
enum ProcessedActionStatusProto { enum ProcessedActionStatusProto {
UNKNOWN_ACTION_STATUS = 0; UNKNOWN_ACTION_STATUS = 0;
...@@ -249,29 +244,3 @@ message UserActionProto { ...@@ -249,29 +244,3 @@ message UserActionProto {
// A unique identifier for this user action. // A unique identifier for this user action.
optional string identifier = 3; optional string identifier = 3;
} }
message DateProto {
optional int64 year = 1;
// Month of the year in the range [1-12].
optional int32 month = 2;
// Day of the month in the range [1-31].
optional int32 day = 3;
}
message TimeProto {
// Hour in the range [0-23].
optional int32 hour = 1;
// Minute in the range [0-59].
optional int32 minute = 2;
// Second in the range [0-59].
optional int32 second = 3;
}
message DateTimeProto {
optional DateProto date = 1;
optional TimeProto time = 2;
}
...@@ -1424,6 +1424,32 @@ message StopProto { ...@@ -1424,6 +1424,32 @@ message StopProto {
reserved 1; // stop_action_type reserved 1; // stop_action_type
} }
message DateProto {
optional int64 year = 1;
// Month of the year in the range [1-12].
optional int32 month = 2;
// Day of the month in the range [1-31].
optional int32 day = 3;
}
message TimeProto {
// Hour in the range [0-23].
optional int32 hour = 1;
// Minute in the range [0-59].
optional int32 minute = 2;
// Second in the range [0-59].
optional int32 second = 3;
}
message DateTimeProto {
optional DateProto date = 1;
optional TimeProto time = 2;
}
message DetailsChangesProto { message DetailsChangesProto {
// Whether the changes require user approval. This de-emphasize // Whether the changes require user approval. This de-emphasize
// non-highlighted fields. // non-highlighted fields.
......
...@@ -49,8 +49,6 @@ bool operator==(const ValueProto& value_a, const ValueProto& value_b) { ...@@ -49,8 +49,6 @@ bool operator==(const ValueProto& value_a, const ValueProto& value_b) {
return value_a.ints().values() == value_b.ints().values(); return value_a.ints().values() == value_b.ints().values();
case ValueProto::kUserActions: case ValueProto::kUserActions:
return value_a.user_actions().values() == value_b.user_actions().values(); return value_a.user_actions().values() == value_b.user_actions().values();
case ValueProto::kDates:
return value_a.dates().values() == value_b.dates().values();
case ValueProto::KIND_NOT_SET: case ValueProto::KIND_NOT_SET:
return true; return true;
} }
...@@ -91,12 +89,6 @@ bool operator==(const UserActionProto& value_a, ...@@ -91,12 +89,6 @@ bool operator==(const UserActionProto& value_a,
value_a.identifier() == value_b.identifier(); value_a.identifier() == value_b.identifier();
} }
// Compares two |DateProto| instances and returns true if they exactly match.
bool operator==(const DateProto& value_a, const DateProto& value_b) {
return value_a.year() == value_b.year() &&
value_a.month() == value_b.month() && value_a.day() == value_b.day();
}
// Intended for debugging. Writes a string representation of |values| to |out|. // Intended for debugging. Writes a string representation of |values| to |out|.
template <typename T> template <typename T>
std::ostream& WriteRepeatedField(std::ostream& out, const T& values) { std::ostream& WriteRepeatedField(std::ostream& out, const T& values) {
...@@ -130,12 +122,6 @@ std::ostream& operator<<(std::ostream& out, const UserActionProto& value) { ...@@ -130,12 +122,6 @@ std::ostream& operator<<(std::ostream& out, const UserActionProto& value) {
return out; return out;
} }
// Intended for debugging. '<<' operator specialization for DateProto.
std::ostream& operator<<(std::ostream& out, const DateProto& value) {
out << value.year() << "-" << value.month() << "-" << value.day();
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, const ValueProto& value) { std::ostream& operator<<(std::ostream& out, const ValueProto& value) {
switch (value.kind_case()) { switch (value.kind_case()) {
...@@ -151,9 +137,6 @@ std::ostream& operator<<(std::ostream& out, const ValueProto& value) { ...@@ -151,9 +137,6 @@ std::ostream& operator<<(std::ostream& out, const ValueProto& value) {
case ValueProto::kUserActions: case ValueProto::kUserActions:
out << value.user_actions().values(); out << value.user_actions().values();
break; break;
case ValueProto::kDates:
out << value.dates().values();
break;
case ValueProto::KIND_NOT_SET: case ValueProto::KIND_NOT_SET:
break; break;
} }
...@@ -186,15 +169,6 @@ ValueProto SimpleValue(int i) { ...@@ -186,15 +169,6 @@ ValueProto SimpleValue(int i) {
return value; return value;
} }
ValueProto SimpleValue(const DateProto& proto) {
ValueProto value;
auto* date = value.mutable_dates()->add_values();
date->set_year(proto.year());
date->set_month(proto.month());
date->set_day(proto.day());
return value;
}
ModelProto::ModelValue SimpleModelValue(const std::string& identifier, ModelProto::ModelValue SimpleModelValue(const std::string& identifier,
const ValueProto& value) { const ValueProto& value) {
ModelProto::ModelValue model_value; ModelProto::ModelValue model_value;
...@@ -239,10 +213,6 @@ bool AreAllValuesOfSize(const std::vector<ValueProto>& values, ...@@ -239,10 +213,6 @@ bool AreAllValuesOfSize(const std::vector<ValueProto>& values,
if (value.user_actions().values_size() != target_size) if (value.user_actions().values_size() != target_size)
return false; return false;
break; break;
case ValueProto::kDates:
if (value.dates().values_size() != target_size)
return false;
break;
case ValueProto::KIND_NOT_SET: case ValueProto::KIND_NOT_SET:
if (target_size != 0) { if (target_size != 0) {
return false; return false;
...@@ -291,12 +261,6 @@ base::Optional<ValueProto> CombineValues( ...@@ -291,12 +261,6 @@ base::Optional<ValueProto> CombineValues(
*result.mutable_user_actions()->add_values() = action; *result.mutable_user_actions()->add_values() = action;
}); });
break; break;
case ValueProto::kDates:
std::for_each(value.dates().values().begin(),
value.dates().values().end(), [&](const auto& date) {
*result.mutable_dates()->add_values() = date;
});
break;
case ValueProto::KIND_NOT_SET: case ValueProto::KIND_NOT_SET:
NOTREACHED(); NOTREACHED();
return base::nullopt; return base::nullopt;
......
...@@ -31,21 +31,16 @@ bool operator==(const DirectActionProto& value_a, ...@@ -31,21 +31,16 @@ bool operator==(const DirectActionProto& value_a,
// Custom comparison operator for |UserActionProto|. // Custom comparison operator for |UserActionProto|.
bool operator==(const UserActionProto& value_a, const UserActionProto& value_b); bool operator==(const UserActionProto& value_a, const UserActionProto& value_b);
// Custom comparison operator for |DateProto|.
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, 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);
std::ostream& operator<<(std::ostream& out, const DateProto& value);
// Convenience constructors. // Convenience constructors.
ValueProto SimpleValue(bool value); ValueProto SimpleValue(bool value);
ValueProto SimpleValue(const std::string& value); ValueProto SimpleValue(const std::string& value);
ValueProto SimpleValue(int value); ValueProto SimpleValue(int value);
ValueProto SimpleValue(const DateProto& value);
ModelProto::ModelValue SimpleModelValue(const std::string& identifier, ModelProto::ModelValue SimpleModelValue(const std::string& identifier,
const ValueProto& value); const ValueProto& value);
......
...@@ -9,48 +9,38 @@ namespace autofill_assistant { ...@@ -9,48 +9,38 @@ namespace autofill_assistant {
namespace value_util { namespace value_util {
namespace {
ValueProto CreateStringValue() {
ValueProto value;
value.mutable_strings()->add_values("Aurea prima");
value.mutable_strings()->add_values("sata est,");
value.mutable_strings()->add_values("aetas quae");
value.mutable_strings()->add_values("vindice nullo");
value.mutable_strings()->add_values("ü万𠜎");
return value;
}
ValueProto CreateIntValue() {
ValueProto value;
value.mutable_ints()->add_values(1);
value.mutable_ints()->add_values(123);
value.mutable_ints()->add_values(5);
value.mutable_ints()->add_values(-132);
return value;
}
ValueProto CreateBoolValue() {
ValueProto value;
value.mutable_booleans()->add_values(true);
value.mutable_booleans()->add_values(false);
value.mutable_booleans()->add_values(true);
value.mutable_booleans()->add_values(true);
return value;
}
DateProto CreateDateProto(int year, int month, int day) {
DateProto proto;
proto.set_year(year);
proto.set_month(month);
proto.set_day(day);
return proto;
}
} // namespace
class ValueUtilTest : public testing::Test { class ValueUtilTest : public testing::Test {
public: public:
ValueUtilTest() = default; ValueUtilTest() = default;
~ValueUtilTest() override {} ~ValueUtilTest() override {}
ValueProto CreateStringValue() const {
ValueProto value;
value.mutable_strings()->add_values("Aurea prima");
value.mutable_strings()->add_values("sata est,");
value.mutable_strings()->add_values("aetas quae");
value.mutable_strings()->add_values("vindice nullo");
value.mutable_strings()->add_values("ü万𠜎");
return value;
}
ValueProto CreateIntValue() const {
ValueProto value;
value.mutable_ints()->add_values(1);
value.mutable_ints()->add_values(123);
value.mutable_ints()->add_values(5);
value.mutable_ints()->add_values(-132);
return value;
}
ValueProto CreateBoolValue() const {
ValueProto value;
value.mutable_booleans()->add_values(true);
value.mutable_booleans()->add_values(false);
value.mutable_booleans()->add_values(true);
value.mutable_booleans()->add_values(true);
return value;
}
}; };
TEST_F(ValueUtilTest, DifferentTypesComparison) { TEST_F(ValueUtilTest, DifferentTypesComparison) {
...@@ -58,24 +48,18 @@ TEST_F(ValueUtilTest, DifferentTypesComparison) { ...@@ -58,24 +48,18 @@ TEST_F(ValueUtilTest, DifferentTypesComparison) {
ValueProto value_b = CreateStringValue(); ValueProto value_b = CreateStringValue();
ValueProto value_c = CreateIntValue(); ValueProto value_c = CreateIntValue();
ValueProto value_d = CreateBoolValue(); ValueProto value_d = CreateBoolValue();
ValueProto value_e = SimpleValue(CreateDateProto(2020, 8, 30));
EXPECT_FALSE(value_a == value_b); EXPECT_FALSE(value_a == value_b);
EXPECT_FALSE(value_a == value_c); EXPECT_FALSE(value_a == value_c);
EXPECT_FALSE(value_a == value_d); EXPECT_FALSE(value_a == value_d);
EXPECT_FALSE(value_a == value_e);
EXPECT_FALSE(value_b == value_c); EXPECT_FALSE(value_b == value_c);
EXPECT_FALSE(value_b == value_d); EXPECT_FALSE(value_b == value_d);
EXPECT_FALSE(value_b == value_e);
EXPECT_FALSE(value_c == value_d); EXPECT_FALSE(value_c == value_d);
EXPECT_FALSE(value_c == value_e);
EXPECT_FALSE(value_d == value_e);
EXPECT_TRUE(value_a == value_a); EXPECT_TRUE(value_a == value_a);
EXPECT_TRUE(value_b == value_b); EXPECT_TRUE(value_b == value_b);
EXPECT_TRUE(value_c == value_c); EXPECT_TRUE(value_c == value_c);
EXPECT_TRUE(value_d == value_d); EXPECT_TRUE(value_d == value_d);
EXPECT_TRUE(value_e == value_e);
} }
TEST_F(ValueUtilTest, EmptyValueComparison) { TEST_F(ValueUtilTest, EmptyValueComparison) {
...@@ -136,19 +120,6 @@ TEST_F(ValueUtilTest, BoolComparison) { ...@@ -136,19 +120,6 @@ TEST_F(ValueUtilTest, BoolComparison) {
EXPECT_TRUE(value_a == value_b); EXPECT_TRUE(value_a == value_b);
} }
TEST_F(ValueUtilTest, DateComparison) {
ValueProto value_a = SimpleValue(CreateDateProto(2020, 4, 18));
ValueProto value_b = value_a;
EXPECT_TRUE(value_a == value_b);
*value_a.mutable_dates()->add_values() = CreateDateProto(2020, 6, 14);
*value_b.mutable_dates()->add_values() = CreateDateProto(2020, 6, 15);
EXPECT_FALSE(value_a == value_b);
*value_b.mutable_dates()->mutable_values(1) = CreateDateProto(2020, 6, 14);
EXPECT_TRUE(value_a == value_b);
}
TEST_F(ValueUtilTest, AreAllValuesOfType) { TEST_F(ValueUtilTest, AreAllValuesOfType) {
ValueProto value_a; ValueProto value_a;
ValueProto value_b; ValueProto value_b;
......
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