app_list_service_ash.cc revision 424c4d7b64af9d0d8fd9624f381f469654d5e3d2
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 AppListControllerDelegate* CreateControllerDelegate() OVERRIDE;
39
40  DISALLOW_COPY_AND_ASSIGN(AppListServiceAsh);
41};
42
43base::FilePath AppListServiceAsh::GetProfilePath(
44    const base::FilePath& user_data_dir) {
45  return ChromeLauncherController::instance()->profile()->GetPath();
46}
47
48void AppListServiceAsh::CreateForProfile(Profile* default_profile) {}
49
50void AppListServiceAsh::ShowForProfile(Profile* default_profile) {
51  // This may not work correctly if the profile passed in is different from the
52  // one the ash Shell is currently using.
53  // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS).
54  if (!ash::Shell::GetInstance()->GetAppListTargetVisibility())
55    ash::Shell::GetInstance()->ToggleAppList(NULL);
56}
57
58bool AppListServiceAsh::IsAppListVisible() const {
59  return ash::Shell::GetInstance()->GetAppListTargetVisibility();
60}
61
62void AppListServiceAsh::DismissAppList() {
63  if (IsAppListVisible())
64    ash::Shell::GetInstance()->ToggleAppList(NULL);
65}
66
67void AppListServiceAsh::EnableAppList(Profile* initial_profile) {}
68
69gfx::NativeWindow AppListServiceAsh::GetAppListWindow() {
70  if (ash::Shell::HasInstance())
71    return ash::Shell::GetInstance()->GetAppListWindow();
72  return NULL;
73}
74
75AppListControllerDelegate* AppListServiceAsh::CreateControllerDelegate() {
76  return new AppListControllerDelegateAsh();
77}
78
79}  // namespace
80
81namespace chrome {
82
83AppListService* GetAppListServiceAsh() {
84  return AppListServiceAsh::GetInstance();
85}
86
87}  // namespace chrome
88
89// Windows Ash additionally supports a native UI. See app_list_service_win.cc.
90#if !defined(OS_WIN)
91
92// static
93AppListService* AppListService::Get() {
94  return chrome::GetAppListServiceAsh();
95}
96
97// static
98void AppListService::InitAll(Profile* initial_profile) {
99  Get()->Init(initial_profile);
100}
101
102#endif  // !defined(OS_WIN)
103