Chromium Code Reviews| 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) |
| 16 : NotificationBlocker(message_center), | 18 : NotificationBlocker(message_center) { |
| 17 observing_(false) { | 19 UpdateWindowOwners(); |
| 18 // UserManager may not be initialized in unit tests. | |
| 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 } | 20 } |
| 28 | 21 |
| 29 MultiUserNotificationBlockerChromeOS::~MultiUserNotificationBlockerChromeOS() { | 22 MultiUserNotificationBlockerChromeOS::~MultiUserNotificationBlockerChromeOS() { |
| 30 if (observing_) { | 23 } |
| 31 if (ash::Shell::HasInstance()) | 24 |
| 32 ash::Shell::GetInstance()->RemoveShellObserver(this); | 25 void MultiUserNotificationBlockerChromeOS::UpdateWindowOwners() { |
| 33 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); | 26 chrome::MultiUserWindowManager* multi_user_manager = |
| 27 chrome::MultiUserWindowManager::GetInstance(); | |
| 28 | |
| 29 // Browser/apps windows exist only on the default container. | |
|
Mr4D (OOO till 08-26)
2014/01/08 17:29:35
Not quite sure if it is worth while the effort, bu
Jun Mukai
2014/01/08 20:41:24
I added GetWindowOwners() to MultiUserWindowManage
| |
| 30 std::vector<aura::Window*> containers = | |
| 31 ash::Shell::GetContainersFromAllRootWindows( | |
| 32 ash::internal::kShellWindowId_DefaultContainer, NULL); | |
| 33 std::set<std::string> new_ids; | |
|
Mr4D (OOO till 08-26)
2014/01/08 17:29:35
Looking at this I would guess that this should be
Jun Mukai
2014/01/08 20:41:24
Done.
| |
| 34 for (size_t i = 0; i < containers.size(); ++i) { | |
| 35 const aura::Window::Windows& children = containers[i]->children(); | |
| 36 for (size_t i = 0; i < children.size(); ++i) { | |
| 37 aura::Window* child = children[i]; | |
|
Mr4D (OOO till 08-26)
2014/01/08 17:29:35
IsWindowOnDesktopOfUser(<unowned_window>) will ret
Jun Mukai
2014/01/08 20:41:24
this logic itself was removed.
| |
| 38 if (multi_user_manager->IsWindowOnDesktopOfUser(child, active_user_id_)) | |
| 39 new_ids.insert(multi_user_manager->GetWindowOwner(child)); | |
| 40 } | |
| 41 } | |
| 42 if (current_user_ids_ != new_ids) { | |
| 43 current_user_ids_.swap(new_ids); | |
| 44 NotifyBlockingStateChanged(); | |
| 34 } | 45 } |
| 35 } | 46 } |
| 36 | 47 |
| 37 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotification( | 48 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotification( |
| 38 const message_center::NotifierId& notifier_id) const { | 49 const message_center::NotifierId& notifier_id) const { |
| 39 if (!IsActive()) | 50 if (!IsActive()) |
| 40 return true; | 51 return true; |
| 41 | 52 |
| 42 if (ash::system_notifier::IsAshSystemNotifier(notifier_id)) | 53 if (ash::system_notifier::IsAshSystemNotifier(notifier_id)) |
| 43 return true; | 54 return true; |
| 44 | 55 |
| 45 return notifier_id.profile_id == active_user_id_; | 56 return notifier_id.profile_id == active_user_id_; |
| 46 } | 57 } |
| 47 | 58 |
| 48 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotificationAsPopup( | 59 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotificationAsPopup( |
| 49 const message_center::NotifierId& notifier_id) const { | 60 const message_center::NotifierId& notifier_id) const { |
| 50 return ShouldShowNotification(notifier_id); | 61 return (current_user_ids_.find(notifier_id.profile_id) != |
| 51 } | 62 current_user_ids_.end()) || |
| 52 | 63 ShouldShowNotification(notifier_id); |
| 53 void MultiUserNotificationBlockerChromeOS::OnAppTerminating() { | |
| 54 ash::Shell::GetInstance()->RemoveShellObserver(this); | |
| 55 chromeos::UserManager::Get()->RemoveSessionStateObserver(this); | |
| 56 observing_ = false; | |
| 57 } | 64 } |
| 58 | 65 |
| 59 void MultiUserNotificationBlockerChromeOS::ActiveUserChanged( | 66 void MultiUserNotificationBlockerChromeOS::ActiveUserChanged( |
| 60 const chromeos::User* active_user) { | 67 const std::string& user_id) { |
| 61 const std::string& new_user_id = active_user->email(); | 68 if (active_user_id_ == user_id) |
| 62 if (active_user_id_ == new_user_id) | |
| 63 return; | 69 return; |
| 64 | 70 |
| 65 quiet_modes_[active_user_id_] = message_center()->IsQuietMode(); | 71 quiet_modes_[active_user_id_] = message_center()->IsQuietMode(); |
| 66 active_user_id_ = active_user->email(); | 72 active_user_id_ = user_id; |
| 67 std::map<std::string, bool>::const_iterator iter = | 73 std::map<std::string, bool>::const_iterator iter = |
| 68 quiet_modes_.find(active_user_id_); | 74 quiet_modes_.find(active_user_id_); |
| 69 if (iter != quiet_modes_.end() && | 75 if (iter != quiet_modes_.end() && |
| 70 iter->second != message_center()->IsQuietMode()) { | 76 iter->second != message_center()->IsQuietMode()) { |
| 71 message_center()->SetQuietMode(iter->second); | 77 message_center()->SetQuietMode(iter->second); |
| 72 } | 78 } |
| 79 UpdateWindowOwners(); | |
| 73 NotifyBlockingStateChanged(); | 80 NotifyBlockingStateChanged(); |
| 74 } | 81 } |
| 75 | 82 |
| 76 bool MultiUserNotificationBlockerChromeOS::IsActive() const { | 83 bool MultiUserNotificationBlockerChromeOS::IsActive() const { |
| 77 return observing_ && chrome::MultiUserWindowManager::GetMultiProfileMode() == | 84 return chrome::MultiUserWindowManager::GetMultiProfileMode() == |
| 78 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED; | 85 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED; |
| 79 } | 86 } |
| OLD | NEW |