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"
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"
28 ash::SystemTrayNotifier
* GetSystemTrayNotifier() {
29 return ash::Shell::GetInstance()->system_tray_notifier();
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
);
40 chrome::NOTIFICATION_UPGRADE_RECOMMENDED
,
41 content::NotificationService::AllSources());
44 SystemTrayDelegateCommon::~SystemTrayDelegateCommon() {
48 // Overridden from ash::SystemTrayDelegate:
49 void SystemTrayDelegateCommon::Initialize() {
53 void SystemTrayDelegateCommon::Shutdown() {
56 bool SystemTrayDelegateCommon::GetTrayVisibilityOnStartup() {
60 ash::user::LoginStatus
SystemTrayDelegateCommon::GetUserLoginStatus() const {
61 return ash::user::LOGGED_IN_OWNER
;
64 bool SystemTrayDelegateCommon::IsUserSupervised() const {
68 bool SystemTrayDelegateCommon::IsUserChild() const {
72 void SystemTrayDelegateCommon::GetSystemUpdateInfo(
73 ash::UpdateInfo
* info
) const {
74 GetUpdateInfo(UpgradeDetector::GetInstance(), info
);
77 base::HourClockType
SystemTrayDelegateCommon::GetHourClockType() const {
81 void SystemTrayDelegateCommon::ShowChromeSlow() {
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
)
107 : base::k12HourClock
;
108 GetSystemTrayNotifier()->NotifyDateFormatChanged();
111 void SystemTrayDelegateCommon::Observe(
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
);