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

Side by Side Diff: chrome/browser/ui/app_list/search/app_result.cc

Issue 789623003: Use base::Clock instead of base::Time::Now in AppSearchProvider. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@now_source
Patch Set: rebase Created 6 years 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
« no previous file with comments | « no previous file | chrome/browser/ui/app_list/search/app_search_provider.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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
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
OLDNEW
« no previous file with comments | « no previous file | 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