1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chromeos.h"
8 #include "ash/shell_window_ids.h"
9 #include "ash/system/system_notifier.h"
10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
11 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
12 #include "ui/aura/window.h"
13 #include "ui/message_center/message_center.h"
14 #include "ui/message_center/notifier_settings.h"
16 MultiUserNotificationBlockerChromeOS::MultiUserNotificationBlockerChromeOS(
17 message_center::MessageCenter
* message_center
,
18 chrome::MultiUserWindowManager
* multi_user_window_manager
)
19 : NotificationBlocker(message_center
),
20 multi_user_window_manager_(multi_user_window_manager
) {
24 MultiUserNotificationBlockerChromeOS::~MultiUserNotificationBlockerChromeOS() {
27 void MultiUserNotificationBlockerChromeOS::UpdateWindowOwners() {
28 std::set
<std::string
> new_ids
;
29 multi_user_window_manager_
->GetOwnersOfVisibleWindows(&new_ids
);
31 if (current_user_ids_
!= new_ids
) {
32 current_user_ids_
.swap(new_ids
);
33 NotifyBlockingStateChanged();
37 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotification(
38 const message_center::NotifierId
& notifier_id
) const {
42 if (ash::system_notifier::IsAshSystemNotifier(notifier_id
))
45 return notifier_id
.profile_id
== active_user_id_
;
48 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotificationAsPopup(
49 const message_center::NotifierId
& notifier_id
) const {
50 return (current_user_ids_
.find(notifier_id
.profile_id
) !=
51 current_user_ids_
.end()) ||
52 ShouldShowNotification(notifier_id
);
55 void MultiUserNotificationBlockerChromeOS::ActiveUserChanged(
56 const std::string
& user_id
) {
57 if (active_user_id_
== user_id
)
60 quiet_modes_
[active_user_id_
] = message_center()->IsQuietMode();
61 active_user_id_
= user_id
;
62 std::map
<std::string
, bool>::const_iterator iter
=
63 quiet_modes_
.find(active_user_id_
);
64 if (iter
!= quiet_modes_
.end() &&
65 iter
->second
!= message_center()->IsQuietMode()) {
66 message_center()->SetQuietMode(iter
->second
);
69 NotifyBlockingStateChanged();
72 bool MultiUserNotificationBlockerChromeOS::IsActive() const {
73 return chrome::MultiUserWindowManager::GetMultiProfileMode() ==
74 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED
;