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

[Notification scheduler]: Check schedule params against config.

- The deliver window should be within notification expiration config.

Bug: 1057272
Change-Id: Ib859870d16a53f937ac8849d7cc989d08b86975e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2079270Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746069}
parent 64537e30
...@@ -37,36 +37,6 @@ bool CreateTimeCompare(const NotificationEntry* lhs, ...@@ -37,36 +37,6 @@ bool CreateTimeCompare(const NotificationEntry* lhs,
return lhs->create_time <= rhs->create_time; return lhs->create_time <= rhs->create_time;
} }
// Vailidates notification parameters. Returns false if the parameters are
// invalid.
bool ValidateNotificationParams(const NotificationParams& params) {
// Validate time window. Currently we only support deliver notification
// according to a time window.
if (!params.schedule_params.deliver_time_start.has_value() ||
!params.schedule_params.deliver_time_end.has_value() ||
params.schedule_params.deliver_time_start.value() >
params.schedule_params.deliver_time_end.value()) {
return false;
}
// Validate ihnr buttons option. Custom buttons will be overwritten.
if (params.enable_ihnr_buttons && !params.notification_data.buttons.empty()) {
return false;
}
// Validate icon bundle data is correct: icon resource id should never be
// persisted to disk,since it can change in different versions. Client should
// overwrite with Android resource id in BeforeShowNotification callback if it
// is required.
for (const auto& icon_bundle_map : params.notification_data.icons) {
const auto& icon_bundle = icon_bundle_map.second;
if (icon_bundle.resource_id)
return false;
}
return true;
}
// Vailidates notification entry. Returns false if the entry should be deleted. // Vailidates notification entry. Returns false if the entry should be deleted.
bool ValidateNotificationEntry(const NotificationEntry& entry) { bool ValidateNotificationEntry(const NotificationEntry& entry) {
// Check the deliver time window. // Check the deliver time window.
...@@ -430,6 +400,40 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager { ...@@ -430,6 +400,40 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
buttons->emplace_back(std::move(unhelpful_button)); buttons->emplace_back(std::move(unhelpful_button));
} }
// Vailidates notification parameters. Returns false if the parameters are
// invalid.
bool ValidateNotificationParams(const NotificationParams& params) {
// Validate time window. Currently we only support deliver notification
// according to a time window, the deliver window should before the
// expiration duration of notification data in config.
if (!params.schedule_params.deliver_time_start.has_value() ||
!params.schedule_params.deliver_time_end.has_value() ||
params.schedule_params.deliver_time_start.value() >
params.schedule_params.deliver_time_end.value() ||
params.schedule_params.deliver_time_end.value() - base::Time::Now() >=
config_.notification_expiration) {
return false;
}
// Validate ihnr buttons option. Custom buttons will be overwritten.
if (params.enable_ihnr_buttons &&
!params.notification_data.buttons.empty()) {
return false;
}
// Validate icon bundle data is correct: icon resource id should never be
// persisted to disk,since it can change in different versions. Client
// should overwrite with Android resource id in BeforeShowNotification
// callback if it is required.
for (const auto& icon_bundle_map : params.notification_data.icons) {
const auto& icon_bundle = icon_bundle_map.second;
if (icon_bundle.resource_id)
return false;
}
return true;
}
NotificationStore notification_store_; NotificationStore notification_store_;
std::unique_ptr<IconStore> icon_store_; std::unique_ptr<IconStore> icon_store_;
const std::unordered_set<SchedulerClientType> clients_; const std::unordered_set<SchedulerClientType> clients_;
......
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