Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / ash / shell / shell_delegate_impl.cc
blob4cd2172e38d34829e2526e85deed5d399fbdd245
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 "ash/shell/shell_delegate_impl.h"
7 #include "ash/accessibility_delegate.h"
8 #include "ash/default_accessibility_delegate.h"
9 #include "ash/default_user_wallpaper_delegate.h"
10 #include "ash/gpu_support_stub.h"
11 #include "ash/media_delegate.h"
12 #include "ash/new_window_delegate.h"
13 #include "ash/session/session_state_delegate.h"
14 #include "ash/shell/context_menu.h"
15 #include "ash/shell/example_factory.h"
16 #include "ash/shell/keyboard_controller_proxy_stub.h"
17 #include "ash/shell/shelf_delegate_impl.h"
18 #include "ash/shell/toplevel_window.h"
19 #include "ash/shell_window_ids.h"
20 #include "ash/system/tray/default_system_tray_delegate.h"
21 #include "ash/wm/window_state.h"
22 #include "base/message_loop/message_loop.h"
23 #include "base/strings/utf_string_conversions.h"
24 #include "components/user_manager/user_info_impl.h"
25 #include "ui/app_list/app_list_view_delegate.h"
26 #include "ui/aura/window.h"
28 namespace ash {
29 namespace shell {
30 namespace {
32 class NewWindowDelegateImpl : public NewWindowDelegate {
33 public:
34 NewWindowDelegateImpl() {}
35 ~NewWindowDelegateImpl() override {}
37 // NewWindowDelegate:
38 void NewTab() override {}
39 void NewWindow(bool incognito) override {
40 ash::shell::ToplevelWindow::CreateParams create_params;
41 create_params.can_resize = true;
42 create_params.can_maximize = true;
43 ash::shell::ToplevelWindow::CreateToplevelWindow(create_params);
45 void OpenFileManager() override {}
46 void OpenCrosh() override {}
47 void OpenGetHelp() override {}
48 void RestoreTab() override {}
49 void ShowKeyboardOverlay() override {}
50 void ShowTaskManager() override {}
51 void OpenFeedbackPage() override {}
53 private:
54 DISALLOW_COPY_AND_ASSIGN(NewWindowDelegateImpl);
57 class MediaDelegateImpl : public MediaDelegate {
58 public:
59 MediaDelegateImpl() {}
60 ~MediaDelegateImpl() override {}
62 // MediaDelegate:
63 void HandleMediaNextTrack() override {}
64 void HandleMediaPlayPause() override {}
65 void HandleMediaPrevTrack() override {}
66 MediaCaptureState GetMediaCaptureState(
67 content::BrowserContext* context) override {
68 return MEDIA_CAPTURE_VIDEO;
71 private:
72 DISALLOW_COPY_AND_ASSIGN(MediaDelegateImpl);
75 class SessionStateDelegateImpl : public SessionStateDelegate {
76 public:
77 SessionStateDelegateImpl()
78 : screen_locked_(false), user_info_(new user_manager::UserInfoImpl()) {}
80 ~SessionStateDelegateImpl() override {}
82 // SessionStateDelegate:
83 content::BrowserContext* GetBrowserContextByIndex(
84 MultiProfileIndex index) override {
85 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
87 content::BrowserContext* GetBrowserContextForWindow(
88 aura::Window* window) override {
89 return Shell::GetInstance()->delegate()->GetActiveBrowserContext();
91 content::BrowserContext* GetUserPresentingBrowserContextForWindow(
92 aura::Window* window) override {
93 return NULL;
95 int GetMaximumNumberOfLoggedInUsers() const override { return 3; }
96 int NumberOfLoggedInUsers() const override {
97 // ash_shell has 2 users.
98 return 2;
100 bool IsActiveUserSessionStarted() const override { return true; }
101 bool CanLockScreen() const override { return true; }
102 bool IsScreenLocked() const override { return screen_locked_; }
103 bool ShouldLockScreenBeforeSuspending() const override { return false; }
104 void LockScreen() override {
105 shell::CreateLockScreen();
106 screen_locked_ = true;
107 Shell::GetInstance()->UpdateShelfVisibility();
109 void UnlockScreen() override {
110 screen_locked_ = false;
111 Shell::GetInstance()->UpdateShelfVisibility();
113 bool IsUserSessionBlocked() const override {
114 return !IsActiveUserSessionStarted() || IsScreenLocked();
116 SessionState GetSessionState() const override {
117 // Assume that if session is not active we're at login.
118 return IsActiveUserSessionStarted() ? SESSION_STATE_ACTIVE
119 : SESSION_STATE_LOGIN_PRIMARY;
121 const user_manager::UserInfo* GetUserInfo(
122 MultiProfileIndex index) const override {
123 return user_info_.get();
125 const user_manager::UserInfo* GetUserInfo(
126 content::BrowserContext* context) const override {
127 return user_info_.get();
129 bool ShouldShowAvatar(aura::Window* window) const override {
130 return !user_info_->GetImage().isNull();
132 void SwitchActiveUser(const std::string& user_id) override {}
133 void CycleActiveUser(CycleUser cycle_user) override {}
134 bool IsMultiProfileAllowedByPrimaryUserPolicy() const override {
135 return true;
137 void AddSessionStateObserver(ash::SessionStateObserver* observer) override {}
138 void RemoveSessionStateObserver(
139 ash::SessionStateObserver* observer) override {}
141 private:
142 bool screen_locked_;
144 // A pseudo user info.
145 scoped_ptr<user_manager::UserInfo> user_info_;
147 DISALLOW_COPY_AND_ASSIGN(SessionStateDelegateImpl);
150 } // namespace
152 ShellDelegateImpl::ShellDelegateImpl()
153 : watcher_(NULL),
154 shelf_delegate_(NULL),
155 browser_context_(NULL) {
158 ShellDelegateImpl::~ShellDelegateImpl() {
161 void ShellDelegateImpl::SetWatcher(WindowWatcher* watcher) {
162 watcher_ = watcher;
163 if (shelf_delegate_)
164 shelf_delegate_->set_watcher(watcher);
167 bool ShellDelegateImpl::IsFirstRunAfterBoot() const {
168 return false;
171 bool ShellDelegateImpl::IsIncognitoAllowed() const {
172 return true;
175 bool ShellDelegateImpl::IsMultiProfilesEnabled() const {
176 return false;
179 bool ShellDelegateImpl::IsRunningInForcedAppMode() const {
180 return false;
183 bool ShellDelegateImpl::IsMultiAccountEnabled() const {
184 return false;
187 bool ShellDelegateImpl::IsForceMaximizeOnFirstRun() const {
188 return false;
191 void ShellDelegateImpl::PreInit() {
194 void ShellDelegateImpl::PreShutdown() {
197 void ShellDelegateImpl::Exit() {
198 base::MessageLoopForUI::current()->Quit();
201 keyboard::KeyboardControllerProxy*
202 ShellDelegateImpl::CreateKeyboardControllerProxy() {
203 return new KeyboardControllerProxyStub();
206 void ShellDelegateImpl::VirtualKeyboardActivated(bool activated) {
209 void ShellDelegateImpl::AddVirtualKeyboardStateObserver(
210 VirtualKeyboardStateObserver* observer) {
213 void ShellDelegateImpl::RemoveVirtualKeyboardStateObserver(
214 VirtualKeyboardStateObserver* observer) {
217 content::BrowserContext* ShellDelegateImpl::GetActiveBrowserContext() {
218 return browser_context_;
221 app_list::AppListViewDelegate* ShellDelegateImpl::GetAppListViewDelegate() {
222 if (!app_list_view_delegate_)
223 app_list_view_delegate_.reset(ash::shell::CreateAppListViewDelegate());
224 return app_list_view_delegate_.get();
227 ShelfDelegate* ShellDelegateImpl::CreateShelfDelegate(ShelfModel* model) {
228 shelf_delegate_ = new ShelfDelegateImpl(watcher_);
229 return shelf_delegate_;
232 ash::SystemTrayDelegate* ShellDelegateImpl::CreateSystemTrayDelegate() {
233 return new DefaultSystemTrayDelegate;
236 ash::UserWallpaperDelegate* ShellDelegateImpl::CreateUserWallpaperDelegate() {
237 return new DefaultUserWallpaperDelegate();
240 ash::SessionStateDelegate* ShellDelegateImpl::CreateSessionStateDelegate() {
241 return new SessionStateDelegateImpl;
244 ash::AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
245 return new DefaultAccessibilityDelegate;
248 ash::NewWindowDelegate* ShellDelegateImpl::CreateNewWindowDelegate() {
249 return new NewWindowDelegateImpl;
252 ash::MediaDelegate* ShellDelegateImpl::CreateMediaDelegate() {
253 return new MediaDelegateImpl;
256 ui::MenuModel* ShellDelegateImpl::CreateContextMenu(
257 aura::Window* root,
258 ash::ShelfItemDelegate* item_delegate,
259 ash::ShelfItem* item) {
260 return new ContextMenu(root);
263 GPUSupport* ShellDelegateImpl::CreateGPUSupport() {
264 // Real GPU support depends on src/content, so just use a stub.
265 return new GPUSupportStub;
268 base::string16 ShellDelegateImpl::GetProductName() const {
269 return base::string16();
272 } // namespace shell
273 } // namespace ash