Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / ash / system_tray_delegate_common.cc
blobfa6b9e630a36fe1a32def17c1d953d0a8c069f32
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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/system_tray_delegate_common.h"
7 #include "ash/networking_config_delegate.h"
8 #include "ash/shell.h"
9 #include "ash/shell_delegate.h"
10 #include "ash/system/tray/system_tray.h"
11 #include "ash/system/tray/system_tray_notifier.h"
12 #include "ash/volume_control_delegate.h"
13 #include "base/time/time.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/lifetime/application_lifetime.h"
16 #include "chrome/browser/profiles/profile_manager.h"
17 #include "chrome/browser/ui/ash/system_tray_delegate_utils.h"
18 #include "chrome/browser/ui/chrome_pages.h"
19 #include "chrome/browser/ui/host_desktop.h"
20 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
21 #include "chrome/browser/upgrade_detector.h"
22 #include "chrome/grit/locale_settings.h"
23 #include "content/public/browser/notification_service.h"
24 #include "ui/base/l10n/l10n_util.h"
26 namespace {
28 ash::SystemTrayNotifier* GetSystemTrayNotifier() {
29 return ash::Shell::GetInstance()->system_tray_notifier();
32 } // namespace
34 SystemTrayDelegateCommon::SystemTrayDelegateCommon()
35 : clock_type_(base::GetHourClockType()) {
36 // Register notifications on construction so that events such as
37 // PROFILE_CREATED do not get missed if they happen before Initialize().
38 registrar_.reset(new content::NotificationRegistrar);
39 registrar_->Add(this,
40 chrome::NOTIFICATION_UPGRADE_RECOMMENDED,
41 content::NotificationService::AllSources());
44 SystemTrayDelegateCommon::~SystemTrayDelegateCommon() {
45 registrar_.reset();
48 // Overridden from ash::SystemTrayDelegate:
49 void SystemTrayDelegateCommon::Initialize() {
50 UpdateClockType();
53 void SystemTrayDelegateCommon::Shutdown() {
56 bool SystemTrayDelegateCommon::GetTrayVisibilityOnStartup() {
57 return true;
60 ash::user::LoginStatus SystemTrayDelegateCommon::GetUserLoginStatus() const {
61 return ash::user::LOGGED_IN_OWNER;
64 bool SystemTrayDelegateCommon::IsUserSupervised() const {
65 return false;
68 bool SystemTrayDelegateCommon::IsUserChild() const {
69 return false;
72 void SystemTrayDelegateCommon::GetSystemUpdateInfo(
73 ash::UpdateInfo* info) const {
74 GetUpdateInfo(UpgradeDetector::GetInstance(), info);
77 base::HourClockType SystemTrayDelegateCommon::GetHourClockType() const {
78 return clock_type_;
81 void SystemTrayDelegateCommon::ShowChromeSlow() {
82 #if defined(OS_LINUX)
83 chrome::ScopedTabbedBrowserDisplayer displayer(
84 ProfileManager::GetPrimaryUserProfile(), chrome::HOST_DESKTOP_TYPE_ASH);
85 chrome::ShowSlow(displayer.browser());
86 #endif // defined(OS_LINUX)
89 void SystemTrayDelegateCommon::ShowHelp() {
90 chrome::ShowHelpForProfile(ProfileManager::GetLastUsedProfile(),
91 chrome::HOST_DESKTOP_TYPE_ASH,
92 chrome::HELP_SOURCE_MENU);
95 void SystemTrayDelegateCommon::RequestRestartForUpdate() {
96 chrome::AttemptRestart();
99 int SystemTrayDelegateCommon::GetSystemTrayMenuWidth() {
100 return l10n_util::GetLocalizedContentsWidthInPixels(
101 IDS_SYSTEM_TRAY_MENU_BUBBLE_WIDTH_PIXELS);
104 void SystemTrayDelegateCommon::UpdateClockType() {
105 clock_type_ = (base::GetHourClockType() == base::k24HourClock)
106 ? base::k24HourClock
107 : base::k12HourClock;
108 GetSystemTrayNotifier()->NotifyDateFormatChanged();
111 void SystemTrayDelegateCommon::Observe(
112 int type,
113 const content::NotificationSource& source,
114 const content::NotificationDetails& details) {
115 if (type == chrome::NOTIFICATION_UPGRADE_RECOMMENDED) {
116 ash::UpdateInfo info;
117 GetUpdateInfo(content::Source<UpgradeDetector>(source).ptr(), &info);
118 GetSystemTrayNotifier()->NotifyUpdateRecommended(info);
119 } else {
120 NOTREACHED();