Commit 5c12c074 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Notification scheduler: Introduce user interaction interface.

This CL adds an interface to process user events. The glue layer of
the scheduler will implement this interface in a following CL. Also
the guid for the impression data is added to identify the specific
notification that the user interacted with.

This is a temporary solution and later we may convert to use
NotificationDisplayService at some point.

Bug: 930968
Change-Id: I6b5665fe30bec048a0c986bfad2a78ff02f38de8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1582428Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654631}
parent 2a121e9f
...@@ -11,7 +11,7 @@ package notifications.proto; ...@@ -11,7 +11,7 @@ package notifications.proto;
// Contains data to determine when a notification should be shown to the user // Contains data to determine when a notification should be shown to the user
// and the user impression towards this notification. Should match Impression in // and the user impression towards this notification. Should match Impression in
// impression_types.h. // impression_types.h.
// Next tag: 6 // Next tag: 7
message Impression { message Impression {
// The type of user feedback from a displayed notification. Should match // The type of user feedback from a displayed notification. Should match
// UserFeedback in notification_scheduler_types.h. // UserFeedback in notification_scheduler_types.h.
...@@ -56,4 +56,7 @@ message Impression { ...@@ -56,4 +56,7 @@ message Impression {
// The task start time when the notification is shown. // The task start time when the notification is shown.
optional SchedulerTaskTime task_start_time = 5; optional SchedulerTaskTime task_start_time = 5;
// The unique identifier of the notification.
optional string guid = 6;
} }
...@@ -29,6 +29,7 @@ source_set("public") { ...@@ -29,6 +29,7 @@ source_set("public") {
"notification_scheduler_types.h", "notification_scheduler_types.h",
"schedule_params.cc", "schedule_params.cc",
"schedule_params.h", "schedule_params.h",
"user_action_handler.h",
] ]
deps = [ deps = [
......
...@@ -13,7 +13,8 @@ namespace notifications { ...@@ -13,7 +13,8 @@ namespace notifications {
bool Impression::operator==(const Impression& other) const { bool Impression::operator==(const Impression& other) const {
return create_time == other.create_time && feedback == other.feedback && return create_time == other.create_time && feedback == other.feedback &&
impression == other.impression && integrated == other.integrated; impression == other.impression && integrated == other.integrated &&
task_start_time == other.task_start_time && guid == other.guid;
} }
SuppressionInfo::SuppressionInfo(const base::Time& last_trigger, SuppressionInfo::SuppressionInfo(const base::Time& last_trigger,
...@@ -56,7 +57,8 @@ std::string ClientState::DebugPrint() const { ...@@ -56,7 +57,8 @@ std::string ClientState::DebugPrint() const {
<< " \n" << " \n"
<< "integrated: " << impression.integrated << " \n" << "integrated: " << impression.integrated << " \n"
<< "task start time: " << "task start time: "
<< static_cast<int>(impression.task_start_time) << "\n"; << static_cast<int>(impression.task_start_time) << "\n"
<< "guid: " << impression.guid << "\n";
log += stream.str(); log += stream.str();
} }
......
...@@ -45,6 +45,9 @@ struct Impression { ...@@ -45,6 +45,9 @@ struct Impression {
// The task start time when this impression is generated. // The task start time when this impression is generated.
SchedulerTaskTime task_start_time = SchedulerTaskTime::kUnknown; SchedulerTaskTime task_start_time = SchedulerTaskTime::kUnknown;
// The unique identifier of the notification.
std::string guid;
}; };
// Contains details about supression and recovery after suppression expired. // Contains details about supression and recovery after suppression expired.
......
...@@ -194,6 +194,7 @@ void ClientStateToProto(ClientState* client_state, ...@@ -194,6 +194,7 @@ void ClientStateToProto(ClientState* client_state,
impression_ptr->set_integrated(impression.integrated); impression_ptr->set_integrated(impression.integrated);
impression_ptr->set_task_start_time( impression_ptr->set_task_start_time(
ToSchedulerTaskTime(impression.task_start_time)); ToSchedulerTaskTime(impression.task_start_time));
impression_ptr->set_guid(impression.guid);
} }
if (client_state->suppression_info.has_value()) { if (client_state->suppression_info.has_value()) {
...@@ -223,6 +224,7 @@ void ClientStateFromProto(proto::ClientState* proto, ...@@ -223,6 +224,7 @@ void ClientStateFromProto(proto::ClientState* proto,
impression.integrated = proto_impression.integrated(); impression.integrated = proto_impression.integrated();
impression.task_start_time = impression.task_start_time =
FromSchedulerTaskTime(proto_impression.task_start_time()); FromSchedulerTaskTime(proto_impression.task_start_time());
impression.guid = proto_impression.guid();
client_state->impressions.emplace_back(std::move(impression)); client_state->impressions.emplace_back(std::move(impression));
} }
......
...@@ -14,6 +14,7 @@ namespace notifications { ...@@ -14,6 +14,7 @@ namespace notifications {
namespace { namespace {
const char kUuid[] = "123"; const char kUuid[] = "123";
const char kGuid[] = "testGuid";
const char kData[] = "bitmapdata"; const char kData[] = "bitmapdata";
void TestClientStateConversion(ClientState* client_state) { void TestClientStateConversion(ClientState* client_state) {
...@@ -80,9 +81,9 @@ TEST(ProtoConversionTest, ImpressionProtoConversion) { ...@@ -80,9 +81,9 @@ TEST(ProtoConversionTest, ImpressionProtoConversion) {
base::Time create_time; base::Time create_time;
bool success = base::Time::FromString("03/25/19 00:00:00 AM", &create_time); bool success = base::Time::FromString("03/25/19 00:00:00 AM", &create_time);
DCHECK(success); DCHECK(success);
Impression impression{create_time, UserFeedback::kHelpful, Impression impression{
ImpressionResult::kPositive, true, create_time, UserFeedback::kHelpful, ImpressionResult::kPositive,
SchedulerTaskTime::kMorning}; true, SchedulerTaskTime::kMorning, kGuid};
client_state.impressions.emplace_back(impression); client_state.impressions.emplace_back(impression);
TestClientStateConversion(&client_state); TestClientStateConversion(&client_state);
......
// 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_USER_ACTION_HANDLER_H_
#define CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_USER_ACTION_HANDLER_H_
#include <string>
#include "base/macros.h"
namespace notifications {
// Categorizes type of notification buttons. Different type of button clicks
// may result in change of notification shown frequency.
enum class ActionButtonType {
// The action button is not categorized.
kUnknownAction = 0,
// Helpful button indicates the user likes to interact with the notification.
kHelpful = 1,
// Unhelpful button indicates dislike of the notification.
kUnhelpful = 2,
};
// An interface to plumb user actions events to notification scheduling system.
// Each event needs to provide an unique id of the notification shown.
class UserActionHandler {
public:
// Called when the user clicks on the notification.
virtual void OnClick(const std::string& notification_id) = 0;
// Called when the user clicks on a button on the notification.
virtual void OnActionClick(const std::string& notification_id,
ActionButtonType button_type) = 0;
// Called when the user cancels or dismiss the notification.
virtual void OnDismiss(const std::string& notification_id) = 0;
~UserActionHandler() = default;
protected:
UserActionHandler() = default;
private:
DISALLOW_COPY_AND_ASSIGN(UserActionHandler);
};
} // namespace notifications
#endif // CHROME_BROWSER_NOTIFICATIONS_SCHEDULER_USER_ACTION_HANDLER_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