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

Side by Side Diff: chrome/browser/ui/app_list/search/app_result.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_result.h" 5 #include "chrome/browser/ui/app_list/search/app_result.h"
6 6
7 #include "base/time/time.h"
7 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/extension_util.h" 9 #include "chrome/browser/extensions/extension_util.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/app_list/app_context_menu.h" 11 #include "chrome/browser/ui/app_list/app_context_menu.h"
11 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h" 12 #include "chrome/browser/ui/app_list/app_list_controller_delegate.h"
12 #include "chrome/browser/ui/app_list/search/tokenized_string.h" 13 #include "chrome/browser/ui/app_list/search/tokenized_string.h"
13 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h" 14 #include "chrome/browser/ui/app_list/search/tokenized_string_match.h"
14 #include "chrome/browser/ui/extensions/extension_enable_flow.h" 15 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
15 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" 16 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
16 #include "content/public/browser/user_metrics.h" 17 #include "content/public/browser/user_metrics.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 Tags tags; 67 Tags tags;
67 tags.reserve(hits.size()); 68 tags.reserve(hits.size());
68 for (size_t i = 0; i < hits.size(); ++i) 69 for (size_t i = 0; i < hits.size(); ++i)
69 tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end())); 70 tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end()));
70 71
71 set_title(title.text()); 72 set_title(title.text());
72 set_title_tags(tags); 73 set_title_tags(tags);
73 set_relevance(match.relevance()); 74 set_relevance(match.relevance());
74 } 75 }
75 76
77 void AppResult::UpdateFromLastLaunched(const base::Time& current_time,
78 const base::Time& last_launched) {
79 base::TimeDelta delta = current_time - last_launched;
80 DCHECK_LE(0, delta.InSeconds());
81 const int kSecondsInWeek = 60 * 60 * 24 * 7;
82
83 // Set the relevance to a value between 0 and 1. This function decays as the
84 // time delta increases and reaches a value of 0.5 at 1 week.
85 set_relevance(1 / (1 + delta.InSecondsF() / kSecondsInWeek));
86 }
87
76 void AppResult::Open(int event_flags) { 88 void AppResult::Open(int event_flags) {
77 const extensions::Extension* extension = 89 const extensions::Extension* extension =
78 extensions::ExtensionSystem::Get(profile_)->extension_service() 90 extensions::ExtensionSystem::Get(profile_)->extension_service()
79 ->GetInstalledExtension(app_id_); 91 ->GetInstalledExtension(app_id_);
80 if (!extension) 92 if (!extension)
81 return; 93 return;
82 94
83 // Don't auto-enable apps that cannot be launched. 95 // Don't auto-enable apps that cannot be launched.
84 if (!extensions::util::IsAppLaunchable(app_id_, profile_)) 96 if (!extensions::util::IsAppLaunchable(app_id_, profile_))
85 return; 97 return;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 211
200 NotifyItemUninstalled(); 212 NotifyItemUninstalled();
201 } 213 }
202 214
203 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { 215 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) {
204 DCHECK_EQ(extension_registry_, registry); 216 DCHECK_EQ(extension_registry_, registry);
205 StopObservingExtensionRegistry(); 217 StopObservingExtensionRegistry();
206 } 218 }
207 219
208 } // namespace app_list 220 } // namespace app_list
OLDNEW
« no previous file with comments | « chrome/browser/ui/app_list/search/app_result.h ('k') | chrome/browser/ui/app_list/search/app_search_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698