app_list_view_delegate.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/profiles/profile_manager.h" 8#include "chrome/browser/ui/app_list/apps_model_builder.h" 9#include "chrome/browser/ui/app_list/chrome_app_list_item.h" 10#include "chrome/browser/ui/app_list/search_builder.h" 11#include "content/public/browser/user_metrics.h" 12 13#if defined(USE_ASH) 14#include "chrome/browser/ui/ash/app_list/app_sync_ui_state_watcher.h" 15#endif 16 17AppListViewDelegate::AppListViewDelegate(AppListControllerDelegate* controller) 18 : controller_(controller) {} 19 20AppListViewDelegate::~AppListViewDelegate() {} 21 22void AppListViewDelegate::SetModel(app_list::AppListModel* model) { 23 if (model) { 24 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); 25 apps_builder_.reset(new AppsModelBuilder(profile, 26 model->apps(), 27 controller_.get())); 28 apps_builder_->Build(); 29 30 search_builder_.reset(new SearchBuilder(profile, 31 model->search_box(), 32 model->results(), 33 controller_.get())); 34#if defined(USE_ASH) 35 app_sync_ui_state_watcher_.reset(new AppSyncUIStateWatcher(profile, model)); 36#endif 37 } else { 38 apps_builder_.reset(); 39 search_builder_.reset(); 40#if defined(USE_ASH) 41 app_sync_ui_state_watcher_.reset(); 42#endif 43 } 44} 45 46void AppListViewDelegate::ActivateAppListItem( 47 app_list::AppListItemModel* item, 48 int event_flags) { 49 content::RecordAction(content::UserMetricsAction("AppList_ClickOnApp")); 50 static_cast<ChromeAppListItem*>(item)->Activate(event_flags); 51} 52 53void AppListViewDelegate::StartSearch() { 54 if (search_builder_.get()) 55 search_builder_->StartSearch(); 56} 57 58void AppListViewDelegate::StopSearch() { 59 if (search_builder_.get()) 60 search_builder_->StopSearch(); 61} 62 63void AppListViewDelegate::OpenSearchResult( 64 const app_list::SearchResult& result, 65 int event_flags) { 66 if (search_builder_.get()) 67 search_builder_->OpenResult(result, event_flags); 68} 69 70void AppListViewDelegate::InvokeSearchResultAction( 71 const app_list::SearchResult& result, 72 int action_index, 73 int event_flags) { 74 if (search_builder_.get()) 75 search_builder_->InvokeResultAction(result, action_index, event_flags); 76} 77 78void AppListViewDelegate::Close() { 79 controller_->CloseView(); 80} 81 82void AppListViewDelegate::ViewClosing() { 83 controller_->ViewClosing(); 84} 85 86void AppListViewDelegate::ViewActivationChanged(bool active) { 87 controller_->ViewActivationChanged(active); 88} 89