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 const std::string
& initial_user_id
)
20 : NotificationBlocker(message_center
),
21 multi_user_window_manager_(multi_user_window_manager
),
22 active_user_id_(initial_user_id
) {
24 multi_user_window_manager_
->AddObserver(this);
27 MultiUserNotificationBlockerChromeOS::~MultiUserNotificationBlockerChromeOS() {
28 multi_user_window_manager_
->RemoveObserver(this);
31 void MultiUserNotificationBlockerChromeOS::UpdateWindowOwners() {
32 std::set
<std::string
> new_ids
;
33 multi_user_window_manager_
->GetOwnersOfVisibleWindows(&new_ids
);
35 if (current_user_ids_
!= new_ids
) {
36 current_user_ids_
.swap(new_ids
);
37 NotifyBlockingStateChanged();
41 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotification(
42 const message_center::NotifierId
& notifier_id
) const {
46 if (ash::system_notifier::IsAshSystemNotifier(notifier_id
))
49 return notifier_id
.profile_id
== active_user_id_
;
52 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotificationAsPopup(
53 const message_center::NotifierId
& notifier_id
) const {
54 return (current_user_ids_
.find(notifier_id
.profile_id
) !=
55 current_user_ids_
.end()) ||
56 ShouldShowNotification(notifier_id
);
59 void MultiUserNotificationBlockerChromeOS::OnOwnerEntryAdded(
60 aura::Window
* window
) {
64 void MultiUserNotificationBlockerChromeOS::OnOwnerEntryChanged(
65 aura::Window
* window
) {
69 void MultiUserNotificationBlockerChromeOS::OnOwnerEntryRemoved(
70 aura::Window
* window
) {
74 void MultiUserNotificationBlockerChromeOS::ActiveUserChanged(
75 const std::string
& user_id
) {
76 if (active_user_id_
== user_id
)
79 quiet_modes_
[active_user_id_
] = message_center()->IsQuietMode();
80 active_user_id_
= user_id
;
81 std::map
<std::string
, bool>::const_iterator iter
=
82 quiet_modes_
.find(active_user_id_
);
83 if (iter
!= quiet_modes_
.end() &&
84 iter
->second
!= message_center()->IsQuietMode()) {
85 message_center()->SetQuietMode(iter
->second
);
88 NotifyBlockingStateChanged();
91 bool MultiUserNotificationBlockerChromeOS::IsActive() const {
92 return chrome::MultiUserWindowManager::GetMultiProfileMode() ==
93 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED
;