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

Side by Side Diff: ui/app_list/search_controller.cc

Issue 2701123002: AppList Performance Optimization 2 (Closed)
Patch Set: Cache the tokenized name Created 3 years, 9 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
« no previous file with comments | « ui/app_list/search_controller.h ('k') | ui/app_list/search_provider.h » ('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 "ui/app_list/search_controller.h" 5 #include "ui/app_list/search_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/metrics/histogram_macros.h" 13 #include "base/metrics/histogram_macros.h"
14 #include "base/metrics/user_metrics.h" 14 #include "base/metrics/user_metrics.h"
15 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "ui/app_list/app_list_constants.h" 17 #include "ui/app_list/app_list_constants.h"
18 #include "ui/app_list/search/history.h" 18 #include "ui/app_list/search/history.h"
19 #include "ui/app_list/search_box_model.h" 19 #include "ui/app_list/search_box_model.h"
20 #include "ui/app_list/search_provider.h" 20 #include "ui/app_list/search_provider.h"
21 #include "ui/app_list/search_result.h" 21 #include "ui/app_list/search_result.h"
22 22
23 namespace { 23 namespace {
24 24
25 // Maximum time (in milliseconds) to wait to the search providers to finish. 25 // Maximum time (in milliseconds) to wait to the search providers to finish.
26 const int kStopTimeMS = 1500; 26 constexpr int kStopTimeMS = 1500;
27 } 27 }
28 28
29 namespace app_list { 29 namespace app_list {
30 30
31 SearchController::SearchController(SearchBoxModel* search_box, 31 SearchController::SearchController(SearchBoxModel* search_box,
32 AppListModel::SearchResults* results, 32 AppListModel::SearchResults* results,
33 History* history) 33 History* history)
34 : search_box_(search_box), mixer_(new Mixer(results)), history_(history) {} 34 : search_box_(search_box), mixer_(new Mixer(results)), history_(history) {}
35 35
36 SearchController::~SearchController() { 36 SearchController::~SearchController() {
37 } 37 }
38 38
39 void SearchController::Start(bool is_voice_query) { 39 void SearchController::Start(bool is_voice_query) {
40 Stop(); 40 Stop();
41 41
42 base::string16 query; 42 base::string16 query;
43 base::TrimWhitespace(search_box_->text(), base::TRIM_ALL, &query); 43 base::TrimWhitespace(search_box_->text(), base::TRIM_ALL, &query);
44 44
45 dispatching_query_ = true; 45 dispatching_query_ = true;
46 for (Providers::iterator it = providers_.begin(); 46 for (const auto& provider : providers_)
47 it != providers_.end(); 47 provider->Start(is_voice_query, query);
48 ++it) { 48
49 (*it)->Start(is_voice_query, query);
50 }
51 dispatching_query_ = false; 49 dispatching_query_ = false;
52 query_for_recommendation_ = query.empty() ? true : false; 50 query_for_recommendation_ = query.empty() ? true : false;
53 51
54 is_voice_query_ = is_voice_query; 52 is_voice_query_ = is_voice_query;
55 53
56 OnResultsChanged(); 54 OnResultsChanged();
57 55
58 stop_timer_.Start(FROM_HERE, 56 stop_timer_.Start(FROM_HERE,
59 base::TimeDelta::FromMilliseconds(kStopTimeMS), 57 base::TimeDelta::FromMilliseconds(kStopTimeMS),
60 base::Bind(&SearchController::Stop, 58 base::Bind(&SearchController::Stop,
61 base::Unretained(this))); 59 base::Unretained(this)));
62 } 60 }
63 61
64 void SearchController::Stop() { 62 void SearchController::Stop() {
65 stop_timer_.Stop(); 63 stop_timer_.Stop();
66 64
67 for (Providers::iterator it = providers_.begin(); 65 for (const auto& provider : providers_)
68 it != providers_.end(); 66 provider->Stop();
69 ++it) {
70 (*it)->Stop();
71 }
72 } 67 }
73 68
74 void SearchController::OpenResult(SearchResult* result, int event_flags) { 69 void SearchController::OpenResult(SearchResult* result, int event_flags) {
75 // This can happen in certain circumstances due to races. See 70 // This can happen in certain circumstances due to races. See
76 // https://crbug.com/534772 71 // https://crbug.com/534772
77 if (!result) 72 if (!result)
78 return; 73 return;
79 74
80 // Count AppList.Search here because it is composed of search + action. 75 // Count AppList.Search here because it is composed of search + action.
81 base::RecordAction(base::UserMetricsAction("AppList_Search")); 76 base::RecordAction(base::UserMetricsAction("AppList_Search"));
(...skipping 28 matching lines...) Expand all
110 105
111 size_t SearchController::AddGroup(size_t max_results, double multiplier) { 106 size_t SearchController::AddGroup(size_t max_results, double multiplier) {
112 return mixer_->AddGroup(max_results, multiplier); 107 return mixer_->AddGroup(max_results, multiplier);
113 } 108 }
114 109
115 void SearchController::AddProvider(size_t group_id, 110 void SearchController::AddProvider(size_t group_id,
116 std::unique_ptr<SearchProvider> provider) { 111 std::unique_ptr<SearchProvider> provider) {
117 provider->set_result_changed_callback( 112 provider->set_result_changed_callback(
118 base::Bind(&SearchController::OnResultsChanged, base::Unretained(this))); 113 base::Bind(&SearchController::OnResultsChanged, base::Unretained(this)));
119 mixer_->AddProviderToGroup(group_id, provider.get()); 114 mixer_->AddProviderToGroup(group_id, provider.get());
120 providers_.push_back(std::move(provider)); 115 providers_.emplace_back(std::move(provider));
121 } 116 }
122 117
123 void SearchController::OnResultsChanged() { 118 void SearchController::OnResultsChanged() {
124 if (dispatching_query_) 119 if (dispatching_query_)
125 return; 120 return;
126 121
127 KnownResults known_results; 122 KnownResults known_results;
128 if (history_ && history_->IsReady()) { 123 if (history_ && history_->IsReady()) {
129 history_->GetKnownResults(base::UTF16ToUTF8(search_box_->text())) 124 history_->GetKnownResults(base::UTF16ToUTF8(search_box_->text()))
130 ->swap(known_results); 125 ->swap(known_results);
131 } 126 }
132 127
133 size_t num_max_results = 128 size_t num_max_results =
134 query_for_recommendation_ ? kNumStartPageTiles : kMaxSearchResults; 129 query_for_recommendation_ ? kNumStartPageTiles : kMaxSearchResults;
135 mixer_->MixAndPublish(is_voice_query_, known_results, num_max_results); 130 mixer_->MixAndPublish(is_voice_query_, known_results, num_max_results);
136 } 131 }
137 132
138 } // namespace app_list 133 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/search_controller.h ('k') | ui/app_list/search_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698