Index: chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chromeos.cc |
diff --git a/chrome/browser/notifications/multi_user_notification_blocker_chromeos.cc b/chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chromeos.cc |
similarity index 53% |
rename from chrome/browser/notifications/multi_user_notification_blocker_chromeos.cc |
rename to chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chromeos.cc |
index 1d064776bb6d4eef4a8b6461658ab8657e15bd30..16c46950d533eeccdd789970ff0311ec307eae87 100644 |
--- a/chrome/browser/notifications/multi_user_notification_blocker_chromeos.cc |
+++ b/chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chromeos.cc |
@@ -2,35 +2,46 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/notifications/multi_user_notification_blocker_chromeos.h" |
+#include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chromeos.h" |
#include "ash/shell.h" |
+#include "ash/shell_window_ids.h" |
#include "ash/system/system_notifier.h" |
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
+#include "ui/aura/window.h" |
#include "ui/message_center/message_center.h" |
#include "ui/message_center/notifier_settings.h" |
MultiUserNotificationBlockerChromeOS::MultiUserNotificationBlockerChromeOS( |
message_center::MessageCenter* message_center) |
- : NotificationBlocker(message_center), |
- observing_(false) { |
- // UserManager may not be initialized in unit tests. |
- if (!chromeos::UserManager::IsInitialized()) |
- return; |
- |
- // This class is created in the ctor of NotificationUIManager which is created |
- // when a notification is created, so ash::Shell should be initialized. |
- ash::Shell::GetInstance()->AddShellObserver(this); |
- chromeos::UserManager::Get()->AddSessionStateObserver(this); |
- observing_ = true; |
+ : NotificationBlocker(message_center) { |
+ UpdateWindowOwners(); |
} |
MultiUserNotificationBlockerChromeOS::~MultiUserNotificationBlockerChromeOS() { |
- if (observing_) { |
- if (ash::Shell::HasInstance()) |
- ash::Shell::GetInstance()->RemoveShellObserver(this); |
- chromeos::UserManager::Get()->RemoveSessionStateObserver(this); |
+} |
+ |
+void MultiUserNotificationBlockerChromeOS::UpdateWindowOwners() { |
+ chrome::MultiUserWindowManager* multi_user_manager = |
+ chrome::MultiUserWindowManager::GetInstance(); |
+ |
+ // 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
|
+ std::vector<aura::Window*> containers = |
+ ash::Shell::GetContainersFromAllRootWindows( |
+ ash::internal::kShellWindowId_DefaultContainer, NULL); |
+ 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.
|
+ for (size_t i = 0; i < containers.size(); ++i) { |
+ const aura::Window::Windows& children = containers[i]->children(); |
+ for (size_t i = 0; i < children.size(); ++i) { |
+ 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.
|
+ if (multi_user_manager->IsWindowOnDesktopOfUser(child, active_user_id_)) |
+ new_ids.insert(multi_user_manager->GetWindowOwner(child)); |
+ } |
+ } |
+ if (current_user_ids_ != new_ids) { |
+ current_user_ids_.swap(new_ids); |
+ NotifyBlockingStateChanged(); |
} |
} |
@@ -47,33 +58,29 @@ bool MultiUserNotificationBlockerChromeOS::ShouldShowNotification( |
bool MultiUserNotificationBlockerChromeOS::ShouldShowNotificationAsPopup( |
const message_center::NotifierId& notifier_id) const { |
- return ShouldShowNotification(notifier_id); |
-} |
- |
-void MultiUserNotificationBlockerChromeOS::OnAppTerminating() { |
- ash::Shell::GetInstance()->RemoveShellObserver(this); |
- chromeos::UserManager::Get()->RemoveSessionStateObserver(this); |
- observing_ = false; |
+ return (current_user_ids_.find(notifier_id.profile_id) != |
+ current_user_ids_.end()) || |
+ ShouldShowNotification(notifier_id); |
} |
void MultiUserNotificationBlockerChromeOS::ActiveUserChanged( |
- const chromeos::User* active_user) { |
- const std::string& new_user_id = active_user->email(); |
- if (active_user_id_ == new_user_id) |
+ const std::string& user_id) { |
+ if (active_user_id_ == user_id) |
return; |
quiet_modes_[active_user_id_] = message_center()->IsQuietMode(); |
- active_user_id_ = active_user->email(); |
+ active_user_id_ = user_id; |
std::map<std::string, bool>::const_iterator iter = |
quiet_modes_.find(active_user_id_); |
if (iter != quiet_modes_.end() && |
iter->second != message_center()->IsQuietMode()) { |
message_center()->SetQuietMode(iter->second); |
} |
+ UpdateWindowOwners(); |
NotifyBlockingStateChanged(); |
} |
bool MultiUserNotificationBlockerChromeOS::IsActive() const { |
- return observing_ && chrome::MultiUserWindowManager::GetMultiProfileMode() == |
+ return chrome::MultiUserWindowManager::GetMultiProfileMode() == |
chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED; |
} |