OLD | NEW |
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/app_search_provider.h" | 5 #include "chrome/browser/ui/app_list/search/app_search_provider.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 id_to_app_list_index[top_level_item_list_->item_at(i)->id()] = i; | 105 id_to_app_list_index[top_level_item_list_->item_at(i)->id()] = i; |
106 } | 106 } |
107 | 107 |
108 for (const App* app : apps_) { | 108 for (const App* app : apps_) { |
109 scoped_ptr<AppResult> result( | 109 scoped_ptr<AppResult> result( |
110 new AppResult(profile_, app->app_id(), list_controller_, true)); | 110 new AppResult(profile_, app->app_id(), list_controller_, true)); |
111 result->set_title(app->indexed_name().text()); | 111 result->set_title(app->indexed_name().text()); |
112 | 112 |
113 // Use the app list order to tiebreak apps that have never been launched. | 113 // Use the app list order to tiebreak apps that have never been launched. |
114 if (app->last_launch_time().is_null()) { | 114 if (app->last_launch_time().is_null()) { |
115 result->set_relevance( | 115 auto it = id_to_app_list_index.find(app->app_id()); |
116 kUnlaunchedAppRelevanceStepSize * | 116 // If it's in a folder, it won't be in |id_to_app_list_index|. Rank |
117 (apps_.size() - id_to_app_list_index[app->app_id()])); | 117 // those as if they are at the end of the list. |
| 118 size_t app_list_index = |
| 119 it == id_to_app_list_index.end() ? apps_.size() : (*it).second; |
| 120 if (app_list_index > apps_.size()) |
| 121 app_list_index = apps_.size(); |
| 122 |
| 123 result->set_relevance(kUnlaunchedAppRelevanceStepSize * |
| 124 (apps_.size() - app_list_index)); |
118 } else { | 125 } else { |
119 result->UpdateFromLastLaunched(clock_->Now(), app->last_launch_time()); | 126 result->UpdateFromLastLaunched(clock_->Now(), app->last_launch_time()); |
120 } | 127 } |
121 Add(result.Pass()); | 128 Add(result.Pass()); |
122 } | 129 } |
123 } else { | 130 } else { |
124 for (const App* app : apps_) { | 131 for (const App* app : apps_) { |
125 scoped_ptr<AppResult> result( | 132 scoped_ptr<AppResult> result( |
126 new AppResult(profile_, app->app_id(), list_controller_, false)); | 133 new AppResult(profile_, app->app_id(), list_controller_, false)); |
127 TokenizedStringMatch match; | 134 TokenizedStringMatch match; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 RefreshApps(); | 187 RefreshApps(); |
181 if (!update_results_factory_.HasWeakPtrs()) { | 188 if (!update_results_factory_.HasWeakPtrs()) { |
182 base::MessageLoop::current()->PostTask( | 189 base::MessageLoop::current()->PostTask( |
183 FROM_HERE, | 190 FROM_HERE, |
184 base::Bind(&AppSearchProvider::UpdateResults, | 191 base::Bind(&AppSearchProvider::UpdateResults, |
185 update_results_factory_.GetWeakPtr())); | 192 update_results_factory_.GetWeakPtr())); |
186 } | 193 } |
187 } | 194 } |
188 | 195 |
189 } // namespace app_list | 196 } // namespace app_list |
OLD | NEW |