| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "ash/system/chromeos/supervised/tray_supervised_user.h" | 5 #include "ash/system/chromeos/supervised/tray_supervised_user.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/system/chromeos/label_tray_view.h" | 8 #include "ash/system/chromeos/label_tray_view.h" |
| 9 #include "ash/system/system_notifier.h" | 9 #include "ash/system/system_notifier.h" |
| 10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 using message_center::Notification; | 22 using message_center::Notification; |
| 23 | 23 |
| 24 namespace ash { | 24 namespace ash { |
| 25 | 25 |
| 26 const char TraySupervisedUser::kNotificationId[] = | 26 const char TraySupervisedUser::kNotificationId[] = |
| 27 "chrome://user/locally-managed"; | 27 "chrome://user/locally-managed"; |
| 28 | 28 |
| 29 TraySupervisedUser::TraySupervisedUser(SystemTray* system_tray) | 29 TraySupervisedUser::TraySupervisedUser(SystemTray* system_tray) |
| 30 : SystemTrayItem(system_tray), | 30 : SystemTrayItem(system_tray), |
| 31 tray_view_(NULL), | 31 tray_view_(NULL), |
| 32 status_(ash::user::LOGGED_IN_NONE), | 32 status_(ash::user::LOGGED_IN_NONE) { |
| 33 is_user_supervised_(false) { | |
| 34 } | 33 } |
| 35 | 34 |
| 36 TraySupervisedUser::~TraySupervisedUser() { | 35 TraySupervisedUser::~TraySupervisedUser() { |
| 37 } | 36 } |
| 38 | 37 |
| 39 void TraySupervisedUser::UpdateMessage() { | 38 void TraySupervisedUser::UpdateMessage() { |
| 40 base::string16 message = Shell::GetInstance()->system_tray_delegate()-> | 39 base::string16 message = Shell::GetInstance()->system_tray_delegate()-> |
| 41 GetSupervisedUserMessage(); | 40 GetSupervisedUserMessage(); |
| 42 if (tray_view_) | 41 if (tray_view_) |
| 43 tray_view_->SetMessage(message); | 42 tray_view_->SetMessage(message); |
| 44 if (message_center::MessageCenter::Get()->FindVisibleNotificationById( | 43 if (message_center::MessageCenter::Get()->FindVisibleNotificationById( |
| 45 kNotificationId)) | 44 kNotificationId)) |
| 46 CreateOrUpdateNotification(message); | 45 CreateOrUpdateNotification(message); |
| 47 } | 46 } |
| 48 | 47 |
| 49 views::View* TraySupervisedUser::CreateDefaultView( | 48 views::View* TraySupervisedUser::CreateDefaultView( |
| 50 user::LoginStatus status) { | 49 user::LoginStatus status) { |
| 51 CHECK(tray_view_ == NULL); | 50 CHECK(tray_view_ == NULL); |
| 52 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 51 if (status != ash::user::LOGGED_IN_SUPERVISED) |
| 53 if (!delegate->IsUserSupervised()) | |
| 54 return NULL; | 52 return NULL; |
| 55 | 53 |
| 56 tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_SUPERVISED_USER); | 54 tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_SUPERVISED_USER); |
| 57 UpdateMessage(); | 55 UpdateMessage(); |
| 58 return tray_view_; | 56 return tray_view_; |
| 59 } | 57 } |
| 60 | 58 |
| 61 void TraySupervisedUser::DestroyDefaultView() { | 59 void TraySupervisedUser::DestroyDefaultView() { |
| 62 tray_view_ = NULL; | 60 tray_view_ = NULL; |
| 63 } | 61 } |
| 64 | 62 |
| 65 void TraySupervisedUser::OnViewClicked(views::View* sender) { | 63 void TraySupervisedUser::OnViewClicked(views::View* sender) { |
| 66 Shell::GetInstance()->system_tray_delegate()->ShowSupervisedUserInfo(); | 64 Shell::GetInstance()->system_tray_delegate()->ShowSupervisedUserInfo(); |
| 67 } | 65 } |
| 68 | 66 |
| 69 void TraySupervisedUser::UpdateAfterLoginStatusChange( | 67 void TraySupervisedUser::UpdateAfterLoginStatusChange( |
| 70 user::LoginStatus status) { | 68 user::LoginStatus status) { |
| 71 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 69 if (status == status_) |
| 72 | |
| 73 bool is_user_supervised = delegate->IsUserSupervised(); | |
| 74 if (status == status_ && is_user_supervised == is_user_supervised_) | |
| 75 return; | 70 return; |
| 76 | 71 if (status == ash::user::LOGGED_IN_SUPERVISED && |
| 77 if (is_user_supervised && | |
| 78 status_ != ash::user::LOGGED_IN_LOCKED) { | 72 status_ != ash::user::LOGGED_IN_LOCKED) { |
| 73 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| 79 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage()); | 74 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage()); |
| 80 } | 75 } |
| 81 status_ = status; | 76 status_ = status; |
| 82 is_user_supervised_ = is_user_supervised; | |
| 83 } | 77 } |
| 84 | 78 |
| 85 void TraySupervisedUser::CreateOrUpdateNotification( | 79 void TraySupervisedUser::CreateOrUpdateNotification( |
| 86 const base::string16& new_message) { | 80 const base::string16& new_message) { |
| 87 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 81 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 88 scoped_ptr<Notification> notification( | 82 scoped_ptr<Notification> notification( |
| 89 message_center::Notification::CreateSystemNotification( | 83 message_center::Notification::CreateSystemNotification( |
| 90 kNotificationId, | 84 kNotificationId, |
| 91 base::string16() /* no title */, | 85 base::string16() /* no title */, |
| 92 new_message, | 86 new_message, |
| 93 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SUPERVISED_USER), | 87 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SUPERVISED_USER), |
| 94 system_notifier::kNotifierSupervisedUser, | 88 system_notifier::kNotifierSupervisedUser, |
| 95 base::Closure() /* null callback */)); | 89 base::Closure() /* null callback */)); |
| 96 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); | 90 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); |
| 97 } | 91 } |
| 98 | 92 |
| 99 } // namespace ash | 93 } // namespace ash |
| OLD | NEW |