Chromium Code Reviews| 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& last_launched) { | |
| 78 base::TimeDelta delta = base::Time::Now() - last_launched; | |
| 79 DCHECK_LE(0, delta.InSeconds()); | |
| 80 const int kSecondsInWeek = 60 * 60 * 24 * 7; | |
| 81 | |
| 82 // Set the relevance to a value between 0 and 1. This function decays as the | |
| 83 // time delta increases and reaches a value of 0.5 at 1 week. | |
| 84 set_relevance(1 / (1 + delta.InSecondsF() / kSecondsInWeek)); | |
|
Matt Giuca
2014/07/22 04:31:07
Why does the relevance have to be a float? How ing
calamity
2014/07/22 07:24:04
Very. Boost values are +1-4 which rely on the base
Matt Giuca
2014/07/23 01:53:18
Acknowledged.
| |
| 85 } | |
| 86 | |
| 76 void AppResult::Open(int event_flags) { | 87 void AppResult::Open(int event_flags) { |
| 77 const extensions::Extension* extension = | 88 const extensions::Extension* extension = |
| 78 extensions::ExtensionSystem::Get(profile_)->extension_service() | 89 extensions::ExtensionSystem::Get(profile_)->extension_service() |
| 79 ->GetInstalledExtension(app_id_); | 90 ->GetInstalledExtension(app_id_); |
| 80 if (!extension) | 91 if (!extension) |
| 81 return; | 92 return; |
| 82 | 93 |
| 83 // Don't auto-enable apps that cannot be launched. | 94 // Don't auto-enable apps that cannot be launched. |
| 84 if (!extensions::util::IsAppLaunchable(app_id_, profile_)) | 95 if (!extensions::util::IsAppLaunchable(app_id_, profile_)) |
| 85 return; | 96 return; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 | 209 |
| 199 NotifyItemUninstalled(); | 210 NotifyItemUninstalled(); |
| 200 } | 211 } |
| 201 | 212 |
| 202 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { | 213 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { |
| 203 DCHECK_EQ(extension_registry_, registry); | 214 DCHECK_EQ(extension_registry_, registry); |
| 204 StopObservingExtensionRegistry(); | 215 StopObservingExtensionRegistry(); |
| 205 } | 216 } |
| 206 | 217 |
| 207 } // namespace app_list | 218 } // namespace app_list |
| OLD | NEW |