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

Side by Side 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: const Created 6 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/browser/extensions/extension_service.h" 10 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_ui_util.h" 11 #include "chrome/browser/extensions/extension_ui_util.h"
12 #include "chrome/browser/extensions/extension_util.h" 12 #include "chrome/browser/extensions/extension_util.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/app_list/search/app_result.h" 14 #include "chrome/browser/ui/app_list/search/app_result.h"
15 #include "chrome/browser/ui/app_list/search/tokenized_string.h" 15 #include "chrome/browser/ui/app_list/search/tokenized_string.h"
16 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h" 16 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h"
17 #include "extensions/browser/extension_prefs.h"
17 #include "extensions/browser/extension_registry.h" 18 #include "extensions/browser/extension_registry.h"
18 #include "extensions/browser/extension_system.h" 19 #include "extensions/browser/extension_system.h"
19 #include "extensions/common/extension.h" 20 #include "extensions/common/extension.h"
20 #include "extensions/common/extension_set.h" 21 #include "extensions/common/extension_set.h"
21 22
22 using extensions::ExtensionRegistry; 23 using extensions::ExtensionRegistry;
23 24
24 namespace app_list { 25 namespace app_list {
25 26
26 class AppSearchProvider::App { 27 class AppSearchProvider::App {
27 public: 28 public:
28 explicit App(const extensions::Extension* extension) 29 explicit App(const extensions::Extension* extension,
30 const base::Time& last_launch_time)
29 : app_id_(extension->id()), 31 : app_id_(extension->id()),
30 indexed_name_(base::UTF8ToUTF16(extension->name())) { 32 indexed_name_(base::UTF8ToUTF16(extension->name())),
31 } 33 last_launch_time_(last_launch_time) {}
32 ~App() {} 34 ~App() {}
33 35
34 const std::string& app_id() const { return app_id_; } 36 const std::string& app_id() const { return app_id_; }
35 const TokenizedString& indexed_name() const { return indexed_name_; } 37 const TokenizedString& indexed_name() const { return indexed_name_; }
38 const base::Time& last_launch_time() const { return last_launch_time_; }
36 39
37 private: 40 private:
38 const std::string app_id_; 41 const std::string app_id_;
39 TokenizedString indexed_name_; 42 TokenizedString indexed_name_;
43 base::Time last_launch_time_;
40 44
41 DISALLOW_COPY_AND_ASSIGN(App); 45 DISALLOW_COPY_AND_ASSIGN(App);
42 }; 46 };
43 47
44 AppSearchProvider::AppSearchProvider(Profile* profile, 48 AppSearchProvider::AppSearchProvider(Profile* profile,
45 AppListControllerDelegate* list_controller) 49 AppListControllerDelegate* list_controller)
46 : profile_(profile), 50 : profile_(profile),
47 list_controller_(list_controller), 51 list_controller_(list_controller),
48 extension_registry_observer_(this) { 52 extension_registry_observer_(this) {
49 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_)); 53 extension_registry_observer_.Add(ExtensionRegistry::Get(profile_));
50 RefreshApps(); 54 RefreshApps();
51 } 55 }
52 56
53 AppSearchProvider::~AppSearchProvider() {} 57 AppSearchProvider::~AppSearchProvider() {}
54 58
55 void AppSearchProvider::Start(const base::string16& query) { 59 void AppSearchProvider::Start(const base::string16& query) {
60 StartImpl(base::Time::Now(), query);
61 }
62
63 void AppSearchProvider::Stop() {
64 }
65
66 void AppSearchProvider::StartImpl(const base::Time& current_time,
67 const base::string16& query) {
56 const TokenizedString query_terms(query); 68 const TokenizedString query_terms(query);
57 69
58 ClearResults(); 70 ClearResults();
59 71
60 TokenizedStringMatch match; 72 bool show_recommendations = query.empty();
73 // Refresh list of apps to ensure we have the latest launch time information.
74 if (show_recommendations)
75 RefreshApps();
76
61 for (Apps::const_iterator app_it = apps_.begin(); 77 for (Apps::const_iterator app_it = apps_.begin();
62 app_it != apps_.end(); 78 app_it != apps_.end();
63 ++app_it) { 79 ++app_it) {
64 if (!match.Calculate(query_terms, (*app_it)->indexed_name()))
65 continue;
66
67 scoped_ptr<AppResult> result( 80 scoped_ptr<AppResult> result(
68 new AppResult(profile_, (*app_it)->app_id(), list_controller_)); 81 new AppResult(profile_, (*app_it)->app_id(), list_controller_));
69 result->UpdateFromMatch((*app_it)->indexed_name(), match); 82 if (show_recommendations) {
83 result->set_title((*app_it)->indexed_name().text());
84 result->UpdateFromLastLaunched(current_time,
85 (*app_it)->last_launch_time());
86 } else {
87 TokenizedStringMatch match;
88 if (!match.Calculate(query_terms, (*app_it)->indexed_name()))
89 continue;
90
91 result->UpdateFromMatch((*app_it)->indexed_name(), match);
92 }
70 Add(result.PassAs<SearchResult>()); 93 Add(result.PassAs<SearchResult>());
71 } 94 }
72 } 95 }
73 96
74 void AppSearchProvider::Stop() {}
75
76 void AppSearchProvider::AddApps(const extensions::ExtensionSet& extensions) { 97 void AppSearchProvider::AddApps(const extensions::ExtensionSet& extensions) {
98 extensions::ExtensionPrefs* prefs = extensions::ExtensionPrefs::Get(profile_);
77 for (extensions::ExtensionSet::const_iterator iter = extensions.begin(); 99 for (extensions::ExtensionSet::const_iterator iter = extensions.begin();
78 iter != extensions.end(); ++iter) { 100 iter != extensions.end(); ++iter) {
79 const extensions::Extension* app = iter->get(); 101 const extensions::Extension* app = iter->get();
80 102
81 if (!extensions::ui_util::ShouldDisplayInAppLauncher(app, profile_)) 103 if (!extensions::ui_util::ShouldDisplayInAppLauncher(app, profile_))
82 continue; 104 continue;
83 105
84 if (profile_->IsOffTheRecord() && 106 if (profile_->IsOffTheRecord() &&
85 !extensions::util::CanLoadInIncognito(app, profile_)) 107 !extensions::util::CanLoadInIncognito(app, profile_))
86 continue; 108 continue;
87 apps_.push_back(new App(app)); 109
110 apps_.push_back(new App(app, prefs->GetLastLaunchTime(app->id())));
88 } 111 }
89 } 112 }
90 113
91 void AppSearchProvider::RefreshApps() { 114 void AppSearchProvider::RefreshApps() {
92 apps_.clear(); 115 apps_.clear();
93 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_); 116 ExtensionRegistry* registry = ExtensionRegistry::Get(profile_);
94 AddApps(registry->enabled_extensions()); 117 AddApps(registry->enabled_extensions());
95 AddApps(registry->disabled_extensions()); 118 AddApps(registry->disabled_extensions());
96 AddApps(registry->terminated_extensions()); 119 AddApps(registry->terminated_extensions());
97 } 120 }
98 121
99 void AppSearchProvider::OnExtensionLoaded( 122 void AppSearchProvider::OnExtensionLoaded(
100 content::BrowserContext* browser_context, 123 content::BrowserContext* browser_context,
101 const extensions::Extension* extension) { 124 const extensions::Extension* extension) {
102 RefreshApps(); 125 RefreshApps();
103 } 126 }
104 127
105 void AppSearchProvider::OnExtensionUninstalled( 128 void AppSearchProvider::OnExtensionUninstalled(
106 content::BrowserContext* browser_context, 129 content::BrowserContext* browser_context,
107 const extensions::Extension* extension, 130 const extensions::Extension* extension,
108 extensions::UninstallReason reason) { 131 extensions::UninstallReason reason) {
109 RefreshApps(); 132 RefreshApps();
110 } 133 }
111 134
112 } // namespace app_list 135 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698