Commit cb39e453 authored by Travis Skare's avatar Travis Skare Committed by Commit Bot

[Selfshare] Prevent duplicate notifications for multiple profiles.

Attemts the most narrow fix for this in case we want to merge.

Bug: 976873
Change-Id: I633adc6413639f975dac9ab683713fbb3c594684
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1674753Reviewed-by: default avatarTanya Gupta <tgupta@chromium.org>
Commit-Queue: Travis Skare <skare@chromium.org>
Cr-Commit-Position: refs/heads/master@{#672601}
parent ec4778d2
...@@ -144,4 +144,8 @@ void DesktopNotificationHandler::DisplayFailureMessage(const GURL& url) { ...@@ -144,4 +144,8 @@ void DesktopNotificationHandler::DisplayFailureMessage(const GURL& url) {
/*metadata=*/nullptr); /*metadata=*/nullptr);
} }
const Profile* DesktopNotificationHandler::GetProfile() const {
return profile_;
}
} // namespace send_tab_to_self } // namespace send_tab_to_self
...@@ -52,6 +52,9 @@ class DesktopNotificationHandler : public NotificationHandler, ...@@ -52,6 +52,9 @@ class DesktopNotificationHandler : public NotificationHandler,
// Displays a notification telling the user that the tab could not be sent. // Displays a notification telling the user that the tab could not be sent.
void DisplayFailureMessage(const GURL& url); void DisplayFailureMessage(const GURL& url);
// Retrieves the Profile for which this Handler will manage notifications.
const Profile* GetProfile() const;
protected: protected:
Profile* const profile_; Profile* const profile_;
DISALLOW_COPY_AND_ASSIGN(DesktopNotificationHandler); DISALLOW_COPY_AND_ASSIGN(DesktopNotificationHandler);
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include <vector> #include <vector>
#include "base/logging.h" #include "base/logging.h"
#include "build/build_config.h"
#include "chrome/browser/send_tab_to_self/desktop_notification_handler.h"
#include "chrome/browser/send_tab_to_self/receiving_ui_handler.h" #include "chrome/browser/send_tab_to_self/receiving_ui_handler.h"
#include "chrome/browser/send_tab_to_self/receiving_ui_handler_registry.h" #include "chrome/browser/send_tab_to_self/receiving_ui_handler_registry.h"
#include "components/send_tab_to_self/send_tab_to_self_model.h" #include "components/send_tab_to_self/send_tab_to_self_model.h"
...@@ -21,6 +23,8 @@ SendTabToSelfClientService::SendTabToSelfClientService( ...@@ -21,6 +23,8 @@ SendTabToSelfClientService::SendTabToSelfClientService(
model_ = model; model_ = model;
model_->AddObserver(this); model_->AddObserver(this);
profile_ = profile;
SetupHandlerRegistry(profile); SetupHandlerRegistry(profile);
} }
...@@ -37,7 +41,20 @@ void SendTabToSelfClientService::SendTabToSelfModelLoaded() { ...@@ -37,7 +41,20 @@ 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 std::unique_ptr<ReceivingUiHandler>& handler : GetHandlers()) { for (const std::unique_ptr<ReceivingUiHandler>& handler : GetHandlers()) {
#if defined(OS_LINUX) || defined(OS_MACOSX) || defined(OS_WIN)
// Only respond to notifications corresponding to this service's profile
// for these OSes; mobile does not have a Profile.
// Cast note: on desktop, handlers are guaranteed to be the derived class
// DesktopNotificationHandlers; see
// ReceivingUiHandlerRegistry::InstantiatePlatformSpecificHandlers().
auto* desktop_handler =
static_cast<DesktopNotificationHandler*>(handler.get());
if (desktop_handler && desktop_handler->GetProfile() == profile_) {
handler->DisplayNewEntries(new_entries);
}
#else
handler->DisplayNewEntries(new_entries); handler->DisplayNewEntries(new_entries);
#endif
} }
} }
......
...@@ -54,6 +54,8 @@ class SendTabToSelfClientService : public KeyedService, ...@@ -54,6 +54,8 @@ class SendTabToSelfClientService : public KeyedService,
SendTabToSelfModel* model_; SendTabToSelfModel* model_;
// Singleton instance not owned by this class // Singleton instance not owned by this class
ReceivingUiHandlerRegistry* registry_; ReceivingUiHandlerRegistry* registry_;
// Profile for which this service is associated.
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(SendTabToSelfClientService); DISALLOW_COPY_AND_ASSIGN(SendTabToSelfClientService);
}; };
......
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