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