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