Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: chrome/browser/ui/app_list/search/search_controller.cc

Issue 15875007: app_list: Search result launch history and boost. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix win7_aura unit_test Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/app_list/search/search_controller.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/app_list/search/search_controller.h" 5 #include "chrome/browser/ui/app_list/search/search_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/app_list/search/app_search_provider.h" 16 #include "chrome/browser/ui/app_list/search/app_search_provider.h"
15 #include "chrome/browser/ui/app_list/search/chrome_search_result.h" 17 #include "chrome/browser/ui/app_list/search/chrome_search_result.h"
18 #include "chrome/browser/ui/app_list/search/history.h"
19 #include "chrome/browser/ui/app_list/search/history_factory.h"
16 #include "chrome/browser/ui/app_list/search/omnibox_provider.h" 20 #include "chrome/browser/ui/app_list/search/omnibox_provider.h"
17 #include "chrome/browser/ui/app_list/search/search_provider.h" 21 #include "chrome/browser/ui/app_list/search/search_provider.h"
18 #include "chrome/browser/ui/app_list/search/webstore_provider.h" 22 #include "chrome/browser/ui/app_list/search/webstore_provider.h"
19 #include "content/public/browser/user_metrics.h" 23 #include "content/public/browser/user_metrics.h"
20 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
22 #include "ui/app_list/search_box_model.h" 26 #include "ui/app_list/search_box_model.h"
23 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
25 29
26 namespace app_list { 30 namespace app_list {
27 31
28 SearchController::SearchController(Profile* profile, 32 SearchController::SearchController(Profile* profile,
29 SearchBoxModel* search_box, 33 SearchBoxModel* search_box,
30 AppListModel::SearchResults* results, 34 AppListModel::SearchResults* results,
31 AppListControllerDelegate* list_controller) 35 AppListControllerDelegate* list_controller)
32 : profile_(profile), 36 : profile_(profile),
33 search_box_(search_box), 37 search_box_(search_box),
34 list_controller_(list_controller), 38 list_controller_(list_controller),
35 dispatching_query_(false), 39 dispatching_query_(false),
36 mixer_(new Mixer(results)) { 40 mixer_(new Mixer(results)),
41 history_(HistoryFactory::GetForBrowserContext(profile)) {
37 Init(); 42 Init();
38 } 43 }
39 44
40 SearchController::~SearchController() {} 45 SearchController::~SearchController() {}
41 46
42 void SearchController::Init() { 47 void SearchController::Init() {
43 search_box_->SetHintText( 48 search_box_->SetHintText(
44 l10n_util::GetStringUTF16(IDS_SEARCH_BOX_HINT)); 49 l10n_util::GetStringUTF16(IDS_SEARCH_BOX_HINT));
45 search_box_->SetIcon(*ui::ResourceBundle::GetSharedInstance(). 50 search_box_->SetIcon(*ui::ResourceBundle::GetSharedInstance().
46 GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)); 51 GetImageSkiaNamed(IDR_OMNIBOX_SEARCH));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 it != providers_.end(); 91 it != providers_.end();
87 ++it) { 92 ++it) {
88 (*it)->Stop(); 93 (*it)->Stop();
89 } 94 }
90 } 95 }
91 96
92 void SearchController::OpenResult(SearchResult* result, int event_flags) { 97 void SearchController::OpenResult(SearchResult* result, int event_flags) {
93 // Count AppList.Search here because it is composed of search + action. 98 // Count AppList.Search here because it is composed of search + action.
94 content::RecordAction(content::UserMetricsAction("AppList_Search")); 99 content::RecordAction(content::UserMetricsAction("AppList_Search"));
95 100
96 // TODO(xiyuan): Hook up with user learning. 101 ChromeSearchResult* chrome_result =
97 static_cast<app_list::ChromeSearchResult*>(result)->Open(event_flags); 102 static_cast<app_list::ChromeSearchResult*>(result);
103 chrome_result->Open(event_flags);
104
105 if (history_ && history_->IsReady()) {
106 history_->AddLaunchEvent(UTF16ToUTF8(search_box_->text()),
107 chrome_result->id());
108 }
98 } 109 }
99 110
100 void SearchController::InvokeResultAction(SearchResult* result, 111 void SearchController::InvokeResultAction(SearchResult* result,
101 int action_index, 112 int action_index,
102 int event_flags) { 113 int event_flags) {
103 // TODO(xiyuan): Hook up with user learning. 114 // TODO(xiyuan): Hook up with user learning.
104 static_cast<app_list::ChromeSearchResult*>(result)->InvokeAction( 115 static_cast<app_list::ChromeSearchResult*>(result)->InvokeAction(
105 action_index, event_flags); 116 action_index, event_flags);
106 } 117 }
107 118
108 void SearchController::AddProvider(Mixer::GroupId group, 119 void SearchController::AddProvider(Mixer::GroupId group,
109 scoped_ptr<SearchProvider> provider) { 120 scoped_ptr<SearchProvider> provider) {
110 provider->set_result_changed_callback(base::Bind( 121 provider->set_result_changed_callback(base::Bind(
111 &SearchController::OnResultsChanged, 122 &SearchController::OnResultsChanged,
112 base::Unretained(this))); 123 base::Unretained(this)));
113 mixer_->AddProviderToGroup(group, provider.get()); 124 mixer_->AddProviderToGroup(group, provider.get());
114 providers_.push_back(provider.release()); // Takes ownership. 125 providers_.push_back(provider.release()); // Takes ownership.
115 } 126 }
116 127
117 void SearchController::OnResultsChanged() { 128 void SearchController::OnResultsChanged() {
118 if (dispatching_query_) 129 if (dispatching_query_)
119 return; 130 return;
120 131
121 mixer_->MixAndPublish(); 132 KnownResults known_results;
133 if (history_ && history_->IsReady()) {
134 history_->GetKnownResults(UTF16ToUTF8(search_box_->text()))
135 ->swap(known_results);
136 }
137
138 mixer_->MixAndPublish(known_results);
122 } 139 }
123 140
124 } // namespace app_list 141 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search/search_controller.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698