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

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: 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..8604d20e65581d54171126f93cd2438eb89f7360 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) {}
~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) {
+ 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);
};
@@ -52,6 +60,22 @@ AppSearchProvider::AppSearchProvider(Profile* profile,
AppSearchProvider::~AppSearchProvider() {}
+void AppSearchProvider::FetchRecommendations() {
+ ClearResults();
+
+ // Reload apps to ensure we have the latest launch time information.
Matt Giuca 2014/07/22 04:31:07 nit: Don't use the word "reload"; it implies you a
calamity 2014/07/22 07:24:04 Done.
+ RefreshApps();
+
+ for (Apps::const_iterator app_it = apps_.begin(); app_it != apps_.end();
+ ++app_it) {
+ scoped_ptr<AppResult> result(
+ new AppResult(profile_, (*app_it)->app_id(), list_controller_));
+ result->set_title((*app_it)->indexed_name().text());
+ result->UpdateFromLastLaunched((*app_it)->last_launch_time());
+ Add(result.PassAs<SearchResult>());
+ }
+}
+
void AppSearchProvider::Start(const base::string16& query) {
const TokenizedString query_terms(query);
@@ -74,6 +98,7 @@ void AppSearchProvider::Start(const base::string16& query) {
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 +109,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 +120,7 @@ void AppSearchProvider::RefreshApps() {
AddApps(registry->enabled_extensions());
AddApps(registry->disabled_extensions());
AddApps(registry->terminated_extensions());
+ std::sort(apps_.begin(), apps_.end(), &App::AppLaunchedMoreRecent);
}
void AppSearchProvider::OnExtensionLoaded(

Powered by Google App Engine
This is Rietveld 408576698