| 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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/time/clock.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 11 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_ui_util.h" | 12 #include "chrome/browser/extensions/extension_ui_util.h" |
| 12 #include "chrome/browser/extensions/extension_util.h" | 13 #include "chrome/browser/extensions/extension_util.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/app_list/search/app_result.h" | 15 #include "chrome/browser/ui/app_list/search/app_result.h" |
| 15 #include "extensions/browser/extension_prefs.h" | 16 #include "extensions/browser/extension_prefs.h" |
| 16 #include "extensions/browser/extension_registry.h" | 17 #include "extensions/browser/extension_registry.h" |
| 17 #include "extensions/browser/extension_system.h" | 18 #include "extensions/browser/extension_system.h" |
| 18 #include "extensions/common/extension.h" | 19 #include "extensions/common/extension.h" |
| 19 #include "extensions/common/extension_set.h" | 20 #include "extensions/common/extension_set.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 39 | 40 |
| 40 private: | 41 private: |
| 41 const std::string app_id_; | 42 const std::string app_id_; |
| 42 TokenizedString indexed_name_; | 43 TokenizedString indexed_name_; |
| 43 base::Time last_launch_time_; | 44 base::Time last_launch_time_; |
| 44 | 45 |
| 45 DISALLOW_COPY_AND_ASSIGN(App); | 46 DISALLOW_COPY_AND_ASSIGN(App); |
| 46 }; | 47 }; |
| 47 | 48 |
| 48 AppSearchProvider::AppSearchProvider(Profile* profile, | 49 AppSearchProvider::AppSearchProvider(Profile* profile, |
| 49 AppListControllerDelegate* list_controller) | 50 AppListControllerDelegate* list_controller, |
| 51 scoped_ptr<base::Clock> clock) |
| 50 : profile_(profile), | 52 : profile_(profile), |
| 51 list_controller_(list_controller), | 53 list_controller_(list_controller), |
| 52 extension_registry_observer_(this) { | 54 extension_registry_observer_(this), |
| 55 clock_(clock.Pass()) { |
| 53 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); | 56 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); |
| 54 RefreshApps(); | 57 RefreshApps(); |
| 55 } | 58 } |
| 56 | 59 |
| 57 AppSearchProvider::~AppSearchProvider() {} | 60 AppSearchProvider::~AppSearchProvider() {} |
| 58 | 61 |
| 59 void AppSearchProvider::Start(const base::string16& query) { | 62 void AppSearchProvider::Start(const base::string16& query) { |
| 60 StartImpl(base::Time::Now(), query); | 63 query_ = query; |
| 61 } | 64 const TokenizedString query_terms(query); |
| 62 | 65 |
| 63 void AppSearchProvider::Stop() { | 66 ClearResults(); |
| 64 } | |
| 65 | |
| 66 void AppSearchProvider::StartImpl(const base::Time& current_time, | |
| 67 const base::string16& query) { | |
| 68 query_ = query; | |
| 69 search_time_ = current_time; | |
| 70 | 67 |
| 71 bool show_recommendations = query.empty(); | 68 bool show_recommendations = query.empty(); |
| 72 // Refresh list of apps to ensure we have the latest launch time information. | 69 // Refresh list of apps to ensure we have the latest launch time information. |
| 73 // This will also cause the results to update. | 70 // This will also cause the results to update. |
| 74 if (show_recommendations) | 71 if (show_recommendations) |
| 75 RefreshApps(); | 72 RefreshApps(); |
| 76 | 73 |
| 77 UpdateResults(); | 74 UpdateResults(); |
| 78 } | 75 } |
| 79 | 76 |
| 77 void AppSearchProvider::Stop() { |
| 78 } |
| 79 |
| 80 void AppSearchProvider::UpdateResults() { | 80 void AppSearchProvider::UpdateResults() { |
| 81 const TokenizedString query_terms(query_); | 81 const TokenizedString query_terms(query_); |
| 82 bool show_recommendations = query_.empty(); | 82 bool show_recommendations = query_.empty(); |
| 83 ClearResults(); | 83 ClearResults(); |
| 84 | 84 |
| 85 for (Apps::const_iterator app_it = apps_.begin(); | 85 for (Apps::const_iterator app_it = apps_.begin(); |
| 86 app_it != apps_.end(); | 86 app_it != apps_.end(); |
| 87 ++app_it) { | 87 ++app_it) { |
| 88 scoped_ptr<AppResult> result( | 88 scoped_ptr<AppResult> result( |
| 89 new AppResult(profile_, (*app_it)->app_id(), list_controller_)); | 89 new AppResult(profile_, (*app_it)->app_id(), list_controller_)); |
| 90 if (show_recommendations) { | 90 if (show_recommendations) { |
| 91 result->set_title((*app_it)->indexed_name().text()); | 91 result->set_title((*app_it)->indexed_name().text()); |
| 92 result->UpdateFromLastLaunched(search_time_, | 92 result->UpdateFromLastLaunched(clock_->Now(), |
| 93 (*app_it)->last_launch_time()); | 93 (*app_it)->last_launch_time()); |
| 94 } else { | 94 } else { |
| 95 TokenizedStringMatch match; | 95 TokenizedStringMatch match; |
| 96 if (!match.Calculate(query_terms, (*app_it)->indexed_name())) | 96 if (!match.Calculate(query_terms, (*app_it)->indexed_name())) |
| 97 continue; | 97 continue; |
| 98 | 98 |
| 99 result->UpdateFromMatch((*app_it)->indexed_name(), match); | 99 result->UpdateFromMatch((*app_it)->indexed_name(), match); |
| 100 } | 100 } |
| 101 Add(result.Pass()); | 101 Add(result.Pass()); |
| 102 } | 102 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 136 |
| 137 void AppSearchProvider::OnExtensionUninstalled( | 137 void AppSearchProvider::OnExtensionUninstalled( |
| 138 content::BrowserContext* browser_context, | 138 content::BrowserContext* browser_context, |
| 139 const extensions::Extension* extension, | 139 const extensions::Extension* extension, |
| 140 extensions::UninstallReason reason) { | 140 extensions::UninstallReason reason) { |
| 141 RefreshApps(); | 141 RefreshApps(); |
| 142 UpdateResults(); | 142 UpdateResults(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace app_list | 145 } // namespace app_list |
| OLD | NEW |