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