Commit fa9de18f authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

[Notification scheduler]: Polish Notification Data.

- Change a vector of icons to small_icon and large_icon explicitly.
- Wrap Skbitmap to an Icon struct for future extension.

Bug: 963290
Change-Id: I6bd9459dc05e169e281659b67747a55c464e45bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1758708Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688236}
parent c22a96de
...@@ -22,7 +22,7 @@ enum ActionButtonType { ...@@ -22,7 +22,7 @@ enum ActionButtonType {
} }
// Stores data used to display a notification in the UI. // Stores data used to display a notification in the UI.
// Next tag: 6 // Next tag: 7
message NotificationData { message NotificationData {
// Represents the button on the notification. // Represents the button on the notification.
// Next tag: 4 // Next tag: 4
...@@ -38,13 +38,17 @@ message NotificationData { ...@@ -38,13 +38,17 @@ message NotificationData {
// Body text of the notification. // Body text of the notification.
optional string message = 2; optional string message = 2;
// The unique identifiers of the icons on the notification. Each time we
// should only load icons asynchronously into memory.
repeated string icon_uuid = 3;
// Custom data associated with a notification. // Custom data associated with a notification.
repeated CustomData custom_data = 4; repeated CustomData custom_data = 3;
// A list of buttons on the notification. // A list of buttons on the notification.
repeated Button buttons = 5; repeated Button buttons = 4;
// The unique identifier of the small icon on notification, which must be
// loaded asynchronously into memory.
optional string small_icon_uuid = 5;
// The unique identifier of the large icon on notification, which must be
// loaded asynchronously into memory.
optional string large_icon_uuid = 6;
} }
...@@ -21,7 +21,8 @@ bool NotificationEntry::operator==(const NotificationEntry& other) const { ...@@ -21,7 +21,8 @@ bool NotificationEntry::operator==(const NotificationEntry& other) const {
return type == other.type && guid == other.guid && return type == other.type && guid == other.guid &&
create_time == other.create_time && create_time == other.create_time &&
notification_data == other.notification_data && notification_data == other.notification_data &&
icons_uuid == other.icons_uuid && small_icon_uuid == other.small_icon_uuid &&
large_icon_uuid == other.large_icon_uuid &&
schedule_params == other.schedule_params; schedule_params == other.schedule_params;
} }
......
...@@ -37,9 +37,13 @@ struct NotificationEntry { ...@@ -37,9 +37,13 @@ struct NotificationEntry {
// shown. // shown.
NotificationData notification_data; NotificationData notification_data;
// The unique identifier of the icons, which must be loaded asynchronously // The unique identifier of the small icon on notification, which must be
// into memory. // loaded asynchronously into memory.
std::vector<std::string> icons_uuid; std::string small_icon_uuid;
// The unique identifier of the large icon on notification, which must be
// loaded asynchronously into memory.
std::string large_icon_uuid;
// Scheduling details. // Scheduling details.
ScheduleParams schedule_params; ScheduleParams schedule_params;
......
...@@ -415,11 +415,8 @@ void NotificationEntryToProto(NotificationEntry* entry, ...@@ -415,11 +415,8 @@ void NotificationEntryToProto(NotificationEntry* entry,
proto->set_create_time(TimeToMilliseconds(entry->create_time)); proto->set_create_time(TimeToMilliseconds(entry->create_time));
auto* proto_notification_data = proto->mutable_notification_data(); auto* proto_notification_data = proto->mutable_notification_data();
NotificationDataToProto(&entry->notification_data, proto_notification_data); NotificationDataToProto(&entry->notification_data, proto_notification_data);
for (const auto& icon_id : entry->icons_uuid) { proto_notification_data->set_small_icon_uuid(entry->small_icon_uuid);
auto* proto_icon_id = proto_notification_data->add_icon_uuid(); proto_notification_data->set_large_icon_uuid(entry->large_icon_uuid);
*proto_icon_id = icon_id;
}
auto* proto_schedule_params = proto->mutable_schedule_params(); auto* proto_schedule_params = proto->mutable_schedule_params();
ScheduleParamsToProto(&entry->schedule_params, proto_schedule_params); ScheduleParamsToProto(&entry->schedule_params, proto_schedule_params);
} }
...@@ -431,10 +428,8 @@ void NotificationEntryFromProto(proto::NotificationEntry* proto, ...@@ -431,10 +428,8 @@ void NotificationEntryFromProto(proto::NotificationEntry* proto,
entry->create_time = MillisecondsToTime(proto->create_time()); entry->create_time = MillisecondsToTime(proto->create_time());
NotificationDataFromProto(proto->mutable_notification_data(), NotificationDataFromProto(proto->mutable_notification_data(),
&entry->notification_data); &entry->notification_data);
for (int i = 0; i < proto->notification_data().icon_uuid_size(); ++i) { entry->small_icon_uuid = proto->notification_data().small_icon_uuid();
entry->icons_uuid.emplace_back(proto->notification_data().icon_uuid(i)); entry->large_icon_uuid = proto->notification_data().large_icon_uuid();
}
ScheduleParamsFromProto(proto->mutable_schedule_params(), ScheduleParamsFromProto(proto->mutable_schedule_params(),
&entry->schedule_params); &entry->schedule_params);
} }
......
...@@ -191,7 +191,8 @@ TEST(ProtoConversionTest, NotificationEntryConversion) { ...@@ -191,7 +191,8 @@ TEST(ProtoConversionTest, NotificationEntryConversion) {
// Test notification data. // Test notification data.
entry.notification_data.title = base::UTF8ToUTF16("title"); entry.notification_data.title = base::UTF8ToUTF16("title");
entry.notification_data.message = base::UTF8ToUTF16("message"); entry.notification_data.message = base::UTF8ToUTF16("message");
entry.icons_uuid = {"icon_uuid_0", "icon_uuid_1"}; entry.small_icon_uuid = "small_icon_uuid";
entry.large_icon_uuid = "large_icon_uuid";
entry.notification_data.custom_data = {{"url", "https://www.example.com"}}; entry.notification_data.custom_data = {{"url", "https://www.example.com"}};
TestNotificationEntryConversion(&entry); TestNotificationEntryConversion(&entry);
......
...@@ -130,7 +130,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager { ...@@ -130,7 +130,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
notification_store_->Delete( notification_store_->Delete(
guid, guid,
base::BindOnce(&ScheduledNotificationManagerImpl::OnNotificationDeleted, base::BindOnce(&ScheduledNotificationManagerImpl::OnNotificationDeleted,
weak_ptr_factory_.GetWeakPtr(), entry->icons_uuid)); weak_ptr_factory_.GetWeakPtr()));
if (delegate_) if (delegate_)
delegate_->DisplayNotification(std::move(entry)); delegate_->DisplayNotification(std::move(entry));
...@@ -176,7 +176,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager { ...@@ -176,7 +176,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
entry.guid, entry.guid,
base::BindOnce( base::BindOnce(
&ScheduledNotificationManagerImpl::OnNotificationDeleted, &ScheduledNotificationManagerImpl::OnNotificationDeleted,
weak_ptr_factory_.GetWeakPtr(), entry.icons_uuid)); weak_ptr_factory_.GetWeakPtr()));
} }
notifications_.erase(type); notifications_.erase(type);
} }
...@@ -213,7 +213,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager { ...@@ -213,7 +213,7 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
entry->guid, entry->guid,
base::BindOnce( base::BindOnce(
&ScheduledNotificationManagerImpl::OnNotificationDeleted, &ScheduledNotificationManagerImpl::OnNotificationDeleted,
weak_ptr_factory_.GetWeakPtr(), entry->icons_uuid)); weak_ptr_factory_.GetWeakPtr()));
} else if (clients_.count(entry->type)) { } else if (clients_.count(entry->type)) {
notifications_[entry->type].emplace(entry->guid, std::move(*it)); notifications_[entry->type].emplace(entry->guid, std::move(*it));
} }
...@@ -242,16 +242,6 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager { ...@@ -242,16 +242,6 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
notifications_.erase(type); notifications_.erase(type);
return; return;
} }
// TODO(hesen): Address only first icon for now. Handle all icons situation
// in following CLs.
if (entry->notification_data.icons.empty())
return;
encode_icons_callback_.Run(
std::move(entry->notification_data.icons.front()),
base::BindOnce(&ScheduledNotificationManagerImpl::OnIconEncoded,
weak_ptr_factory_.GetWeakPtr(), type, std::move(guid)));
} }
void OnIconEncoded(SchedulerClientType type, void OnIconEncoded(SchedulerClientType type,
...@@ -276,21 +266,9 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager { ...@@ -276,21 +266,9 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
// TODO(hesen): Error handling. // TODO(hesen): Error handling.
if (!entry || !success) if (!entry || !success)
return; return;
entry->icons_uuid.emplace_back(std::move(icon_uuid));
} }
void OnNotificationDeleted(const std::vector<std::string>& icon_uuids, void OnNotificationDeleted(bool success) { NOTIMPLEMENTED(); }
bool success) {
// TODO(hesen): Error handling.
if (!success)
return;
for (const auto& icon_uuid : icon_uuids) {
icon_store_->Delete(
std::move(icon_uuid),
base::BindOnce(&ScheduledNotificationManagerImpl::OnIconDeleted,
weak_ptr_factory_.GetWeakPtr()));
}
}
void OnIconDeleted(bool success) { NOTIMPLEMENTED(); } void OnIconDeleted(bool success) { NOTIMPLEMENTED(); }
......
...@@ -15,13 +15,15 @@ bool NotificationData::Button::operator==(const Button& other) const { ...@@ -15,13 +15,15 @@ bool NotificationData::Button::operator==(const Button& other) const {
NotificationData::Button::~Button() = default; NotificationData::Button::~Button() = default;
NotificationData::Icon::Icon() = default;
NotificationData::Icon::~Icon() = default;
NotificationData::NotificationData() = default; NotificationData::NotificationData() = default;
NotificationData::NotificationData(const NotificationData& other) = default; NotificationData::NotificationData(const NotificationData& other) = default;
bool NotificationData::operator==(const NotificationData& other) const { bool NotificationData::operator==(const NotificationData& other) const {
return title == other.title && message == other.message && return title == other.title && message == other.message &&
icons.size() == other.icons.size() &&
custom_data == other.custom_data && buttons == other.buttons; custom_data == other.custom_data && buttons == other.buttons;
} }
......
...@@ -38,6 +38,14 @@ struct NotificationData { ...@@ -38,6 +38,14 @@ struct NotificationData {
std::string id; std::string id;
}; };
struct Icon {
Icon();
~Icon();
// The icon bitmap.
SkBitmap bitmap;
};
using CustomData = std::map<std::string, std::string>; using CustomData = std::map<std::string, std::string>;
NotificationData(); NotificationData();
NotificationData(const NotificationData& other); NotificationData(const NotificationData& other);
...@@ -50,9 +58,11 @@ struct NotificationData { ...@@ -50,9 +58,11 @@ struct NotificationData {
// The body text of the notification. // The body text of the notification.
base::string16 message; base::string16 message;
// A list of icons. On Android, the first element will be used as small icon, // The small icon of the notification.
// the second as large icon(optional). Icon small_icon;
std::vector<SkBitmap> icons;
// The large icon of the notification.
Icon large_icon;
// Custom key value pair data associated with each notification. Will be sent // Custom key value pair data associated with each notification. Will be sent
// back after user interaction. // back after user interaction.
......
...@@ -105,10 +105,8 @@ std::string DebugString(const NotificationEntry* entry) { ...@@ -105,10 +105,8 @@ std::string DebugString(const NotificationEntry* entry) {
<< " : " << static_cast<int>(mapping.second); << " : " << static_cast<int>(mapping.second);
} }
stream << " \n icons_id:"; stream << " \n small_icons_id:" << entry->small_icon_uuid << " ";
for (const auto& icon_id : entry->icons_uuid) stream << " \n large_icons_id:" << entry->large_icon_uuid << " ";
stream << icon_id << " ";
return stream.str(); return stream.str();
} }
......
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