Home | History | Annotate | Download | only in multi_user
      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.
      4 
      5 #include "chrome/browser/ui/ash/multi_user/multi_user_notification_blocker_chromeos.h"
      6 
      7 #include "ash/system/system_notifier.h"
      8 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
      9 #include "ui/message_center/message_center.h"
     10 #include "ui/message_center/notifier_settings.h"
     11 
     12 MultiUserNotificationBlockerChromeOS::MultiUserNotificationBlockerChromeOS(
     13     message_center::MessageCenter* message_center,
     14     const std::string& initial_user_id)
     15     : NotificationBlocker(message_center),
     16       active_user_id_(initial_user_id) {
     17 }
     18 
     19 MultiUserNotificationBlockerChromeOS::~MultiUserNotificationBlockerChromeOS() {
     20 }
     21 
     22 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotification(
     23     const message_center::NotifierId& notifier_id) const {
     24   if (!IsActive())
     25     return true;
     26 
     27   if (ash::system_notifier::IsAshSystemNotifier(notifier_id))
     28     return true;
     29 
     30   return notifier_id.profile_id == active_user_id_;
     31 }
     32 
     33 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotificationAsPopup(
     34     const message_center::NotifierId& notifier_id) const {
     35   return ShouldShowNotification(notifier_id);
     36 }
     37 
     38 void MultiUserNotificationBlockerChromeOS::ActiveUserChanged(
     39     const std::string& user_id) {
     40   if (active_user_id_ == user_id)
     41     return;
     42 
     43   quiet_modes_[active_user_id_] = message_center()->IsQuietMode();
     44   active_user_id_ = user_id;
     45   std::map<std::string, bool>::const_iterator iter =
     46       quiet_modes_.find(active_user_id_);
     47   if (iter != quiet_modes_.end() &&
     48       iter->second != message_center()->IsQuietMode()) {
     49     message_center()->SetQuietMode(iter->second);
     50   }
     51   NotifyBlockingStateChanged();
     52 }
     53 
     54 bool MultiUserNotificationBlockerChromeOS::IsActive() const {
     55   return chrome::MultiUserWindowManager::GetMultiProfileMode() ==
     56       chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED;
     57 }
     58