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"
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/root_window.h"
14 #include "ui/aura/window.h"
15 #include "ui/message_center/message_center.h"
17 LoginStateNotificationBlockerChromeOS::LoginStateNotificationBlockerChromeOS(
18 message_center::MessageCenter* message_center)
19 : NotificationBlocker(message_center),
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);
31 LoginStateNotificationBlockerChromeOS::
32 ~LoginStateNotificationBlockerChromeOS() {
33 // In some tests, the notification blockers may be removed without calling
34 // OnAppTerminating().
35 if (chromeos::LoginState::IsInitialized())
36 chromeos::LoginState::Get()->RemoveObserver(this);
37 if (observing_ && ash::Shell::HasInstance())
38 ash::Shell::GetInstance()->RemoveShellObserver(this);
41 bool LoginStateNotificationBlockerChromeOS::ShouldShowNotificationAsPopup(
42 const message_center::NotifierId& notifier_id) const {
43 if (ash::system_notifier::ShouldAlwaysShowPopups(notifier_id))
49 if (chromeos::LoginState::IsInitialized())
50 return chromeos::LoginState::Get()->IsUserLoggedIn();
55 void LoginStateNotificationBlockerChromeOS::OnLockStateChanged(bool locked) {
58 NotificationBlocker::Observer, observers(), OnBlockingStateChanged());
61 void LoginStateNotificationBlockerChromeOS::OnAppTerminating() {
62 ash::Shell::GetInstance()->RemoveShellObserver(this);
66 void LoginStateNotificationBlockerChromeOS::LoggedInStateChanged() {
68 NotificationBlocker::Observer, observers(), OnBlockingStateChanged());