- add sources.
[platform/framework/web/crosswalk.git] / src / ash / system / chromeos / enterprise / tray_enterprise.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/enterprise/tray_enterprise.h"
6
7 #include "ash/shell.h"
8 #include "ash/system/chromeos/label_tray_view.h"
9 #include "ash/system/tray/system_tray_notifier.h"
10 #include "ash/system/user/login_status.h"
11 #include "base/logging.h"
12 #include "grit/ash_resources.h"
13
14 namespace ash {
15 namespace internal {
16
17 TrayEnterprise::TrayEnterprise(SystemTray* system_tray)
18     : SystemTrayItem(system_tray),
19       tray_view_(NULL) {
20   Shell::GetInstance()->system_tray_notifier()->
21       AddEnterpriseDomainObserver(this);
22 }
23
24 TrayEnterprise::~TrayEnterprise() {
25   Shell::GetInstance()->system_tray_notifier()->
26       RemoveEnterpriseDomainObserver(this);
27 }
28
29 void TrayEnterprise::UpdateEnterpriseMessage() {
30   base::string16 message = Shell::GetInstance()->system_tray_delegate()->
31       GetEnterpriseMessage();
32   if (tray_view_)
33     tray_view_->SetMessage(message);
34 }
35
36 views::View* TrayEnterprise::CreateDefaultView(user::LoginStatus status) {
37   CHECK(tray_view_ == NULL);
38   // For public accounts, enterprise ownership is indicated in the user details
39   // instead.
40   if (status == ash::user::LOGGED_IN_PUBLIC)
41     return NULL;
42   tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_ENTERPRISE_DARK);
43   UpdateEnterpriseMessage();
44   return tray_view_;
45 }
46
47 void TrayEnterprise::DestroyDefaultView() {
48   tray_view_ = NULL;
49 }
50
51 void TrayEnterprise::OnEnterpriseDomainChanged() {
52   UpdateEnterpriseMessage();
53 }
54
55 void TrayEnterprise::OnViewClicked(views::View* sender) {
56   Shell::GetInstance()->system_tray_delegate()->ShowEnterpriseInfo();
57 }
58
59 } // namespace internal
60 } // namespace ash