app_list_service_ash.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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.h"
12#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
13
14namespace {
15
16class AppListServiceAsh : public AppListService {
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
35  DISALLOW_COPY_AND_ASSIGN(AppListServiceAsh);
36};
37
38base::FilePath AppListServiceAsh::GetAppListProfilePath(
39    const base::FilePath& user_data_dir) {
40  return ChromeLauncherController::instance()->profile()->GetPath();
41}
42
43void AppListServiceAsh::ShowAppList(Profile* default_profile) {
44  // This may not work correctly if the profile passed in is different from the
45  // one the ash Shell is currently using.
46  // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS).
47  if (!ash::Shell::GetInstance()->GetAppListTargetVisibility())
48    ash::Shell::GetInstance()->ToggleAppList(NULL);
49}
50
51bool AppListServiceAsh::IsAppListVisible() const {
52  return ash::Shell::GetInstance()->GetAppListTargetVisibility();
53}
54
55void AppListServiceAsh::DismissAppList() {
56  if (IsAppListVisible())
57    ash::Shell::GetInstance()->ToggleAppList(NULL);
58}
59
60}  // namespace
61
62namespace chrome {
63
64AppListService* GetAppListServiceAsh() {
65  return AppListServiceAsh::GetInstance();
66}
67
68}  // namespace chrome
69