| 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) { |
| 33 } | 34 } |
| 34 | 35 |
| 35 TraySupervisedUser::~TraySupervisedUser() { | 36 TraySupervisedUser::~TraySupervisedUser() { |
| 36 } | 37 } |
| 37 | 38 |
| 38 void TraySupervisedUser::UpdateMessage() { | 39 void TraySupervisedUser::UpdateMessage() { |
| 39 base::string16 message = Shell::GetInstance()->system_tray_delegate()-> | 40 base::string16 message = Shell::GetInstance()->system_tray_delegate()-> |
| 40 GetSupervisedUserMessage(); | 41 GetSupervisedUserMessage(); |
| 41 if (tray_view_) | 42 if (tray_view_) |
| 42 tray_view_->SetMessage(message); | 43 tray_view_->SetMessage(message); |
| 43 if (message_center::MessageCenter::Get()->FindVisibleNotificationById( | 44 if (message_center::MessageCenter::Get()->FindVisibleNotificationById( |
| 44 kNotificationId)) | 45 kNotificationId)) |
| 45 CreateOrUpdateNotification(message); | 46 CreateOrUpdateNotification(message); |
| 46 } | 47 } |
| 47 | 48 |
| 48 views::View* TraySupervisedUser::CreateDefaultView( | 49 views::View* TraySupervisedUser::CreateDefaultView( |
| 49 user::LoginStatus status) { | 50 user::LoginStatus status) { |
| 50 CHECK(tray_view_ == NULL); | 51 CHECK(tray_view_ == NULL); |
| 51 if (status != ash::user::LOGGED_IN_SUPERVISED) | 52 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| 53 if (!delegate->IsUserSupervised()) |
| 52 return NULL; | 54 return NULL; |
| 53 | 55 |
| 54 tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_SUPERVISED_USER); | 56 tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_SUPERVISED_USER); |
| 55 UpdateMessage(); | 57 UpdateMessage(); |
| 56 return tray_view_; | 58 return tray_view_; |
| 57 } | 59 } |
| 58 | 60 |
| 59 void TraySupervisedUser::DestroyDefaultView() { | 61 void TraySupervisedUser::DestroyDefaultView() { |
| 60 tray_view_ = NULL; | 62 tray_view_ = NULL; |
| 61 } | 63 } |
| 62 | 64 |
| 63 void TraySupervisedUser::OnViewClicked(views::View* sender) { | 65 void TraySupervisedUser::OnViewClicked(views::View* sender) { |
| 64 Shell::GetInstance()->system_tray_delegate()->ShowSupervisedUserInfo(); | 66 Shell::GetInstance()->system_tray_delegate()->ShowSupervisedUserInfo(); |
| 65 } | 67 } |
| 66 | 68 |
| 67 void TraySupervisedUser::UpdateAfterLoginStatusChange( | 69 void TraySupervisedUser::UpdateAfterLoginStatusChange( |
| 68 user::LoginStatus status) { | 70 user::LoginStatus status) { |
| 69 if (status == status_) | 71 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
| 72 |
| 73 bool is_user_supervised = delegate->IsUserSupervised(); |
| 74 if (status == status_ && is_user_supervised == is_user_supervised_) |
| 70 return; | 75 return; |
| 71 if (status == ash::user::LOGGED_IN_SUPERVISED && | 76 |
| 77 if (is_user_supervised && |
| 72 status_ != ash::user::LOGGED_IN_LOCKED) { | 78 status_ != ash::user::LOGGED_IN_LOCKED) { |
| 73 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | |
| 74 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage()); | 79 CreateOrUpdateNotification(delegate->GetSupervisedUserMessage()); |
| 75 } | 80 } |
| 76 status_ = status; | 81 status_ = status; |
| 82 is_user_supervised_ = is_user_supervised; |
| 77 } | 83 } |
| 78 | 84 |
| 79 void TraySupervisedUser::CreateOrUpdateNotification( | 85 void TraySupervisedUser::CreateOrUpdateNotification( |
| 80 const base::string16& new_message) { | 86 const base::string16& new_message) { |
| 81 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 87 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 82 scoped_ptr<Notification> notification( | 88 scoped_ptr<Notification> notification( |
| 83 message_center::Notification::CreateSystemNotification( | 89 message_center::Notification::CreateSystemNotification( |
| 84 kNotificationId, | 90 kNotificationId, |
| 85 base::string16() /* no title */, | 91 base::string16() /* no title */, |
| 86 new_message, | 92 new_message, |
| 87 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SUPERVISED_USER), | 93 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SUPERVISED_USER), |
| 88 system_notifier::kNotifierSupervisedUser, | 94 system_notifier::kNotifierSupervisedUser, |
| 89 base::Closure() /* null callback */)); | 95 base::Closure() /* null callback */)); |
| 90 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); | 96 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); |
| 91 } | 97 } |
| 92 | 98 |
| 93 } // namespace ash | 99 } // namespace ash |
| OLD | NEW |