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