Commit 3619737e authored by Xiyuan Xia's avatar Xiyuan Xia Committed by Commit Bot

Handle ARC notifications in ash

Makes ui/arc code run inside ash instead of the browser. The code
itself will be moved to //ash in follow-up CLs.

- ArcNotificationManager lives in ash::MessageCenterController;
- Arc bridge host forwards the NotificationsInstance mojo interface
  to ash via AshMessageCenterController interface;
- ArcNotificationSurfaceManager lives in ash::WaylandServerController;

Bug: 768439
Change-Id: Id3572a64cd4d8fac709cd2c22f86b392571d5041
Reviewed-on: https://chromium-review.googlesource.com/1011205
Commit-Queue: Xiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Reviewed-by: default avatarHidehiko Abe <hidehiko@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553397}
parent 88632365
...@@ -1235,6 +1235,7 @@ component("ash") { ...@@ -1235,6 +1235,7 @@ component("ash") {
"//third_party/qcms", "//third_party/qcms",
"//third_party/re2", "//third_party/re2",
"//ui/accessibility", "//ui/accessibility",
"//ui/arc",
"//ui/base", "//ui/base",
"//ui/base:ui_data_pack", "//ui/base:ui_data_pack",
"//ui/base/ime", "//ui/base/ime",
......
...@@ -111,6 +111,9 @@ specific_include_rules = { ...@@ -111,6 +111,9 @@ specific_include_rules = {
"app_launch_unittest.cc": [ "app_launch_unittest.cc": [
"+ash/components/quick_launch/public", "+ash/components/quick_launch/public",
], ],
"message_center_controller\.*": [
"+components/arc/common/notifications.mojom.h"
],
"root_window_controller\.*": [ "root_window_controller\.*": [
"+ash/host" "+ash/host"
], ],
......
...@@ -6,9 +6,12 @@ ...@@ -6,9 +6,12 @@
#include "ash/public/cpp/ash_switches.h" #include "ash/public/cpp/ash_switches.h"
#include "ash/public/cpp/vector_icons/vector_icons.h" #include "ash/public/cpp/vector_icons/vector_icons.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/unguessable_token.h" #include "base/unguessable_token.h"
#include "components/signin/core/account_id/account_id.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notification.h" #include "ui/message_center/public/cpp/notification.h"
...@@ -148,6 +151,19 @@ void MessageCenterController::SetClient( ...@@ -148,6 +151,19 @@ void MessageCenterController::SetClient(
client_.Bind(std::move(client)); client_.Bind(std::move(client));
} }
void MessageCenterController::SetArcNotificationsInstance(
arc::mojom::NotificationsInstancePtr arc_notification_instance) {
if (!arc_notification_manager_) {
arc_notification_manager_ = std::make_unique<arc::ArcNotificationManager>(
Shell::Get()
->session_controller()
->GetPrimaryUserSession()
->user_info->account_id,
message_center::MessageCenter::Get());
}
arc_notification_manager_->SetInstance(std::move(arc_notification_instance));
}
void MessageCenterController::ShowClientNotification( void MessageCenterController::ShowClientNotification(
const message_center::Notification& notification, const message_center::Notification& notification,
const base::UnguessableToken& display_token) { const base::UnguessableToken& display_token) {
......
...@@ -11,8 +11,10 @@ ...@@ -11,8 +11,10 @@
#include "ash/system/web_notification/inactive_user_notification_blocker.h" #include "ash/system/web_notification/inactive_user_notification_blocker.h"
#include "ash/system/web_notification/session_state_notification_blocker.h" #include "ash/system/web_notification/session_state_notification_blocker.h"
#include "base/macros.h" #include "base/macros.h"
#include "components/arc/common/notifications.mojom.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/binding_set.h" #include "mojo/public/cpp/bindings/binding_set.h"
#include "ui/arc/notification/arc_notification_manager.h"
namespace message_center { namespace message_center {
struct NotifierId; struct NotifierId;
...@@ -37,6 +39,8 @@ class ASH_EXPORT MessageCenterController ...@@ -37,6 +39,8 @@ class ASH_EXPORT MessageCenterController
// mojom::AshMessageCenterController: // mojom::AshMessageCenterController:
void SetClient( void SetClient(
mojom::AshMessageCenterClientAssociatedPtrInfo client) override; mojom::AshMessageCenterClientAssociatedPtrInfo client) override;
void SetArcNotificationsInstance(
arc::mojom::NotificationsInstancePtr arc_notification_instance) override;
void ShowClientNotification( void ShowClientNotification(
const message_center::Notification& notification, const message_center::Notification& notification,
const base::UnguessableToken& display_token) override; const base::UnguessableToken& display_token) override;
...@@ -88,6 +92,8 @@ class ASH_EXPORT MessageCenterController ...@@ -88,6 +92,8 @@ class ASH_EXPORT MessageCenterController
mojom::AshMessageCenterClientAssociatedPtr client_; mojom::AshMessageCenterClientAssociatedPtr client_;
std::unique_ptr<arc::ArcNotificationManager> arc_notification_manager_;
DISALLOW_COPY_AND_ASSIGN(MessageCenterController); DISALLOW_COPY_AND_ASSIGN(MessageCenterController);
}; };
......
...@@ -61,6 +61,7 @@ mojom("interfaces_internal") { ...@@ -61,6 +61,7 @@ mojom("interfaces_internal") {
public_deps = [ public_deps = [
"//chromeos/components/proximity_auth/public/interfaces", "//chromeos/components/proximity_auth/public/interfaces",
"//chromeos/services/assistant/public/mojom", "//chromeos/services/assistant/public/mojom",
"//components/arc/common:notifications",
"//components/password_manager/public/interfaces", "//components/password_manager/public/interfaces",
"//components/signin/public/interfaces", "//components/signin/public/interfaces",
"//components/sync/mojo:interfaces", "//components/sync/mojo:interfaces",
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
module ash.mojom; module ash.mojom;
import "components/arc/common/notifications.mojom";
import "ui/gfx/image/mojo/image.mojom"; import "ui/gfx/image/mojo/image.mojom";
import "ui/message_center/public/mojo/notification.mojom"; import "ui/message_center/public/mojo/notification.mojom";
import "ui/message_center/public/mojo/notifier_id.mojom"; import "ui/message_center/public/mojo/notifier_id.mojom";
...@@ -34,6 +35,9 @@ struct NotifierUiData { ...@@ -34,6 +35,9 @@ struct NotifierUiData {
interface AshMessageCenterController { interface AshMessageCenterController {
SetClient(associated AshMessageCenterClient client); SetClient(associated AshMessageCenterClient client);
// Sets the ARC notification instance.
SetArcNotificationsInstance(arc.mojom.NotificationsInstance instance);
// Shows a notification. |display_token| will be used to reference this // Shows a notification. |display_token| will be used to reference this
// notification for AshMessageCenterClient::Close(). // notification for AshMessageCenterClient::Close().
ShowClientNotification(message_center.mojom.Notification notification, ShowClientNotification(message_center.mojom.Notification notification,
......
...@@ -424,11 +424,9 @@ void Shell::RegisterUserProfilePrefs(PrefRegistrySimple* registry, ...@@ -424,11 +424,9 @@ void Shell::RegisterUserProfilePrefs(PrefRegistrySimple* registry,
PowerPrefs::RegisterUserProfilePrefs(registry, for_test); PowerPrefs::RegisterUserProfilePrefs(registry, for_test);
} }
void Shell::InitWaylandServer( void Shell::InitWaylandServer(std::unique_ptr<exo::FileHelper> file_helper) {
exo::NotificationSurfaceManager* notification_surface_manager, wayland_server_controller_ =
std::unique_ptr<exo::FileHelper> file_helper) { WaylandServerController::CreateIfNecessary(std::move(file_helper));
wayland_server_controller_ = WaylandServerController::CreateIfNecessary(
notification_surface_manager, std::move(file_helper));
} }
void Shell::DestroyWaylandServer() { void Shell::DestroyWaylandServer() {
......
...@@ -46,7 +46,6 @@ class DisplayManager; ...@@ -46,7 +46,6 @@ class DisplayManager;
namespace exo { namespace exo {
class FileHelper; class FileHelper;
class NotificationSurfaceManager;
} // namespace exo } // namespace exo
namespace gfx { namespace gfx {
...@@ -290,9 +289,7 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -290,9 +289,7 @@ class ASH_EXPORT Shell : public SessionObserver,
bool for_test = false); bool for_test = false);
// If necessary, initializes the Wayland server. // If necessary, initializes the Wayland server.
void InitWaylandServer( void InitWaylandServer(std::unique_ptr<exo::FileHelper> file_helper);
exo::NotificationSurfaceManager* notification_surface_manager,
std::unique_ptr<exo::FileHelper> file_helper);
void DestroyWaylandServer(); void DestroyWaylandServer();
// Creates a default views::NonClientFrameView for use by windows in the // Creates a default views::NonClientFrameView for use by windows in the
......
...@@ -103,7 +103,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() { ...@@ -103,7 +103,7 @@ void ShellBrowserMainParts::PreMainMessageLoopRun() {
ash::Shell::GetPrimaryRootWindow()->GetHost()->Show(); ash::Shell::GetPrimaryRootWindow()->GetHost()->Show();
ash::Shell::Get()->InitWaylandServer(nullptr, nullptr); ash::Shell::Get()->InitWaylandServer(nullptr);
} }
void ShellBrowserMainParts::PostMainMessageLoopRun() { void ShellBrowserMainParts::PostMainMessageLoopRun() {
......
...@@ -16,5 +16,6 @@ source_set("wayland") { ...@@ -16,5 +16,6 @@ source_set("wayland") {
"//components/exo", "//components/exo",
"//components/exo/wayland", "//components/exo/wayland",
"//skia", "//skia",
"//ui/arc",
] ]
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "components/exo/file_helper.h" #include "components/exo/file_helper.h"
#include "components/exo/wayland/server.h" #include "components/exo/wayland/server.h"
#include "components/exo/wm_helper.h" #include "components/exo/wm_helper.h"
#include "ui/arc/notification/arc_notification_surface_manager_impl.h"
namespace ash { namespace ash {
...@@ -46,15 +47,13 @@ class WaylandServerController::WaylandWatcher ...@@ -46,15 +47,13 @@ class WaylandServerController::WaylandWatcher
// static // static
std::unique_ptr<WaylandServerController> std::unique_ptr<WaylandServerController>
WaylandServerController::CreateIfNecessary( WaylandServerController::CreateIfNecessary(
exo::NotificationSurfaceManager* notification_surface_manager,
std::unique_ptr<exo::FileHelper> file_helper) { std::unique_ptr<exo::FileHelper> file_helper) {
if (!base::CommandLine::ForCurrentProcess()->HasSwitch( if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAshEnableWaylandServer)) { switches::kAshEnableWaylandServer)) {
return nullptr; return nullptr;
} }
return base::WrapUnique(new WaylandServerController( return base::WrapUnique(new WaylandServerController(std::move(file_helper)));
notification_surface_manager, std::move(file_helper)));
} }
WaylandServerController::~WaylandServerController() { WaylandServerController::~WaylandServerController() {
...@@ -66,12 +65,13 @@ WaylandServerController::~WaylandServerController() { ...@@ -66,12 +65,13 @@ WaylandServerController::~WaylandServerController() {
} }
WaylandServerController::WaylandServerController( WaylandServerController::WaylandServerController(
exo::NotificationSurfaceManager* notification_surface_manager,
std::unique_ptr<exo::FileHelper> file_helper) { std::unique_ptr<exo::FileHelper> file_helper) {
arc_notification_surface_manager_ =
std::make_unique<arc::ArcNotificationSurfaceManagerImpl>();
wm_helper_ = std::make_unique<exo::WMHelper>(); wm_helper_ = std::make_unique<exo::WMHelper>();
exo::WMHelper::SetInstance(wm_helper_.get()); exo::WMHelper::SetInstance(wm_helper_.get());
display_ = std::make_unique<exo::Display>(notification_surface_manager, display_ = std::make_unique<exo::Display>(
std::move(file_helper)); arc_notification_surface_manager_.get(), std::move(file_helper));
wayland_server_ = exo::wayland::Server::Create(display_.get()); wayland_server_ = exo::wayland::Server::Create(display_.get());
// Wayland server creation can fail if XDG_RUNTIME_DIR is not set correctly. // Wayland server creation can fail if XDG_RUNTIME_DIR is not set correctly.
if (wayland_server_) if (wayland_server_)
......
...@@ -9,10 +9,13 @@ ...@@ -9,10 +9,13 @@
#include "base/macros.h" #include "base/macros.h"
namespace arc {
class ArcNotificationSurfaceManagerImpl;
} // namespace arc
namespace exo { namespace exo {
class Display; class Display;
class FileHelper; class FileHelper;
class NotificationSurfaceManager;
class WMHelper; class WMHelper;
namespace wayland { namespace wayland {
class Server; class Server;
...@@ -26,14 +29,12 @@ class WaylandServerController { ...@@ -26,14 +29,12 @@ class WaylandServerController {
// Creates WaylandServerController. Returns null if controller should not be // Creates WaylandServerController. Returns null if controller should not be
// created. // created.
static std::unique_ptr<WaylandServerController> CreateIfNecessary( static std::unique_ptr<WaylandServerController> CreateIfNecessary(
exo::NotificationSurfaceManager* notification_surface_manager,
std::unique_ptr<exo::FileHelper> file_helper); std::unique_ptr<exo::FileHelper> file_helper);
~WaylandServerController(); ~WaylandServerController();
private: private:
WaylandServerController( explicit WaylandServerController(
exo::NotificationSurfaceManager* notification_surface_manager,
std::unique_ptr<exo::FileHelper> file_helper); std::unique_ptr<exo::FileHelper> file_helper);
std::unique_ptr<exo::WMHelper> wm_helper_; std::unique_ptr<exo::WMHelper> wm_helper_;
...@@ -42,6 +43,9 @@ class WaylandServerController { ...@@ -42,6 +43,9 @@ class WaylandServerController {
class WaylandWatcher; class WaylandWatcher;
std::unique_ptr<WaylandWatcher> wayland_watcher_; std::unique_ptr<WaylandWatcher> wayland_watcher_;
std::unique_ptr<arc::ArcNotificationSurfaceManagerImpl>
arc_notification_surface_manager_;
DISALLOW_COPY_AND_ASSIGN(WaylandServerController); DISALLOW_COPY_AND_ASSIGN(WaylandServerController);
}; };
......
...@@ -340,10 +340,8 @@ void WindowManager::OnWmConnected() { ...@@ -340,10 +340,8 @@ void WindowManager::OnWmConnected() {
// We only create controller in the ash process for mash. // We only create controller in the ash process for mash.
if (Shell::GetAshConfig() == Config::MASH) { if (Shell::GetAshConfig() == Config::MASH) {
// TODO(penghuang): wire up notification surface manager.
// https://crbug.com/768439
// TODO(hirono): wire up the file helper. http://crbug.com/768395 // TODO(hirono): wire up the file helper. http://crbug.com/768395
Shell::Get()->InitWaylandServer(nullptr, nullptr); Shell::Get()->InitWaylandServer(nullptr);
} }
} }
......
...@@ -62,7 +62,6 @@ ...@@ -62,7 +62,6 @@
#include "components/arc/volume_mounter/arc_volume_mounter_bridge.h" #include "components/arc/volume_mounter/arc_volume_mounter_bridge.h"
#include "components/arc/wake_lock/arc_wake_lock_bridge.h" #include "components/arc/wake_lock/arc_wake_lock_bridge.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "ui/arc/notification/arc_notification_manager.h"
namespace arc { namespace arc {
namespace { namespace {
...@@ -156,10 +155,6 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) { ...@@ -156,10 +155,6 @@ void ArcServiceLauncher::OnPrimaryUserProfilePrepared(Profile* profile) {
ArcMetricsService::GetForBrowserContext(profile); ArcMetricsService::GetForBrowserContext(profile);
ArcMidisBridge::GetForBrowserContext(profile); ArcMidisBridge::GetForBrowserContext(profile);
ArcNetHostImpl::GetForBrowserContext(profile); ArcNetHostImpl::GetForBrowserContext(profile);
// TODO(https://crbug.com/816441): Remove the callback workaround.
ArcNotificationManager::GetForBrowserContext(profile)
->set_get_app_id_callback(
ArcAppListPrefs::Get(profile)->GetAppIdByPackageNameCallback());
ArcObbMounterBridge::GetForBrowserContext(profile); ArcObbMounterBridge::GetForBrowserContext(profile);
ArcOemCryptoBridge::GetForBrowserContext(profile); ArcOemCryptoBridge::GetForBrowserContext(profile);
ArcPolicyBridge::GetForBrowserContext(profile); ArcPolicyBridge::GetForBrowserContext(profile);
......
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include "content/public/common/drop_data.h" #include "content/public/common/drop_data.h"
#include "storage/browser/fileapi/file_system_context.h" #include "storage/browser/fileapi/file_system_context.h"
#include "storage/browser/fileapi/file_system_url.h" #include "storage/browser/fileapi/file_system_url.h"
#include "ui/arc/notification/arc_notification_surface_manager_impl.h"
namespace { namespace {
...@@ -123,10 +122,7 @@ ExoParts::~ExoParts() { ...@@ -123,10 +122,7 @@ ExoParts::~ExoParts() {
ExoParts::ExoParts() { ExoParts::ExoParts() {
DCHECK(!ash_util::IsRunningInMash()); DCHECK(!ash_util::IsRunningInMash());
arc_notification_surface_manager_ =
std::make_unique<arc::ArcNotificationSurfaceManagerImpl>();
std::unique_ptr<ChromeFileHelper> file_helper = std::unique_ptr<ChromeFileHelper> file_helper =
std::make_unique<ChromeFileHelper>(); std::make_unique<ChromeFileHelper>();
ash::Shell::Get()->InitWaylandServer(arc_notification_surface_manager_.get(), ash::Shell::Get()->InitWaylandServer(std::move(file_helper));
std::move(file_helper));
} }
...@@ -9,10 +9,6 @@ ...@@ -9,10 +9,6 @@
#include "base/macros.h" #include "base/macros.h"
namespace arc {
class ArcNotificationSurfaceManagerImpl;
}
class ExoParts { class ExoParts {
public: public:
// Creates ExoParts. Returns null if exo should not be created. // Creates ExoParts. Returns null if exo should not be created.
...@@ -23,9 +19,6 @@ class ExoParts { ...@@ -23,9 +19,6 @@ class ExoParts {
private: private:
ExoParts(); ExoParts();
std::unique_ptr<arc::ArcNotificationSurfaceManagerImpl>
arc_notification_surface_manager_;
DISALLOW_COPY_AND_ASSIGN(ExoParts); DISALLOW_COPY_AND_ASSIGN(ExoParts);
}; };
......
...@@ -149,11 +149,6 @@ static_library("arc_base") { ...@@ -149,11 +149,6 @@ static_library("arc_base") {
"arc_stop_reason.h", "arc_stop_reason.h",
"arc_util.cc", "arc_util.cc",
"arc_util.h", "arc_util.h",
"connection_holder.h",
"connection_notifier.cc",
"connection_notifier.h",
"connection_observer.h",
"mojo_channel.h",
] ]
deps = [ deps = [
...@@ -165,16 +160,33 @@ static_library("arc_base") { ...@@ -165,16 +160,33 @@ static_library("arc_base") {
"//components/prefs", "//components/prefs",
"//components/signin/core/account_id", "//components/signin/core/account_id",
"//components/user_manager", "//components/user_manager",
"//content/public/common",
"//mojo/edk", "//mojo/edk",
"//ui/aura", "//ui/aura",
] ]
public_deps = [ public_deps = [
":connection_holder",
":prefs", ":prefs",
"//components/arc/common", "//components/arc/common",
] ]
} }
source_set("connection_holder") {
sources = [
"connection_holder.h",
"connection_notifier.cc",
"connection_notifier.h",
"connection_observer.h",
"mojo_channel.h",
]
deps = [
"//base",
"//mojo/public/cpp/bindings",
]
}
static_library("arc_test_support") { static_library("arc_test_support") {
testonly = true testonly = true
sources = [ sources = [
......
...@@ -22,6 +22,11 @@ include_rules = [ ...@@ -22,6 +22,11 @@ include_rules = [
] ]
specific_include_rules = { specific_include_rules = {
"arc_bridge_host_impl.cc": [
"+ash/public",
"+content/public/common/service_manager_connection.h",
"+services/service_manager/public",
],
"arc_util.cc": [ "arc_util.cc": [
"+ui/aura", "+ui/aura",
], ],
......
...@@ -7,10 +7,14 @@ ...@@ -7,10 +7,14 @@
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include "ash/public/interfaces/ash_message_center_controller.mojom.h"
#include "ash/public/interfaces/constants.mojom.h"
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "components/arc/arc_bridge_service.h" #include "components/arc/arc_bridge_service.h"
#include "components/arc/mojo_channel.h" #include "components/arc/mojo_channel.h"
#include "content/public/common/service_manager_connection.h"
#include "services/service_manager/public/cpp/connector.h"
namespace arc { namespace arc {
...@@ -139,8 +143,13 @@ void ArcBridgeHostImpl::OnNetInstanceReady(mojom::NetInstancePtr net_ptr) { ...@@ -139,8 +143,13 @@ void ArcBridgeHostImpl::OnNetInstanceReady(mojom::NetInstancePtr net_ptr) {
void ArcBridgeHostImpl::OnNotificationsInstanceReady( void ArcBridgeHostImpl::OnNotificationsInstanceReady(
mojom::NotificationsInstancePtr notifications_ptr) { mojom::NotificationsInstancePtr notifications_ptr) {
OnInstanceReady(arc_bridge_service_->notifications(), // Forward notification instance to ash.
std::move(notifications_ptr)); ash::mojom::AshMessageCenterControllerPtr ash_message_center_controller;
content::ServiceManagerConnection::GetForProcess()
->GetConnector()
->BindInterface(ash::mojom::kServiceName, &ash_message_center_controller);
ash_message_center_controller->SetArcNotificationsInstance(
std::move(notifications_ptr));
} }
void ArcBridgeHostImpl::OnObbMounterInstanceReady( void ArcBridgeHostImpl::OnObbMounterInstanceReady(
......
...@@ -51,8 +51,6 @@ class MidisHost; ...@@ -51,8 +51,6 @@ class MidisHost;
class MidisInstance; class MidisInstance;
class NetHost; class NetHost;
class NetInstance; class NetInstance;
class NotificationsHost;
class NotificationsInstance;
class ObbMounterHost; class ObbMounterHost;
class ObbMounterInstance; class ObbMounterInstance;
class OemCryptoHost; class OemCryptoHost;
...@@ -163,10 +161,6 @@ class ArcBridgeService { ...@@ -163,10 +161,6 @@ class ArcBridgeService {
return &midis_; return &midis_;
} }
ConnectionHolder<mojom::NetInstance, mojom::NetHost>* net() { return &net_; } ConnectionHolder<mojom::NetInstance, mojom::NetHost>* net() { return &net_; }
ConnectionHolder<mojom::NotificationsInstance, mojom::NotificationsHost>*
notifications() {
return &notifications_;
}
ConnectionHolder<mojom::ObbMounterInstance, mojom::ObbMounterHost>* ConnectionHolder<mojom::ObbMounterInstance, mojom::ObbMounterHost>*
obb_mounter() { obb_mounter() {
return &obb_mounter_; return &obb_mounter_;
...@@ -257,8 +251,6 @@ class ArcBridgeService { ...@@ -257,8 +251,6 @@ class ArcBridgeService {
ConnectionHolder<mojom::MetricsInstance, mojom::MetricsHost> metrics_; ConnectionHolder<mojom::MetricsInstance, mojom::MetricsHost> metrics_;
ConnectionHolder<mojom::MidisInstance, mojom::MidisHost> midis_; ConnectionHolder<mojom::MidisInstance, mojom::MidisHost> midis_;
ConnectionHolder<mojom::NetInstance, mojom::NetHost> net_; ConnectionHolder<mojom::NetInstance, mojom::NetHost> net_;
ConnectionHolder<mojom::NotificationsInstance, mojom::NotificationsHost>
notifications_;
ConnectionHolder<mojom::ObbMounterInstance, mojom::ObbMounterHost> ConnectionHolder<mojom::ObbMounterInstance, mojom::ObbMounterHost>
obb_mounter_; obb_mounter_;
ConnectionHolder<mojom::OemCryptoInstance, mojom::OemCryptoHost> oemcrypto_; ConnectionHolder<mojom::OemCryptoInstance, mojom::OemCryptoHost> oemcrypto_;
......
...@@ -17,7 +17,6 @@ if (is_chromeos) { ...@@ -17,7 +17,6 @@ if (is_chromeos) {
"audio.mojom", "audio.mojom",
"auth.mojom", "auth.mojom",
"backup_settings.mojom", "backup_settings.mojom",
"bitmap.mojom",
"bluetooth.mojom", "bluetooth.mojom",
"boot_phase_monitor.mojom", "boot_phase_monitor.mojom",
"cast_receiver.mojom", "cast_receiver.mojom",
...@@ -33,7 +32,6 @@ if (is_chromeos) { ...@@ -33,7 +32,6 @@ if (is_chromeos) {
"metrics.mojom", "metrics.mojom",
"midis.mojom", "midis.mojom",
"net.mojom", "net.mojom",
"notifications.mojom",
"obb_mounter.mojom", "obb_mounter.mojom",
"oemcrypto.mojom", "oemcrypto.mojom",
"oemcrypto_daemon.mojom", "oemcrypto_daemon.mojom",
...@@ -58,12 +56,24 @@ if (is_chromeos) { ...@@ -58,12 +56,24 @@ if (is_chromeos) {
public_deps = [ public_deps = [
":media", ":media",
":notifications",
"//device/usb/public/mojom", "//device/usb/public/mojom",
"//mojo/common:common_custom_types", "//mojo/common:common_custom_types",
"//mojo/public/mojom/base", "//mojo/public/mojom/base",
"//ui/gfx/geometry/mojo", "//ui/gfx/geometry/mojo",
] ]
} }
mojom("notifications") {
sources = [
"bitmap.mojom",
"notifications.mojom",
]
deps = [
":media", # for gfx.mojom
]
}
} }
# Media related mojo interfaces. There are used by # Media related mojo interfaces. There are used by
......
...@@ -28,11 +28,10 @@ static_library("arc") { ...@@ -28,11 +28,10 @@ static_library("arc") {
] ]
deps = [ deps = [
"//ash",
"//base", "//base",
"//components/arc:arc_base", "//components/arc:connection_holder",
"//components/arc/common:notifications",
"//components/exo", "//components/exo",
"//components/keyed_service/content:content",
"//components/signin/core/account_id", "//components/signin/core/account_id",
"//mojo/public/cpp/system", "//mojo/public/cpp/system",
"//skia", "//skia",
......
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
#include "ui/arc/notification/arc_notification_content_view.h" #include "ui/arc/notification/arc_notification_content_view.h"
#include "ash/wm/window_util.h" // TODO(https://crbug.com/768439): Remove nogncheck when moved to ash.
#include "ash/wm/window_util.h" // nogncheck
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "components/exo/notification_surface.h" #include "components/exo/notification_surface.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
......
...@@ -7,7 +7,8 @@ ...@@ -7,7 +7,8 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "ash/shelf/shelf_constants.h" // TODO(https://crbug.com/768439): Remove nogncheck when moved to ash.
#include "ash/shelf/shelf_constants.h" // nogncheck
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/arc/notification/arc_notification_delegate.h" #include "ui/arc/notification/arc_notification_delegate.h"
......
...@@ -7,13 +7,13 @@ ...@@ -7,13 +7,13 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "base/memory/ptr_util.h" // TODO(https://crbug.com/768439): Remove nogncheck when moved to ash.
#include "base/memory/singleton.h" #include "ash/login_status.h" // nogncheck
#include "ash/session/session_controller.h" // nogncheck
#include "ash/shell.h" // nogncheck
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/arc/arc_bridge_service.h" #include "components/arc/mojo_channel.h"
#include "components/arc/arc_browser_context_keyed_service_factory_base.h"
#include "components/arc/arc_util.h"
#include "ui/arc/notification/arc_notification_delegate.h" #include "ui/arc/notification/arc_notification_delegate.h"
#include "ui/arc/notification/arc_notification_item_impl.h" #include "ui/arc/notification/arc_notification_item_impl.h"
#include "ui/arc/notification/arc_notification_view.h" #include "ui/arc/notification/arc_notification_view.h"
...@@ -33,43 +33,51 @@ std::unique_ptr<message_center::MessageView> CreateCustomMessageView( ...@@ -33,43 +33,51 @@ std::unique_ptr<message_center::MessageView> CreateCustomMessageView(
return arc_delegate->CreateCustomMessageView(notification); return arc_delegate->CreateCustomMessageView(notification);
} }
// Singleton factory for ArcNotificationManager. bool IsPublicSessionOrKiosk() {
class ArcNotificationManagerFactory const ash::LoginStatus login_status =
: public internal::ArcBrowserContextKeyedServiceFactoryBase< ash::Shell::Get()->session_controller()->login_status();
ArcNotificationManager,
ArcNotificationManagerFactory> { return login_status == ash::LoginStatus::PUBLIC ||
login_status == ash::LoginStatus::KIOSK_APP ||
login_status == ash::LoginStatus::ARC_KIOSK_APP;
}
} // namespace
class ArcNotificationManager::InstanceOwner {
public: public:
// Factory name used by ArcBrowserContextKeyedServiceFactoryBase. InstanceOwner() = default;
static constexpr const char* kName = "ArcNotificationManagerFactory"; ~InstanceOwner() = default;
void SetInstancePtr(mojom::NotificationsInstancePtr instance_ptr) {
DCHECK(!channel_);
channel_ = std::make_unique<
MojoChannel<mojom::NotificationsInstance, mojom::NotificationsHost>>(
&holder_, std::move(instance_ptr));
static ArcNotificationManagerFactory* GetInstance() { // Using base::Unretained because |this| owns |channel_|.
return base::Singleton<ArcNotificationManagerFactory>::get(); channel_->set_connection_error_handler(
base::BindOnce(&InstanceOwner::OnDisconnected, base::Unretained(this)));
channel_->QueryVersion();
}
ConnectionHolder<mojom::NotificationsInstance, mojom::NotificationsHost>*
holder() {
return &holder_;
} }
private: private:
friend base::DefaultSingletonTraits<ArcNotificationManagerFactory>; void OnDisconnected() { channel_.reset(); }
ArcNotificationManagerFactory() = default;
~ArcNotificationManagerFactory() override = default;
};
} // namespace ConnectionHolder<mojom::NotificationsInstance, mojom::NotificationsHost>
holder_;
std::unique_ptr<
MojoChannel<mojom::NotificationsInstance, mojom::NotificationsHost>>
channel_;
// static DISALLOW_COPY_AND_ASSIGN(InstanceOwner);
ArcNotificationManager* ArcNotificationManager::GetForBrowserContext( };
content::BrowserContext* context) {
return ArcNotificationManagerFactory::GetForBrowserContext(context);
}
// static
std::unique_ptr<ArcNotificationManager>
ArcNotificationManager::CreateForTesting(
ArcBridgeService* bridge_service,
const AccountId& main_profile_id,
message_center::MessageCenter* message_center) {
// MakeUnique cannot be used because the used ctor is private.
return base::WrapUnique(new ArcNotificationManager(
bridge_service, main_profile_id, message_center));
}
// static // static
void ArcNotificationManager::SetCustomNotificationViewFactory() { void ArcNotificationManager::SetCustomNotificationViewFactory() {
...@@ -77,28 +85,31 @@ void ArcNotificationManager::SetCustomNotificationViewFactory() { ...@@ -77,28 +85,31 @@ void ArcNotificationManager::SetCustomNotificationViewFactory() {
base::Bind(&CreateCustomMessageView)); base::Bind(&CreateCustomMessageView));
} }
ArcNotificationManager::ArcNotificationManager(content::BrowserContext* context,
ArcBridgeService* bridge_service)
: ArcNotificationManager(bridge_service,
ArcServiceManager::Get()->account_id(),
message_center::MessageCenter::Get()) {}
ArcNotificationManager::ArcNotificationManager( ArcNotificationManager::ArcNotificationManager(
ArcBridgeService* bridge_service,
const AccountId& main_profile_id, const AccountId& main_profile_id,
message_center::MessageCenter* message_center) message_center::MessageCenter* message_center)
: arc_bridge_service_(bridge_service), : main_profile_id_(main_profile_id),
main_profile_id_(main_profile_id), message_center_(message_center),
message_center_(message_center) { instance_owner_(std::make_unique<InstanceOwner>()) {
arc_bridge_service_->notifications()->SetHost(this); instance_owner_->holder()->SetHost(this);
arc_bridge_service_->notifications()->AddObserver(this); instance_owner_->holder()->AddObserver(this);
if (!message_center::MessageViewFactory::HasCustomNotificationViewFactory()) if (!message_center::MessageViewFactory::HasCustomNotificationViewFactory())
SetCustomNotificationViewFactory(); SetCustomNotificationViewFactory();
} }
ArcNotificationManager::~ArcNotificationManager() { ArcNotificationManager::~ArcNotificationManager() {
arc_bridge_service_->notifications()->RemoveObserver(this); instance_owner_->holder()->RemoveObserver(this);
arc_bridge_service_->notifications()->SetHost(nullptr); instance_owner_->holder()->SetHost(nullptr);
}
void ArcNotificationManager::SetInstance(
mojom::NotificationsInstancePtr instance) {
instance_owner_->SetInstancePtr(std::move(instance));
}
ConnectionHolder<mojom::NotificationsInstance, mojom::NotificationsHost>*
ArcNotificationManager::GetConnectionHolderForTest() {
return instance_owner_->holder();
} }
void ArcNotificationManager::OnConnectionReady() { void ArcNotificationManager::OnConnectionReady() {
...@@ -187,7 +198,7 @@ void ArcNotificationManager::SendNotificationRemovedFromChrome( ...@@ -187,7 +198,7 @@ void ArcNotificationManager::SendNotificationRemovedFromChrome(
items_.erase(it); items_.erase(it);
auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->notifications(), SendNotificationEventToAndroid); instance_owner_->holder(), SendNotificationEventToAndroid);
// On shutdown, the ARC channel may quit earlier than notifications. // On shutdown, the ARC channel may quit earlier than notifications.
if (!notifications_instance) { if (!notifications_instance) {
...@@ -209,7 +220,7 @@ void ArcNotificationManager::SendNotificationClickedOnChrome( ...@@ -209,7 +220,7 @@ void ArcNotificationManager::SendNotificationClickedOnChrome(
} }
auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->notifications(), SendNotificationEventToAndroid); instance_owner_->holder(), SendNotificationEventToAndroid);
// On shutdown, the ARC channel may quit earlier than notifications. // On shutdown, the ARC channel may quit earlier than notifications.
if (!notifications_instance) { if (!notifications_instance) {
...@@ -232,7 +243,7 @@ void ArcNotificationManager::SendNotificationButtonClickedOnChrome( ...@@ -232,7 +243,7 @@ void ArcNotificationManager::SendNotificationButtonClickedOnChrome(
} }
auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->notifications(), SendNotificationEventToAndroid); instance_owner_->holder(), SendNotificationEventToAndroid);
// On shutdown, the ARC channel may quit earlier than notifications. // On shutdown, the ARC channel may quit earlier than notifications.
if (!notifications_instance) { if (!notifications_instance) {
...@@ -275,7 +286,7 @@ void ArcNotificationManager::CreateNotificationWindow(const std::string& key) { ...@@ -275,7 +286,7 @@ void ArcNotificationManager::CreateNotificationWindow(const std::string& key) {
} }
auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->notifications(), CreateNotificationWindow); instance_owner_->holder(), CreateNotificationWindow);
if (!notifications_instance) if (!notifications_instance)
return; return;
...@@ -290,7 +301,7 @@ void ArcNotificationManager::CloseNotificationWindow(const std::string& key) { ...@@ -290,7 +301,7 @@ void ArcNotificationManager::CloseNotificationWindow(const std::string& key) {
} }
auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->notifications(), CloseNotificationWindow); instance_owner_->holder(), CloseNotificationWindow);
if (!notifications_instance) if (!notifications_instance)
return; return;
...@@ -305,7 +316,7 @@ void ArcNotificationManager::OpenNotificationSettings(const std::string& key) { ...@@ -305,7 +316,7 @@ void ArcNotificationManager::OpenNotificationSettings(const std::string& key) {
} }
auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->notifications(), OpenNotificationSettings); instance_owner_->holder(), OpenNotificationSettings);
// On shutdown, the ARC channel may quit earlier than notifications. // On shutdown, the ARC channel may quit earlier than notifications.
if (!notifications_instance) if (!notifications_instance)
...@@ -316,7 +327,7 @@ void ArcNotificationManager::OpenNotificationSettings(const std::string& key) { ...@@ -316,7 +327,7 @@ void ArcNotificationManager::OpenNotificationSettings(const std::string& key) {
bool ArcNotificationManager::IsOpeningSettingsSupported() const { bool ArcNotificationManager::IsOpeningSettingsSupported() const {
const auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD( const auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->notifications(), OpenNotificationSettings); instance_owner_->holder(), OpenNotificationSettings);
return notifications_instance != nullptr; return notifications_instance != nullptr;
} }
...@@ -329,7 +340,7 @@ void ArcNotificationManager::SendNotificationToggleExpansionOnChrome( ...@@ -329,7 +340,7 @@ void ArcNotificationManager::SendNotificationToggleExpansionOnChrome(
} }
auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD( auto* notifications_instance = ARC_GET_INSTANCE_FOR_METHOD(
arc_bridge_service_->notifications(), SendNotificationEventToAndroid); instance_owner_->holder(), SendNotificationEventToAndroid);
// On shutdown, the ARC channel may quit earlier than notifications. // On shutdown, the ARC channel may quit earlier than notifications.
if (!notifications_instance) { if (!notifications_instance) {
...@@ -342,10 +353,6 @@ void ArcNotificationManager::SendNotificationToggleExpansionOnChrome( ...@@ -342,10 +353,6 @@ void ArcNotificationManager::SendNotificationToggleExpansionOnChrome(
key, mojom::ArcNotificationEvent::TOGGLE_EXPANSION); key, mojom::ArcNotificationEvent::TOGGLE_EXPANSION);
} }
void ArcNotificationManager::Shutdown() {
get_app_id_callback_.Reset();
}
bool ArcNotificationManager::ShouldIgnoreNotification( bool ArcNotificationManager::ShouldIgnoreNotification(
arc::mojom::ArcNotificationData* data) { arc::mojom::ArcNotificationData* data) {
if (data->priority == mojom::ArcNotificationPriority::NONE) if (data->priority == mojom::ArcNotificationPriority::NONE)
...@@ -354,7 +361,8 @@ bool ArcNotificationManager::ShouldIgnoreNotification( ...@@ -354,7 +361,8 @@ bool ArcNotificationManager::ShouldIgnoreNotification(
// Notifications from Play Store are ignored in Public Session and Kiosk mode. // Notifications from Play Store are ignored in Public Session and Kiosk mode.
// TODO: Use centralized const for Play Store package. // TODO: Use centralized const for Play Store package.
if (data->package_name.has_value() && if (data->package_name.has_value() &&
*data->package_name == kPlayStorePackageName && IsRobotAccountMode()) { *data->package_name == kPlayStorePackageName &&
IsPublicSessionOrKiosk()) {
return true; return true;
} }
......
...@@ -10,47 +10,33 @@ ...@@ -10,47 +10,33 @@
#include <unordered_map> #include <unordered_map>
#include "components/arc/common/notifications.mojom.h" #include "components/arc/common/notifications.mojom.h"
#include "components/arc/connection_holder.h"
#include "components/arc/connection_observer.h" #include "components/arc/connection_observer.h"
#include "components/keyed_service/core/keyed_service.h"
#include "components/signin/core/account_id/account_id.h" #include "components/signin/core/account_id/account_id.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
namespace content {
class BrowserContext;
} // namespace content
namespace arc { namespace arc {
class ArcBridgeService;
class ArcNotificationItem; class ArcNotificationItem;
class ArcNotificationManager class ArcNotificationManager
: public KeyedService, : public ConnectionObserver<mojom::NotificationsInstance>,
public ConnectionObserver<mojom::NotificationsInstance>,
public mojom::NotificationsHost { public mojom::NotificationsHost {
public: public:
// Returns singleton instance for the given BrowserContext,
// or nullptr if the browser |context| is not allowed to use ARC.
static ArcNotificationManager* GetForBrowserContext(
content::BrowserContext* context);
// Returns a created instance for testing.
static std::unique_ptr<ArcNotificationManager> CreateForTesting(
ArcBridgeService* bridge_service,
const AccountId& main_profile_id,
message_center::MessageCenter* message_center);
// Sets the factory function to create ARC notification views. Exposed for // Sets the factory function to create ARC notification views. Exposed for
// testing. // testing.
static void SetCustomNotificationViewFactory(); static void SetCustomNotificationViewFactory();
// TODO(hidehiko): Make ctor private to enforce all service users should ArcNotificationManager(const AccountId& main_profile_id,
// use GetForBrowserContext(). message_center::MessageCenter* message_center);
ArcNotificationManager(content::BrowserContext* context,
ArcBridgeService* bridge_service);
~ArcNotificationManager() override; ~ArcNotificationManager() override;
void SetInstance(mojom::NotificationsInstancePtr instance);
ConnectionHolder<mojom::NotificationsInstance, mojom::NotificationsHost>*
GetConnectionHolderForTest();
void set_get_app_id_callback( void set_get_app_id_callback(
base::RepeatingCallback<std::string(const std::string&)> base::RepeatingCallback<std::string(const std::string&)>
get_app_id_callback) { get_app_id_callback) {
...@@ -77,20 +63,15 @@ class ArcNotificationManager ...@@ -77,20 +63,15 @@ class ArcNotificationManager
bool IsOpeningSettingsSupported() const; bool IsOpeningSettingsSupported() const;
void SendNotificationToggleExpansionOnChrome(const std::string& key); void SendNotificationToggleExpansionOnChrome(const std::string& key);
// Overridden from KeyedService:
void Shutdown() override;
private: private:
ArcNotificationManager(ArcBridgeService* bridge_service, // Helper class to own MojoChannel and ConnectionHolder.
const AccountId& main_profile_id, class InstanceOwner;
message_center::MessageCenter* message_center);
bool ShouldIgnoreNotification(mojom::ArcNotificationData* data); bool ShouldIgnoreNotification(mojom::ArcNotificationData* data);
// Calls |get_app_id_callback_| to retrieve the app id from ArcAppListPrefs. // Calls |get_app_id_callback_| to retrieve the app id from ArcAppListPrefs.
std::string GetAppId(const std::string& package_name) const; std::string GetAppId(const std::string& package_name) const;
ArcBridgeService* const arc_bridge_service_; // Owned by ArcServiceManager.
const AccountId main_profile_id_; const AccountId main_profile_id_;
message_center::MessageCenter* const message_center_; message_center::MessageCenter* const message_center_;
...@@ -102,6 +83,10 @@ class ArcNotificationManager ...@@ -102,6 +83,10 @@ class ArcNotificationManager
bool ready_ = false; bool ready_ = false;
// Put as a last member to ensure that any callback tied to the elements
// is not invoked.
std::unique_ptr<InstanceOwner> instance_owner_;
DISALLOW_COPY_AND_ASSIGN(ArcNotificationManager); DISALLOW_COPY_AND_ASSIGN(ArcNotificationManager);
}; };
......
...@@ -10,10 +10,11 @@ ...@@ -10,10 +10,11 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "components/arc/arc_bridge_service.h"
#include "components/arc/connection_holder.h" #include "components/arc/connection_holder.h"
#include "components/arc/test/connection_holder_util.h" #include "components/arc/test/connection_holder_util.h"
#include "components/arc/test/fake_notifications_instance.h" #include "components/arc/test/fake_notifications_instance.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/interface_ptr.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/arc/notification/arc_notification_manager.h" #include "ui/arc/notification/arc_notification_manager.h"
#include "ui/message_center/fake_message_center.h" #include "ui/message_center/fake_message_center.h"
...@@ -63,8 +64,8 @@ class MockMessageCenter : public message_center::FakeMessageCenter { ...@@ -63,8 +64,8 @@ class MockMessageCenter : public message_center::FakeMessageCenter {
class ArcNotificationManagerTest : public testing::Test { class ArcNotificationManagerTest : public testing::Test {
public: public:
ArcNotificationManagerTest() {} ArcNotificationManagerTest() = default;
~ArcNotificationManagerTest() override { base::RunLoop().RunUntilIdle(); } ~ArcNotificationManagerTest() override = default;
protected: protected:
FakeNotificationsInstance* arc_notifications_instance() { FakeNotificationsInstance* arc_notifications_instance() {
...@@ -91,32 +92,40 @@ class ArcNotificationManagerTest : public testing::Test { ...@@ -91,32 +92,40 @@ class ArcNotificationManagerTest : public testing::Test {
return key; return key;
} }
private: void FlushInstanceCall() { binding_->FlushForTesting(); }
base::MessageLoop loop_;
std::unique_ptr<ArcBridgeService> service_;
std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_;
std::unique_ptr<ArcNotificationManager> arc_notification_manager_;
std::unique_ptr<MockMessageCenter> message_center_;
private:
void SetUp() override { void SetUp() override {
arc_notifications_instance_ = std::make_unique<FakeNotificationsInstance>(); arc_notifications_instance_ = std::make_unique<FakeNotificationsInstance>();
service_ = std::make_unique<ArcBridgeService>();
message_center_ = std::make_unique<MockMessageCenter>(); message_center_ = std::make_unique<MockMessageCenter>();
arc_notification_manager_ = ArcNotificationManager::CreateForTesting( arc_notification_manager_ = std::make_unique<ArcNotificationManager>(
service_.get(), EmptyAccountId(), message_center_.get()); EmptyAccountId(), message_center_.get());
binding_ = std::make_unique<mojo::Binding<mojom::NotificationsInstance>>(
arc_notifications_instance_.get());
mojom::NotificationsInstancePtr instance_ptr;
binding_->Bind(mojo::MakeRequest(&instance_ptr));
service_->notifications()->SetInstance(arc_notifications_instance_.get()); arc_notification_manager_->SetInstance(std::move(instance_ptr));
WaitForInstanceReady(service_->notifications()); WaitForInstanceReady(
arc_notification_manager_->GetConnectionHolderForTest());
} }
void TearDown() override { void TearDown() override {
arc_notification_manager_.reset(); arc_notification_manager_.reset();
message_center_.reset(); message_center_.reset();
service_.reset(); binding_.reset();
arc_notifications_instance_.reset(); arc_notifications_instance_.reset();
base::RunLoop().RunUntilIdle();
} }
base::MessageLoop loop_;
std::unique_ptr<FakeNotificationsInstance> arc_notifications_instance_;
std::unique_ptr<mojo::Binding<mojom::NotificationsInstance>> binding_;
std::unique_ptr<ArcNotificationManager> arc_notification_manager_;
std::unique_ptr<MockMessageCenter> message_center_;
DISALLOW_COPY_AND_ASSIGN(ArcNotificationManagerTest); DISALLOW_COPY_AND_ASSIGN(ArcNotificationManagerTest);
}; };
...@@ -142,6 +151,8 @@ TEST_F(ArcNotificationManagerTest, NotificationRemovedByChrome) { ...@@ -142,6 +151,8 @@ TEST_F(ArcNotificationManagerTest, NotificationRemovedByChrome) {
// |notification| gets stale here. // |notification| gets stale here.
} }
FlushInstanceCall();
ASSERT_EQ(1u, arc_notifications_instance()->events().size()); ASSERT_EQ(1u, arc_notifications_instance()->events().size());
EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first); EXPECT_EQ(key, arc_notifications_instance()->events().at(0).first);
EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED, EXPECT_EQ(mojom::ArcNotificationEvent::CLOSED,
......
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