| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/enterprise/tray_enterprise.h" | 5 #include "ash/system/enterprise/tray_enterprise.h" |
| 6 | 6 |
| 7 #include "ash/login_status.h" | 7 #include "ash/login_status.h" |
| 8 #include "ash/resources/vector_icons/vector_icons.h" | 8 #include "ash/resources/vector_icons/vector_icons.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/strings/grit/ash_strings.h" |
| 10 #include "ash/system/tray/label_tray_view.h" | 11 #include "ash/system/tray/label_tray_view.h" |
| 11 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_controller.h" |
| 12 #include "ash/system/tray/system_tray_notifier.h" | 13 #include "ash/system/tray/system_tray_notifier.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
| 15 | 18 |
| 16 namespace ash { | 19 namespace ash { |
| 20 namespace { |
| 21 |
| 22 base::string16 GetEnterpriseMessage() { |
| 23 SystemTrayController* controller = Shell::Get()->system_tray_controller(); |
| 24 |
| 25 // Active Directory devices do not show a domain name. |
| 26 if (controller->active_directory_managed()) |
| 27 return l10n_util::GetStringUTF16(IDS_ASH_ENTERPRISE_DEVICE_MANAGED); |
| 28 |
| 29 if (!controller->enterprise_domain().empty()) { |
| 30 return l10n_util::GetStringFUTF16( |
| 31 IDS_ASH_ENTERPRISE_DEVICE_MANAGED_BY, |
| 32 base::UTF8ToUTF16(controller->enterprise_domain())); |
| 33 } |
| 34 return base::string16(); |
| 35 } |
| 36 |
| 37 } // namespace |
| 17 | 38 |
| 18 TrayEnterprise::TrayEnterprise(SystemTray* system_tray) | 39 TrayEnterprise::TrayEnterprise(SystemTray* system_tray) |
| 19 : SystemTrayItem(system_tray, UMA_ENTERPRISE), tray_view_(nullptr) { | 40 : SystemTrayItem(system_tray, UMA_ENTERPRISE), tray_view_(nullptr) { |
| 20 Shell::Get()->system_tray_notifier()->AddEnterpriseDomainObserver(this); | 41 Shell::Get()->system_tray_notifier()->AddEnterpriseDomainObserver(this); |
| 21 } | 42 } |
| 22 | 43 |
| 23 TrayEnterprise::~TrayEnterprise() { | 44 TrayEnterprise::~TrayEnterprise() { |
| 24 Shell::Get()->system_tray_notifier()->RemoveEnterpriseDomainObserver(this); | 45 Shell::Get()->system_tray_notifier()->RemoveEnterpriseDomainObserver(this); |
| 25 } | 46 } |
| 26 | 47 |
| 27 void TrayEnterprise::UpdateEnterpriseMessage() { | 48 void TrayEnterprise::UpdateEnterpriseMessage() { |
| 28 base::string16 message = | |
| 29 Shell::Get()->system_tray_delegate()->GetEnterpriseMessage(); | |
| 30 if (tray_view_) | 49 if (tray_view_) |
| 31 tray_view_->SetMessage(message); | 50 tray_view_->SetMessage(GetEnterpriseMessage()); |
| 32 } | 51 } |
| 33 | 52 |
| 34 views::View* TrayEnterprise::CreateDefaultView(LoginStatus status) { | 53 views::View* TrayEnterprise::CreateDefaultView(LoginStatus status) { |
| 35 DCHECK(!tray_view_); | 54 DCHECK(!tray_view_); |
| 36 // For public accounts, enterprise ownership is indicated in the user details | 55 // For public accounts, enterprise ownership is indicated in the user details |
| 37 // instead. | 56 // instead. |
| 38 if (status == LoginStatus::PUBLIC) | 57 if (status == LoginStatus::PUBLIC) |
| 39 return nullptr; | 58 return nullptr; |
| 40 tray_view_ = new LabelTrayView(this, kSystemMenuBusinessIcon); | 59 tray_view_ = new LabelTrayView(this, kSystemMenuBusinessIcon); |
| 41 UpdateEnterpriseMessage(); | 60 UpdateEnterpriseMessage(); |
| 42 return tray_view_; | 61 return tray_view_; |
| 43 } | 62 } |
| 44 | 63 |
| 45 void TrayEnterprise::DestroyDefaultView() { | 64 void TrayEnterprise::DestroyDefaultView() { |
| 46 tray_view_ = nullptr; | 65 tray_view_ = nullptr; |
| 47 } | 66 } |
| 48 | 67 |
| 49 void TrayEnterprise::OnEnterpriseDomainChanged() { | 68 void TrayEnterprise::OnEnterpriseDomainChanged() { |
| 50 UpdateEnterpriseMessage(); | 69 UpdateEnterpriseMessage(); |
| 51 } | 70 } |
| 52 | 71 |
| 53 void TrayEnterprise::OnViewClicked(views::View* sender) { | 72 void TrayEnterprise::OnViewClicked(views::View* sender) { |
| 54 Shell::Get()->system_tray_delegate()->ShowEnterpriseInfo(); | 73 Shell::Get()->system_tray_controller()->ShowEnterpriseInfo(); |
| 55 } | 74 } |
| 56 | 75 |
| 57 } // namespace ash | 76 } // namespace ash |
| OLD | NEW |