Commit f0d5ac92 authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Notification scheduler: Add custom data to impression proto.

On each user action, the client now can receive the custom data map.
This CL adds the custom data to impression proto. We will plumb this
data to the client and add this data to impression tracker in a
following CL.

Bug: 977255
Change-Id: I4b9552bf30c620a66d466cf6eeabc0f2549666fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1717703
Commit-Queue: Xing Liu <xingliu@chromium.org>
Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683413}
parent ff808a23
......@@ -8,10 +8,12 @@ option optimize_for = LITE_RUNTIME;
package notifications.proto;
import "notification_data.proto";
// Contains data to determine when a notification should be shown to the user
// and the user impression towards this notification. Should match Impression in
// impression_types.h.
// Next tag: 8
// Next tag: 9
message Impression {
// The type of user feedback from a displayed notification. Should match
// UserFeedback in notification_scheduler_types.h.
......@@ -67,5 +69,9 @@ message Impression {
// The unique identifier of the notification.
optional string guid = 6;
// Used to generate impression result.
repeated ImpressionMapping impression_mapping = 7;
// Custom data associated with a notification.
repeated CustomData custom_data = 8;
}
......@@ -21,7 +21,8 @@ bool Impression::operator==(const Impression& other) const {
return create_time == other.create_time && feedback == other.feedback &&
impression == other.impression && integrated == other.integrated &&
task_start_time == other.task_start_time && guid == other.guid &&
type == other.type && impression_mapping == other.impression_mapping;
type == other.type && impression_mapping == other.impression_mapping &&
custom_data == other.custom_data;
}
SuppressionInfo::SuppressionInfo(const base::Time& last_trigger,
......
......@@ -25,6 +25,7 @@ namespace notifications {
// an impression result, which may affect notification exposure.
// 4. The impression is deleted after it expires.
struct Impression {
using CustomData = std::map<std::string, std::string>;
Impression();
Impression(SchedulerClientType type,
const std::string& guid,
......@@ -63,6 +64,10 @@ struct Impression {
// Used to override default impression result.
std::map<UserFeedback, ImpressionResult> impression_mapping;
// Custom data associated with a notification. Send back to the client when
// the user interacts with the notification.
CustomData custom_data;
};
// Contains details about supression and recovery after suppression expired.
......
......@@ -325,6 +325,12 @@ void ClientStateToProto(ClientState* client_state,
proto_impression_mapping->set_impression_result(
ToImpressionResult(mapping.second));
}
for (const auto& pair : impression.custom_data) {
auto* data = impression_ptr->add_custom_data();
data->set_key(pair.first);
data->set_value(pair.second);
}
}
if (client_state->suppression_info.has_value()) {
......@@ -367,6 +373,11 @@ void ClientStateFromProto(proto::ClientState* proto,
impression.impression_mapping[user_feedback] = impression_result;
}
for (int i = 0; i < proto_impression.custom_data_size(); ++i) {
const auto& pair = proto_impression.custom_data(i);
impression.custom_data.emplace(pair.key(), pair.value());
}
client_state->impressions.emplace_back(std::move(impression));
}
......
......@@ -154,6 +154,10 @@ TEST(ProtoConversionTest, ImpressionProtoConversion) {
first_impression.impression_mapping[UserFeedback::kClick] =
ImpressionResult::kNeutral;
TestClientStateConversion(&client_state);
// Verify custom data.
first_impression.custom_data = {{"url", "https://www.example.com"}};
TestClientStateConversion(&client_state);
}
// Verifies multiple impressions are serialized correctly.
......
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