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