Commit 3fd1c30b authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Use NotificationActionType Mojo type instead of PlatformNotificationActionType

This CL replaces all uses of blink::PlatformNotificationActionType with
blink::mojom::NotificationActionType in order to reduce type conversion
between them.

Bug: 919392
Change-Id: I70426fe09f9d42085fa54ffaebf8a0587ca8ca04
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2498241Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#821125}
parent 98b751e8
...@@ -452,7 +452,7 @@ PlatformNotificationServiceImpl::CreateNotificationFromData( ...@@ -452,7 +452,7 @@ PlatformNotificationServiceImpl::CreateNotificationFromData(
// the 1x bitmap - crbug.com/585815. // the 1x bitmap - crbug.com/585815.
button.icon = button.icon =
gfx::Image::CreateFrom1xBitmap(notification_resources.action_icons[i]); gfx::Image::CreateFrom1xBitmap(notification_resources.action_icons[i]);
if (action.type == blink::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT) { if (action.type == blink::mojom::NotificationActionType::TEXT) {
button.placeholder = action.placeholder.value_or( button.placeholder = action.placeholder.value_or(
l10n_util::GetStringUTF16(IDS_NOTIFICATION_REPLY_PLACEHOLDER)); l10n_util::GetStringUTF16(IDS_NOTIFICATION_REPLY_PLACEHOLDER));
} }
......
...@@ -213,9 +213,9 @@ TEST_F(PlatformNotificationServiceTest, DisplayPersistentPropertiesMatch) { ...@@ -213,9 +213,9 @@ TEST_F(PlatformNotificationServiceTest, DisplayPersistentPropertiesMatch) {
data.vibration_pattern = vibration_pattern; data.vibration_pattern = vibration_pattern;
data.silent = true; data.silent = true;
data.actions.resize(2); data.actions.resize(2);
data.actions[0].type = blink::PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON; data.actions[0].type = blink::mojom::NotificationActionType::BUTTON;
data.actions[0].title = base::ASCIIToUTF16("Button 1"); data.actions[0].title = base::ASCIIToUTF16("Button 1");
data.actions[1].type = blink::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT; data.actions[1].type = blink::mojom::NotificationActionType::TEXT;
data.actions[1].title = base::ASCIIToUTF16("Button 2"); data.actions[1].title = base::ASCIIToUTF16("Button 2");
NotificationResources notification_resources; NotificationResources notification_resources;
......
...@@ -152,10 +152,10 @@ bool DeserializeNotificationDatabaseData(const std::string& input, ...@@ -152,10 +152,10 @@ bool DeserializeNotificationDatabaseData(const std::string& input,
switch (payload_action.type()) { switch (payload_action.type()) {
case NotificationDatabaseDataProto::NotificationAction::BUTTON: case NotificationDatabaseDataProto::NotificationAction::BUTTON:
action.type = blink::PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON; action.type = blink::mojom::NotificationActionType::BUTTON;
break; break;
case NotificationDatabaseDataProto::NotificationAction::TEXT: case NotificationDatabaseDataProto::NotificationAction::TEXT:
action.type = blink::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT; action.type = blink::mojom::NotificationActionType::TEXT;
break; break;
default: default:
NOTREACHED(); NOTREACHED();
...@@ -240,11 +240,11 @@ bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input, ...@@ -240,11 +240,11 @@ bool SerializeNotificationDatabaseData(const NotificationDatabaseData& input,
payload->add_actions(); payload->add_actions();
switch (action.type) { switch (action.type) {
case blink::PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON: case blink::mojom::NotificationActionType::BUTTON:
payload_action->set_type( payload_action->set_type(
NotificationDatabaseDataProto::NotificationAction::BUTTON); NotificationDatabaseDataProto::NotificationAction::BUTTON);
break; break;
case blink::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT: case blink::mojom::NotificationActionType::TEXT:
payload_action->set_type( payload_action->set_type(
NotificationDatabaseDataProto::NotificationAction::TEXT); NotificationDatabaseDataProto::NotificationAction::TEXT);
break; break;
......
...@@ -45,8 +45,8 @@ const int kTimeUntilFirstClickMillis = 11111; ...@@ -45,8 +45,8 @@ const int kTimeUntilFirstClickMillis = 11111;
const int kTimeUntilLastClickMillis = 22222; const int kTimeUntilLastClickMillis = 22222;
const int kTimeUntilCloseMillis = 33333; const int kTimeUntilCloseMillis = 33333;
const blink::PlatformNotificationActionType kNotificationActionType = const blink::mojom::NotificationActionType kNotificationActionType =
blink::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT; blink::mojom::NotificationActionType::TEXT;
const char kOrigin[] = "https://example.com/"; const char kOrigin[] = "https://example.com/";
const char kNotificationTitle[] = "My Notification"; const char kNotificationTitle[] = "My Notification";
const char kNotificationLang[] = "nl"; const char kNotificationLang[] = "nl";
...@@ -221,11 +221,11 @@ TEST(NotificationDatabaseConversionsTest, ActionDeserializationIsNotAdditive) { ...@@ -221,11 +221,11 @@ TEST(NotificationDatabaseConversionsTest, ActionDeserializationIsNotAdditive) {
} }
TEST(NotificationDatabaseConversionsTest, SerializeAndDeserializeActionTypes) { TEST(NotificationDatabaseConversionsTest, SerializeAndDeserializeActionTypes) {
blink::PlatformNotificationActionType action_types[] = { blink::mojom::NotificationActionType action_types[] = {
blink::PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON, blink::mojom::NotificationActionType::BUTTON,
blink::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT}; blink::mojom::NotificationActionType::TEXT};
for (blink::PlatformNotificationActionType action_type : action_types) { for (blink::mojom::NotificationActionType action_type : action_types) {
blink::PlatformNotificationData notification_data; blink::PlatformNotificationData notification_data;
blink::PlatformNotificationAction action; blink::PlatformNotificationAction action;
......
...@@ -39,7 +39,7 @@ message NotificationDatabaseDataProto { ...@@ -39,7 +39,7 @@ message NotificationDatabaseDataProto {
// //
// Next tag: 6 // Next tag: 6
message NotificationAction { message NotificationAction {
// Corresponds to blink::PlatformNotificationActionType. // Corresponds to blink::mojom::NotificationActionType.
enum Type { enum Type {
BUTTON = 0; BUTTON = 0;
TEXT = 1; TEXT = 1;
......
...@@ -42,39 +42,6 @@ bool ValidateData(const std::vector<char>& data) { ...@@ -42,39 +42,6 @@ bool ValidateData(const std::vector<char>& data) {
namespace mojo { namespace mojo {
using blink::mojom::NotificationActionType;
// static
NotificationActionType
EnumTraits<NotificationActionType, blink::PlatformNotificationActionType>::
ToMojom(blink::PlatformNotificationActionType input) {
switch (input) {
case blink::PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON:
return NotificationActionType::BUTTON;
case blink::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT:
return NotificationActionType::TEXT;
}
NOTREACHED();
return NotificationActionType::BUTTON;
}
// static
bool EnumTraits<NotificationActionType, blink::PlatformNotificationActionType>::
FromMojom(NotificationActionType input,
blink::PlatformNotificationActionType* out) {
switch (input) {
case NotificationActionType::BUTTON:
*out = blink::PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON;
return true;
case NotificationActionType::TEXT:
*out = blink::PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT;
return true;
}
return false;
}
// static // static
bool StructTraits<blink::mojom::NotificationActionDataView, bool StructTraits<blink::mojom::NotificationActionDataView,
blink::PlatformNotificationAction>:: blink::PlatformNotificationAction>::
......
...@@ -62,13 +62,15 @@ TEST(NotificationStructTraitsTest, NotificationDataRoundtrip) { ...@@ -62,13 +62,15 @@ TEST(NotificationStructTraitsTest, NotificationDataRoundtrip) {
notification_data.data.assign(data, data + base::size(data)); notification_data.data.assign(data, data + base::size(data));
notification_data.actions.resize(2); notification_data.actions.resize(2);
notification_data.actions[0].type = PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON; notification_data.actions[0].type =
blink::mojom::NotificationActionType::BUTTON;
notification_data.actions[0].action = "buttonAction"; notification_data.actions[0].action = "buttonAction";
notification_data.actions[0].title = base::ASCIIToUTF16("Button Title!"); notification_data.actions[0].title = base::ASCIIToUTF16("Button Title!");
notification_data.actions[0].icon = GURL("https://example.com/aButton.png"); notification_data.actions[0].icon = GURL("https://example.com/aButton.png");
notification_data.actions[0].placeholder = base::nullopt; notification_data.actions[0].placeholder = base::nullopt;
notification_data.actions[1].type = PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT; notification_data.actions[1].type =
blink::mojom::NotificationActionType::TEXT;
notification_data.actions[1].action = "textAction"; notification_data.actions[1].action = "textAction";
notification_data.actions[1].title = base::ASCIIToUTF16("Reply Button Title"); notification_data.actions[1].title = base::ASCIIToUTF16("Reply Button Title");
notification_data.actions[1].icon = GURL("https://example.com/reply.png"); notification_data.actions[1].icon = GURL("https://example.com/reply.png");
......
...@@ -20,21 +20,11 @@ ...@@ -20,21 +20,11 @@
namespace mojo { namespace mojo {
template <>
struct BLINK_COMMON_EXPORT EnumTraits<blink::mojom::NotificationActionType,
blink::PlatformNotificationActionType> {
static blink::mojom::NotificationActionType ToMojom(
blink::PlatformNotificationActionType input);
static bool FromMojom(blink::mojom::NotificationActionType input,
blink::PlatformNotificationActionType* out);
};
template <> template <>
struct BLINK_COMMON_EXPORT struct BLINK_COMMON_EXPORT
StructTraits<blink::mojom::NotificationActionDataView, StructTraits<blink::mojom::NotificationActionDataView,
blink::PlatformNotificationAction> { blink::PlatformNotificationAction> {
static blink::PlatformNotificationActionType type( static blink::mojom::NotificationActionType type(
const blink::PlatformNotificationAction& action) { const blink::PlatformNotificationAction& action) {
return action.type; return action.type;
} }
......
...@@ -17,11 +17,6 @@ ...@@ -17,11 +17,6 @@
namespace blink { namespace blink {
enum PlatformNotificationActionType {
PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON = 0,
PLATFORM_NOTIFICATION_ACTION_TYPE_TEXT,
};
// A notification action (button or text input); corresponds to Blink // A notification action (button or text input); corresponds to Blink
// WebNotificationAction. // WebNotificationAction.
struct BLINK_COMMON_EXPORT PlatformNotificationAction { struct BLINK_COMMON_EXPORT PlatformNotificationAction {
...@@ -30,8 +25,7 @@ struct BLINK_COMMON_EXPORT PlatformNotificationAction { ...@@ -30,8 +25,7 @@ struct BLINK_COMMON_EXPORT PlatformNotificationAction {
~PlatformNotificationAction(); ~PlatformNotificationAction();
// Type of the action (button or text input). // Type of the action (button or text input).
PlatformNotificationActionType type = mojom::NotificationActionType type = mojom::NotificationActionType::BUTTON;
PLATFORM_NOTIFICATION_ACTION_TYPE_BUTTON;
// Action name that the author can use to distinguish them. // Action name that the author can use to distinguish them.
std::string action; std::string action;
......
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