Commit 98e9f7c5 authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

[Notification scheduler]: Enable inline helpful buttons for notification.

- Add switch to enable/disable helpful/unhelpful buttons.
- Complete the logic to build helpful/unhelpful buttons if switch is on.
- TODO: Replace the button text from GRD.

Bug: 988117
Change-Id: Ia46ca3781fb036de4143193031d5906333158cf4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1730254
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Reviewed-by: default avatarXing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683770}
parent 2123a14b
......@@ -20,6 +20,7 @@
#include "chrome/browser/notifications/scheduler/internal/scheduler_config.h"
#include "chrome/browser/notifications/scheduler/internal/scheduler_utils.h"
#include "chrome/browser/notifications/scheduler/public/notification_params.h"
#include "chrome/browser/notifications/scheduler/public/notification_scheduler_constant.h"
namespace notifications {
namespace {
......@@ -70,10 +71,16 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
return;
}
if (notification_params->enable_ihnr_buttons) {
DCHECK(notification_params->notification_data.buttons.empty());
CreateInhrButtonsPair(&notification_params->notification_data.buttons);
}
auto entry =
std::make_unique<NotificationEntry>(notification_params->type, guid);
entry->notification_data =
std::move(notification_params->notification_data);
entry->schedule_params = std::move(notification_params->schedule_params);
auto* entry_ptr = entry.get();
notifications_[type][guid] = std::move(entry);
......@@ -271,6 +278,21 @@ class ScheduledNotificationManagerImpl : public ScheduledNotificationManager {
return notifications_[type][guid].get();
}
// Create two default buttons {Helpful, Unhelpful} for notification.
void CreateInhrButtonsPair(std::vector<NotificationData::Button>* buttons) {
buttons->clear();
// TODO(hesen): Fill button text field with GRD string resource.
NotificationData::Button helpful_button;
helpful_button.type = ActionButtonType::kHelpful;
helpful_button.id = notifications::kDefaultHelpfulButtonId;
buttons->emplace_back(std::move(helpful_button));
NotificationData::Button unhelpful_button;
unhelpful_button.type = ActionButtonType::kUnhelpful;
unhelpful_button.id = notifications::kDefaultUnhelpfulButtonId;
buttons->emplace_back(std::move(unhelpful_button));
}
NotificationStore notification_store_;
std::unique_ptr<IconStore> icon_store_;
const std::unordered_set<SchedulerClientType> clients_;
......
......@@ -17,6 +17,7 @@
#include "chrome/browser/notifications/scheduler/internal/notification_entry.h"
#include "chrome/browser/notifications/scheduler/internal/scheduler_config.h"
#include "chrome/browser/notifications/scheduler/public/notification_params.h"
#include "chrome/browser/notifications/scheduler/public/notification_scheduler_constant.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -182,6 +183,7 @@ TEST_F(ScheduledNotificationManagerTest, ScheduleNotification) {
schedule_params.priority = ScheduleParams::Priority::kHigh;
auto params = std::make_unique<NotificationParams>(
SchedulerClientType::kTest1, notification_data, schedule_params);
params->enable_ihnr_buttons = true;
std::string guid = params->guid;
EXPECT_FALSE(guid.empty());
......@@ -204,6 +206,13 @@ TEST_F(ScheduledNotificationManagerTest, ScheduleNotification) {
// TODO(xingliu): change these to compare with operator==.
EXPECT_EQ(base::UTF16ToUTF8(entry->notification_data.title), kTitle);
EXPECT_EQ(entry->schedule_params.priority, ScheduleParams::Priority::kHigh);
auto buttons = entry->notification_data.buttons;
EXPECT_EQ(buttons.size(), 2u);
EXPECT_EQ(buttons[0].id, notifications::kDefaultHelpfulButtonId);
EXPECT_EQ(buttons[0].type, ActionButtonType::kHelpful);
EXPECT_EQ(buttons[1].id, notifications::kDefaultUnhelpfulButtonId);
EXPECT_EQ(buttons[1].type, ActionButtonType::kUnhelpful);
}
// Test to schedule a notification without guid, we will auto generated one.
......
......@@ -23,6 +23,7 @@ source_set("public") {
"notification_scheduler_client.h",
"notification_scheduler_client_registrar.cc",
"notification_scheduler_client_registrar.h",
"notification_scheduler_constant.h",
"notification_scheduler_types.cc",
"notification_scheduler_types.h",
"schedule_params.cc",
......
......@@ -16,6 +16,7 @@ NotificationParams::NotificationParams(SchedulerClientType type,
ScheduleParams schedule_params)
: type(type),
guid(base::GenerateGUID()),
enable_ihnr_buttons(false),
notification_data(std::move(notification_data)),
schedule_params(std::move(schedule_params)) {}
......
......@@ -26,6 +26,10 @@ struct NotificationParams {
// An auto generated unique id of the scheduled notification.
std::string guid;
// Will overwrite custom buttons in notification data with inline
// helpful/unhelpful buttons if set true.
bool enable_ihnr_buttons;
// Data used to show the notification, such as text or title on the
// notification.
NotificationData notification_data;
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_PUBLIC_NOTIFICATION_SCHEDULER_CONSTANT_H_
#define CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_PUBLIC_NOTIFICATION_SCHEDULER_CONSTANT_H_
namespace notifications {
constexpr char kDefaultHelpfulButtonId[] =
"NOTIFICATION_SCHEDULER_DEFAULT_HELPFUL_BUTTON_ID";
constexpr char kDefaultUnhelpfulButtonId[] =
"NOTIFICATION_SCHEDULER_DEFAULT_UNHELPFUL_BUTTON_ID";
} // namespace notifications
#endif // CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_PUBLIC_NOTIFICATION_SCHEDULER_CONSTANT_H_
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