12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file.
42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/chromeos/enterprise/tray_enterprise.h"
62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "ash/shell.h"
8c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "ash/system/chromeos/label_tray_view.h"
95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "ash/system/tray/system_tray_delegate.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h"
112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ash/system/user/login_status.h"
122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/logging.h"
135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/strings/string16.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "grit/ash_resources.h"
152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace ash {
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TrayEnterprise::TrayEnterprise(SystemTray* system_tray)
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    : SystemTrayItem(system_tray),
20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)      tray_view_(NULL) {
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetInstance()->system_tray_notifier()->
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      AddEnterpriseDomainObserver(this);
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TrayEnterprise::~TrayEnterprise() {
262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetInstance()->system_tray_notifier()->
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      RemoveEnterpriseDomainObserver(this);
282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TrayEnterprise::UpdateEnterpriseMessage() {
31c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  base::string16 message = Shell::GetInstance()->system_tray_delegate()->
322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      GetEnterpriseMessage();
33c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  if (tray_view_)
34c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    tray_view_->SetMessage(message);
352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)views::View* TrayEnterprise::CreateDefaultView(user::LoginStatus status) {
38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  CHECK(tray_view_ == NULL);
392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // For public accounts, enterprise ownership is indicated in the user details
402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // instead.
412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  if (status == ash::user::LOGGED_IN_PUBLIC)
422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    return NULL;
430529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_ENTERPRISE);
442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UpdateEnterpriseMessage();
45c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  return tray_view_;
462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TrayEnterprise::DestroyDefaultView() {
49c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  tray_view_ = NULL;
502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TrayEnterprise::OnEnterpriseDomainChanged() {
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  UpdateEnterpriseMessage();
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)void TrayEnterprise::OnViewClicked(views::View* sender) {
572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  Shell::GetInstance()->system_tray_delegate()->ShowEnterpriseInfo();
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace ash
61