OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/notifications/multi_user_notification_blocker_chromeos.
h" | 5 #include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chrom
eos.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" |
8 #include "ash/system/system_notifier.h" | 9 #include "ash/system/system_notifier.h" |
9 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 10 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
10 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 11 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 12 #include "ui/aura/window.h" |
11 #include "ui/message_center/message_center.h" | 13 #include "ui/message_center/message_center.h" |
12 #include "ui/message_center/notifier_settings.h" | 14 #include "ui/message_center/notifier_settings.h" |
13 | 15 |
14 MultiUserNotificationBlockerChromeOS::MultiUserNotificationBlockerChromeOS( | 16 MultiUserNotificationBlockerChromeOS::MultiUserNotificationBlockerChromeOS( |
15 message_center::MessageCenter* message_center) | 17 message_center::MessageCenter* message_center, |
| 18 chrome::MultiUserWindowManager* multi_user_window_manager) |
16 : NotificationBlocker(message_center), | 19 : NotificationBlocker(message_center), |
17 observing_(false) { | 20 multi_user_window_manager_(multi_user_window_manager) { |
18 // UserManager may not be initialized in unit tests. | 21 UpdateWindowOwners(); |
19 if (!chromeos::UserManager::IsInitialized()) | |
20 return; | |
21 | |
22 // This class is created in the ctor of NotificationUIManager which is created | |
23 // when a notification is created, so ash::Shell should be initialized. | |
24 ash::Shell::GetInstance()->AddShellObserver(this); | |
25 chromeos::UserManager::Get()->AddSessionStateObserver(this); | |
26 observing_ = true; | |
27 } | 22 } |
28 | 23 |
29 MultiUserNotificationBlockerChromeOS::~MultiUserNotificationBlockerChromeOS() { | 24 MultiUserNotificationBlockerChromeOS::~MultiUserNotificationBlockerChromeOS() { |
30 if (observing_) { | 25 } |
31 if (ash::Shell::HasInstance()) | 26 |
32 ash::Shell::GetInstance()->RemoveShellObserver(this); | 27 void MultiUserNotificationBlockerChromeOS::UpdateWindowOwners() { |
33 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); | 28 std::set<std::string> new_ids; |
| 29 multi_user_window_manager_->GetWindowOwners(&new_ids); |
| 30 |
| 31 if (current_user_ids_ != new_ids) { |
| 32 current_user_ids_.swap(new_ids); |
| 33 NotifyBlockingStateChanged(); |
34 } | 34 } |
35 } | 35 } |
36 | 36 |
37 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotification( | 37 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotification( |
38 const message_center::NotifierId& notifier_id) const { | 38 const message_center::NotifierId& notifier_id) const { |
39 if (!IsActive()) | 39 if (!IsActive()) |
40 return true; | 40 return true; |
41 | 41 |
42 if (ash::system_notifier::IsAshSystemNotifier(notifier_id)) | 42 if (ash::system_notifier::IsAshSystemNotifier(notifier_id)) |
43 return true; | 43 return true; |
44 | 44 |
45 return notifier_id.profile_id == active_user_id_; | 45 return notifier_id.profile_id == active_user_id_; |
46 } | 46 } |
47 | 47 |
48 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotificationAsPopup( | 48 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotificationAsPopup( |
49 const message_center::NotifierId& notifier_id) const { | 49 const message_center::NotifierId& notifier_id) const { |
50 return ShouldShowNotification(notifier_id); | 50 return (current_user_ids_.find(notifier_id.profile_id) != |
51 } | 51 current_user_ids_.end()) || |
52 | 52 ShouldShowNotification(notifier_id); |
53 void MultiUserNotificationBlockerChromeOS::OnAppTerminating() { | |
54 ash::Shell::GetInstance()->RemoveShellObserver(this); | |
55 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); | |
56 observing_ = false; | |
57 } | 53 } |
58 | 54 |
59 void MultiUserNotificationBlockerChromeOS::ActiveUserChanged( | 55 void MultiUserNotificationBlockerChromeOS::ActiveUserChanged( |
60 const chromeos::User* active_user) { | 56 const std::string& user_id) { |
61 const std::string& new_user_id = active_user->email(); | 57 if (active_user_id_ == user_id) |
62 if (active_user_id_ == new_user_id) | |
63 return; | 58 return; |
64 | 59 |
65 quiet_modes_[active_user_id_] = message_center()->IsQuietMode(); | 60 quiet_modes_[active_user_id_] = message_center()->IsQuietMode(); |
66 active_user_id_ = active_user->email(); | 61 active_user_id_ = user_id; |
67 std::map<std::string, bool>::const_iterator iter = | 62 std::map<std::string, bool>::const_iterator iter = |
68 quiet_modes_.find(active_user_id_); | 63 quiet_modes_.find(active_user_id_); |
69 if (iter != quiet_modes_.end() && | 64 if (iter != quiet_modes_.end() && |
70 iter->second != message_center()->IsQuietMode()) { | 65 iter->second != message_center()->IsQuietMode()) { |
71 message_center()->SetQuietMode(iter->second); | 66 message_center()->SetQuietMode(iter->second); |
72 } | 67 } |
| 68 UpdateWindowOwners(); |
73 NotifyBlockingStateChanged(); | 69 NotifyBlockingStateChanged(); |
74 } | 70 } |
75 | 71 |
76 bool MultiUserNotificationBlockerChromeOS::IsActive() const { | 72 bool MultiUserNotificationBlockerChromeOS::IsActive() const { |
77 return observing_ && chrome::MultiUserWindowManager::GetMultiProfileMode() == | 73 return chrome::MultiUserWindowManager::GetMultiProfileMode() == |
78 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED; | 74 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED; |
79 } | 75 } |
OLD | NEW |