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