Commit 25743923 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Use Profile* instead of std::string in NotificationPlatformBridge

The individual bridges can always convert from Profile* to profile id
easily, but the reverse is not true. This is an issue when the profile
manager is shutting down because the reverse lookup depends on the
profile manager still being operational.

Unlike when the bridge is handling interactions with a notification,
the profile must already be loaded when Display(), Close() or
GetDisplayed() is called.

This is blocking fixing some bugs in NotificationPlatformBridgeChromeOs:
https://chromium-review.googlesource.com/c/chromium/src/+/979268

Bug: none
Change-Id: Ibcb2b61cf2f03408a432edfd0a252ec01e9fe30b
Reviewed-on: https://chromium-review.googlesource.com/982648
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarFinnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548298}
parent a6ac8c52
......@@ -833,6 +833,7 @@ jumbo_split_static_library("browser") {
"notifications/notification_handler.h",
"notifications/notification_permission_context.cc",
"notifications/notification_permission_context.h",
"notifications/notification_platform_bridge.cc",
"notifications/notification_platform_bridge.h",
"notifications/notification_platform_bridge_mac.h",
"notifications/notification_platform_bridge_mac.mm",
......
......@@ -83,8 +83,7 @@ ChromeAshMessageCenterClient::~ChromeAshMessageCenterClient() {}
// NotificationPlatformBridge interface.
void ChromeAshMessageCenterClient::Display(
NotificationHandler::Type /*notification_type*/,
const std::string& /*profile_id*/,
bool /*is_incognito*/,
Profile* /* profile */,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) {
controller_->ShowClientNotification(notification);
......@@ -92,7 +91,7 @@ void ChromeAshMessageCenterClient::Display(
// The unused variable here will not be a part of the future
// NotificationPlatformBridge interface.
void ChromeAshMessageCenterClient::Close(const std::string& /*profile_id*/,
void ChromeAshMessageCenterClient::Close(Profile* /* profile */,
const std::string& notification_id) {
controller_->CloseClientNotification(notification_id);
}
......@@ -100,8 +99,7 @@ void ChromeAshMessageCenterClient::Close(const std::string& /*profile_id*/,
// The unused variables here will not be a part of the future
// NotificationPlatformBridge interface.
void ChromeAshMessageCenterClient::GetDisplayed(
const std::string& /*profile_id*/,
bool /*incognito*/,
Profile* /* profile */,
GetDisplayedNotificationsCallback callback) const {
// Right now, this is only used to get web notifications that were created by
// and have outlived a previous browser process. Ash itself doesn't outlive
......
......@@ -28,14 +28,11 @@ class ChromeAshMessageCenterClient : public NotificationPlatformBridge,
// NotificationPlatformBridge:
void Display(NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) override;
void Close(const std::string& profile_id,
const std::string& notification_id) override;
void GetDisplayed(const std::string& profile_id,
bool incognito,
void Close(Profile* profile, const std::string& notification_id) override;
void GetDisplayed(Profile* profile,
GetDisplayedNotificationsCallback callback) const override;
void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
......
......@@ -98,16 +98,6 @@ std::unique_ptr<NotificationPlatformBridge> CreateMessageCenterBridge(
#endif
}
std::string GetProfileId(Profile* profile) {
#if defined(OS_WIN)
return base::WideToUTF8(profile->GetPath().BaseName().value());
#elif defined(OS_POSIX)
return profile->GetPath().BaseName().value();
#else
#error "Not implemented for !OS_WIN && !OS_POSIX."
#endif
}
void OperationCompleted() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
}
......@@ -227,8 +217,7 @@ void NotificationDisplayServiceImpl::Display(
: message_center_bridge_.get();
DCHECK(bridge);
bridge->Display(notification_type, GetProfileId(profile_),
profile_->IsOffTheRecord(), notification,
bridge->Display(notification_type, profile_, notification,
std::move(metadata));
NotificationHandler* handler = GetNotificationHandler(notification_type);
......@@ -252,7 +241,7 @@ void NotificationDisplayServiceImpl::Close(
: message_center_bridge_.get();
DCHECK(bridge);
bridge->Close(GetProfileId(profile_), notification_id);
bridge->Close(profile_, notification_id);
}
void NotificationDisplayServiceImpl::GetDisplayed(
......@@ -263,8 +252,7 @@ void NotificationDisplayServiceImpl::GetDisplayed(
return;
}
bridge_->GetDisplayed(GetProfileId(profile_), profile_->IsOffTheRecord(),
std::move(callback));
bridge_->GetDisplayed(profile_, std::move(callback));
}
// Callback to run once the profile has been loaded in order to perform a
......
......@@ -35,14 +35,11 @@ class MockNotificationPlatformBridge : public NotificationPlatformBridge {
// NotificationPlatformBridge implementation:
void Display(
NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) override {}
void Close(const std::string& profile_id,
const std::string& notification_id) override {}
void GetDisplayed(const std::string& profile_id,
bool incognito,
void Close(Profile* profile, const std::string& notification_id) override {}
void GetDisplayed(Profile* profile,
GetDisplayedNotificationsCallback callback) const override {
auto displayed_notifications = std::make_unique<std::set<std::string>>();
std::move(callback).Run(std::move(displayed_notifications),
......
// Copyright 2018 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.
#include "chrome/browser/notifications/notification_platform_bridge.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile.h"
#if defined(OS_WIN)
#include "base/strings/utf_string_conversions.h"
#endif
// static
std::string NotificationPlatformBridge::GetProfileId(Profile* profile) {
#if defined(OS_WIN)
return base::WideToUTF8(profile->GetPath().BaseName().value());
#elif defined(OS_POSIX)
return profile->GetPath().BaseName().value();
#else
#error "Not implemented for !OS_WIN && !OS_POSIX."
#endif
}
......@@ -35,26 +35,26 @@ class NotificationPlatformBridge {
// can't handle TRANSIENT notifications.
static bool CanHandleType(NotificationHandler::Type notification_type);
// Returns a unique string identifier for |profile|.
static std::string GetProfileId(Profile* profile);
virtual ~NotificationPlatformBridge() {}
// Shows a toast on screen using the data passed in |notification|.
virtual void Display(
NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) = 0;
// Closes a nofication with |notification_id| and |profile_id| if being
// Closes a nofication with |notification_id| and |profile| if being
// displayed.
virtual void Close(const std::string& profile_id,
const std::string& notification_id) = 0;
virtual void Close(Profile* profile, const std::string& notification_id) = 0;
// Writes the ids of all currently displaying notifications and posts
// |callback| with the result.
virtual void GetDisplayed(
const std::string& profile_id,
bool incognito,
Profile* profile,
GetDisplayedNotificationsCallback callback) const = 0;
// Calls |callback| once |this| is initialized. The argument is
......
......@@ -222,8 +222,7 @@ void NotificationPlatformBridgeAndroid::OnNotificationClosed(
void NotificationPlatformBridgeAndroid::Display(
NotificationHandler::Type notification_type,
const std::string& profile_id,
bool incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) {
JNIEnv* env = AttachCurrentThread();
......@@ -273,11 +272,11 @@ void NotificationPlatformBridgeAndroid::Display(
base::android::ToJavaIntArray(env, notification.vibration_pattern());
ScopedJavaLocalRef<jstring> j_profile_id =
ConvertUTF8ToJavaString(env, profile_id);
ConvertUTF8ToJavaString(env, GetProfileId(profile));
Java_NotificationPlatformBridge_displayNotification(
env, java_object_, j_notification_id, j_origin, j_scope_url, j_profile_id,
incognito, title, body, image, notification_icon, badge,
profile->IsOffTheRecord(), title, body, image, notification_icon, badge,
vibration_pattern, notification.timestamp().ToJavaTime(),
notification.renotify(), notification.silent(), actions);
......@@ -286,7 +285,7 @@ void NotificationPlatformBridgeAndroid::Display(
}
void NotificationPlatformBridgeAndroid::Close(
const std::string& profile_id,
Profile* profile,
const std::string& notification_id) {
const auto iterator = regenerated_notification_infos_.find(notification_id);
if (iterator == regenerated_notification_infos_.end())
......@@ -319,8 +318,7 @@ void NotificationPlatformBridgeAndroid::Close(
}
void NotificationPlatformBridgeAndroid::GetDisplayed(
const std::string& profile_id,
bool incognito,
Profile* profile,
GetDisplayedNotificationsCallback callback) const {
auto displayed_notifications = std::make_unique<std::set<std::string>>();
content::BrowserThread::PostTask(
......
......@@ -71,14 +71,11 @@ class NotificationPlatformBridgeAndroid : public NotificationPlatformBridge {
// NotificationPlatformBridge implementation.
void Display(NotificationHandler::Type notification_type,
const std::string& profile_id,
bool incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) override;
void Close(const std::string& profile_id,
const std::string& notification_id) override;
void GetDisplayed(const std::string& profile_id,
bool incognito,
void Close(Profile* profile, const std::string& notification_id) override;
void GetDisplayed(Profile* profile,
GetDisplayedNotificationsCallback callback) const override;
void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
......
......@@ -13,20 +13,6 @@
#include "chrome/browser/ui/app_icon_loader.h"
#include "ui/gfx/image/image.h"
namespace {
// TODO(estade): remove this function. NotificationPlatformBridge should either
// get Profile* pointers or, longer term, all profile management should be moved
// up a layer to NativeNotificationDisplayService.
Profile* GetProfileFromId(const std::string& profile_id, bool incognito) {
ProfileManager* manager = g_browser_process->profile_manager();
Profile* profile =
manager->GetProfile(manager->user_data_dir().AppendASCII(profile_id));
return incognito ? profile->GetOffTheRecordProfile() : profile;
}
} // namespace
// static
NotificationPlatformBridge* NotificationPlatformBridge::Create() {
return new NotificationPlatformBridgeChromeOs();
......@@ -45,14 +31,12 @@ NotificationPlatformBridgeChromeOs::~NotificationPlatformBridgeChromeOs() {}
void NotificationPlatformBridgeChromeOs::Display(
NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) {
auto active_notification = std::make_unique<ProfileNotification>(
GetProfileFromId(profile_id, is_incognito), notification,
notification_type);
impl_->Display(NotificationHandler::Type::MAX, std::string(), false,
profile, notification, notification_type);
impl_->Display(NotificationHandler::Type::MAX, nullptr /* profile */,
active_notification->notification(), std::move(metadata));
std::string profile_notification_id =
......@@ -62,16 +46,15 @@ void NotificationPlatformBridgeChromeOs::Display(
}
void NotificationPlatformBridgeChromeOs::Close(
const std::string& profile_id,
Profile* profile,
const std::string& notification_id) {
impl_->Close(profile_id, notification_id);
impl_->Close(profile, notification_id);
}
void NotificationPlatformBridgeChromeOs::GetDisplayed(
const std::string& profile_id,
bool incognito,
Profile* profile,
GetDisplayedNotificationsCallback callback) const {
impl_->GetDisplayed(profile_id, incognito, std::move(callback));
impl_->GetDisplayed(profile, std::move(callback));
}
void NotificationPlatformBridgeChromeOs::SetReadyCallback(
......
......@@ -55,14 +55,11 @@ class NotificationPlatformBridgeChromeOs
// NotificationPlatformBridge:
void Display(NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) override;
void Close(const std::string& profile_id,
const std::string& notification_id) override;
void GetDisplayed(const std::string& profile_id,
bool incognito,
void Close(Profile* profile, const std::string& notification_id) override;
void GetDisplayed(Profile* profile,
GetDisplayedNotificationsCallback callback) const override;
void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
......
......@@ -276,8 +276,7 @@ class NotificationPlatformBridgeLinuxImpl
void Display(
NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) override {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
......@@ -291,28 +290,27 @@ class NotificationPlatformBridgeLinuxImpl
FROM_HERE,
base::BindOnce(
&NotificationPlatformBridgeLinuxImpl::DisplayOnTaskRunner, this,
notification_type, profile_id, is_incognito,
notification_type, GetProfileId(profile), profile->IsOffTheRecord(),
std::move(notification_copy)));
}
void Close(const std::string& profile_id,
const std::string& notification_id) override {
void Close(Profile* profile, const std::string& notification_id) override {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&NotificationPlatformBridgeLinuxImpl::CloseOnTaskRunner,
this, profile_id, notification_id));
this, GetProfileId(profile), notification_id));
}
void GetDisplayed(const std::string& profile_id,
bool incognito,
void GetDisplayed(Profile* profile,
GetDisplayedNotificationsCallback callback) const override {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
&NotificationPlatformBridgeLinuxImpl::GetDisplayedOnTaskRunner,
this, profile_id, incognito, std::move(callback)));
this, GetProfileId(profile), profile->IsOffTheRecord(),
std::move(callback)));
}
void SetReadyCallback(NotificationBridgeReadyCallback callback) override {
......@@ -987,25 +985,22 @@ NotificationPlatformBridgeLinux::~NotificationPlatformBridgeLinux() = default;
void NotificationPlatformBridgeLinux::Display(
NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) {
impl_->Display(notification_type, profile_id, is_incognito, notification,
std::move(metadata));
impl_->Display(notification_type, profile, notification, std::move(metadata));
}
void NotificationPlatformBridgeLinux::Close(
const std::string& profile_id,
Profile* profile,
const std::string& notification_id) {
impl_->Close(profile_id, notification_id);
impl_->Close(profile, notification_id);
}
void NotificationPlatformBridgeLinux::GetDisplayed(
const std::string& profile_id,
bool incognito,
Profile* profile,
GetDisplayedNotificationsCallback callback) const {
impl_->GetDisplayed(profile_id, incognito, std::move(callback));
impl_->GetDisplayed(profile, std::move(callback));
}
void NotificationPlatformBridgeLinux::SetReadyCallback(
......
......@@ -26,14 +26,11 @@ class NotificationPlatformBridgeLinux : public NotificationPlatformBridge {
// NotificationPlatformBridge:
void Display(NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) override;
void Close(const std::string& profile_id,
const std::string& notification_id) override;
void GetDisplayed(const std::string& profile_id,
bool incognito,
void Close(Profile* profile, const std::string& notification_id) override;
void GetDisplayed(Profile* profile,
GetDisplayedNotificationsCallback callback) const override;
void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
......
......@@ -15,12 +15,11 @@
#include "base/memory/ref_counted.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/notification_test_util.h"
#include "content/public/test/test_browser_thread_bundle.h"
#include "chrome/test/base/browser_with_test_window_test.h"
#include "content/public/test/test_utils.h"
#include "dbus/mock_bus.h"
#include "dbus/mock_object_proxy.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/re2/src/re2/re2.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/message_center/public/cpp/notification.h"
......@@ -271,12 +270,13 @@ MATCHER_P(Calls, member, "") {
} // namespace
class NotificationPlatformBridgeLinuxTest : public testing::Test {
class NotificationPlatformBridgeLinuxTest : public BrowserWithTestWindowTest {
public:
NotificationPlatformBridgeLinuxTest() = default;
~NotificationPlatformBridgeLinuxTest() override = default;
void SetUp() override {
BrowserWithTestWindowTest::SetUp();
mock_bus_ = new dbus::MockBus(dbus::Bus::Options());
mock_notification_proxy_ = new StrictMock<dbus::MockObjectProxy>(
mock_bus_.get(), kFreedesktopNotificationsName,
......@@ -289,6 +289,7 @@ class NotificationPlatformBridgeLinuxTest : public testing::Test {
notification_bridge_linux_.reset();
mock_notification_proxy_ = nullptr;
mock_bus_ = nullptr;
BrowserWithTestWindowTest::TearDown();
}
protected:
......@@ -340,8 +341,6 @@ class NotificationPlatformBridgeLinuxTest : public testing::Test {
MOCK_METHOD1(MockableNotificationBridgeReadyCallback, void(bool));
content::TestBrowserThreadBundle thread_bundle_;
scoped_refptr<dbus::MockBus> mock_bus_;
scoped_refptr<dbus::MockObjectProxy> mock_notification_proxy_;
......@@ -368,9 +367,9 @@ TEST_F(NotificationPlatformBridgeLinuxTest, NotifyAndCloseFormat) {
CreateNotificationBridgeLinux(TestParams());
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("").GetResult(), nullptr);
notification_bridge_linux_->Close("", "");
notification_bridge_linux_->Close(profile(), "");
}
TEST_F(NotificationPlatformBridgeLinuxTest, ProgressPercentageAddedToSummary) {
......@@ -386,7 +385,7 @@ TEST_F(NotificationPlatformBridgeLinuxTest, ProgressPercentageAddedToSummary) {
CreateNotificationBridgeLinux(TestParams());
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("")
.SetType(message_center::NOTIFICATION_TYPE_PROGRESS)
.SetProgress(42)
......@@ -406,7 +405,7 @@ TEST_F(NotificationPlatformBridgeLinuxTest, NotificationListItemsInBody) {
CreateNotificationBridgeLinux(TestParams());
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("")
.SetType(message_center::NOTIFICATION_TYPE_MULTIPLE)
.SetItems(std::vector<message_center::NotificationItem>{
......@@ -434,10 +433,10 @@ TEST_F(NotificationPlatformBridgeLinuxTest, NotificationTimeoutsNoPersistence) {
CreateNotificationBridgeLinux(TestParams());
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("1").SetNeverTimeout(false).GetResult(), nullptr);
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("2").SetNeverTimeout(true).GetResult(), nullptr);
}
......@@ -455,7 +454,7 @@ TEST_F(NotificationPlatformBridgeLinuxTest,
CreateNotificationBridgeLinux(TestParams().SetCapabilities(
std::vector<std::string>{"actions", "body", "persistence"}));
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("1").GetResult(), nullptr);
}
......@@ -493,7 +492,7 @@ TEST_F(NotificationPlatformBridgeLinuxTest, NotificationImages) {
CreateNotificationBridgeLinux(TestParams());
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("")
.SetType(message_center::NOTIFICATION_TYPE_IMAGE)
.SetImage(original_image)
......@@ -515,7 +514,7 @@ TEST_F(NotificationPlatformBridgeLinuxTest, NotificationAttribution) {
CreateNotificationBridgeLinux(TestParams());
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("")
.SetMessage(base::ASCIIToUTF16("Body text"))
.SetOriginUrl(GURL("https://google.com/search?q=test&ie=UTF8"))
......@@ -551,7 +550,7 @@ TEST_F(NotificationPlatformBridgeLinuxTest, EscapeHtml) {
CreateNotificationBridgeLinux(TestParams());
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("")
.SetMessage(
base::ASCIIToUTF16("<span id='1' class=\"2\">&#39;</span>"))
......@@ -575,10 +574,10 @@ TEST_F(NotificationPlatformBridgeLinuxTest, Silent) {
CreateNotificationBridgeLinux(TestParams());
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("1").SetSilent(false).GetResult(), nullptr);
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("2").SetSilent(true).GetResult(), nullptr);
}
......@@ -614,31 +613,31 @@ TEST_F(NotificationPlatformBridgeLinuxTest, OriginUrlFormat) {
CreateNotificationBridgeLinux(TestParams().SetCapabilities(
std::vector<std::string>{"actions", "body"}));
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("1")
.SetOriginUrl(GURL("https://google.com"))
.GetResult(),
nullptr);
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("2")
.SetOriginUrl(GURL("https://mail.google.com"))
.GetResult(),
nullptr);
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("3")
.SetOriginUrl(GURL("https://123.123.123.123"))
.GetResult(),
nullptr);
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("4")
.SetOriginUrl(GURL("https://a.b.c.co.uk/file.html"))
.GetResult(),
nullptr);
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("5")
.SetOriginUrl(GURL(
"https://google.com.blahblahblahblahblahblahblah.evilsite.com"))
......@@ -664,6 +663,6 @@ TEST_F(NotificationPlatformBridgeLinuxTest,
CreateNotificationBridgeLinux(TestParams().SetServerName("cinnamon"));
notification_bridge_linux_->Display(
NotificationHandler::Type::WEB_PERSISTENT, "", false,
NotificationHandler::Type::WEB_PERSISTENT, profile(),
NotificationBuilder("").GetResult(), nullptr);
}
......@@ -35,15 +35,12 @@ class NotificationPlatformBridgeMac : public NotificationPlatformBridge {
// NotificationPlatformBridge implementation.
void Display(NotificationHandler::Type notification_type,
const std::string& profile_id,
bool incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) override;
void Close(const std::string& profile_id,
const std::string& notification_id) override;
void GetDisplayed(const std::string& profile_id,
bool incognito,
void Close(Profile* profile, const std::string& notification_id) override;
void GetDisplayed(Profile* profile,
GetDisplayedNotificationsCallback callback) const override;
void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
......
......@@ -206,8 +206,7 @@ bool NotificationPlatformBridge::CanHandleType(
void NotificationPlatformBridgeMac::Display(
NotificationHandler::Type notification_type,
const std::string& profile_id,
bool incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) {
base::scoped_nsobject<NotificationBuilder> builder(
......@@ -271,8 +270,8 @@ void NotificationPlatformBridgeMac::Display(
[builder setOrigin:base::SysUTF8ToNSString(notification.origin_url().spec())];
[builder setNotificationId:base::SysUTF8ToNSString(notification.id())];
[builder setProfileId:base::SysUTF8ToNSString(profile_id)];
[builder setIncognito:incognito];
[builder setProfileId:base::SysUTF8ToNSString(GetProfileId(profile))];
[builder setIncognito:profile->IsOffTheRecord()];
[builder
setNotificationType:[NSNumber numberWithInteger:static_cast<NSInteger>(
notification_type)]];
......@@ -289,10 +288,10 @@ void NotificationPlatformBridgeMac::Display(
}
}
void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
void NotificationPlatformBridgeMac::Close(Profile* profile,
const std::string& notification_id) {
NSString* candidate_id = base::SysUTF8ToNSString(notification_id);
NSString* current_profile_id = base::SysUTF8ToNSString(profile_id);
NSString* current_profile_id = base::SysUTF8ToNSString(GetProfileId(profile));
bool notification_removed = false;
for (NSUserNotification* toast in
......@@ -320,12 +319,11 @@ void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
}
void NotificationPlatformBridgeMac::GetDisplayed(
const std::string& profile_id,
bool incognito,
Profile* profile,
GetDisplayedNotificationsCallback callback) const {
[alert_dispatcher_
getDisplayedAlertsForProfileId:base::SysUTF8ToNSString(profile_id)
incognito:incognito
[alert_dispatcher_ getDisplayedAlertsForProfileId:base::SysUTF8ToNSString(
GetProfileId(profile))
incognito:profile->IsOffTheRecord()
notificationCenter:notification_center_
callback:std::move(callback)];
}
......
......@@ -88,10 +88,11 @@ NotificationPlatformBridgeMessageCenter::
void NotificationPlatformBridgeMessageCenter::Display(
NotificationHandler::Type notification_type,
const std::string& /* profile_id */,
bool /* is_incognito */,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> /* metadata */) {
DCHECK_EQ(profile, profile_);
NotificationUIManager* ui_manager =
g_browser_process->notification_ui_manager();
if (!ui_manager)
......@@ -112,8 +113,10 @@ void NotificationPlatformBridgeMessageCenter::Display(
}
void NotificationPlatformBridgeMessageCenter::Close(
const std::string& /* profile_id */,
Profile* profile,
const std::string& notification_id) {
DCHECK_EQ(profile, profile_);
NotificationUIManager* ui_manager =
g_browser_process->notification_ui_manager();
if (!ui_manager)
......@@ -124,9 +127,10 @@ void NotificationPlatformBridgeMessageCenter::Close(
}
void NotificationPlatformBridgeMessageCenter::GetDisplayed(
const std::string& /* profile_id */,
bool /* incognito */,
Profile* profile,
GetDisplayedNotificationsCallback callback) const {
DCHECK_EQ(profile, profile_);
auto displayed_notifications = std::make_unique<std::set<std::string>>(
g_browser_process->notification_ui_manager()->GetAllIdsByProfile(
NotificationUIManager::GetProfileID(profile_)));
......
......@@ -25,14 +25,11 @@ class NotificationPlatformBridgeMessageCenter
// NotificationPlatformBridge implementation:
void Display(NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) override;
void Close(const std::string& profile_id,
const std::string& notification_id) override;
void GetDisplayed(const std::string& profile_id,
bool incognito,
void Close(Profile* profile, const std::string& notification_id) override;
void GetDisplayed(Profile* profile,
GetDisplayedNotificationsCallback callback) const override;
void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
......
......@@ -813,8 +813,7 @@ NotificationPlatformBridgeWin::~NotificationPlatformBridgeWin() = default;
void NotificationPlatformBridgeWin::Display(
NotificationHandler::Type notification_type,
const std::string& profile_id,
bool is_incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
......@@ -828,26 +827,27 @@ void NotificationPlatformBridgeWin::Display(
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&NotificationPlatformBridgeWinImpl::Display, impl_,
notification_type, profile_id, is_incognito,
std::move(notification_copy), std::move(metadata)));
notification_type, GetProfileId(profile),
profile->IsOffTheRecord(), std::move(notification_copy),
std::move(metadata)));
}
void NotificationPlatformBridgeWin::Close(const std::string& profile_id,
void NotificationPlatformBridgeWin::Close(Profile* profile,
const std::string& notification_id) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
task_runner_->PostTask(
FROM_HERE, base::BindOnce(&NotificationPlatformBridgeWinImpl::Close,
impl_, notification_id, profile_id));
impl_, notification_id, GetProfileId(profile)));
}
void NotificationPlatformBridgeWin::GetDisplayed(
const std::string& profile_id,
bool incognito,
Profile* profile,
GetDisplayedNotificationsCallback callback) const {
task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&NotificationPlatformBridgeWinImpl::GetDisplayed, impl_,
profile_id, incognito, std::move(callback)));
GetProfileId(profile), profile->IsOffTheRecord(),
std::move(callback)));
}
void NotificationPlatformBridgeWin::SetReadyCallback(
......
......@@ -31,14 +31,11 @@ class NotificationPlatformBridgeWin : public NotificationPlatformBridge {
// NotificationPlatformBridge implementation.
void Display(NotificationHandler::Type notification_type,
const std::string& profile_id,
bool incognito,
Profile* profile,
const message_center::Notification& notification,
std::unique_ptr<NotificationCommon::Metadata> metadata) override;
void Close(const std::string& profile_id,
const std::string& notification_id) override;
void GetDisplayed(const std::string& profile_id,
bool incognito,
void Close(Profile* profile, const std::string& notification_id) override;
void GetDisplayed(Profile* profile,
GetDisplayedNotificationsCallback callback) const override;
void SetReadyCallback(NotificationBridgeReadyCallback callback) override;
......
......@@ -8,15 +8,21 @@
#include <wrl/client.h>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/path_service.h"
#include "base/run_loop.h"
#include "base/strings/string16.h"
#include "base/threading/thread_restrictions.h"
#include "base/win/scoped_hstring.h"
#include "base/win/windows_version.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/notifications/mock_itoastnotification.h"
#include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/notifications/notification_platform_bridge_win.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
......@@ -27,6 +33,29 @@ namespace winxml = ABI::Windows::Data::Xml;
namespace {
Profile* CreateTestingProfile(const base::FilePath& path) {
base::ScopedAllowBlockingForTesting allow_blocking;
ProfileManager* profile_manager = g_browser_process->profile_manager();
size_t starting_number_of_profiles = profile_manager->GetNumberOfProfiles();
if (!base::PathExists(path) && !base::CreateDirectory(path))
NOTREACHED() << "Could not create directory at " << path.MaybeAsASCII();
Profile* profile =
Profile::CreateProfile(path, nullptr, Profile::CREATE_MODE_SYNCHRONOUS);
profile_manager->RegisterTestingProfile(profile, true, false);
EXPECT_EQ(starting_number_of_profiles + 1,
profile_manager->GetNumberOfProfiles());
return profile;
}
Profile* CreateTestingProfile(const std::string& profile_name) {
base::FilePath path;
PathService::Get(chrome::DIR_USER_DATA, &path);
path = path.AppendASCII(profile_name);
return CreateTestingProfile(path);
}
base::string16 GetToastString(const base::string16& notification_id,
const base::string16& profile_id,
bool incognito) {
......@@ -286,7 +315,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) {
{
base::RunLoop run_loop;
bridge->GetDisplayed(
"Default" /* profile_id */, false /* incognito */,
browser()->profile(),
base::BindRepeating(
&NotificationPlatformBridgeWinUITest::DisplayedNotifications,
base::Unretained(this), run_loop.QuitClosure()));
......@@ -297,12 +326,16 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) {
// Add four items (two in each profile, one for each being incognito and one
// for each that is not).
bool incognito = true;
Profile* profile1 = CreateTestingProfile("P1");
MockIToastNotification item1(GetToastString(L"P1i", L"P1", incognito),
L"tag");
notifications.push_back(&item1);
MockIToastNotification item2(GetToastString(L"P1reg", L"P1", !incognito),
L"tag");
notifications.push_back(&item2);
Profile* profile2 = CreateTestingProfile("P2");
MockIToastNotification item3(GetToastString(L"P2i", L"P2", incognito),
L"tag");
notifications.push_back(&item3);
......@@ -314,7 +347,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) {
{
base::RunLoop run_loop;
bridge->GetDisplayed(
"P1" /* profile_id */, true /* incognito */,
profile1->GetOffTheRecordProfile(),
base::BindRepeating(
&NotificationPlatformBridgeWinUITest::DisplayedNotifications,
base::Unretained(this), run_loop.QuitClosure()));
......@@ -327,7 +360,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) {
{
base::RunLoop run_loop;
bridge->GetDisplayed(
"P1" /* profile_id */, false /* incognito */,
profile1,
base::BindRepeating(
&NotificationPlatformBridgeWinUITest::DisplayedNotifications,
base::Unretained(this), run_loop.QuitClosure()));
......@@ -340,7 +373,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) {
{
base::RunLoop run_loop;
bridge->GetDisplayed(
"P2" /* profile_id */, true /* incognito */,
profile2->GetOffTheRecordProfile(),
base::BindRepeating(
&NotificationPlatformBridgeWinUITest::DisplayedNotifications,
base::Unretained(this), run_loop.QuitClosure()));
......@@ -353,7 +386,7 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) {
{
base::RunLoop run_loop;
bridge->GetDisplayed(
"P2" /* profile_id */, false /* incognito */,
profile2,
base::BindRepeating(
&NotificationPlatformBridgeWinUITest::DisplayedNotifications,
base::Unretained(this), run_loop.QuitClosure()));
......@@ -362,17 +395,5 @@ IN_PROC_BROWSER_TEST_F(NotificationPlatformBridgeWinUITest, GetDisplayed) {
EXPECT_EQ(1U, displayed_notifications_.count("P2reg"));
}
// Query for non-existing profile (should return 0 items).
{
base::RunLoop run_loop;
bridge->GetDisplayed(
"NotFound" /* profile_id */, false /* incognito */,
base::BindRepeating(
&NotificationPlatformBridgeWinUITest::DisplayedNotifications,
base::Unretained(this), run_loop.QuitClosure()));
run_loop.Run();
EXPECT_EQ(0U, displayed_notifications_.size());
}
bridge->SetDisplayedNotificationsForTesting(nullptr);
}
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