app_list_service_ash.cc revision 1e9bf3e0803691d0a228da41fc608347b6db4340
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/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/app_list/app_list_service_impl.h"
12#include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
13#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
14
15namespace {
16
17class AppListServiceAsh : public AppListServiceImpl {
18 public:
19  static AppListServiceAsh* GetInstance() {
20    return Singleton<AppListServiceAsh,
21                     LeakySingletonTraits<AppListServiceAsh> >::get();
22  }
23
24 private:
25  friend struct DefaultSingletonTraits<AppListServiceAsh>;
26
27  AppListServiceAsh() {}
28
29  // AppListService overrides:
30  virtual base::FilePath GetProfilePath(
31      const base::FilePath& user_data_dir) OVERRIDE;
32  virtual void CreateForProfile(Profile* default_profile) OVERRIDE;
33  virtual void ShowForProfile(Profile* default_profile) OVERRIDE;
34  virtual bool IsAppListVisible() const OVERRIDE;
35  virtual void DismissAppList() OVERRIDE;
36  virtual void EnableAppList(Profile* initial_profile) OVERRIDE;
37  virtual gfx::NativeWindow GetAppListWindow() OVERRIDE;
38  virtual Profile* GetCurrentAppListProfile() OVERRIDE;
39  virtual AppListControllerDelegate* CreateControllerDelegate() OVERRIDE;
40
41  DISALLOW_COPY_AND_ASSIGN(AppListServiceAsh);
42};
43
44base::FilePath AppListServiceAsh::GetProfilePath(
45    const base::FilePath& user_data_dir) {
46  return ChromeLauncherController::instance()->profile()->GetPath();
47}
48
49void AppListServiceAsh::CreateForProfile(Profile* default_profile) {}
50
51void AppListServiceAsh::ShowForProfile(Profile* default_profile) {
52  // This may not work correctly if the profile passed in is different from the
53  // one the ash Shell is currently using.
54  // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS).
55  if (!ash::Shell::GetInstance()->GetAppListTargetVisibility())
56    ash::Shell::GetInstance()->ToggleAppList(NULL);
57}
58
59bool AppListServiceAsh::IsAppListVisible() const {
60  return ash::Shell::GetInstance()->GetAppListTargetVisibility();
61}
62
63void AppListServiceAsh::DismissAppList() {
64  if (IsAppListVisible())
65    ash::Shell::GetInstance()->ToggleAppList(NULL);
66}
67
68void AppListServiceAsh::EnableAppList(Profile* initial_profile) {}
69
70gfx::NativeWindow AppListServiceAsh::GetAppListWindow() {
71  if (ash::Shell::HasInstance())
72    return ash::Shell::GetInstance()->GetAppListWindow();
73  return NULL;
74}
75
76Profile* AppListServiceAsh::GetCurrentAppListProfile() {
77  return ChromeLauncherController::instance()->profile();
78}
79
80AppListControllerDelegate* AppListServiceAsh::CreateControllerDelegate() {
81  return new AppListControllerDelegateAsh();
82}
83
84}  // namespace
85
86namespace chrome {
87
88AppListService* GetAppListServiceAsh() {
89  return AppListServiceAsh::GetInstance();
90}
91
92}  // namespace chrome
93
94// Windows Ash additionally supports a native UI. See app_list_service_win.cc.
95#if !defined(OS_WIN)
96
97// static
98AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) {
99  return chrome::GetAppListServiceAsh();
100}
101
102// static
103void AppListService::InitAll(Profile* initial_profile) {
104  AppListServiceAsh::GetInstance()->Init(initial_profile);
105}
106
107#endif  // !defined(OS_WIN)
108