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

Unified Diff: chrome/browser/ui/app_list/search/app_search_provider.cc

Issue 379333005: Allow AppSearchProvider to provide recommendations. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comments Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/app_list/search/app_search_provider.cc
diff --git a/chrome/browser/ui/app_list/search/app_search_provider.cc b/chrome/browser/ui/app_list/search/app_search_provider.cc
index 9237b076500c9b6c34b8061ede32b14b23132dd5..ce3e8c93375e76fee59ffaa9310eee8f58bd9793 100644
--- a/chrome/browser/ui/app_list/search/app_search_provider.cc
+++ b/chrome/browser/ui/app_list/search/app_search_provider.cc
@@ -14,6 +14,7 @@
#include "chrome/browser/ui/app_list/search/app_result.h"
#include "chrome/browser/ui/app_list/search/tokenized_string.h"
#include "chrome/browser/ui/app_list/search/tokenized_string_match.h"
+#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/extension.h"
@@ -25,18 +26,25 @@ namespace app_list {
class AppSearchProvider::App {
public:
- explicit App(const extensions::Extension* extension)
+ explicit App(const extensions::Extension* extension,
+ const base::Time& last_launch_time)
: app_id_(extension->id()),
- indexed_name_(base::UTF8ToUTF16(extension->name())) {
- }
+ indexed_name_(base::UTF8ToUTF16(extension->name())),
+ last_launch_time_(last_launch_time) {}
Matt Giuca 2014/07/23 01:53:18 nit: Is this ClangFormatted? I believe you should
calamity 2014/07/28 02:55:26 Yeah, git cl format wants this apparently.
Matt Giuca 2014/07/28 02:59:35 Acknowledged.
~App() {}
const std::string& app_id() const { return app_id_; }
const TokenizedString& indexed_name() const { return indexed_name_; }
+ const base::Time& last_launch_time() const { return last_launch_time_; }
+
+ static bool AppLaunchedMoreRecent(App* const app1, App* const app2) {
Matt Giuca 2014/07/23 01:53:18 "App* const"? Did you mean "const App*"? ("App* c
calamity 2014/07/28 02:55:27 Removed.
+ return app1->last_launch_time() > app2->last_launch_time();
+ }
private:
const std::string app_id_;
TokenizedString indexed_name_;
+ base::Time last_launch_time_;
DISALLOW_COPY_AND_ASSIGN(App);
};
@@ -53,27 +61,45 @@ AppSearchProvider::AppSearchProvider(Profile* profile,
AppSearchProvider::~AppSearchProvider() {}
void AppSearchProvider::Start(const base::string16& query) {
+ StartImpl(base::Time::Now(), query);
+}
+
+void AppSearchProvider::Stop() {
+}
+
+void AppSearchProvider::StartImpl(const base::Time& current_time,
+ const base::string16& query) {
const TokenizedString query_terms(query);
ClearResults();
- TokenizedStringMatch match;
+ bool show_recommendations = query.empty();
+ // Refresh list of apps to ensure we have the latest launch time information.
+ if (show_recommendations)
+ RefreshApps();
+
for (Apps::const_iterator app_it = apps_.begin();
app_it != apps_.end();
++app_it) {
- if (!match.Calculate(query_terms, (*app_it)->indexed_name()))
- continue;
-
scoped_ptr<AppResult> result(
new AppResult(profile_, (*app_it)->app_id(), list_controller_));
- result->UpdateFromMatch((*app_it)->indexed_name(), match);
+ if (show_recommendations) {
+ result->set_title((*app_it)->indexed_name().text());
+ result->UpdateFromLastLaunched(current_time,
+ (*app_it)->last_launch_time());
+ } else {
+ TokenizedStringMatch match;
+ if (!match.Calculate(query_terms, (*app_it)->indexed_name()))
+ continue;
+
+ result->UpdateFromMatch((*app_it)->indexed_name(), match);
+ }
Add(result.PassAs<SearchResult>());
}
}
-void AppSearchProvider::Stop() {}
-
void AppSearchProvider::AddApps(const extensions::ExtensionSet& extensions) {
+ extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
iter != extensions.end(); ++iter) {
const extensions::Extension* app = iter->get();
@@ -84,7 +110,8 @@ void AppSearchProvider::AddApps(const extensions::ExtensionSet& extensions) {
if (profile_->IsOffTheRecord() &&
!extensions::util::CanLoadInIncognito(app, profile_))
continue;
- apps_.push_back(new App(app));
+
+ apps_.push_back(new App(app, prefs->GetLastLaunchTime(app->id())));
}
}
@@ -94,6 +121,7 @@ void AppSearchProvider::RefreshApps() {
AddApps(registry->enabled_extensions());
AddApps(registry->disabled_extensions());
AddApps(registry->terminated_extensions());
+ std::sort(apps_.begin(), apps_.end(), &App::AppLaunchedMoreRecent);
Matt Giuca 2014/07/23 01:53:18 Question: Does this actually need to be sorted her
calamity 2014/07/28 02:55:27 You are indeed correct. This should have been remo
}
void AppSearchProvider::OnExtensionLoaded(

Powered by Google App Engine
This is Rietveld 408576698