Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / ui / ash / chrome_shell_delegate.cc
blob88998525db8117bb5342cdda7a63554ce6da4a56
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.
5 #include "chrome/browser/ui/ash/chrome_shell_delegate.h"
7 #include "ash/content_support/gpu_support_impl.h"
8 #include "ash/wm/window_state.h"
9 #include "ash/wm/window_util.h"
10 #include "chrome/browser/app_mode/app_mode_utils.h"
11 #include "chrome/browser/lifetime/application_lifetime.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/profiles/profiles_state.h"
14 #include "chrome/browser/ui/app_list/app_list_view_delegate.h"
15 #include "chrome/browser/ui/ash/app_list/app_list_service_ash.h"
16 #include "chrome/browser/ui/ash/ash_keyboard_controller_proxy.h"
17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
18 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
19 #include "chrome/browser/ui/browser_commands.h"
20 #include "chrome/grit/chromium_strings.h"
21 #include "components/signin/core/common/profile_management_switches.h"
22 #include "ui/base/l10n/l10n_util.h"
24 #if defined(OS_CHROMEOS)
25 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h"
26 #include "chrome/browser/chromeos/display/display_configuration_observer.h"
27 #include "components/user_manager/user_manager.h"
28 #endif
30 // static
31 ChromeShellDelegate* ChromeShellDelegate::instance_ = NULL;
33 ChromeShellDelegate::ChromeShellDelegate()
34 : shelf_delegate_(NULL) {
35 instance_ = this;
36 PlatformInit();
39 ChromeShellDelegate::~ChromeShellDelegate() {
40 if (instance_ == this)
41 instance_ = NULL;
44 bool ChromeShellDelegate::IsMultiProfilesEnabled() const {
45 if (!profiles::IsMultipleProfilesEnabled())
46 return false;
47 #if defined(OS_CHROMEOS)
48 // If there is a user manager, we need to see that we can at least have 2
49 // simultaneous users to allow this feature.
50 if (!user_manager::UserManager::IsInitialized())
51 return false;
52 size_t admitted_users_to_be_added =
53 user_manager::UserManager::Get()->GetUsersAllowedForMultiProfile().size();
54 size_t logged_in_users =
55 user_manager::UserManager::Get()->GetLoggedInUsers().size();
56 if (!logged_in_users) {
57 // The shelf gets created on the login screen and as such we have to create
58 // all multi profile items of the the system tray menu before the user logs
59 // in. For special cases like Kiosk mode and / or guest mode this isn't a
60 // problem since either the browser gets restarted and / or the flag is not
61 // allowed, but for an "ephermal" user (see crbug.com/312324) it is not
62 // decided yet if he could add other users to his session or not.
63 // TODO(skuhne): As soon as the issue above needs to be resolved, this logic
64 // should change.
65 logged_in_users = 1;
67 if (admitted_users_to_be_added + logged_in_users <= 1)
68 return false;
69 #endif
70 return true;
73 bool ChromeShellDelegate::IsIncognitoAllowed() const {
74 #if defined(OS_CHROMEOS)
75 return chromeos::AccessibilityManager::Get()->IsIncognitoAllowed();
76 #endif
77 return true;
80 bool ChromeShellDelegate::IsRunningInForcedAppMode() const {
81 return chrome::IsRunningInForcedAppMode();
84 bool ChromeShellDelegate::IsMultiAccountEnabled() const {
85 #if defined(OS_CHROMEOS)
86 return switches::IsEnableAccountConsistency();
87 #endif
88 return false;
91 void ChromeShellDelegate::Exit() {
92 chrome::AttemptUserExit();
95 content::BrowserContext* ChromeShellDelegate::GetActiveBrowserContext() {
96 #if defined(OS_CHROMEOS)
97 DCHECK(user_manager::UserManager::Get()->GetLoggedInUsers().size());
98 #endif
99 return ProfileManager::GetActiveUserProfile();
102 app_list::AppListViewDelegate* ChromeShellDelegate::GetAppListViewDelegate() {
103 DCHECK(ash::Shell::HasInstance());
104 return AppListServiceAsh::GetInstance()->GetViewDelegate(
105 Profile::FromBrowserContext(GetActiveBrowserContext()));
108 ash::ShelfDelegate* ChromeShellDelegate::CreateShelfDelegate(
109 ash::ShelfModel* model) {
110 if (!shelf_delegate_) {
111 shelf_delegate_ = ChromeLauncherController::CreateInstance(NULL, model);
112 shelf_delegate_->Init();
114 return shelf_delegate_;
117 ui::MenuModel* ChromeShellDelegate::CreateContextMenu(
118 aura::Window* root,
119 ash::ShelfItemDelegate* item_delegate,
120 ash::ShelfItem* item) {
121 DCHECK(shelf_delegate_);
122 // Don't show context menu for exclusive app runtime mode.
123 if (chrome::IsRunningInAppMode())
124 return NULL;
126 if (item_delegate && item)
127 return new LauncherContextMenu(shelf_delegate_, item_delegate, item, root);
129 return new LauncherContextMenu(shelf_delegate_, root);
132 ash::GPUSupport* ChromeShellDelegate::CreateGPUSupport() {
133 // Chrome uses real GPU support.
134 return new ash::GPUSupportImpl;
137 base::string16 ChromeShellDelegate::GetProductName() const {
138 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
141 keyboard::KeyboardControllerProxy*
142 ChromeShellDelegate::CreateKeyboardControllerProxy() {
143 return new AshKeyboardControllerProxy(
144 ProfileManager::GetActiveUserProfile());
147 void ChromeShellDelegate::VirtualKeyboardActivated(bool activated) {
148 FOR_EACH_OBSERVER(ash::VirtualKeyboardStateObserver,
149 keyboard_state_observer_list_,
150 OnVirtualKeyboardStateChanged(activated));
153 void ChromeShellDelegate::AddVirtualKeyboardStateObserver(
154 ash::VirtualKeyboardStateObserver* observer) {
155 keyboard_state_observer_list_.AddObserver(observer);
158 void ChromeShellDelegate::RemoveVirtualKeyboardStateObserver(
159 ash::VirtualKeyboardStateObserver* observer) {
160 keyboard_state_observer_list_.RemoveObserver(observer);