Commit 916cb3c7 authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

[Notification scheduler]: Early return for icon store calls.

- Return early if icon store input is empty. Avoid calls to protodb.

Bug: 963290
Change-Id: Ic037a5853c81afdfc74c95126f86f961f6adbd36
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1793751Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695352}
parent fbb324b2
...@@ -55,7 +55,7 @@ void IconProtoDbStore::InitAndLoadKeys(InitAndLoadKeysCallback callback) { ...@@ -55,7 +55,7 @@ void IconProtoDbStore::InitAndLoadKeys(InitAndLoadKeysCallback callback) {
void IconProtoDbStore::AddIcons(IconTypeBundleMap icons, AddCallback callback) { void IconProtoDbStore::AddIcons(IconTypeBundleMap icons, AddCallback callback) {
if (icons.empty()) { if (icons.empty()) {
std::move(callback).Run({} /*IconTypeUuidMap*/, true); std::move(callback).Run(IconTypeUuidMap{}, true);
return; return;
} }
...@@ -80,6 +80,10 @@ void IconProtoDbStore::AddIcons(IconTypeBundleMap icons, AddCallback callback) { ...@@ -80,6 +80,10 @@ void IconProtoDbStore::AddIcons(IconTypeBundleMap icons, AddCallback callback) {
void IconProtoDbStore::LoadIcons(const std::vector<std::string>& keys, void IconProtoDbStore::LoadIcons(const std::vector<std::string>& keys,
LoadIconsCallback callback) { LoadIconsCallback callback) {
if (keys.empty()) {
std::move(callback).Run(true, LoadedIconsMap{});
return;
}
db_->LoadKeysAndEntriesWithFilter( db_->LoadKeysAndEntriesWithFilter(
base::BindRepeating(&HasKeyInDb, keys), base::BindRepeating(&HasKeyInDb, keys),
base::BindOnce(&IconProtoDbStore::OnIconEntriesLoaded, base::BindOnce(&IconProtoDbStore::OnIconEntriesLoaded,
...@@ -88,6 +92,10 @@ void IconProtoDbStore::LoadIcons(const std::vector<std::string>& keys, ...@@ -88,6 +92,10 @@ void IconProtoDbStore::LoadIcons(const std::vector<std::string>& keys,
void IconProtoDbStore::DeleteIcons(const std::vector<std::string>& keys, void IconProtoDbStore::DeleteIcons(const std::vector<std::string>& keys,
UpdateCallback callback) { UpdateCallback callback) {
if (keys.empty()) {
std::move(callback).Run(true);
return;
}
auto keys_to_delete = std::make_unique<KeyVector>(); auto keys_to_delete = std::make_unique<KeyVector>();
for (size_t i = 0; i < keys.size(); i++) for (size_t i = 0; i < keys.size(); i++)
keys_to_delete->emplace_back(keys[i]); keys_to_delete->emplace_back(keys[i]);
...@@ -124,7 +132,7 @@ void IconProtoDbStore::OnIconEntriesLoaded( ...@@ -124,7 +132,7 @@ void IconProtoDbStore::OnIconEntriesLoaded(
bool success, bool success,
std::unique_ptr<std::map<std::string, IconEntry>> icon_entries) { std::unique_ptr<std::map<std::string, IconEntry>> icon_entries) {
if (!success) { if (!success) {
std::move(callback).Run(false, {} /*IconsMap*/); std::move(callback).Run(false, LoadedIconsMap{});
return; return;
} }
...@@ -175,7 +183,7 @@ void IconProtoDbStore::OnIconsDecoded( ...@@ -175,7 +183,7 @@ void IconProtoDbStore::OnIconsDecoded(
std::unique_ptr<DecodeResult> decoded_result) { std::unique_ptr<DecodeResult> decoded_result) {
stats::LogPngIconConverterDecodeResult(decoded_result->success); stats::LogPngIconConverterDecodeResult(decoded_result->success);
if (!decoded_result->success) { if (!decoded_result->success) {
std::move(callback).Run(false, {} /*IconsMap*/); std::move(callback).Run(false, LoadedIconsMap{});
return; return;
} }
......
...@@ -315,7 +315,7 @@ TEST_F(ScheduledNotificationManagerTest, ScheduleNotification) { ...@@ -315,7 +315,7 @@ TEST_F(ScheduledNotificationManagerTest, ScheduleNotification) {
EXPECT_CALL(*icon_store(), AddIcons(_, _)) EXPECT_CALL(*icon_store(), AddIcons(_, _))
.WillOnce(Invoke([](IconStore::IconTypeBundleMap icons, .WillOnce(Invoke([](IconStore::IconTypeBundleMap icons,
IconStore::AddCallback callback) { IconStore::AddCallback callback) {
std::move(callback).Run({}, true); std::move(callback).Run(IconStore::IconTypeUuidMap{}, true);
})); }));
EXPECT_CALL(*notification_store(), Add(guid, _, _)) EXPECT_CALL(*notification_store(), Add(guid, _, _))
.WillOnce(Invoke([guid](const std::string&, const NotificationEntry&, .WillOnce(Invoke([guid](const std::string&, const NotificationEntry&,
...@@ -358,7 +358,7 @@ TEST_F(ScheduledNotificationManagerTest, ScheduleNotificationEmptyGuid) { ...@@ -358,7 +358,7 @@ TEST_F(ScheduledNotificationManagerTest, ScheduleNotificationEmptyGuid) {
EXPECT_CALL(*icon_store(), AddIcons(_, _)) EXPECT_CALL(*icon_store(), AddIcons(_, _))
.WillOnce(Invoke([](IconStore::IconTypeBundleMap icons, .WillOnce(Invoke([](IconStore::IconTypeBundleMap icons,
IconStore::AddCallback callback) { IconStore::AddCallback callback) {
std::move(callback).Run({}, true); std::move(callback).Run(IconStore::IconTypeUuidMap{}, true);
})); }));
EXPECT_CALL(*notification_store(), Add(_, _, _)) EXPECT_CALL(*notification_store(), Add(_, _, _))
.WillOnce(Invoke( .WillOnce(Invoke(
...@@ -696,7 +696,7 @@ TEST_F(ScheduledNotificationManagerTest, DisplayNotificationWithIconsFailed) { ...@@ -696,7 +696,7 @@ TEST_F(ScheduledNotificationManagerTest, DisplayNotificationWithIconsFailed) {
EXPECT_CALL(*icon_store(), LoadIcons(_, _)) EXPECT_CALL(*icon_store(), LoadIcons(_, _))
.WillOnce(Invoke([](std::vector<std::string> keys, .WillOnce(Invoke([](std::vector<std::string> keys,
IconStore::LoadIconsCallback callback) { IconStore::LoadIconsCallback callback) {
std::move(callback).Run(false, {}); std::move(callback).Run(false, IconStore::LoadedIconsMap{});
})); }));
EXPECT_CALL(*notification_store(), Delete(kGuid, _)); EXPECT_CALL(*notification_store(), Delete(kGuid, _));
EXPECT_CALL(*icon_store(), DeleteIcons(_, _)); EXPECT_CALL(*icon_store(), DeleteIcons(_, _));
......
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