No dual_mode on Win10+ shortcuts.
[chromium-blink-merge.git] / chrome / browser / notifications / login_state_notification_blocker_chromeos.cc
blob79b3617ac37b9fca5fa6652935f792b5884a371f
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
3 // found in the LICENSE file.
5 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos.h"
7 #include "ash/root_window_controller.h"
8 #include "ash/shell.h"
9 #include "ash/system/system_notifier.h"
10 #include "ash/wm/window_properties.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "content/public/browser/notification_service.h"
13 #include "ui/aura/window.h"
14 #include "ui/aura/window_event_dispatcher.h"
15 #include "ui/message_center/message_center.h"
17 LoginStateNotificationBlockerChromeOS::LoginStateNotificationBlockerChromeOS(
18 message_center::MessageCenter* message_center)
19 : NotificationBlocker(message_center),
20 locked_(false),
21 observing_(true) {
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);
26 // LoginState may not exist in some tests.
27 if (chromeos::LoginState::IsInitialized())
28 chromeos::LoginState::Get()->AddObserver(this);
29 chromeos::UserAddingScreen::Get()->AddObserver(this);
32 LoginStateNotificationBlockerChromeOS::
33 ~LoginStateNotificationBlockerChromeOS() {
34 // In some tests, the notification blockers may be removed without calling
35 // OnAppTerminating().
36 if (chromeos::LoginState::IsInitialized())
37 chromeos::LoginState::Get()->RemoveObserver(this);
38 if (observing_) {
39 if (ash::Shell::HasInstance())
40 ash::Shell::GetInstance()->RemoveShellObserver(this);
41 chromeos::UserAddingScreen::Get()->RemoveObserver(this);
45 bool LoginStateNotificationBlockerChromeOS::ShouldShowNotificationAsPopup(
46 const message_center::NotifierId& notifier_id) const {
47 if (ash::system_notifier::ShouldAlwaysShowPopups(notifier_id))
48 return true;
50 if (locked_)
51 return false;
53 if (chromeos::UserAddingScreen::Get()->IsRunning())
54 return false;
56 if (chromeos::LoginState::IsInitialized())
57 return chromeos::LoginState::Get()->IsUserLoggedIn();
59 return true;
62 void LoginStateNotificationBlockerChromeOS::OnLockStateChanged(bool locked) {
63 locked_ = locked;
64 NotifyBlockingStateChanged();
67 void LoginStateNotificationBlockerChromeOS::OnAppTerminating() {
68 ash::Shell::GetInstance()->RemoveShellObserver(this);
69 chromeos::UserAddingScreen::Get()->RemoveObserver(this);
70 observing_ = false;
73 void LoginStateNotificationBlockerChromeOS::LoggedInStateChanged() {
74 NotifyBlockingStateChanged();
77 void LoginStateNotificationBlockerChromeOS::OnUserAddingStarted() {
78 NotifyBlockingStateChanged();
81 void LoginStateNotificationBlockerChromeOS::OnUserAddingFinished() {
82 NotifyBlockingStateChanged();