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/login_state_notification_blocker_chromeos
.h" | 5 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos
.h" |
6 | 6 |
7 #include "ash/common/system/system_notifier.h" | 7 #include "ash/common/system/system_notifier.h" |
8 #include "ash/common/wm_shell.h" | |
9 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/shell.h" |
10 #include "ash/wm/window_properties.h" | 10 #include "ash/wm/window_properties.h" |
11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
12 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
14 #include "ui/aura/window_event_dispatcher.h" | 14 #include "ui/aura/window_event_dispatcher.h" |
15 #include "ui/message_center/message_center.h" | 15 #include "ui/message_center/message_center.h" |
16 | 16 |
17 LoginStateNotificationBlockerChromeOS::LoginStateNotificationBlockerChromeOS( | 17 LoginStateNotificationBlockerChromeOS::LoginStateNotificationBlockerChromeOS( |
18 message_center::MessageCenter* message_center) | 18 message_center::MessageCenter* message_center) |
19 : NotificationBlocker(message_center), | 19 : NotificationBlocker(message_center), |
20 locked_(false), | 20 locked_(false), |
21 observing_(true) { | 21 observing_(true) { |
22 // This class is created in the ctor of NotificationUIManager which is created | 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, except | 23 // when a notification is created, so ash::Shell should be initialized, except |
24 // when running as a mus client (ash::Shell is not initialized when that is | 24 // when running as a mus client (ash::Shell is not initialized when that is |
25 // the case). | 25 // the case). |
26 if (ash::WmShell::HasInstance()) | 26 if (ash::Shell::HasInstance()) |
27 ash::WmShell::Get()->AddShellObserver(this); | 27 ash::Shell::GetInstance()->AddShellObserver(this); |
28 | 28 |
29 // LoginState may not exist in some tests. | 29 // LoginState may not exist in some tests. |
30 if (chromeos::LoginState::IsInitialized()) | 30 if (chromeos::LoginState::IsInitialized()) |
31 chromeos::LoginState::Get()->AddObserver(this); | 31 chromeos::LoginState::Get()->AddObserver(this); |
32 chromeos::UserAddingScreen::Get()->AddObserver(this); | 32 chromeos::UserAddingScreen::Get()->AddObserver(this); |
33 } | 33 } |
34 | 34 |
35 LoginStateNotificationBlockerChromeOS:: | 35 LoginStateNotificationBlockerChromeOS:: |
36 ~LoginStateNotificationBlockerChromeOS() { | 36 ~LoginStateNotificationBlockerChromeOS() { |
37 // In some tests, the notification blockers may be removed without calling | 37 // In some tests, the notification blockers may be removed without calling |
38 // OnAppTerminating(). | 38 // OnAppTerminating(). |
39 if (chromeos::LoginState::IsInitialized()) | 39 if (chromeos::LoginState::IsInitialized()) |
40 chromeos::LoginState::Get()->RemoveObserver(this); | 40 chromeos::LoginState::Get()->RemoveObserver(this); |
41 if (observing_) { | 41 if (observing_) { |
42 if (ash::WmShell::HasInstance()) | 42 if (ash::Shell::HasInstance()) |
43 ash::WmShell::Get()->RemoveShellObserver(this); | 43 ash::Shell::GetInstance()->RemoveShellObserver(this); |
44 chromeos::UserAddingScreen::Get()->RemoveObserver(this); | 44 chromeos::UserAddingScreen::Get()->RemoveObserver(this); |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 bool LoginStateNotificationBlockerChromeOS::ShouldShowNotificationAsPopup( | 48 bool LoginStateNotificationBlockerChromeOS::ShouldShowNotificationAsPopup( |
49 const message_center::Notification& notification) const { | 49 const message_center::Notification& notification) const { |
50 if (ash::system_notifier::ShouldAlwaysShowPopups(notification.notifier_id())) | 50 if (ash::system_notifier::ShouldAlwaysShowPopups(notification.notifier_id())) |
51 return true; | 51 return true; |
52 | 52 |
53 if (locked_) | 53 if (locked_) |
54 return false; | 54 return false; |
55 | 55 |
56 if (chromeos::UserAddingScreen::Get()->IsRunning()) | 56 if (chromeos::UserAddingScreen::Get()->IsRunning()) |
57 return false; | 57 return false; |
58 | 58 |
59 if (chromeos::LoginState::IsInitialized()) | 59 if (chromeos::LoginState::IsInitialized()) |
60 return chromeos::LoginState::Get()->IsUserLoggedIn(); | 60 return chromeos::LoginState::Get()->IsUserLoggedIn(); |
61 | 61 |
62 return true; | 62 return true; |
63 } | 63 } |
64 | 64 |
65 void LoginStateNotificationBlockerChromeOS::OnLockStateChanged(bool locked) { | 65 void LoginStateNotificationBlockerChromeOS::OnLockStateChanged(bool locked) { |
66 locked_ = locked; | 66 locked_ = locked; |
67 NotifyBlockingStateChanged(); | 67 NotifyBlockingStateChanged(); |
68 } | 68 } |
69 | 69 |
70 void LoginStateNotificationBlockerChromeOS::OnAppTerminating() { | 70 void LoginStateNotificationBlockerChromeOS::OnAppTerminating() { |
71 if (ash::WmShell::HasInstance()) | 71 if (ash::Shell::HasInstance()) |
72 ash::WmShell::Get()->RemoveShellObserver(this); | 72 ash::Shell::GetInstance()->RemoveShellObserver(this); |
73 chromeos::UserAddingScreen::Get()->RemoveObserver(this); | 73 chromeos::UserAddingScreen::Get()->RemoveObserver(this); |
74 observing_ = false; | 74 observing_ = false; |
75 } | 75 } |
76 | 76 |
77 void LoginStateNotificationBlockerChromeOS::LoggedInStateChanged() { | 77 void LoginStateNotificationBlockerChromeOS::LoggedInStateChanged() { |
78 NotifyBlockingStateChanged(); | 78 NotifyBlockingStateChanged(); |
79 } | 79 } |
80 | 80 |
81 void LoginStateNotificationBlockerChromeOS::OnUserAddingStarted() { | 81 void LoginStateNotificationBlockerChromeOS::OnUserAddingStarted() { |
82 NotifyBlockingStateChanged(); | 82 NotifyBlockingStateChanged(); |
83 } | 83 } |
84 | 84 |
85 void LoginStateNotificationBlockerChromeOS::OnUserAddingFinished() { | 85 void LoginStateNotificationBlockerChromeOS::OnUserAddingFinished() { |
86 NotifyBlockingStateChanged(); | 86 NotifyBlockingStateChanged(); |
87 } | 87 } |
OLD | NEW |