root/chrome/browser/ui/ash/app_list/app_list_service_ash.cc

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. GetInstance
  2. GetProfilePath
  3. CreateForProfile
  4. ShowForProfile
  5. IsAppListVisible
  6. DismissAppList
  7. EnableAppList
  8. GetAppListWindow
  9. GetCurrentAppListProfile
  10. GetControllerDelegate
  11. GetAppListServiceAsh
  12. Get
  13. InitAll

// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/app_list/app_list_service_ash.h"

#include "ash/shell.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/singleton.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/app_list_service_impl.h"
#include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h"
#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"

namespace {

class AppListServiceAsh : public AppListServiceImpl {
 public:
  static AppListServiceAsh* GetInstance() {
    return Singleton<AppListServiceAsh,
                     LeakySingletonTraits<AppListServiceAsh> >::get();
  }

 private:
  friend struct DefaultSingletonTraits<AppListServiceAsh>;

  AppListServiceAsh();
  virtual ~AppListServiceAsh();

  // AppListService overrides:
  virtual base::FilePath GetProfilePath(
      const base::FilePath& user_data_dir) OVERRIDE;
  virtual void CreateForProfile(Profile* default_profile) OVERRIDE;
  virtual void ShowForProfile(Profile* default_profile) OVERRIDE;
  virtual bool IsAppListVisible() const OVERRIDE;
  virtual void DismissAppList() OVERRIDE;
  virtual void EnableAppList(Profile* initial_profile,
                             AppListEnableSource enable_source) OVERRIDE;
  virtual gfx::NativeWindow GetAppListWindow() OVERRIDE;
  virtual Profile* GetCurrentAppListProfile() OVERRIDE;
  virtual AppListControllerDelegate* GetControllerDelegate() OVERRIDE;

  scoped_ptr<AppListControllerDelegateAsh> controller_delegate_;

  DISALLOW_COPY_AND_ASSIGN(AppListServiceAsh);
};

AppListServiceAsh::AppListServiceAsh()
    : controller_delegate_(new AppListControllerDelegateAsh()) {
}

AppListServiceAsh::~AppListServiceAsh() {
}

base::FilePath AppListServiceAsh::GetProfilePath(
    const base::FilePath& user_data_dir) {
  return ChromeLauncherController::instance()->profile()->GetPath();
}

void AppListServiceAsh::CreateForProfile(Profile* default_profile) {}

void AppListServiceAsh::ShowForProfile(Profile* default_profile) {
  // This may not work correctly if the profile passed in is different from the
  // one the ash Shell is currently using.
  // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS).
  if (!ash::Shell::GetInstance()->GetAppListTargetVisibility())
    ash::Shell::GetInstance()->ToggleAppList(NULL);
}

bool AppListServiceAsh::IsAppListVisible() const {
  return ash::Shell::GetInstance()->GetAppListTargetVisibility();
}

void AppListServiceAsh::DismissAppList() {
  if (IsAppListVisible())
    ash::Shell::GetInstance()->ToggleAppList(NULL);
}

void AppListServiceAsh::EnableAppList(Profile* initial_profile,
                                      AppListEnableSource enable_source) {}

gfx::NativeWindow AppListServiceAsh::GetAppListWindow() {
  if (ash::Shell::HasInstance())
    return ash::Shell::GetInstance()->GetAppListWindow();
  return NULL;
}

Profile* AppListServiceAsh::GetCurrentAppListProfile() {
  return ChromeLauncherController::instance()->profile();
}

AppListControllerDelegate* AppListServiceAsh::GetControllerDelegate() {
  return controller_delegate_.get();
}

}  // namespace

namespace chrome {

AppListService* GetAppListServiceAsh() {
  return AppListServiceAsh::GetInstance();
}

}  // namespace chrome

// Windows Ash additionally supports a native UI. See app_list_service_win.cc.
#if !defined(OS_WIN)

// static
AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) {
  return chrome::GetAppListServiceAsh();
}

// static
void AppListService::InitAll(Profile* initial_profile) {
  AppListServiceAsh::GetInstance()->Init(initial_profile);
}

#endif  // !defined(OS_WIN)

/* [<][>][^][v][top][bottom][index][help] */