app_list_view_delegate.cc revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
1// Copyright (c) 2012 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_view_delegate.h" 6 7#include "chrome/browser/browser_process.h" 8#include "chrome/browser/extensions/extension_service.h" 9#include "chrome/browser/feedback/feedback_util.h" 10#include "chrome/browser/profiles/profile_manager.h" 11#include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 12#include "chrome/browser/ui/app_list/apps_model_builder.h" 13#include "chrome/browser/ui/app_list/chrome_app_list_item.h" 14#include "chrome/browser/ui/app_list/chrome_signin_delegate.h" 15#include "chrome/browser/ui/app_list/search/search_controller.h" 16#include "chrome/browser/ui/browser_finder.h" 17#include "chrome/browser/ui/chrome_pages.h" 18#include "chrome/browser/ui/host_desktop.h" 19#include "chrome/common/extensions/extension_constants.h" 20#include "chrome/common/url_constants.h" 21#include "content/public/browser/page_navigator.h" 22#include "content/public/browser/user_metrics.h" 23 24#if defined(USE_ASH) 25#include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" 26#endif 27 28AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller, 29 Profile* profile) 30 : controller_(controller), 31 profile_(profile) {} 32 33AppListViewDelegate::~AppListViewDelegate() {} 34 35void AppListViewDelegate::SetModel(app_list::AppListModel* model) { 36 if (model) { 37 apps_builder_.reset(new AppsModelBuilder(profile_, 38 model->apps(), 39 controller_.get())); 40 apps_builder_->Build(); 41 42 search_controller_.reset(new app_list::SearchController( 43 profile_, model->search_box(), model->results(), controller_.get())); 44 45 signin_delegate_.reset(new ChromeSigninDelegate(profile_)); 46 47#if defined(USE_ASH) 48 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile_, 49 model)); 50#endif 51 } else { 52 apps_builder_.reset(); 53 search_controller_.reset(); 54#if defined(USE_ASH) 55 app_sync_ui_state_watcher_.reset(); 56#endif 57 } 58} 59 60app_list::SigninDelegate* AppListViewDelegate::GetSigninDelegate() { 61 return signin_delegate_.get(); 62} 63 64void AppListViewDelegate::ActivateAppListItem( 65 app_list::AppListItemModel* item, 66 int event_flags) { 67 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp")); 68 static_cast<ChromeAppListItem*>(item)->Activate(event_flags); 69} 70 71void AppListViewDelegate::StartSearch() { 72 if (search_controller_.get()) 73 search_controller_->Start(); 74} 75 76void AppListViewDelegate::StopSearch() { 77 if (search_controller_.get()) 78 search_controller_->Stop(); 79} 80 81void AppListViewDelegate::OpenSearchResult( 82 app_list::SearchResult* result, 83 int event_flags) { 84 search_controller_->OpenResult(result, event_flags); 85} 86 87void AppListViewDelegate::InvokeSearchResultAction( 88 app_list::SearchResult* result, 89 int action_index, 90 int event_flags) { 91 search_controller_->InvokeResultAction(result, action_index, event_flags); 92} 93 94void AppListViewDelegate::Dismiss() { 95 controller_->DismissView(); 96} 97 98void AppListViewDelegate::ViewClosing() { 99 controller_->ViewClosing(); 100} 101 102void AppListViewDelegate::ViewActivationChanged(bool active) { 103 controller_->ViewActivationChanged(active); 104} 105 106gfx::ImageSkia AppListViewDelegate::GetWindowIcon() { 107 return controller_->GetWindowIcon(); 108} 109 110string16 AppListViewDelegate::GetCurrentUserName() { 111 ProfileInfoCache& cache = 112 g_browser_process->profile_manager()->GetProfileInfoCache(); 113 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); 114 if (profile_index != std::string::npos) 115 return cache.GetNameOfProfileAtIndex(profile_index); 116 117 return string16(); 118} 119 120string16 AppListViewDelegate::GetCurrentUserEmail() { 121 ProfileInfoCache& cache = 122 g_browser_process->profile_manager()->GetProfileInfoCache(); 123 size_t profile_index = cache.GetIndexOfProfileWithPath(profile_->GetPath()); 124 if (profile_index != std::string::npos) 125 return cache.GetUserNameOfProfileAtIndex(profile_index); 126 127 return string16(); 128} 129 130void AppListViewDelegate::OpenSettings() { 131 ExtensionService* service = profile_->GetExtensionService(); 132 DCHECK(service); 133 const extensions::Extension* extension = service->GetInstalledExtension( 134 extension_misc::kSettingsAppId); 135 DCHECK(extension); 136 controller_->ActivateApp(profile_, extension, 0); 137} 138 139void AppListViewDelegate::OpenHelp() { 140 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 141 controller_->GetAppListWindow()); 142 Browser* browser = chrome::FindOrCreateTabbedBrowser( 143 profile_, desktop); 144 browser->OpenURL(content::OpenURLParams(GURL(chrome::kAppLauncherHelpURL), 145 content::Referrer(), 146 NEW_FOREGROUND_TAB, 147 content::PAGE_TRANSITION_LINK, 148 false)); 149} 150 151void AppListViewDelegate::OpenFeedback() { 152 chrome::HostDesktopType desktop = chrome::GetHostDesktopTypeForNativeWindow( 153 controller_->GetAppListWindow()); 154 Browser* browser = chrome::FindOrCreateTabbedBrowser( 155 profile_, desktop); 156 chrome::ShowFeedbackPage(browser, std::string(), 157 chrome::kAppLauncherCategoryTag); 158} 159