Commit e4cd27d4 authored by Tanya Gupta's avatar Tanya Gupta Committed by Commit Bot

Made all functions in ReceivingUIHandler consistent


Conditioned STTS behavior on model being loaded.

Added histogram to capture cases it wasn't

Bug: 944591
Change-Id: I279a1577de416d7519ed25fdb605d135bd8f6ed6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1545726
Commit-Queue: Tanya Gupta <tgupta@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#646467}
parent 496b70ca
......@@ -18,19 +18,21 @@ using base::android::ConvertUTF8ToJavaString;
namespace send_tab_to_self {
void AndroidNotificationHandler::DisplayNewEntry(
const SendTabToSelfEntry* entry) {
JNIEnv* env = AttachCurrentThread();
// Set the expiration to 10 days from when the notification is displayed.
base::Time expiraton_time =
entry->GetSharedTime() + base::TimeDelta::FromDays(10);
Java_NotificationManager_showNotification(
env, ConvertUTF8ToJavaString(env, entry->GetGUID()),
ConvertUTF8ToJavaString(env, entry->GetURL().spec()),
ConvertUTF8ToJavaString(env, entry->GetTitle()),
expiraton_time.ToJavaTime());
void AndroidNotificationHandler::DisplayNewEntries(
const std::vector<const SendTabToSelfEntry*>& new_entries) {
for (const SendTabToSelfEntry* entry : new_entries) {
JNIEnv* env = AttachCurrentThread();
// Set the expiration to 10 days from when the notification is displayed.
base::Time expiraton_time =
entry->GetSharedTime() + base::TimeDelta::FromDays(10);
Java_NotificationManager_showNotification(
env, ConvertUTF8ToJavaString(env, entry->GetGUID()),
ConvertUTF8ToJavaString(env, entry->GetURL().spec()),
ConvertUTF8ToJavaString(env, entry->GetTitle()),
expiraton_time.ToJavaTime());
}
}
void AndroidNotificationHandler::DismissEntries(
......
......@@ -23,7 +23,8 @@ class AndroidNotificationHandler : public ReceivingUiHandler {
private:
// ReceivingUiHandler implementation.
void DisplayNewEntry(const SendTabToSelfEntry* entry) override;
void DisplayNewEntries(
const std::vector<const SendTabToSelfEntry*>& new_entries) override;
void DismissEntries(const std::vector<std::string>& guids) override;
};
......
......@@ -35,24 +35,26 @@ DesktopNotificationHandler::DesktopNotificationHandler(Profile* profile)
DesktopNotificationHandler::~DesktopNotificationHandler() = default;
void DesktopNotificationHandler::DisplayNewEntry(
const SendTabToSelfEntry* entry) {
const base::string16 device_info = l10n_util::GetStringFUTF16(
IDS_MESSAGE_NOTIFICATION_SEND_TAB_TO_SELF_DEVICE_INFO,
base::UTF8ToUTF16(entry->GetDeviceName()));
const GURL& url = entry->GetURL();
message_center::RichNotificationData optional_fields;
// Set the notification to be persistent
optional_fields.never_timeout = true;
// Declare a notification
message_center::Notification notification(
message_center::NOTIFICATION_TYPE_SIMPLE, entry->GetGUID(),
base::UTF8ToUTF16(entry->GetTitle()), device_info, gfx::Image(),
base::UTF8ToUTF16(url.host()), url, message_center::NotifierId(url),
optional_fields, /*delegate=*/nullptr);
NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
NotificationHandler::Type::SEND_TAB_TO_SELF, notification,
/*metadata=*/nullptr);
void DesktopNotificationHandler::DisplayNewEntries(
const std::vector<const SendTabToSelfEntry*>& new_entries) {
for (const SendTabToSelfEntry* entry : new_entries) {
const base::string16 device_info = l10n_util::GetStringFUTF16(
IDS_MESSAGE_NOTIFICATION_SEND_TAB_TO_SELF_DEVICE_INFO,
base::UTF8ToUTF16(entry->GetDeviceName()));
const GURL& url = entry->GetURL();
message_center::RichNotificationData optional_fields;
// Set the notification to be persistent
optional_fields.never_timeout = true;
// Declare a notification
message_center::Notification notification(
message_center::NOTIFICATION_TYPE_SIMPLE, entry->GetGUID(),
base::UTF8ToUTF16(entry->GetTitle()), device_info, gfx::Image(),
base::UTF8ToUTF16(url.host()), url, message_center::NotifierId(url),
optional_fields, /*delegate=*/nullptr);
NotificationDisplayServiceFactory::GetForProfile(profile_)->Display(
NotificationHandler::Type::SEND_TAB_TO_SELF, notification,
/*metadata=*/nullptr);
}
}
void DesktopNotificationHandler::DismissEntries(
......
......@@ -27,7 +27,8 @@ class DesktopNotificationHandler : public NotificationHandler,
~DesktopNotificationHandler() override;
// ReceivingUiHandler implementation.
void DisplayNewEntry(const SendTabToSelfEntry* entry) override;
void DisplayNewEntries(
const std::vector<const SendTabToSelfEntry*>& new_entries) override;
void DismissEntries(const std::vector<std::string>& guids) override;
// NotificationHandler implementation.
......
......@@ -127,7 +127,7 @@ class DesktopNotificationHandlerTest : public BrowserWithTestWindowTest {
NotificationDisplayServiceMock* display_service_mock_;
};
TEST_F(DesktopNotificationHandlerTest, DisplayNewEntry) {
TEST_F(DesktopNotificationHandlerTest, DisplayNewEntries) {
const GURL& url = GURL(kDesktopNotificationOrigin);
message_center::RichNotificationData optional_fields;
optional_fields.never_timeout = true;
......@@ -142,6 +142,8 @@ TEST_F(DesktopNotificationHandlerTest, DisplayNewEntry) {
kDesktopNotificationTitle, base::Time::Now(),
base::Time::Now(), kDesktopNotificationDeviceInfo,
kDesktopNotificationTargetDeviceSyncCacheGuid);
std::vector<const SendTabToSelfEntry*> entries;
entries.push_back(&entry);
DesktopNotificationHandler handler(profile());
EXPECT_CALL(*display_service_mock_,
......@@ -149,7 +151,7 @@ TEST_F(DesktopNotificationHandlerTest, DisplayNewEntry) {
EqualNotification(notification), nullptr))
.WillOnce(::testing::Return());
handler.DisplayNewEntry(&entry);
handler.DisplayNewEntries(entries);
}
TEST_F(DesktopNotificationHandlerTest, DismissEntries) {
......
......@@ -21,13 +21,13 @@ class ReceivingUiHandler {
ReceivingUiHandler() {}
virtual ~ReceivingUiHandler() {}
// Display the new entry passed in as an argument. The entry is owned by the
// model and should not be modified.
virtual void DisplayNewEntry(const SendTabToSelfEntry* entry) = 0;
// Display the new entries passed in as an argument. The entries are owned by
// the model and should not be modified.
virtual void DisplayNewEntries(
const std::vector<const SendTabToSelfEntry*>& new_entries) = 0;
// Dismiss any UI associated with this entry.
// Entry object is owned by the the model and should not be
// modified by any implementors of this class.
// TODO(crbug.com/944591): Pass a string at a time instead.
virtual void DismissEntries(const std::vector<std::string>& guids) = 0;
};
......
......@@ -35,10 +35,8 @@ void SendTabToSelfClientService::SendTabToSelfModelLoaded() {
void SendTabToSelfClientService::EntriesAddedRemotely(
const std::vector<const SendTabToSelfEntry*>& new_entries) {
for (const SendTabToSelfEntry* entry : new_entries) {
for (const std::unique_ptr<ReceivingUiHandler>& handler : GetHandlers()) {
handler->DisplayNewEntry(entry);
}
for (const std::unique_ptr<ReceivingUiHandler>& handler : GetHandlers()) {
handler->DisplayNewEntries(new_entries);
}
}
......
......@@ -23,8 +23,9 @@ class TestReceivingUiHandler : public ReceivingUiHandler {
TestReceivingUiHandler() = default;
~TestReceivingUiHandler() override {}
void DisplayNewEntry(const SendTabToSelfEntry* entry) override {
++number_displayed_entries_;
void DisplayNewEntries(
const std::vector<const SendTabToSelfEntry*>& new_entries) override {
number_displayed_entries_ = number_displayed_entries_ + new_entries.size();
}
void DismissEntries(const std::vector<std::string>& guids) override {}
......
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