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_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 Loading... |
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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 | 210 |
199 NotifyItemUninstalled(); | 211 NotifyItemUninstalled(); |
200 } | 212 } |
201 | 213 |
202 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { | 214 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { |
203 DCHECK_EQ(extension_registry_, registry); | 215 DCHECK_EQ(extension_registry_, registry); |
204 StopObservingExtensionRegistry(); | 216 StopObservingExtensionRegistry(); |
205 } | 217 } |
206 | 218 |
207 } // namespace app_list | 219 } // namespace app_list |
OLD | NEW |