Chromium Code Reviews| 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 } |
|
Matt Giuca
2014/12/10 07:16:12
Accidentally deleted line?
calamity
2014/12/11 05:05:01
Done.
| |
| 79 | |
| 80 void AppSearchProvider::UpdateResults() { | 76 void AppSearchProvider::UpdateResults() { |
| 81 const TokenizedString query_terms(query_); | 77 const TokenizedString query_terms(query_); |
| 82 bool show_recommendations = query_.empty(); | 78 bool show_recommendations = query_.empty(); |
| 83 ClearResults(); | 79 ClearResults(); |
| 84 | 80 |
| 85 for (Apps::const_iterator app_it = apps_.begin(); | 81 for (Apps::const_iterator app_it = apps_.begin(); |
| 86 app_it != apps_.end(); | 82 app_it != apps_.end(); |
| 87 ++app_it) { | 83 ++app_it) { |
| 88 scoped_ptr<AppResult> result( | 84 scoped_ptr<AppResult> result( |
| 89 new AppResult(profile_, (*app_it)->app_id(), list_controller_)); | 85 new AppResult(profile_, (*app_it)->app_id(), list_controller_)); |
| 90 if (show_recommendations) { | 86 if (show_recommendations) { |
| 91 result->set_title((*app_it)->indexed_name().text()); | 87 result->set_title((*app_it)->indexed_name().text()); |
| 92 result->UpdateFromLastLaunched(search_time_, | 88 result->UpdateFromLastLaunched(clock_->Now(), |
| 93 (*app_it)->last_launch_time()); | 89 (*app_it)->last_launch_time()); |
| 94 } else { | 90 } else { |
| 95 TokenizedStringMatch match; | 91 TokenizedStringMatch match; |
| 96 if (!match.Calculate(query_terms, (*app_it)->indexed_name())) | 92 if (!match.Calculate(query_terms, (*app_it)->indexed_name())) |
| 97 continue; | 93 continue; |
| 98 | 94 |
| 99 result->UpdateFromMatch((*app_it)->indexed_name(), match); | 95 result->UpdateFromMatch((*app_it)->indexed_name(), match); |
| 100 } | 96 } |
| 101 Add(result.Pass()); | 97 Add(result.Pass()); |
| 102 } | 98 } |
| 103 } | 99 } |
| 104 | 100 |
| 101 void AppSearchProvider::Stop() { | |
|
Matt Giuca
2014/12/10 07:16:12
Why did this move?
calamity
2014/12/11 05:05:01
Fixed.
| |
| 102 } | |
| 103 | |
| 105 void AppSearchProvider::AddApps(const extensions::ExtensionSet& extensions) { | 104 void AppSearchProvider::AddApps(const extensions::ExtensionSet& extensions) { |
| 106 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); | 105 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_); |
| 107 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); | 106 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); |
| 108 iter != extensions.end(); ++iter) { | 107 iter != extensions.end(); ++iter) { |
| 109 const extensions::Extension* app = iter->get(); | 108 const extensions::Extension* app = iter->get(); |
| 110 | 109 |
| 111 if (!extensions::ui_util::ShouldDisplayInAppLauncher(app, profile_)) | 110 if (!extensions::ui_util::ShouldDisplayInAppLauncher(app, profile_)) |
| 112 continue; | 111 continue; |
| 113 | 112 |
| 114 if (profile_->IsOffTheRecord() && | 113 if (profile_->IsOffTheRecord() && |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 136 | 135 |
| 137 void AppSearchProvider::OnExtensionUninstalled( | 136 void AppSearchProvider::OnExtensionUninstalled( |
| 138 content::BrowserContext* browser_context, | 137 content::BrowserContext* browser_context, |
| 139 const extensions::Extension* extension, | 138 const extensions::Extension* extension, |
| 140 extensions::UninstallReason reason) { | 139 extensions::UninstallReason reason) { |
| 141 RefreshApps(); | 140 RefreshApps(); |
| 142 UpdateResults(); | 141 UpdateResults(); |
| 143 } | 142 } |
| 144 | 143 |
| 145 } // namespace app_list | 144 } // namespace app_list |
| OLD | NEW |