Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(216)

Side by Side Diff: chrome/browser/notifications/multi_user_notification_blocker_chromeos.cc

Issue 127423002: Supports window teleports for notifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix wallpaper private api test Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "chrome/browser/notifications/multi_user_notification_blocker_chromeos. h"
6
7 #include "ash/shell.h"
8 #include "ash/system/system_notifier.h"
9 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
10 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
11 #include "ui/message_center/message_center.h"
12 #include "ui/message_center/notifier_settings.h"
13
14 MultiUserNotificationBlockerChromeOS::MultiUserNotificationBlockerChromeOS(
15 message_center::MessageCenter* message_center)
16 : NotificationBlocker(message_center),
17 observing_(false) {
18 // UserManager may not be initialized in unit tests.
19 if (!chromeos::UserManager::IsInitialized())
20 return;
21
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);
25 chromeos::UserManager::Get()->AddSessionStateObserver(this);
26 observing_ = true;
27 }
28
29 MultiUserNotificationBlockerChromeOS::~MultiUserNotificationBlockerChromeOS() {
30 if (observing_) {
31 if (ash::Shell::HasInstance())
32 ash::Shell::GetInstance()->RemoveShellObserver(this);
33 chromeos::UserManager::Get()->RemoveSessionStateObserver(this);
34 }
35 }
36
37 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotification(
38 const message_center::NotifierId& notifier_id) const {
39 if (!IsActive())
40 return true;
41
42 if (ash::system_notifier::IsAshSystemNotifier(notifier_id))
43 return true;
44
45 return notifier_id.profile_id == active_user_id_;
46 }
47
48 bool MultiUserNotificationBlockerChromeOS::ShouldShowNotificationAsPopup(
49 const message_center::NotifierId& notifier_id) const {
50 return ShouldShowNotification(notifier_id);
51 }
52
53 void MultiUserNotificationBlockerChromeOS::OnAppTerminating() {
54 ash::Shell::GetInstance()->RemoveShellObserver(this);
55 chromeos::UserManager::Get()->RemoveSessionStateObserver(this);
56 observing_ = false;
57 }
58
59 void MultiUserNotificationBlockerChromeOS::ActiveUserChanged(
60 const chromeos::User* active_user) {
61 const std::string& new_user_id = active_user->email();
62 if (active_user_id_ == new_user_id)
63 return;
64
65 quiet_modes_[active_user_id_] = message_center()->IsQuietMode();
66 active_user_id_ = active_user->email();
67 std::map<std::string, bool>::const_iterator iter =
68 quiet_modes_.find(active_user_id_);
69 if (iter != quiet_modes_.end() &&
70 iter->second != message_center()->IsQuietMode()) {
71 message_center()->SetQuietMode(iter->second);
72 }
73 NotifyBlockingStateChanged();
74 }
75
76 bool MultiUserNotificationBlockerChromeOS::IsActive() const {
77 return observing_ && chrome::MultiUserWindowManager::GetMultiProfileMode() ==
78 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED;
79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698