app_list_service_ash.cc revision a93a17c8d99d686bd4a1511e5504e5e6cc9fcadf
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 GetAppListProfilePath(
30      const base::FilePath& user_data_dir) OVERRIDE;
31  virtual void ShowAppList(Profile* default_profile) OVERRIDE;
32  virtual bool IsAppListVisible() const OVERRIDE;
33  virtual void DismissAppList() OVERRIDE;
34  virtual void EnableAppList() OVERRIDE;
35
36  DISALLOW_COPY_AND_ASSIGN(AppListServiceAsh);
37};
38
39base::FilePath AppListServiceAsh::GetAppListProfilePath(
40    const base::FilePath& user_data_dir) {
41  return ChromeLauncherController::instance()->profile()->GetPath();
42}
43
44void AppListServiceAsh::ShowAppList(Profile* default_profile) {
45  // This may not work correctly if the profile passed in is different from the
46  // one the ash Shell is currently using.
47  // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS).
48  if (!ash::Shell::GetInstance()->GetAppListTargetVisibility())
49    ash::Shell::GetInstance()->ToggleAppList(NULL);
50}
51
52bool AppListServiceAsh::IsAppListVisible() const {
53  return ash::Shell::GetInstance()->GetAppListTargetVisibility();
54}
55
56void AppListServiceAsh::DismissAppList() {
57  if (IsAppListVisible())
58    ash::Shell::GetInstance()->ToggleAppList(NULL);
59}
60
61void AppListServiceAsh::EnableAppList() {}
62
63}  // namespace
64
65namespace chrome {
66
67AppListService* GetAppListServiceAsh() {
68  return AppListServiceAsh::GetInstance();
69}
70
71}  // namespace chrome
72
73// Windows Ash additionally supports a native UI. See app_list_service_win.cc.
74#if !defined(OS_WIN)
75
76// static
77AppListService* AppListService::Get() {
78  return chrome::GetAppListServiceAsh();
79}
80
81// static
82void AppListService::InitAll(Profile* initial_profile) {
83  Get()->Init(initial_profile);
84}
85
86#endif  // !defined(OS_WIN)
87