- add sources.
[platform/framework/web/crosswalk.git] / src / ash / system / chromeos / managed / tray_locally_managed_user.cc
1 // Copyright (c) 2012 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 "ash/system/chromeos/managed/tray_locally_managed_user.h"
6
7 #include "ash/shell.h"
8 #include "ash/system/chromeos/label_tray_view.h"
9 #include "ash/system/system_notifier.h"
10 #include "ash/system/tray/system_tray_notifier.h"
11 #include "ash/system/tray/tray_notification_view.h"
12 #include "ash/system/user/login_status.h"
13 #include "base/logging.h"
14 #include "grit/ash_resources.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/message_center/message_center.h"
17 #include "ui/message_center/notification.h"
18 #include "ui/message_center/notification_delegate.h"
19
20 using message_center::Notification;
21
22 namespace ash {
23 namespace internal {
24
25 const char TrayLocallyManagedUser::kNotificationId[] =
26     "chrome://user/locally-managed";
27
28 TrayLocallyManagedUser::TrayLocallyManagedUser(SystemTray* system_tray)
29     : SystemTrayItem(system_tray),
30       tray_view_(NULL),
31       status_(ash::user::LOGGED_IN_NONE) {
32 }
33
34 TrayLocallyManagedUser::~TrayLocallyManagedUser() {
35 }
36
37 void TrayLocallyManagedUser::UpdateMessage() {
38   base::string16 message = Shell::GetInstance()->system_tray_delegate()->
39       GetLocallyManagedUserMessage();
40   if (tray_view_)
41     tray_view_->SetMessage(message);
42   if (message_center::MessageCenter::Get()->HasNotification(kNotificationId))
43     CreateOrUpdateNotification(message);
44 }
45
46 views::View* TrayLocallyManagedUser::CreateDefaultView(
47     user::LoginStatus status) {
48   CHECK(tray_view_ == NULL);
49   if (status != ash::user::LOGGED_IN_LOCALLY_MANAGED)
50     return NULL;
51
52   tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_MANAGED_USER);
53   UpdateMessage();
54   return tray_view_;
55 }
56
57 void TrayLocallyManagedUser::DestroyDefaultView() {
58   tray_view_ = NULL;
59 }
60
61 void TrayLocallyManagedUser::OnViewClicked(views::View* sender) {
62   Shell::GetInstance()->system_tray_delegate()->ShowLocallyManagedUserInfo();
63 }
64
65 void TrayLocallyManagedUser::UpdateAfterLoginStatusChange(
66     user::LoginStatus status) {
67   if (status == status_)
68     return;
69   if (status == ash::user::LOGGED_IN_LOCALLY_MANAGED &&
70       status_ != ash::user::LOGGED_IN_LOCKED) {
71     SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate();
72     CreateOrUpdateNotification(delegate->GetLocallyManagedUserMessage());
73   }
74   status_ = status;
75 }
76
77 void TrayLocallyManagedUser::CreateOrUpdateNotification(
78     const base::string16& new_message) {
79   ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
80   scoped_ptr<Notification> notification(new Notification(
81       message_center::NOTIFICATION_TYPE_SIMPLE,
82       kNotificationId,
83       string16() /* no title */,
84       new_message,
85       bundle.GetImageNamed(IDR_AURA_UBER_TRAY_MANAGED_USER),
86       base::string16() /* display_source */,
87       message_center::NotifierId(
88           system_notifier::NOTIFIER_LOCALLY_MANAGED_USER),
89       message_center::RichNotificationData(),
90       NULL /* no delegate */));
91   notification->SetSystemPriority();
92   message_center::MessageCenter::Get()->AddNotification(notification.Pass());
93 }
94
95 } // namespace internal
96 } // namespace ash