1// Copyright 2013 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.
4
5#include "chrome/browser/ui/ash/app_list/app_list_service_ash.h"
6
7#include "ash/shell.h"
8#include "base/files/file_path.h"
9#include "base/memory/singleton.h"
10#include "chrome/browser/profiles/profile.h"
11#include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
12#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
13
14// static
15AppListServiceAsh* AppListServiceAsh::GetInstance() {
16  return Singleton<AppListServiceAsh,
17                   LeakySingletonTraits<AppListServiceAsh> >::get();
18}
19
20AppListServiceAsh::AppListServiceAsh()
21    : controller_delegate_(new AppListControllerDelegateAsh()) {
22}
23
24AppListServiceAsh::~AppListServiceAsh() {
25}
26
27base::FilePath AppListServiceAsh::GetProfilePath(
28    const base::FilePath& user_data_dir) {
29  return ChromeLauncherController::instance()->profile()->GetPath();
30}
31
32void AppListServiceAsh::CreateForProfile(Profile* default_profile) {}
33
34void AppListServiceAsh::ShowForProfile(Profile* default_profile) {
35  // This may not work correctly if the profile passed in is different from the
36  // one the ash Shell is currently using.
37  // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS).
38  ash::Shell::GetInstance()->ShowAppList(NULL);
39}
40
41bool AppListServiceAsh::IsAppListVisible() const {
42  return ash::Shell::GetInstance()->GetAppListTargetVisibility();
43}
44
45void AppListServiceAsh::DismissAppList() {
46  ash::Shell::GetInstance()->DismissAppList();
47}
48
49void AppListServiceAsh::EnableAppList(Profile* initial_profile,
50                                      AppListEnableSource enable_source) {}
51
52gfx::NativeWindow AppListServiceAsh::GetAppListWindow() {
53  if (ash::Shell::HasInstance())
54    return ash::Shell::GetInstance()->GetAppListWindow();
55  return NULL;
56}
57
58Profile* AppListServiceAsh::GetCurrentAppListProfile() {
59  return ChromeLauncherController::instance()->profile();
60}
61
62AppListControllerDelegate* AppListServiceAsh::GetControllerDelegate() {
63  return controller_delegate_.get();
64}
65
66void AppListServiceAsh::DestroyAppList() {
67  // On Ash, the app list is torn down whenever it is dismissed, so just ensure
68  // that it is dismissed.
69  DismissAppList();
70}
71
72// Windows and Linux Ash additionally supports a native UI. See
73// app_list_service_{win,linux}.cc.
74#if defined(OS_CHROMEOS)
75
76// static
77AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) {
78  return AppListServiceAsh::GetInstance();
79}
80
81// static
82void AppListService::InitAll(Profile* initial_profile) {
83  AppListServiceAsh::GetInstance()->Init(initial_profile);
84}
85
86#endif  // !defined(OS_WIN)
87