| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 const double kUnlaunchedAppRelevanceStepSize = 0.0001; | 44 const double kUnlaunchedAppRelevanceStepSize = 0.0001; |
| 45 } | 45 } |
| 46 | 46 |
| 47 namespace app_list { | 47 namespace app_list { |
| 48 | 48 |
| 49 class AppSearchProvider::App { | 49 class AppSearchProvider::App { |
| 50 public: | 50 public: |
| 51 App(AppSearchProvider::DataSource* data_source, | 51 App(AppSearchProvider::DataSource* data_source, |
| 52 const std::string& id, | 52 const std::string& id, |
| 53 const std::string& name, | 53 const std::string& name, |
| 54 const base::Time& last_launch_time) | 54 const base::Time& last_launch_time, |
| 55 const base::Time& install_time) |
| 55 : data_source_(data_source), | 56 : data_source_(data_source), |
| 56 id_(id), | 57 id_(id), |
| 57 indexed_name_(base::UTF8ToUTF16(name)), | 58 indexed_name_(base::UTF8ToUTF16(name)), |
| 58 last_launch_time_(last_launch_time) {} | 59 last_launch_time_(last_launch_time), |
| 60 install_time_(install_time) {} |
| 59 ~App() {} | 61 ~App() {} |
| 60 | 62 |
| 61 AppSearchProvider::DataSource* data_source() { return data_source_; } | 63 AppSearchProvider::DataSource* data_source() { return data_source_; } |
| 62 const std::string& id() const { return id_; } | 64 const std::string& id() const { return id_; } |
| 63 const TokenizedString& indexed_name() const { return indexed_name_; } | 65 const TokenizedString& indexed_name() const { return indexed_name_; } |
| 64 const base::Time& last_launch_time() const { return last_launch_time_; } | 66 const base::Time& last_launch_time() const { return last_launch_time_; } |
| 67 const base::Time& install_time() const { return install_time_; } |
| 65 | 68 |
| 66 private: | 69 private: |
| 67 AppSearchProvider::DataSource* data_source_; | 70 AppSearchProvider::DataSource* data_source_; |
| 68 const std::string id_; | 71 const std::string id_; |
| 69 const TokenizedString indexed_name_; | 72 const TokenizedString indexed_name_; |
| 70 const base::Time last_launch_time_; | 73 const base::Time last_launch_time_; |
| 74 const base::Time install_time_; |
| 71 | 75 |
| 72 DISALLOW_COPY_AND_ASSIGN(App); | 76 DISALLOW_COPY_AND_ASSIGN(App); |
| 73 }; | 77 }; |
| 74 | 78 |
| 75 class AppSearchProvider::DataSource { | 79 class AppSearchProvider::DataSource { |
| 76 public: | 80 public: |
| 77 DataSource(Profile* profile, AppSearchProvider* owner) | 81 DataSource(Profile* profile, AppSearchProvider* owner) |
| 78 : profile_(profile), | 82 : profile_(profile), |
| 79 owner_(owner) {} | 83 owner_(owner) {} |
| 80 virtual ~DataSource() {} | 84 virtual ~DataSource() {} |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 continue; | 157 continue; |
| 154 } | 158 } |
| 155 | 159 |
| 156 if (profile()->IsOffTheRecord() && | 160 if (profile()->IsOffTheRecord() && |
| 157 !extensions::util::CanLoadInIncognito(extension, profile())) { | 161 !extensions::util::CanLoadInIncognito(extension, profile())) { |
| 158 continue; | 162 continue; |
| 159 } | 163 } |
| 160 | 164 |
| 161 std::unique_ptr<AppSearchProvider::App> app(new AppSearchProvider::App( | 165 std::unique_ptr<AppSearchProvider::App> app(new AppSearchProvider::App( |
| 162 this, extension->id(), extension->short_name(), | 166 this, extension->id(), extension->short_name(), |
| 163 prefs->GetLastLaunchTime(extension->id()))); | 167 prefs->GetLastLaunchTime(extension->id()), |
| 168 prefs->GetInstallTime(extension->id()))); |
| 164 apps->push_back(std::move(app)); | 169 apps->push_back(std::move(app)); |
| 165 } | 170 } |
| 166 } | 171 } |
| 167 | 172 |
| 168 ScopedObserver<extensions::ExtensionRegistry, | 173 ScopedObserver<extensions::ExtensionRegistry, |
| 169 extensions::ExtensionRegistryObserver> | 174 extensions::ExtensionRegistryObserver> |
| 170 extension_registry_observer_; | 175 extension_registry_observer_; |
| 171 | 176 |
| 172 DISALLOW_COPY_AND_ASSIGN(ExtensionDataSource); | 177 DISALLOW_COPY_AND_ASSIGN(ExtensionDataSource); |
| 173 }; | 178 }; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 196 continue; | 201 continue; |
| 197 | 202 |
| 198 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | 203 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = |
| 199 arc_prefs->GetApp(app_id); | 204 arc_prefs->GetApp(app_id); |
| 200 if (!app_info) { | 205 if (!app_info) { |
| 201 NOTREACHED(); | 206 NOTREACHED(); |
| 202 continue; | 207 continue; |
| 203 } | 208 } |
| 204 | 209 |
| 205 std::unique_ptr<AppSearchProvider::App> app(new AppSearchProvider::App( | 210 std::unique_ptr<AppSearchProvider::App> app(new AppSearchProvider::App( |
| 206 this, app_id, app_info->name, app_info->last_launch_time)); | 211 this, app_id, app_info->name, app_info->last_launch_time, |
| 212 app_info->install_time)); |
| 207 apps->push_back(std::move(app)); | 213 apps->push_back(std::move(app)); |
| 208 } | 214 } |
| 209 } | 215 } |
| 210 | 216 |
| 211 std::unique_ptr<AppResult> CreateResult( | 217 std::unique_ptr<AppResult> CreateResult( |
| 212 const std::string& app_id, | 218 const std::string& app_id, |
| 213 AppListControllerDelegate* list_controller, | 219 AppListControllerDelegate* list_controller, |
| 214 AppListItemList* top_level_item_list, | 220 AppListItemList* top_level_item_list, |
| 215 bool is_recommended) override { | 221 bool is_recommended) override { |
| 216 return std::unique_ptr<AppResult>( | 222 return std::unique_ptr<AppResult>( |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 for (size_t i = 0; i < top_level_item_list_->item_count(); ++i) { | 305 for (size_t i = 0; i < top_level_item_list_->item_count(); ++i) { |
| 300 id_to_app_list_index[top_level_item_list_->item_at(i)->id()] = i; | 306 id_to_app_list_index[top_level_item_list_->item_at(i)->id()] = i; |
| 301 } | 307 } |
| 302 | 308 |
| 303 for (auto& app : apps_) { | 309 for (auto& app : apps_) { |
| 304 std::unique_ptr<AppResult> result = app->data_source()->CreateResult( | 310 std::unique_ptr<AppResult> result = app->data_source()->CreateResult( |
| 305 app->id(), list_controller_, top_level_item_list_, true); | 311 app->id(), list_controller_, top_level_item_list_, true); |
| 306 result->set_title(app->indexed_name().text()); | 312 result->set_title(app->indexed_name().text()); |
| 307 | 313 |
| 308 // Use the app list order to tiebreak apps that have never been launched. | 314 // Use the app list order to tiebreak apps that have never been launched. |
| 309 if (app->last_launch_time().is_null()) { | 315 // The apps that have been installed or launched recently should be |
| 316 // more relevant than other apps. |
| 317 const base::Time time = app->last_launch_time().is_null() |
| 318 ? app->install_time() |
| 319 : app->last_launch_time(); |
| 320 if (time.is_null()) { |
| 310 auto it = id_to_app_list_index.find(app->id()); | 321 auto it = id_to_app_list_index.find(app->id()); |
| 311 // If it's in a folder, it won't be in |id_to_app_list_index|. Rank | 322 // If it's in a folder, it won't be in |id_to_app_list_index|. Rank |
| 312 // those as if they are at the end of the list. | 323 // those as if they are at the end of the list. |
| 313 size_t app_list_index = | 324 size_t app_list_index = |
| 314 it == id_to_app_list_index.end() ? apps_.size() : (*it).second; | 325 it == id_to_app_list_index.end() ? apps_.size() : (*it).second; |
| 315 if (app_list_index > apps_.size()) | 326 if (app_list_index > apps_.size()) |
| 316 app_list_index = apps_.size(); | 327 app_list_index = apps_.size(); |
| 317 | 328 |
| 318 result->set_relevance(kUnlaunchedAppRelevanceStepSize * | 329 result->set_relevance(kUnlaunchedAppRelevanceStepSize * |
| 319 (apps_.size() - app_list_index)); | 330 (apps_.size() - app_list_index)); |
| 320 } else { | 331 } else { |
| 321 result->UpdateFromLastLaunched(clock_->Now(), app->last_launch_time()); | 332 result->UpdateFromLastLaunchedOrInstalledTime(clock_->Now(), time); |
| 322 } | 333 } |
| 323 Add(std::move(result)); | 334 Add(std::move(result)); |
| 324 } | 335 } |
| 325 } else { | 336 } else { |
| 326 for (auto& app : apps_) { | 337 for (auto& app : apps_) { |
| 327 std::unique_ptr<AppResult> result = app->data_source()->CreateResult( | 338 std::unique_ptr<AppResult> result = app->data_source()->CreateResult( |
| 328 app->id(), list_controller_, top_level_item_list_, false); | 339 app->id(), list_controller_, top_level_item_list_, false); |
| 329 TokenizedStringMatch match; | 340 TokenizedStringMatch match; |
| 330 if (!match.Calculate(query_terms, app->indexed_name())) | 341 if (!match.Calculate(query_terms, app->indexed_name())) |
| 331 continue; | 342 continue; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 346 } else { | 357 } else { |
| 347 if (!update_results_factory_.HasWeakPtrs()) { | 358 if (!update_results_factory_.HasWeakPtrs()) { |
| 348 base::ThreadTaskRunnerHandle::Get()->PostTask( | 359 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 349 FROM_HERE, base::Bind(&AppSearchProvider::UpdateResults, | 360 FROM_HERE, base::Bind(&AppSearchProvider::UpdateResults, |
| 350 update_results_factory_.GetWeakPtr())); | 361 update_results_factory_.GetWeakPtr())); |
| 351 } | 362 } |
| 352 } | 363 } |
| 353 } | 364 } |
| 354 | 365 |
| 355 } // namespace app_list | 366 } // namespace app_list |
| OLD | NEW |