app_list_service_ash.cc revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
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/scoped_ptr.h" 10#include "base/memory/singleton.h" 11#include "chrome/browser/profiles/profile.h" 12#include "chrome/browser/ui/app_list/app_list_service_impl.h" 13#include "chrome/browser/ui/ash/app_list/app_list_controller_ash.h" 14#include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 15 16namespace { 17 18class AppListServiceAsh : public AppListServiceImpl { 19 public: 20 static AppListServiceAsh* GetInstance() { 21 return Singleton<AppListServiceAsh, 22 LeakySingletonTraits<AppListServiceAsh> >::get(); 23 } 24 25 private: 26 friend struct DefaultSingletonTraits<AppListServiceAsh>; 27 28 AppListServiceAsh(); 29 virtual ~AppListServiceAsh(); 30 31 // AppListService overrides: 32 virtual base::FilePath GetProfilePath( 33 const base::FilePath& user_data_dir) OVERRIDE; 34 virtual void CreateForProfile(Profile* default_profile) OVERRIDE; 35 virtual void ShowForProfile(Profile* default_profile) OVERRIDE; 36 virtual bool IsAppListVisible() const OVERRIDE; 37 virtual void DismissAppList() OVERRIDE; 38 virtual void EnableAppList(Profile* initial_profile, 39 AppListEnableSource enable_source) OVERRIDE; 40 virtual gfx::NativeWindow GetAppListWindow() OVERRIDE; 41 virtual Profile* GetCurrentAppListProfile() OVERRIDE; 42 virtual AppListControllerDelegate* GetControllerDelegate() OVERRIDE; 43 44 scoped_ptr<AppListControllerDelegateAsh> controller_delegate_; 45 46 DISALLOW_COPY_AND_ASSIGN(AppListServiceAsh); 47}; 48 49AppListServiceAsh::AppListServiceAsh() 50 : controller_delegate_(new AppListControllerDelegateAsh()) { 51} 52 53AppListServiceAsh::~AppListServiceAsh() { 54} 55 56base::FilePath AppListServiceAsh::GetProfilePath( 57 const base::FilePath& user_data_dir) { 58 return ChromeLauncherController::instance()->profile()->GetPath(); 59} 60 61void AppListServiceAsh::CreateForProfile(Profile* default_profile) {} 62 63void AppListServiceAsh::ShowForProfile(Profile* default_profile) { 64 // This may not work correctly if the profile passed in is different from the 65 // one the ash Shell is currently using. 66 // TODO(ananta): Handle profile changes correctly when !defined(OS_CHROMEOS). 67 if (!ash::Shell::GetInstance()->GetAppListTargetVisibility()) 68 ash::Shell::GetInstance()->ToggleAppList(NULL); 69} 70 71bool AppListServiceAsh::IsAppListVisible() const { 72 return ash::Shell::GetInstance()->GetAppListTargetVisibility(); 73} 74 75void AppListServiceAsh::DismissAppList() { 76 if (IsAppListVisible()) 77 ash::Shell::GetInstance()->ToggleAppList(NULL); 78} 79 80void AppListServiceAsh::EnableAppList(Profile* initial_profile, 81 AppListEnableSource enable_source) {} 82 83gfx::NativeWindow AppListServiceAsh::GetAppListWindow() { 84 if (ash::Shell::HasInstance()) 85 return ash::Shell::GetInstance()->GetAppListWindow(); 86 return NULL; 87} 88 89Profile* AppListServiceAsh::GetCurrentAppListProfile() { 90 return ChromeLauncherController::instance()->profile(); 91} 92 93AppListControllerDelegate* AppListServiceAsh::GetControllerDelegate() { 94 return controller_delegate_.get(); 95} 96 97} // namespace 98 99namespace chrome { 100 101AppListService* GetAppListServiceAsh() { 102 return AppListServiceAsh::GetInstance(); 103} 104 105} // namespace chrome 106 107// Windows Ash additionally supports a native UI. See app_list_service_win.cc. 108#if !defined(OS_WIN) 109 110// static 111AppListService* AppListService::Get(chrome::HostDesktopType desktop_type) { 112 return chrome::GetAppListServiceAsh(); 113} 114 115// static 116void AppListService::InitAll(Profile* initial_profile) { 117 AppListServiceAsh::GetInstance()->Init(initial_profile); 118} 119 120#endif // !defined(OS_WIN) 121