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 "base/time/time.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_util.h" | 9 #include "chrome/browser/extensions/extension_util.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end())); | 74 tags.push_back(Tag(Tag::MATCH, hits[i].start(), hits[i].end())); |
75 | 75 |
76 set_title(title.text()); | 76 set_title(title.text()); |
77 set_title_tags(tags); | 77 set_title_tags(tags); |
78 set_relevance(match.relevance()); | 78 set_relevance(match.relevance()); |
79 } | 79 } |
80 | 80 |
81 void AppResult::UpdateFromLastLaunched(const base::Time& current_time, | 81 void AppResult::UpdateFromLastLaunched(const base::Time& current_time, |
82 const base::Time& last_launched) { | 82 const base::Time& last_launched) { |
83 base::TimeDelta delta = current_time - last_launched; | 83 base::TimeDelta delta = current_time - last_launched; |
84 DCHECK_LE(0, delta.InSeconds()); | 84 // |current_time| can be before |last_launched| in weird cases such as users |
| 85 // playing with their clocks. Handle this gracefully. |
| 86 if (current_time < last_launched) { |
| 87 set_relevance(1.0); |
| 88 return; |
| 89 } |
| 90 |
85 const int kSecondsInWeek = 60 * 60 * 24 * 7; | 91 const int kSecondsInWeek = 60 * 60 * 24 * 7; |
86 | 92 |
87 // Set the relevance to a value between 0 and 1. This function decays as the | 93 // Set the relevance to a value between 0 and 1. This function decays as the |
88 // time delta increases and reaches a value of 0.5 at 1 week. | 94 // time delta increases and reaches a value of 0.5 at 1 week. |
89 set_relevance(1 / (1 + delta.InSecondsF() / kSecondsInWeek)); | 95 set_relevance(1 / (1 + delta.InSecondsF() / kSecondsInWeek)); |
90 } | 96 } |
91 | 97 |
92 void AppResult::Open(int event_flags) { | 98 void AppResult::Open(int event_flags) { |
93 RecordHistogram(APP_SEARCH_RESULT); | 99 RecordHistogram(APP_SEARCH_RESULT); |
94 const extensions::Extension* extension = | 100 const extensions::Extension* extension = |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 const extensions::Extension* extension) { | 206 const extensions::Extension* extension) { |
201 UpdateIcon(); | 207 UpdateIcon(); |
202 } | 208 } |
203 | 209 |
204 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { | 210 void AppResult::OnShutdown(extensions::ExtensionRegistry* registry) { |
205 DCHECK_EQ(extension_registry_, registry); | 211 DCHECK_EQ(extension_registry_, registry); |
206 StopObservingExtensionRegistry(); | 212 StopObservingExtensionRegistry(); |
207 } | 213 } |
208 | 214 |
209 } // namespace app_list | 215 } // namespace app_list |
OLD | NEW |